From 9a66301ec75afac445c93ee703918d6e45e092b0 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Thu, 28 Mar 2024 16:47:43 +0800 Subject: [PATCH] refactor: default role & default field storage (#3844) * refactor: default role & default field storage * refactor: verification * refactor: verification --- .../core/client/src/schema-component/antd/form/Form.tsx | 1 + .../@nocobase/plugin-acl/src/client/schemas/roles.ts | 7 +++++++ .../plugin-file-manager/src/client/FileStorage.tsx | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/packages/core/client/src/schema-component/antd/form/Form.tsx b/packages/core/client/src/schema-component/antd/form/Form.tsx index d3375b044..3f3c20469 100644 --- a/packages/core/client/src/schema-component/antd/form/Form.tsx +++ b/packages/core/client/src/schema-component/antd/form/Form.tsx @@ -101,6 +101,7 @@ export const Form: React.FC & { Designer?: any } = observer( async onSuccess(data) { await form.reset(); form.setValues(data?.data); + form.setInitialValues(data?.data); }, }, props, diff --git a/packages/plugins/@nocobase/plugin-acl/src/client/schemas/roles.ts b/packages/plugins/@nocobase/plugin-acl/src/client/schemas/roles.ts index 3d3643ceb..5e9321d22 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/client/schemas/roles.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/client/schemas/roles.ts @@ -43,6 +43,13 @@ export const roleEditSchema = { 'x-component': 'CollectionField', 'x-decorator': 'FormItem', 'x-content': '{{t("Default role")}}', + 'x-reactions': (field) => { + if (field.initialValue) { + field.disabled = true; + } else { + field.disabled = false; + } + }, }, footer: { type: 'void', diff --git a/packages/plugins/@nocobase/plugin-file-manager/src/client/FileStorage.tsx b/packages/plugins/@nocobase/plugin-file-manager/src/client/FileStorage.tsx index 83ab7d0f9..850e50e54 100644 --- a/packages/plugins/@nocobase/plugin-file-manager/src/client/FileStorage.tsx +++ b/packages/plugins/@nocobase/plugin-file-manager/src/client/FileStorage.tsx @@ -96,6 +96,15 @@ export const EditStorage = () => { onClick={() => { setVisible(true); const storageType = plugin.storageTypes.get(record.type); + if (storageType.properties['default']) { + storageType.properties['default']['x-reactions'] = (field) => { + if (field.initialValue) { + field.disabled = true; + } else { + field.disabled = false; + } + }; + } setSchema({ type: 'object', properties: {