feat(variable): add a new variable named 'API token' (#4850)
Some checks are pending
Build Docker Image / build-and-push (push) Waiting to run
Build Pro Image / build-and-push (push) Waiting to run
deploy client docs / Build (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase FrontEnd Test / frontend-test (18) (push) Waiting to run

* feat(variable): add a variable named 'Current token'

* refactor: rename to 'API Token'

* test: add e2e tests

* chore: update unit test
This commit is contained in:
Zeke Zhang 2024-07-09 14:42:12 +08:00 committed by GitHub
parent f8e9385845
commit c2260c76c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
45 changed files with 284 additions and 35 deletions

View File

@ -547,6 +547,7 @@ test.describe('actions schema settings', () => {
'Constant',
'Current user',
'Current role',
'API token',
'Date variables',
'Current form',
]);

View File

@ -86,6 +86,7 @@ test.describe('linkage rules', () => {
'Constant',
'Current user',
'Current role',
'API token',
'Date variables',
'Current form',
]);
@ -161,7 +162,13 @@ test.describe('linkage rules', () => {
await page.getByText('Expression').click();
await page.getByText('xSelect a variable').click();
await expectSupportedVariables(page, ['Current user', 'Current role', 'Date variables', 'Current form']);
await expectSupportedVariables(page, [
'Current user',
'Current role',
'API token',
'Date variables',
'Current form',
]);
await page.getByRole('menuitemcheckbox', { name: 'Current form right' }).click();
await page.getByRole('menuitemcheckbox', { name: 'number' }).click();
await page.getByRole('button', { name: 'OK', exact: true }).click();

View File

@ -442,6 +442,7 @@ test.describe('actions schema settings', () => {
'Constant',
'Current user',
'Current role',
'API token',
'Date variables',
'Current record',
]);

View File

@ -165,7 +165,7 @@ test.describe('table block schema settings', () => {
await page.getByTestId('select-filter-field').click();
await page.getByRole('menuitemcheckbox', { name: 'singleLineText' }).click();
await page.getByLabel('variable-button').click();
await expectSupportedVariables(page, ['Constant', 'Current user', 'Current role', 'Date variables']);
await expectSupportedVariables(page, ['Constant', 'Current user', 'Current role', 'API token', 'Date variables']);
await page.getByRole('menuitemcheckbox', { name: 'Current user' }).click();
await page.getByRole('menuitemcheckbox', { name: 'Nickname' }).click();
await page.getByRole('button', { name: 'OK', exact: true }).click();

View File

@ -8,7 +8,7 @@
*/
import { expect, test } from '@nocobase/test/e2e';
import { tableViewLinkageRulesVariables } from './templates';
import { APIToken, tableViewLinkageRulesVariables } from './templates';
test.describe('variables', () => {
test('linkage rules of table view action', async ({ page, mockPage }) => {
@ -21,8 +21,26 @@ test.describe('variables', () => {
await page.getByLabel('variable-button').click();
// 2. 断言应该显示的变量
['Constant', 'Current user', 'Current role', 'Date variables', 'Current record'].forEach(async (name) => {
await expect(page.getByRole('menuitemcheckbox', { name })).toBeVisible();
['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current record'].forEach(
async (name) => {
await expect(page.getByRole('menuitemcheckbox', { name })).toBeVisible();
},
);
});
test('API token', async ({ page, mockPage }) => {
await mockPage(APIToken).goto();
const token = await page.evaluate(() => {
return window.localStorage.getItem('NOCOBASE_TOKEN');
});
await page.getByLabel('block-item-CollectionField-').hover();
await page.getByLabel('designer-schema-settings-CollectionField-fieldSettings:FormItem-users-users.').hover();
await page.getByRole('menuitem', { name: 'Set default value' }).click();
await page.getByLabel('variable-button').click();
await page.getByRole('menuitemcheckbox', { name: 'API token' }).click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
await expect(page.getByRole('textbox')).toHaveValue(token);
});
});

View File

@ -236,3 +236,155 @@ export const tableViewLinkageRulesVariables = {
'x-index': 1,
},
};
export const APIToken = {
pageSchema: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Page',
properties: {
r28kx8924cy: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'page:addBlock',
properties: {
kegw9lkmsko: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '1.2.12-alpha',
properties: {
hcz0lcfp2r6: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '1.2.12-alpha',
properties: {
zjkxyalwtcd: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-acl-action-props': {
skipScopeCheck: true,
},
'x-acl-action': 'users:create',
'x-decorator': 'FormBlockProvider',
'x-use-decorator-props': 'useCreateFormBlockDecoratorProps',
'x-decorator-props': {
dataSource: 'main',
collection: 'users',
},
'x-toolbar': 'BlockSchemaToolbar',
'x-settings': 'blockSettings:createForm',
'x-component': 'CardItem',
'x-app-version': '1.2.12-alpha',
properties: {
'2slb70mzs8l': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'FormV2',
'x-use-component-props': 'useCreateFormBlockProps',
'x-app-version': '1.2.12-alpha',
properties: {
grid: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'form:configureFields',
'x-app-version': '1.2.12-alpha',
properties: {
'69ap338gq78': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '1.2.12-alpha',
properties: {
hmhzxyuiifs: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '1.2.12-alpha',
properties: {
nickname: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'string',
'x-toolbar': 'FormItemSchemaToolbar',
'x-settings': 'fieldSettings:FormItem',
'x-component': 'CollectionField',
'x-decorator': 'FormItem',
'x-collection-field': 'users.nickname',
'x-component-props': {},
'x-app-version': '1.2.12-alpha',
'x-uid': 'jcfpjom4noq',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '80ukdxgyeqb',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'c9pt8v2kl0v',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'dmnhyyaodkk',
'x-async': false,
'x-index': 1,
},
mblb6m9xrkf: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-initializer': 'createForm:configureActions',
'x-component': 'ActionBar',
'x-component-props': {
layout: 'one-column',
},
'x-app-version': '1.2.12-alpha',
'x-uid': 'a9607zzwsqi',
'x-async': false,
'x-index': 2,
},
},
'x-uid': 'vgoxgrp2txi',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'qs79h7guar7',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'wsngjdocbsr',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'je25ukg8n1g',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'j5m7s1k5a6d',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '4kh00y276rq',
'x-async': true,
'x-index': 1,
},
};

View File

@ -8,10 +8,10 @@
*/
import { IRecursionFieldProps, ISchemaFieldProps, RecursionField, Schema } from '@formily/react';
import { useUpdate } from 'ahooks';
import React, { useContext, useMemo } from 'react';
import { SchemaComponentContext } from '../context';
import { SchemaComponentOptions } from './SchemaComponentOptions';
import { useUpdate } from 'ahooks';
type SchemaComponentOnChange = {
onChange?: (s: Schema) => void;

View File

@ -7,9 +7,10 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
export * from './useAPITokenVariable';
export * from './useBaseVariable';
export * from './useDateVariable';
export * from './useRoleVariable';
export * from './useURLSearchParamsVariable';
export * from './useUserVariable';
export * from './useVariableOptions';
export * from './useURLSearchParamsVariable';
export * from './useRoleVariable';

View File

@ -0,0 +1,37 @@
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { useAPIClient } from '../../../api-client/hooks/useAPIClient';
import { useBaseVariable } from './useBaseVariable';
/**
* `当前 Token`
* @param param0
* @returns
*/
export const useAPITokenVariable = ({
noDisabled,
}: {
noDisabled?: boolean;
} = {}) => {
const apiClient = useAPIClient();
const apiTokenSettings = useBaseVariable({
name: '$nToken',
title: 'API token',
noDisabled,
noChildren: true,
});
return {
/** 变量配置项 */
apiTokenSettings,
/** 变量的值 */
apiTokenCtx: apiClient.auth?.token,
};
};

View File

@ -55,9 +55,9 @@ interface GetOptionsParams {
interface BaseProps {
// 当前字段
collectionField: CollectionFieldOptions_deprecated;
collectionField?: CollectionFieldOptions_deprecated;
/** 当前字段的 `uiSchema`,和 `collectionField.uiSchema` 不同,该值也包含操作符中 schema参见 useValues */
uiSchema: any;
uiSchema?: any;
/** 消费变量值的字段 */
targetFieldSchema?: Schema;
maxDepth?: number;
@ -66,7 +66,7 @@ interface BaseProps {
/**
* collectionName$user collectionName users
*/
collectionName: string;
collectionName?: string;
/**
* 使
*/

View File

@ -11,6 +11,7 @@ import { Form } from '@formily/core';
import { ISchema, Schema } from '@formily/react';
import { useMemo } from 'react';
import { CollectionFieldOptions_deprecated } from '../../../collection-manager';
import { useAPITokenVariable } from './useAPITokenVariable';
import { useDatetimeVariable } from './useDateVariable';
import { useCurrentFormVariable } from './useFormVariable';
import { useCurrentObjectVariable } from './useIterationVariable';
@ -71,6 +72,7 @@ export const useVariableOptions = ({
noDisabled,
targetFieldSchema,
});
const { apiTokenSettings } = useAPITokenVariable({ noDisabled });
const { datetimeSettings } = useDatetimeVariable({ operator, schema: uiSchema, noDisabled });
const { currentFormSettings, shouldDisplayCurrentForm } = useCurrentFormVariable({
schema: uiSchema,
@ -116,6 +118,7 @@ export const useVariableOptions = ({
return [
currentUserSettings,
currentRoleSettings,
apiTokenSettings,
datetimeSettings,
shouldDisplayCurrentForm && currentFormSettings,
shouldDisplayCurrentObject && currentObjectSettings,
@ -128,6 +131,7 @@ export const useVariableOptions = ({
}, [
currentUserSettings,
currentRoleSettings,
apiTokenSettings,
datetimeSettings,
shouldDisplayCurrentForm,
currentFormSettings,

View File

@ -81,6 +81,8 @@ const { apiClient, mockRequest } = mockAPIClient();
// 用于解析 `$nRole` 的值
apiClient.auth.role = 'root';
// 用于解析 `$nToken` 的值
apiClient.auth.token = 'token';
mockRequest.onGet('/auth:check').reply(() => {
return [
@ -247,6 +249,7 @@ describe('useVariables', () => {
"yesterday": [Function],
},
"$nRole": "root",
"$nToken": "token",
"$nURLSearchParams": {},
"$system": {
"now": [Function],
@ -474,6 +477,7 @@ describe('useVariables', () => {
"yesterday": [Function],
},
"$nRole": "root",
"$nToken": "token",
"$nURLSearchParams": {},
"$system": {
"now": [Function],
@ -559,6 +563,7 @@ describe('useVariables', () => {
"yesterday": [Function],
},
"$nRole": "root",
"$nToken": "token",
"$nURLSearchParams": {},
"$new": {
"name": "new variable",

View File

@ -11,6 +11,7 @@ import { dayjs } from '@nocobase/utils/client';
import { useMemo } from 'react';
import { DEFAULT_DATA_SOURCE_KEY } from '../../data-source/data-source/DataSourceManager';
import { useCurrentUserVariable, useDatetimeVariable } from '../../schema-settings';
import { useAPITokenVariable } from '../../schema-settings/VariableInput/hooks/useAPITokenVariable';
import { useCurrentRoleVariable } from '../../schema-settings/VariableInput/hooks/useRoleVariable';
import { useURLSearchParamsVariable } from '../../schema-settings/VariableInput/hooks/useURLSearchParamsVariable';
import { VariableOption } from '../types';
@ -22,6 +23,7 @@ import { VariableOption } from '../types';
const useBuiltInVariables = () => {
const { currentUserCtx } = useCurrentUserVariable();
const { currentRoleCtx } = useCurrentRoleVariable();
const { apiTokenCtx } = useAPITokenVariable();
const { datetimeCtx } = useDatetimeVariable();
const { urlSearchParamsCtx, name: urlSearchParamsName, defaultValue } = useURLSearchParamsVariable();
const builtinVariables: VariableOption[] = useMemo(() => {
@ -37,6 +39,10 @@ const useBuiltInVariables = () => {
ctx: currentRoleCtx as any,
collectionName: 'roles',
},
{
name: '$nToken',
ctx: apiTokenCtx as any,
},
/**
* @deprecated
*

View File

@ -140,6 +140,7 @@ test.describe('form item & create form', () => {
'Constant',
'Current user',
'Current role',
'API token',
'Date variables',
'Current form',
]);

View File

@ -130,6 +130,7 @@ test.describe('form item & edit form', () => {
'Constant',
'Current user',
'Current role',
'API token',
'Date variables',
'Current form',
]);

View File

@ -64,7 +64,7 @@ test.describe('form item & create form', () => {
})
.hover();
},
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
inputConstantValue: async () => {
// 默认应该是没有被选中的,点击后应该被选中

View File

@ -66,7 +66,7 @@ test.describe('form item & create form', () => {
})
.hover();
})(page, 'checkboxGroup'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByLabel('Option1').click();

View File

@ -66,7 +66,7 @@ test.describe('form item & create form', () => {
})
.hover();
})(page, 'chinaRegion'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').click();

View File

@ -64,7 +64,7 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'datetime'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByPlaceholder('Select date').click();

View File

@ -62,7 +62,7 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'email'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
constantValue: 'test@nocobase.com',
variableValue: ['Current user', 'Email'],

View File

@ -142,6 +142,7 @@ test.describe('form item & create form', () => {
'Constant',
'Current user',
'Current role',
'API token',
'Date variables',
'Current form',
]);

View File

@ -126,6 +126,7 @@ test.describe('form item & edit form', () => {
'Constant',
'Current user',
'Current role',
'API token',
'Date variables',
'Current form',
]);

View File

@ -62,7 +62,7 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'icon'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByRole('button', { name: 'Select icon' }).click();

View File

@ -63,7 +63,7 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'integer'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
variableValue: ['Current user', 'ID'], // 值为 1
inputConstantValue: async () => {

View File

@ -65,7 +65,7 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'longText'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
constantValue: 'test long text',
variableValue: ['Current user', 'Email'], // 值为 admin@nocobase.com

View File

@ -76,7 +76,7 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'manyToMany'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByTestId('select-object-multiple').click();
@ -165,6 +165,7 @@ test.describe('form item & create form', () => {
'Constant',
'Current user',
'Current role',
'API token',
'Date variables',
'Current form',
]);

View File

@ -127,6 +127,7 @@ test.describe('form item & edit form', () => {
'Constant',
'Current user',
'Current role',
'API token',
'Date variables',
'Current form',
]);

View File

@ -75,7 +75,7 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'manyToOne'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
inputConstantValue: async () => {
await page
@ -175,6 +175,7 @@ test.describe('form item & create form', () => {
'Constant',
'Current user',
'Current role',
'API token',
'Date variables',
'Current form',
]);

View File

@ -126,6 +126,7 @@ test.describe('form item & edit form', () => {
'Constant',
'Current user',
'Current role',
'API token',
'Date variables',
'Current form',
]);

View File

@ -62,7 +62,7 @@ test.describe('form item & create form', () => {
})
.hover();
},
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
constantValue: 'test markdown',
expectConstantValue: async () => {

View File

@ -66,7 +66,7 @@ test.describe('form item & create form', () => {
})
.hover();
})(page, 'multipleSelect'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByTestId('select-multiple').click();

View File

@ -63,7 +63,7 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'number'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByRole('spinbutton').click();

View File

@ -141,6 +141,7 @@ test.describe('form item & create form', () => {
'Constant',
'Current user',
'Current role',
'API token',
'Date variables',
'Current form',
]);

View File

@ -127,6 +127,7 @@ test.describe('form item & edit form', () => {
'Constant',
'Current user',
'Current role',
'API token',
'Date variables',
'Current form',
]);

View File

@ -63,7 +63,7 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'password'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
constantValue: 'test112233password',
variableValue: ['Current user', 'Email'], // 值为 admin@nocobase.com

View File

@ -63,7 +63,7 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'percent'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByRole('spinbutton').click();

View File

@ -62,7 +62,7 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'phone'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
constantValue: '17777777777',
variableValue: ['Current user', 'ID'], // 值为 1

View File

@ -66,7 +66,7 @@ test.describe('form item & create form', () => {
})
.hover();
})(page, 'radioGroup'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByLabel('Option2').click();

View File

@ -62,7 +62,7 @@ test.describe('form item & create form', () => {
})
.hover();
},
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').locator('.ql-editor').click();

View File

@ -45,6 +45,7 @@ test.describe('form item & sub form', () => {
'Constant',
'Current user',
'Current role',
'API token',
'Date variables',
'Current form',
'Current object',
@ -129,6 +130,7 @@ test.describe('table column & sub-table in edit form', () => {
'Constant',
'Current user',
'Current role',
'API token',
'Current form',
'Current object',
'Current popup record',

View File

@ -60,7 +60,7 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.singleLineText`)
.hover();
},
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
constantValue: 'test single line text',
variableValue: ['Current user', 'Email'], // 值为 admin@nocobase.com

View File

@ -66,7 +66,7 @@ test.describe('form item & create form', () => {
})
.hover();
})(page, 'singleSelect'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').click();

View File

@ -61,7 +61,7 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.time`)
.hover();
},
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByPlaceholder('Select time').click();

View File

@ -62,7 +62,7 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'url'),
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'API token', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record', 'Parent popup record'],
constantValue: 'https://nocobase.com',
variableValue: ['Current user', 'Email'], // 值为 admin@nocobase.com

View File

@ -9,6 +9,7 @@
import { ISchema, useField } from '@formily/react';
import {
useAPITokenVariable,
useCurrentRoleVariable,
useCurrentUserVariable,
useDatetimeVariable,
@ -28,12 +29,16 @@ export const useGeneralVariableOptions = (
uiSchema: schema,
});
const { currentRoleSettings } = useCurrentRoleVariable({ uiSchema: schema });
const { apiTokenSettings } = useAPITokenVariable({ noDisabled: true });
const { datetimeSettings } = useDatetimeVariable({ operator, schema, noDisabled: true });
const { urlSearchParamsSettings } = useURLSearchParamsVariable();
const result = useMemo(
() => [currentUserSettings, currentRoleSettings, datetimeSettings, urlSearchParamsSettings].filter(Boolean),
[datetimeSettings, currentUserSettings, currentRoleSettings, urlSearchParamsSettings],
() =>
[currentUserSettings, currentRoleSettings, apiTokenSettings, datetimeSettings, urlSearchParamsSettings].filter(
Boolean,
),
[datetimeSettings, currentUserSettings, currentRoleSettings, urlSearchParamsSettings, apiTokenSettings],
);
if (!schema) return [];