feat(custom-request): support "Current form" variable (#5871)

* feat(custom-request): support "Current form" variable

* test: add e2e test
This commit is contained in:
Zeke Zhang 2024-12-12 20:37:27 +08:00 committed by GitHub
parent b897a8d5e6
commit eb2f5c77fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 926 additions and 10 deletions

View File

@ -0,0 +1,97 @@
/**
* 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 { expect, test } from '@nocobase/test/e2e';
import { supportedVariablesInCustomRequestButtonsAcrossDifferentBlocks } from './template';
test.describe('custom request action', () => {
test('supported variables in custom request buttons across different blocks', async ({ page, mockPage }) => {
await mockPage(supportedVariablesInCustomRequestButtonsAcrossDifferentBlocks).goto();
const expectSupportedVariables = async (variables: string[]) => {
for (const variable of variables) {
await expect(page.getByRole('menuitemcheckbox', { name: variable })).toBeVisible();
}
};
// 1. 表格顶部的 “Custom request” 按钮,支持什么变量
await page.getByLabel('action-CustomRequestAction-Custom request-customize:table:request:global-users-').hover();
await page
.getByRole('button', { name: 'designer-schema-settings-CustomRequestAction-actionSettings:customRequest-users' })
.hover();
await page.getByRole('menuitem', { name: 'Request settings' }).click();
await page.getByLabel('block-item-Variable.TextArea-').getByLabel('variable-button').click();
await expectSupportedVariables(['Current user right', 'Current time', 'API token']);
await page.getByText('Request settings*HTTP method:').getByLabel('Close', { exact: true }).click();
// 2. 新增表单的 “Custom request” 按钮,支持什么变量
await page.getByLabel('action-Action-Add new-create-').click();
await page
.getByTestId('drawer-Action.Container-users-Add record')
.getByLabel('action-CustomRequestAction-')
.hover();
await page
.getByTestId('drawer-Action.Container-users-Add record')
.getByLabel('designer-schema-settings-CustomRequestAction-actionSettings:customRequest-users')
.hover();
await page.getByRole('menuitem', { name: 'Request settings' }).click();
await page.getByLabel('block-item-Variable.TextArea-').getByLabel('variable-button').click();
await expectSupportedVariables(['Current form right', 'Current user right', 'Current time', 'API token']);
await page.getByText('Request settings*HTTP method:').getByLabel('Close', { exact: true }).click();
await page.getByLabel('drawer-Action.Container-users-Add record-mask').click();
// 3. 表格行的 “Custom request” 按钮,支持什么变量
await page.getByLabel('action-CustomRequestAction-Custom request-customize:table:request-users-table-').hover();
await page
.getByRole('button', { name: 'designer-schema-settings-CustomRequestAction-actionSettings:customRequest-users' })
.hover();
await page.getByRole('menuitem', { name: 'Request settings' }).click();
await page.getByLabel('block-item-Variable.TextArea-').getByLabel('variable-button').click();
await expectSupportedVariables(['Current record right', 'Current user right', 'Current time', 'API token']);
await page.getByText('Request settings*HTTP method:').getByLabel('Close', { exact: true }).click();
// 4. 详情区块的 “Custom request” 按钮,支持什么变量
await page.getByLabel('action-Action.Link-View-view-').click();
await page
.getByTestId('drawer-Action.Container-users-View record')
.getByLabel('action-CustomRequestAction-')
.hover();
await page
.getByTestId('drawer-Action.Container-users-View record')
.getByLabel('designer-schema-settings-CustomRequestAction-actionSettings:customRequest-users')
.hover();
await page.getByRole('menuitem', { name: 'Request settings' }).click();
await page.getByLabel('block-item-Variable.TextArea-').getByLabel('variable-button').click();
await expectSupportedVariables(['Current record right', 'Current user right', 'Current time', 'API token']);
await page.getByText('Request settings*HTTP method:').getByLabel('Close', { exact: true }).click();
await page.getByLabel('drawer-Action.Container-users-View record-mask').click();
// 5. 编辑表单的 “Custom request” 按钮,支持什么变量
await page.getByLabel('action-Action.Link-Edit-').click();
await page
.getByTestId('drawer-Action.Container-users-Edit record')
.getByLabel('action-CustomRequestAction-')
.hover();
await page
.getByTestId('drawer-Action.Container-users-Edit record')
.getByLabel('designer-schema-settings-CustomRequestAction-actionSettings:customRequest-users')
.hover();
await page.getByRole('menuitem', { name: 'Request settings' }).click();
await page.getByLabel('block-item-Variable.TextArea-').getByLabel('variable-button').click();
await expectSupportedVariables([
'Current record right',
'Current form right',
'Current user right',
'Current time',
'API token',
]);
await page.getByText('Request settings*HTTP method:').getByLabel('Close', { exact: true }).click();
await page.getByLabel('drawer-Action.Container-users-Edit record-mask').click();
});
});

View File

@ -0,0 +1,813 @@
/**
* 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.
*/
export const supportedVariablesInCustomRequestButtonsAcrossDifferentBlocks = {
pageSchema: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Page',
'x-app-version': '1.4.9',
properties: {
l2czy177k07: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'page:addBlock',
'x-app-version': '1.4.9',
properties: {
oi97jxvci1c: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '1.4.9',
properties: {
'6u129cei0gf': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '1.4.9',
properties: {
yygk0xl9w18: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'TableBlockProvider',
'x-acl-action': 'users:list',
'x-use-decorator-props': 'useTableBlockDecoratorProps',
'x-decorator-props': {
collection: 'users',
dataSource: 'main',
action: 'list',
params: {
pageSize: 20,
},
rowKey: 'id',
showIndex: true,
dragSort: false,
},
'x-toolbar': 'BlockSchemaToolbar',
'x-settings': 'blockSettings:table',
'x-component': 'CardItem',
'x-filter-targets': [],
'x-app-version': '1.4.9',
properties: {
actions: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-initializer': 'table:configureActions',
'x-component': 'ActionBar',
'x-component-props': {
style: {
marginBottom: 'var(--nb-spacing)',
},
},
'x-app-version': '1.4.9',
properties: {
'5e0y2knzdeg': {
_isJSONSchemaObject: true,
version: '2.0',
title: '{{ t("Custom request") }}',
'x-component': 'CustomRequestAction',
'x-action': 'customize:table:request:global',
'x-toolbar': 'ActionSchemaToolbar',
'x-settings': 'actionSettings:customRequest',
'x-decorator': 'CustomRequestAction.Decorator',
'x-action-settings': {
onSuccess: {
manualClose: false,
redirecting: false,
successMessage: '{{t("Request success")}}',
},
},
type: 'void',
'x-app-version': '1.4.9',
'x-uid': 'wp7pw8xm95i',
'x-async': false,
'x-index': 1,
},
gndvfq5o0rt: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-action': 'create',
'x-acl-action': 'create',
title: "{{t('Add new')}}",
'x-toolbar': 'ActionSchemaToolbar',
'x-settings': 'actionSettings:addNew',
'x-component': 'Action',
'x-decorator': 'ACLActionProvider',
'x-component-props': {
openMode: 'drawer',
type: 'primary',
component: 'CreateRecordAction',
icon: 'PlusOutlined',
},
'x-action-context': {
dataSource: 'main',
collection: 'users',
},
'x-align': 'right',
'x-acl-action-props': {
skipScopeCheck: true,
},
'x-app-version': '1.4.9',
properties: {
drawer: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{ t("Add record") }}',
'x-component': 'Action.Container',
'x-component-props': {
className: 'nb-action-popup',
},
'x-app-version': '1.4.9',
properties: {
tabs: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Tabs',
'x-component-props': {},
'x-initializer': 'popup:addTab',
'x-initializer-props': {
gridInitializer: 'popup:addNew:addBlock',
},
'x-app-version': '1.4.9',
properties: {
tab1: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{t("Add new")}}',
'x-component': 'Tabs.TabPane',
'x-designer': 'Tabs.Designer',
'x-component-props': {},
'x-app-version': '1.4.9',
properties: {
grid: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'popup:addNew:addBlock',
'x-app-version': '1.4.9',
properties: {
wz8bi424vnn: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '1.4.9',
properties: {
bm1b41hve8y: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '1.4.9',
properties: {
'52s0p4fw2vh': {
'x-uid': '7fmse7abggm',
_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.4.9',
'x-component-props': {
title: 'Add New',
},
properties: {
tgxae7rbozi: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'FormV2',
'x-use-component-props': 'useCreateFormBlockProps',
'x-app-version': '1.4.9',
properties: {
grid: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'form:configureFields',
'x-app-version': '1.4.9',
'x-uid': 'uhj26pi84hp',
'x-async': false,
'x-index': 1,
},
'2sm3jj8jnua': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-initializer': 'createForm:configureActions',
'x-component': 'ActionBar',
'x-component-props': {
layout: 'one-column',
},
'x-app-version': '1.4.9',
properties: {
'15skh3b6c2r': {
_isJSONSchemaObject: true,
version: '2.0',
title: '{{ t("Custom request") }}',
'x-component': 'CustomRequestAction',
'x-action': 'customize:form:request',
'x-toolbar': 'ActionSchemaToolbar',
'x-settings': 'actionSettings:customRequest',
'x-decorator': 'CustomRequestAction.Decorator',
'x-action-settings': {
onSuccess: {
manualClose: false,
redirecting: false,
successMessage: '{{t("Request success")}}',
},
},
type: 'void',
'x-app-version': '1.4.9',
'x-uid': 'sfxshd3kyxr',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'wgljemjsdpk',
'x-async': false,
'x-index': 2,
},
},
'x-uid': 'i2a6y8gh9ar',
'x-async': false,
'x-index': 1,
},
},
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'nmiyh3usv8z',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '8qvjs9amn6v',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'wqrux14mdkm',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'kj5yxwyj6fb',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'u6qdu8n4ur6',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'zxuxnlhtgng',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'nurbmqvfzwe',
'x-async': false,
'x-index': 2,
},
},
'x-uid': 'dncilohtx27',
'x-async': false,
'x-index': 1,
},
xv8hw9artvt: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'array',
'x-initializer': 'table:configureColumns',
'x-component': 'TableV2',
'x-use-component-props': 'useTableBlockProps',
'x-component-props': {
rowKey: 'id',
rowSelection: {
type: 'checkbox',
},
},
'x-app-version': '1.4.9',
properties: {
actions: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{ t("Actions") }}',
'x-action-column': 'actions',
'x-decorator': 'TableV2.Column.ActionBar',
'x-component': 'TableV2.Column',
'x-toolbar': 'TableColumnSchemaToolbar',
'x-initializer': 'table:configureItemActions',
'x-settings': 'fieldSettings:TableColumn',
'x-toolbar-props': {
initializer: 'table:configureItemActions',
},
'x-app-version': '1.4.9',
properties: {
e667gjchy76: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'DndContext',
'x-component': 'Space',
'x-component-props': {
split: '|',
},
'x-app-version': '1.4.9',
properties: {
'57a3d0qnm55': {
_isJSONSchemaObject: true,
version: '2.0',
title: '{{ t("Custom request") }}',
'x-component': 'CustomRequestAction',
'x-action': 'customize:table:request',
'x-toolbar': 'ActionSchemaToolbar',
'x-settings': 'actionSettings:customRequest',
'x-decorator': 'CustomRequestAction.Decorator',
'x-action-settings': {
onSuccess: {
manualClose: false,
redirecting: false,
successMessage: '{{t("Request success")}}',
},
},
'x-designer-props': {
linkageAction: true,
},
type: 'void',
'x-uid': 'q4d1ew52ne6',
'x-async': false,
'x-index': 1,
},
'236h7t7gfqr': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{ t("View") }}',
'x-action': 'view',
'x-toolbar': 'ActionSchemaToolbar',
'x-settings': 'actionSettings:view',
'x-component': 'Action.Link',
'x-component-props': {
openMode: 'drawer',
},
'x-action-context': {
dataSource: 'main',
collection: 'users',
},
'x-decorator': 'ACLActionProvider',
'x-designer-props': {
linkageAction: true,
},
properties: {
drawer: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{ t("View record") }}',
'x-component': 'Action.Container',
'x-component-props': {
className: 'nb-action-popup',
},
properties: {
tabs: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Tabs',
'x-component-props': {},
'x-initializer': 'popup:addTab',
properties: {
tab1: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{t("Details")}}',
'x-component': 'Tabs.TabPane',
'x-designer': 'Tabs.Designer',
'x-component-props': {},
properties: {
grid: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'popup:common:addBlock',
properties: {
'9bly4qjqtni': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '1.4.9',
properties: {
a2j1crfu0wz: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '1.4.9',
properties: {
'87x4b0tyu7a': {
'x-uid': '3758igtec2j',
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-acl-action': 'users:get',
'x-decorator': 'DetailsBlockProvider',
'x-use-decorator-props': 'useDetailsDecoratorProps',
'x-decorator-props': {
dataSource: 'main',
collection: 'users',
readPretty: true,
action: 'get',
},
'x-toolbar': 'BlockSchemaToolbar',
'x-settings': 'blockSettings:details',
'x-component': 'CardItem',
'x-app-version': '1.4.9',
'x-component-props': {
title: 'Details Block',
},
properties: {
tgoyjostrz2: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Details',
'x-read-pretty': true,
'x-use-component-props': 'useDetailsProps',
'x-app-version': '1.4.9',
properties: {
cl2zie8fksf: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-initializer': 'details:configureActions',
'x-component': 'ActionBar',
'x-component-props': {
style: {
marginBottom: 24,
},
},
'x-app-version': '1.4.9',
properties: {
g6804yrsmej: {
_isJSONSchemaObject: true,
version: '2.0',
title: '{{ t("Custom request") }}',
'x-component': 'CustomRequestAction',
'x-action': 'customize:form:request',
'x-toolbar': 'ActionSchemaToolbar',
'x-settings':
'actionSettings:customRequest',
'x-decorator':
'CustomRequestAction.Decorator',
'x-action-settings': {
onSuccess: {
manualClose: false,
redirecting: false,
successMessage:
'{{t("Request success")}}',
},
},
type: 'void',
'x-app-version': '1.4.9',
'x-uid': '08qzdravmnk',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'ikpqtoqls2q',
'x-async': false,
'x-index': 1,
},
grid: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'details:configureFields',
'x-app-version': '1.4.9',
'x-uid': 't6xzlhp86pb',
'x-async': false,
'x-index': 2,
},
},
'x-uid': '1blkro6oeke',
'x-async': false,
'x-index': 1,
},
},
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'na4tyhc5buj',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'ar025tj1462',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'i43dbau58tk',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'o1880x1ookc',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'n854f9see0r',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'ck67w9x0yr0',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '80lo3141tnh',
'x-async': false,
'x-index': 2,
},
hnpfviytps8: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{ t("Edit") }}',
'x-action': 'update',
'x-toolbar': 'ActionSchemaToolbar',
'x-settings': 'actionSettings:edit',
'x-component': 'Action.Link',
'x-component-props': {
openMode: 'drawer',
icon: 'EditOutlined',
},
'x-action-context': {
dataSource: 'main',
collection: 'users',
},
'x-decorator': 'ACLActionProvider',
'x-designer-props': {
linkageAction: true,
},
properties: {
drawer: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{ t("Edit record") }}',
'x-component': 'Action.Container',
'x-component-props': {
className: 'nb-action-popup',
},
properties: {
tabs: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Tabs',
'x-component-props': {},
'x-initializer': 'popup:addTab',
properties: {
tab1: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{t("Edit")}}',
'x-component': 'Tabs.TabPane',
'x-designer': 'Tabs.Designer',
'x-component-props': {},
properties: {
grid: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'popup:common:addBlock',
properties: {
'9rz96k15gab': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '1.4.9',
properties: {
oh4gj5e2532: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '1.4.9',
properties: {
qqlb3ayhx6x: {
'x-uid': 'psobem7jvqr',
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-acl-action-props': {
skipScopeCheck: false,
},
'x-acl-action': 'users:update',
'x-decorator': 'FormBlockProvider',
'x-use-decorator-props':
'useEditFormBlockDecoratorProps',
'x-decorator-props': {
action: 'get',
dataSource: 'main',
collection: 'users',
},
'x-toolbar': 'BlockSchemaToolbar',
'x-settings': 'blockSettings:editForm',
'x-component': 'CardItem',
'x-app-version': '1.4.9',
'x-component-props': {
title: 'Edit Form',
},
properties: {
rg4cm688pz8: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'FormV2',
'x-use-component-props': 'useEditFormBlockProps',
'x-app-version': '1.4.9',
properties: {
grid: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'form:configureFields',
'x-app-version': '1.4.9',
'x-uid': 'h9q5vpijkd4',
'x-async': false,
'x-index': 1,
},
ldr3hvyecof: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-initializer': 'editForm:configureActions',
'x-component': 'ActionBar',
'x-component-props': {
layout: 'one-column',
},
'x-app-version': '1.4.9',
properties: {
mwlnx2xruww: {
_isJSONSchemaObject: true,
version: '2.0',
title: '{{ t("Custom request") }}',
'x-component': 'CustomRequestAction',
'x-action': 'customize:form:request',
'x-toolbar': 'ActionSchemaToolbar',
'x-settings':
'actionSettings:customRequest',
'x-decorator':
'CustomRequestAction.Decorator',
'x-action-settings': {
onSuccess: {
manualClose: false,
redirecting: false,
successMessage:
'{{t("Request success")}}',
},
},
type: 'void',
'x-app-version': '1.4.9',
'x-uid': 'z2vi6h1d890',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'h4afny53h2n',
'x-async': false,
'x-index': 2,
},
},
'x-uid': 'zir1u01jwgo',
'x-async': false,
'x-index': 1,
},
},
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'plcd90g1ezo',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'w1ash3kerb7',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'jfgtbdij6cd',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'g9tfsr2i0p0',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'jomdl5d9v0t',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'c7ju4zoufbl',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '1gghbos9qfe',
'x-async': false,
'x-index': 3,
},
},
'x-uid': 'zb2qwwdzugb',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'pqgy4fb9qdf',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'l1yqohzlnmw',
'x-async': false,
'x-index': 2,
},
},
'x-uid': 's4vgqg5htie',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '7mfd1t6kx6u',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'wmujeqpvlgw',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'r93k7xt0x5i',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 's2rlvbhn6g0',
'x-async': true,
'x-index': 1,
},
};

View File

@ -69,7 +69,6 @@ export function CustomRequestSettingsItem() {
'x-uid': fieldSchema['x-uid'],
},
});
refresh();
message.success(t('Saved successfully'));
}}
/>

View File

@ -9,6 +9,7 @@
import {
DEFAULT_DATA_SOURCE_KEY,
useBlockContext,
useCollection_deprecated,
useCollectionFilterOptions,
useCollectionRecordData,
@ -24,6 +25,7 @@ export const useCustomRequestVariableOptions = () => {
const userFieldOptions = useCollectionFilterOptions('users', DEFAULT_DATA_SOURCE_KEY);
const compile = useCompile();
const recordData = useCollectionRecordData();
const { name: blockType } = useBlockContext();
const [fields, userFields] = useMemo(() => {
return [compile(fieldsOptions), compile(userFieldOptions)];
@ -36,6 +38,11 @@ export const useCustomRequestVariableOptions = () => {
title: t('Current record', { ns: 'client' }),
children: [...fields],
},
blockType === 'form' && {
name: '$nForm',
title: t('Current form', { ns: 'client' }),
children: [...fields],
},
{
name: 'currentUser',
title: t('Current user', { ns: 'client' }),
@ -52,5 +59,5 @@ export const useCustomRequestVariableOptions = () => {
children: null,
},
].filter(Boolean);
}, [recordData, t, fields, userFields]);
}, [recordData, t, fields, blockType, userFields]);
};

View File

@ -11,10 +11,11 @@ import { useField, useFieldSchema, useForm } from '@formily/react';
import {
useAPIClient,
useActionContext,
useBlockContext,
useCollectionRecordData,
useCompile,
useDataSourceKey,
useNavigateNoUpdate,
useRecord,
} from '@nocobase/client';
import { isURL } from '@nocobase/utils/client';
import { App } from 'antd';
@ -26,8 +27,9 @@ export const useCustomizeRequestActionProps = () => {
const actionSchema = useFieldSchema();
const compile = useCompile();
const form = useForm();
const { name: blockType } = useBlockContext();
// const { getPrimaryKey } = useCollection_deprecated();
const record = useRecord();
const recordData = useCollectionRecordData();
const fieldSchema = useFieldSchema();
const actionField = useField();
const { setVisible } = useActionContext();
@ -42,11 +44,6 @@ export const useCustomizeRequestActionProps = () => {
await form.submit();
}
let formValues = { ...record };
if (xAction === 'customize:form:request') {
formValues = form.values;
}
actionField.data ??= {};
actionField.data.loading = true;
try {
@ -58,8 +55,9 @@ export const useCustomizeRequestActionProps = () => {
// id: record[getPrimaryKey()],
// appends: result.params[0]?.appends,
dataSourceKey,
data: formValues,
data: recordData,
},
$nForm: blockType === 'form' ? form.values : undefined,
},
responseType: fieldSchema['x-response-type'] === 'stream' ? 'blob' : 'json',
});

View File

@ -72,6 +72,7 @@ export async function send(this: CustomRequestPlugin, ctx: Context, next: Next)
appends: [],
data: {},
},
$nForm,
} = values;
// root role has all permissions
@ -152,6 +153,7 @@ export async function send(this: CustomRequestPlugin, ctx: Context, next: Next)
currentUser,
currentTime: new Date().toISOString(),
$nToken: ctx.getBearerToken(),
$nForm,
};
const axiosRequestConfig = {