From 28222fce99b8aa483d3d5b624abd671b73db4e85 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Mon, 26 Feb 2024 21:26:02 +0800 Subject: [PATCH] fix: actions schema key should be uid (#3570) * fix: actions in table column should be uid * fix: actins name in form block * fix: actions schema key should be uid * fix: actions schema key should be uid --- .../items/TableActionColumnInitializer.tsx | 4 ++-- packages/core/client/src/schema-initializer/utils.ts | 10 +++++----- .../src/client/instruction/FormBlockInitializer.tsx | 8 ++++++-- .../src/client/instruction/forms/create.tsx | 5 ++++- .../src/client/instruction/forms/custom.tsx | 5 ++++- .../src/client/instruction/forms/update.tsx | 5 ++++- 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/packages/core/client/src/schema-initializer/items/TableActionColumnInitializer.tsx b/packages/core/client/src/schema-initializer/items/TableActionColumnInitializer.tsx index a96b90723..35fae6ebd 100644 --- a/packages/core/client/src/schema-initializer/items/TableActionColumnInitializer.tsx +++ b/packages/core/client/src/schema-initializer/items/TableActionColumnInitializer.tsx @@ -1,5 +1,5 @@ import React from 'react'; - +import { uid } from '@formily/shared'; import { InitializerWithSwitch } from './InitializerWithSwitch'; import { useSchemaInitializerItem } from '../../application'; @@ -13,7 +13,7 @@ export const TableActionColumnInitializer = () => { 'x-initializer': 'TableActionColumnInitializers', 'x-action-column': 'actions', properties: { - actions: { + [uid()]: { type: 'void', 'x-decorator': 'DndContext', 'x-component': 'Space', diff --git a/packages/core/client/src/schema-initializer/utils.ts b/packages/core/client/src/schema-initializer/utils.ts index 4d70177e9..ba516f42e 100644 --- a/packages/core/client/src/schema-initializer/utils.ts +++ b/packages/core/client/src/schema-initializer/utils.ts @@ -1193,7 +1193,7 @@ export const createFormBlockSchema = (options) => { 'x-initializer': formItemInitializers, properties: {}, }, - actions: { + [uid()]: { type: 'void', 'x-initializer': actionInitializers, 'x-component': 'ActionBar', @@ -1254,7 +1254,7 @@ export const createFilterFormBlockSchema = (options) => { 'x-initializer': formItemInitializers, properties: {}, }, - actions: { + [uid()]: { type: 'void', 'x-initializer': actionInitializers, 'x-component': 'ActionBar', @@ -1308,7 +1308,7 @@ export const createReadPrettyFormBlockSchema = (options) => { useProps: '{{ useFormBlockProps }}', }, properties: { - actions: { + [uid()]: { type: 'void', 'x-initializer': actionInitializers, 'x-component': 'ActionBar', @@ -1402,7 +1402,7 @@ export const createTableBlockSchema = (options) => { 'x-designer': 'TableV2.ActionColumnDesigner', 'x-initializer': tableActionColumnInitializers ?? 'TableActionColumnInitializers', properties: { - actions: { + [uid()]: { type: 'void', 'x-decorator': 'DndContext', 'x-component': 'Space', @@ -1470,7 +1470,7 @@ export const createTableSelectorSchema = (options) => { 'x-designer': 'TableSelectorDesigner', 'x-component': 'CardItem', properties: { - actions: { + [uid()]: { type: 'void', 'x-initializer': 'TableActionInitializers', 'x-component': 'ActionBar', diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/FormBlockInitializer.tsx b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/FormBlockInitializer.tsx index 2d8b2546c..5bb5ee3b8 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/FormBlockInitializer.tsx +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/FormBlockInitializer.tsx @@ -46,8 +46,12 @@ function InternalFormBlockInitializer({ schema, ...others }) { delete result['x-acl-action-props']; delete result['x-acl-action']; const [formKey] = Object.keys(result.properties); - result.properties[formKey].properties.actions['x-decorator'] = 'ActionBarProvider'; - result.properties[formKey].properties.actions['x-component-props'].style = { + //获取actionBar的schemakey + const actionKey = + Object.entries(result.properties[formKey].properties).find(([key, f]) => f['x-component'] === 'ActionBar')?.[0] || + 'actions'; + result.properties[formKey].properties[actionKey]['x-decorator'] = 'ActionBarProvider'; + result.properties[formKey].properties[actionKey]['x-component-props'].style = { marginTop: '1.5em', flexWrap: 'wrap', }; diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/forms/create.tsx b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/forms/create.tsx index e1fde959a..1ae095fd8 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/forms/create.tsx +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/forms/create.tsx @@ -87,10 +87,13 @@ export default { formBlocks.forEach((formBlock) => { const [formKey] = Object.keys(formBlock.properties); const formSchema = formBlock.properties[formKey]; + //获取actionBar的schemakey + const actionKey = + Object.entries(formSchema.properties).find(([key, f]) => f['x-component'] === 'ActionBar')?.[0] || 'actions'; forms[formKey] = { type: 'create', title: formBlock['x-component-props']?.title || formKey, - actions: findSchema(formSchema.properties.actions, (item) => item['x-component'] === 'Action').map( + actions: findSchema(formSchema.properties[actionKey], (item) => item['x-component'] === 'Action').map( (item) => ({ status: item['x-decorator-props'].value, values: item['x-action-settings']?.assignedValues?.values, diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/forms/custom.tsx b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/forms/custom.tsx index d431060a5..bde085a07 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/forms/custom.tsx +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/forms/custom.tsx @@ -378,10 +378,13 @@ export default { formBlock['x-decorator-props'].collection.fields = fields.map( (field) => field['x-component-props']?.field ?? field['x-interface-options'], ); + //获取actionBar的schemakey + const actionKey = + Object.entries(formSchema.properties).find(([key, f]) => f['x-component'] === 'ActionBar')?.[0] || 'actions'; forms[formKey] = { type: 'custom', title: formBlock['x-component-props']?.title || formKey, - actions: findSchema(formSchema.properties.actions, (item) => item['x-component'] === 'Action').map( + actions: findSchema(formSchema.properties[actionKey], (item) => item['x-component'] === 'Action').map( (item) => ({ status: item['x-decorator-props'].value, values: item['x-action-settings']?.assignedValues?.values, diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/forms/update.tsx b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/forms/update.tsx index 2a8e26eee..479d22cf2 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/forms/update.tsx +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/instruction/forms/update.tsx @@ -125,11 +125,14 @@ export default { formBlocks.forEach((formBlock) => { const [formKey] = Object.keys(formBlock.properties); const formSchema = formBlock.properties[formKey]; + //获取actionBar的schemakey + const actionKey = + Object.entries(formSchema.properties).find(([key, f]) => f['x-component'] === 'ActionBar')?.[0] || 'actions'; forms[formKey] = { ...formBlock['x-decorator-props'], type: 'update', title: formBlock['x-component-props']?.title || formKey, - actions: findSchema(formSchema.properties.actions, (item) => item['x-component'] === 'Action').map( + actions: findSchema(formSchema.properties[actionKey], (item) => item['x-component'] === 'Action').map( (item) => ({ status: item['x-decorator-props'].value, values: item['x-action-settings']?.assignedValues?.values,