From c2260c76c062b05b16f19d74bb0d181819936a45 Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Tue, 9 Jul 2024 14:42:12 +0800 Subject: [PATCH] feat(variable): add a new variable named 'API token' (#4850) * feat(variable): add a variable named 'Current token' * refactor: rename to 'API Token' * test: add e2e tests * chore: update unit test --- .../form-create/schemaSettings.test.ts | 1 + .../form-create/schemaSettings2.test.ts | 9 +- .../table/__e2e__/schemaSettings.test.ts | 1 + .../table/__e2e__/schemaSettings1.test.ts | 2 +- .../modules/variable/__e2e__/basic.test.ts | 24 ++- .../src/modules/variable/__e2e__/templates.ts | 152 ++++++++++++++++++ .../schema-component/core/SchemaComponent.tsx | 2 +- .../VariableInput/hooks/index.ts | 5 +- .../hooks/useAPITokenVariable.ts | 37 +++++ .../VariableInput/hooks/useBaseVariable.tsx | 6 +- .../VariableInput/hooks/useVariableOptions.ts | 4 + .../variables/__tests__/useVariables.test.tsx | 5 + .../variables/hooks/useBuiltinVariables.ts | 6 + .../fields/belongsTo/schemaSettings1.test.ts | 1 + .../fields/belongsTo/schemaSettings2.test.ts | 1 + .../fields/checkbox/schemaSettings.test.ts | 2 +- .../checkboxGroup/schemaSettings.test.ts | 2 +- .../fields/chinaRegion/schemaSettings.test.ts | 2 +- .../fields/datetime/schemaSettings.test.ts | 2 +- .../fields/email/schemaSettings.test.ts | 2 +- .../fields/hasOne/schemaSettings1.test.ts | 1 + .../fields/hasOne/schemaSettings2.test.ts | 1 + .../fields/icon/schemaSettings.test.ts | 2 +- .../fields/integer/schemaSettings.test.ts | 2 +- .../fields/longText/schemaSettings1.test.ts | 2 +- .../fields/manyToMany/schemaSettings1.test.ts | 3 +- .../fields/manyToMany/schemaSettings2.test.ts | 1 + .../fields/manyToOne/schemaSettings1.test.ts | 3 +- .../fields/manyToOne/schemaSettings2.test.ts | 1 + .../fields/markdown/schemaSettings.test.ts | 2 +- .../mutipleSelect/schemaSettings.test.ts | 2 +- .../fields/number/schemaSettings.test.ts | 2 +- .../fields/oneToMany/schemaSettings1.test.ts | 1 + .../fields/oneToMany/schemaSettings2.test.ts | 1 + .../fields/password/schemaSettings1.test.ts | 2 +- .../fields/percent/schemaSettings.test.ts | 2 +- .../fields/phone/schemaSettings.test.ts | 2 +- .../fields/radioGroup/schemaSettings.test.ts | 2 +- .../fields/richText/schemaSettings.test.ts | 2 +- .../singleLineText/schemaSettings.test.ts | 2 + .../singleLineText/schemaSettings1.test.ts | 2 +- .../singleSelect/schemaSettings.test.ts | 2 +- .../fields/time/schemaSettings.test.ts | 2 +- .../__e2e__/fields/url/schemaSettings.test.ts | 2 +- .../src/client/hooks/useVariableOptions.ts | 9 +- 45 files changed, 284 insertions(+), 35 deletions(-) create mode 100644 packages/core/client/src/schema-settings/VariableInput/hooks/useAPITokenVariable.ts diff --git a/packages/core/client/src/modules/blocks/data-blocks/form/__e2e__/form-create/schemaSettings.test.ts b/packages/core/client/src/modules/blocks/data-blocks/form/__e2e__/form-create/schemaSettings.test.ts index a91dc590b0..de5bfe2db3 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/form/__e2e__/form-create/schemaSettings.test.ts +++ b/packages/core/client/src/modules/blocks/data-blocks/form/__e2e__/form-create/schemaSettings.test.ts @@ -547,6 +547,7 @@ test.describe('actions schema settings', () => { 'Constant', 'Current user', 'Current role', + 'API token', 'Date variables', 'Current form', ]); diff --git a/packages/core/client/src/modules/blocks/data-blocks/form/__e2e__/form-create/schemaSettings2.test.ts b/packages/core/client/src/modules/blocks/data-blocks/form/__e2e__/form-create/schemaSettings2.test.ts index 75cbf0d6ff..599ff6b647 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/form/__e2e__/form-create/schemaSettings2.test.ts +++ b/packages/core/client/src/modules/blocks/data-blocks/form/__e2e__/form-create/schemaSettings2.test.ts @@ -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(); diff --git a/packages/core/client/src/modules/blocks/data-blocks/table/__e2e__/schemaSettings.test.ts b/packages/core/client/src/modules/blocks/data-blocks/table/__e2e__/schemaSettings.test.ts index 2e6e266bb7..ffd3f953fe 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/table/__e2e__/schemaSettings.test.ts +++ b/packages/core/client/src/modules/blocks/data-blocks/table/__e2e__/schemaSettings.test.ts @@ -442,6 +442,7 @@ test.describe('actions schema settings', () => { 'Constant', 'Current user', 'Current role', + 'API token', 'Date variables', 'Current record', ]); diff --git a/packages/core/client/src/modules/blocks/data-blocks/table/__e2e__/schemaSettings1.test.ts b/packages/core/client/src/modules/blocks/data-blocks/table/__e2e__/schemaSettings1.test.ts index e770c23846..1d15e7320b 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/table/__e2e__/schemaSettings1.test.ts +++ b/packages/core/client/src/modules/blocks/data-blocks/table/__e2e__/schemaSettings1.test.ts @@ -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(); diff --git a/packages/core/client/src/modules/variable/__e2e__/basic.test.ts b/packages/core/client/src/modules/variable/__e2e__/basic.test.ts index 3f2864e2fc..28394eb95a 100644 --- a/packages/core/client/src/modules/variable/__e2e__/basic.test.ts +++ b/packages/core/client/src/modules/variable/__e2e__/basic.test.ts @@ -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); }); }); diff --git a/packages/core/client/src/modules/variable/__e2e__/templates.ts b/packages/core/client/src/modules/variable/__e2e__/templates.ts index 93d1ee45cb..a9176eec36 100644 --- a/packages/core/client/src/modules/variable/__e2e__/templates.ts +++ b/packages/core/client/src/modules/variable/__e2e__/templates.ts @@ -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, + }, +}; diff --git a/packages/core/client/src/schema-component/core/SchemaComponent.tsx b/packages/core/client/src/schema-component/core/SchemaComponent.tsx index 3135b53483..bd1cf3a56f 100644 --- a/packages/core/client/src/schema-component/core/SchemaComponent.tsx +++ b/packages/core/client/src/schema-component/core/SchemaComponent.tsx @@ -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; diff --git a/packages/core/client/src/schema-settings/VariableInput/hooks/index.ts b/packages/core/client/src/schema-settings/VariableInput/hooks/index.ts index 2ff3af19c2..432ceadfa5 100644 --- a/packages/core/client/src/schema-settings/VariableInput/hooks/index.ts +++ b/packages/core/client/src/schema-settings/VariableInput/hooks/index.ts @@ -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'; diff --git a/packages/core/client/src/schema-settings/VariableInput/hooks/useAPITokenVariable.ts b/packages/core/client/src/schema-settings/VariableInput/hooks/useAPITokenVariable.ts new file mode 100644 index 0000000000..3538a7d746 --- /dev/null +++ b/packages/core/client/src/schema-settings/VariableInput/hooks/useAPITokenVariable.ts @@ -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, + }; +}; diff --git a/packages/core/client/src/schema-settings/VariableInput/hooks/useBaseVariable.tsx b/packages/core/client/src/schema-settings/VariableInput/hooks/useBaseVariable.tsx index cf8ce7ab2f..324c05858b 100644 --- a/packages/core/client/src/schema-settings/VariableInput/hooks/useBaseVariable.tsx +++ b/packages/core/client/src/schema-settings/VariableInput/hooks/useBaseVariable.tsx @@ -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; /** * 不需要禁用选项,一般会在表达式中使用 */ diff --git a/packages/core/client/src/schema-settings/VariableInput/hooks/useVariableOptions.ts b/packages/core/client/src/schema-settings/VariableInput/hooks/useVariableOptions.ts index e6e4eb7d18..e8d3e5c78c 100644 --- a/packages/core/client/src/schema-settings/VariableInput/hooks/useVariableOptions.ts +++ b/packages/core/client/src/schema-settings/VariableInput/hooks/useVariableOptions.ts @@ -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, diff --git a/packages/core/client/src/variables/__tests__/useVariables.test.tsx b/packages/core/client/src/variables/__tests__/useVariables.test.tsx index cb47b02997..06186b5d63 100644 --- a/packages/core/client/src/variables/__tests__/useVariables.test.tsx +++ b/packages/core/client/src/variables/__tests__/useVariables.test.tsx @@ -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", diff --git a/packages/core/client/src/variables/hooks/useBuiltinVariables.ts b/packages/core/client/src/variables/hooks/useBuiltinVariables.ts index 8af69176e4..c7d59b61ae 100644 --- a/packages/core/client/src/variables/hooks/useBuiltinVariables.ts +++ b/packages/core/client/src/variables/hooks/useBuiltinVariables.ts @@ -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 * 兼容老版本 diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/belongsTo/schemaSettings1.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/belongsTo/schemaSettings1.test.ts index c14a2522f5..2d81ec58ea 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/belongsTo/schemaSettings1.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/belongsTo/schemaSettings1.test.ts @@ -140,6 +140,7 @@ test.describe('form item & create form', () => { 'Constant', 'Current user', 'Current role', + 'API token', 'Date variables', 'Current form', ]); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/belongsTo/schemaSettings2.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/belongsTo/schemaSettings2.test.ts index 8dcca52baf..1a06b327e7 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/belongsTo/schemaSettings2.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/belongsTo/schemaSettings2.test.ts @@ -130,6 +130,7 @@ test.describe('form item & edit form', () => { 'Constant', 'Current user', 'Current role', + 'API token', 'Date variables', 'Current form', ]); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/checkbox/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/checkbox/schemaSettings.test.ts index 9e5096ac3c..19c231581c 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/checkbox/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/checkbox/schemaSettings.test.ts @@ -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 () => { // 默认应该是没有被选中的,点击后应该被选中 diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/checkboxGroup/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/checkboxGroup/schemaSettings.test.ts index b61685a4a3..2b3e25d95d 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/checkboxGroup/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/checkboxGroup/schemaSettings.test.ts @@ -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(); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/chinaRegion/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/chinaRegion/schemaSettings.test.ts index 15fb67d217..971b36e98a 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/chinaRegion/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/chinaRegion/schemaSettings.test.ts @@ -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(); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/datetime/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/datetime/schemaSettings.test.ts index 2a004d5c49..090dca31c9 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/datetime/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/datetime/schemaSettings.test.ts @@ -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(); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/email/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/email/schemaSettings.test.ts index b163caab76..a4a2ea7091 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/email/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/email/schemaSettings.test.ts @@ -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'], diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/hasOne/schemaSettings1.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/hasOne/schemaSettings1.test.ts index 94571a32b3..cc507fcd2f 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/hasOne/schemaSettings1.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/hasOne/schemaSettings1.test.ts @@ -142,6 +142,7 @@ test.describe('form item & create form', () => { 'Constant', 'Current user', 'Current role', + 'API token', 'Date variables', 'Current form', ]); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/hasOne/schemaSettings2.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/hasOne/schemaSettings2.test.ts index f2e67a051a..63ef39273b 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/hasOne/schemaSettings2.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/hasOne/schemaSettings2.test.ts @@ -126,6 +126,7 @@ test.describe('form item & edit form', () => { 'Constant', 'Current user', 'Current role', + 'API token', 'Date variables', 'Current form', ]); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/icon/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/icon/schemaSettings.test.ts index 1f070895b8..33011cd40d 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/icon/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/icon/schemaSettings.test.ts @@ -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(); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/integer/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/integer/schemaSettings.test.ts index 4c656b2f7e..b81f65ac33 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/integer/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/integer/schemaSettings.test.ts @@ -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 () => { diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/longText/schemaSettings1.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/longText/schemaSettings1.test.ts index 6594422313..fc9a7e2790 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/longText/schemaSettings1.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/longText/schemaSettings1.test.ts @@ -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 diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/manyToMany/schemaSettings1.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/manyToMany/schemaSettings1.test.ts index 01947502f0..ea0bf672fb 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/manyToMany/schemaSettings1.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/manyToMany/schemaSettings1.test.ts @@ -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', ]); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/manyToMany/schemaSettings2.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/manyToMany/schemaSettings2.test.ts index 0b66405ec9..8e775e065c 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/manyToMany/schemaSettings2.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/manyToMany/schemaSettings2.test.ts @@ -127,6 +127,7 @@ test.describe('form item & edit form', () => { 'Constant', 'Current user', 'Current role', + 'API token', 'Date variables', 'Current form', ]); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/manyToOne/schemaSettings1.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/manyToOne/schemaSettings1.test.ts index 5449b02d3e..168c187016 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/manyToOne/schemaSettings1.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/manyToOne/schemaSettings1.test.ts @@ -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', ]); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/manyToOne/schemaSettings2.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/manyToOne/schemaSettings2.test.ts index 29eca4318b..1a42fd1134 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/manyToOne/schemaSettings2.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/manyToOne/schemaSettings2.test.ts @@ -126,6 +126,7 @@ test.describe('form item & edit form', () => { 'Constant', 'Current user', 'Current role', + 'API token', 'Date variables', 'Current form', ]); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/markdown/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/markdown/schemaSettings.test.ts index 7382c46aa0..e3633b1e7f 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/markdown/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/markdown/schemaSettings.test.ts @@ -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 () => { diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/mutipleSelect/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/mutipleSelect/schemaSettings.test.ts index 9ddfba9579..69d8c003ba 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/mutipleSelect/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/mutipleSelect/schemaSettings.test.ts @@ -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(); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/number/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/number/schemaSettings.test.ts index b3ba33d0b6..8532767041 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/number/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/number/schemaSettings.test.ts @@ -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(); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/oneToMany/schemaSettings1.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/oneToMany/schemaSettings1.test.ts index 2f7a813e98..1c86b928c9 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/oneToMany/schemaSettings1.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/oneToMany/schemaSettings1.test.ts @@ -141,6 +141,7 @@ test.describe('form item & create form', () => { 'Constant', 'Current user', 'Current role', + 'API token', 'Date variables', 'Current form', ]); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/oneToMany/schemaSettings2.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/oneToMany/schemaSettings2.test.ts index 4625ae0c14..619edfdc64 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/oneToMany/schemaSettings2.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/oneToMany/schemaSettings2.test.ts @@ -127,6 +127,7 @@ test.describe('form item & edit form', () => { 'Constant', 'Current user', 'Current role', + 'API token', 'Date variables', 'Current form', ]); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/password/schemaSettings1.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/password/schemaSettings1.test.ts index 46961f9782..5a3e76a382 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/password/schemaSettings1.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/password/schemaSettings1.test.ts @@ -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 diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/percent/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/percent/schemaSettings.test.ts index 3f7c851710..33ad3f3535 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/percent/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/percent/schemaSettings.test.ts @@ -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(); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/phone/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/phone/schemaSettings.test.ts index 679c1829f2..108ff364f2 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/phone/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/phone/schemaSettings.test.ts @@ -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 diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/radioGroup/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/radioGroup/schemaSettings.test.ts index 21d326d448..441118a2c3 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/radioGroup/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/radioGroup/schemaSettings.test.ts @@ -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(); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/richText/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/richText/schemaSettings.test.ts index 31774b0c01..349ac6db66 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/richText/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/richText/schemaSettings.test.ts @@ -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(); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/singleLineText/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/singleLineText/schemaSettings.test.ts index 0c6352c6a8..c774359a4c 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/singleLineText/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/singleLineText/schemaSettings.test.ts @@ -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', diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/singleLineText/schemaSettings1.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/singleLineText/schemaSettings1.test.ts index 9e0a9283c9..a05444df8d 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/singleLineText/schemaSettings1.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/singleLineText/schemaSettings1.test.ts @@ -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 diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/singleSelect/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/singleSelect/schemaSettings.test.ts index 75a7897d17..4f6729a0fe 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/singleSelect/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/singleSelect/schemaSettings.test.ts @@ -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(); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/time/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/time/schemaSettings.test.ts index f0be146e9e..2bc7cf4338 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/time/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/time/schemaSettings.test.ts @@ -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(); diff --git a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/url/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/url/schemaSettings.test.ts index 60af15c8c5..03883b6d46 100644 --- a/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/url/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-main/src/client/__e2e__/fields/url/schemaSettings.test.ts @@ -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 diff --git a/packages/plugins/@nocobase/plugin-data-visualization/src/client/hooks/useVariableOptions.ts b/packages/plugins/@nocobase/plugin-data-visualization/src/client/hooks/useVariableOptions.ts index cd6e57e5b7..53212b5896 100644 --- a/packages/plugins/@nocobase/plugin-data-visualization/src/client/hooks/useVariableOptions.ts +++ b/packages/plugins/@nocobase/plugin-data-visualization/src/client/hooks/useVariableOptions.ts @@ -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 [];