mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 01:56:16 +00:00
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
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:
parent
f8e9385845
commit
c2260c76c0
@ -547,6 +547,7 @@ test.describe('actions schema settings', () => {
|
||||
'Constant',
|
||||
'Current user',
|
||||
'Current role',
|
||||
'API token',
|
||||
'Date variables',
|
||||
'Current form',
|
||||
]);
|
||||
|
@ -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();
|
||||
|
@ -442,6 +442,7 @@ test.describe('actions schema settings', () => {
|
||||
'Constant',
|
||||
'Current user',
|
||||
'Current role',
|
||||
'API token',
|
||||
'Date variables',
|
||||
'Current record',
|
||||
]);
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
@ -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,
|
||||
},
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -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';
|
||||
|
@ -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,
|
||||
};
|
||||
};
|
@ -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;
|
||||
/**
|
||||
* 不需要禁用选项,一般会在表达式中使用
|
||||
*/
|
||||
|
@ -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,
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
* 兼容老版本
|
||||
|
@ -140,6 +140,7 @@ test.describe('form item & create form', () => {
|
||||
'Constant',
|
||||
'Current user',
|
||||
'Current role',
|
||||
'API token',
|
||||
'Date variables',
|
||||
'Current form',
|
||||
]);
|
||||
|
@ -130,6 +130,7 @@ test.describe('form item & edit form', () => {
|
||||
'Constant',
|
||||
'Current user',
|
||||
'Current role',
|
||||
'API token',
|
||||
'Date variables',
|
||||
'Current form',
|
||||
]);
|
||||
|
@ -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 () => {
|
||||
// 默认应该是没有被选中的,点击后应该被选中
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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'],
|
||||
|
@ -142,6 +142,7 @@ test.describe('form item & create form', () => {
|
||||
'Constant',
|
||||
'Current user',
|
||||
'Current role',
|
||||
'API token',
|
||||
'Date variables',
|
||||
'Current form',
|
||||
]);
|
||||
|
@ -126,6 +126,7 @@ test.describe('form item & edit form', () => {
|
||||
'Constant',
|
||||
'Current user',
|
||||
'Current role',
|
||||
'API token',
|
||||
'Date variables',
|
||||
'Current form',
|
||||
]);
|
||||
|
@ -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();
|
||||
|
@ -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 () => {
|
||||
|
@ -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
|
||||
|
@ -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',
|
||||
]);
|
||||
|
@ -127,6 +127,7 @@ test.describe('form item & edit form', () => {
|
||||
'Constant',
|
||||
'Current user',
|
||||
'Current role',
|
||||
'API token',
|
||||
'Date variables',
|
||||
'Current form',
|
||||
]);
|
||||
|
@ -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',
|
||||
]);
|
||||
|
@ -126,6 +126,7 @@ test.describe('form item & edit form', () => {
|
||||
'Constant',
|
||||
'Current user',
|
||||
'Current role',
|
||||
'API token',
|
||||
'Date variables',
|
||||
'Current form',
|
||||
]);
|
||||
|
@ -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 () => {
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -141,6 +141,7 @@ test.describe('form item & create form', () => {
|
||||
'Constant',
|
||||
'Current user',
|
||||
'Current role',
|
||||
'API token',
|
||||
'Date variables',
|
||||
'Current form',
|
||||
]);
|
||||
|
@ -127,6 +127,7 @@ test.describe('form item & edit form', () => {
|
||||
'Constant',
|
||||
'Current user',
|
||||
'Current role',
|
||||
'API token',
|
||||
'Date variables',
|
||||
'Current form',
|
||||
]);
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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',
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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 [];
|
||||
|
Loading…
Reference in New Issue
Block a user