From a44c582b1d9a3c29fdaddb34ab3cc7f49daed056 Mon Sep 17 00:00:00 2001 From: sealday Date: Tue, 19 Mar 2024 13:09:14 +0800 Subject: [PATCH] fix: add schema item max stack exceeded --- .../@hera/plugin-core/src/client/index.tsx | 16 ++++---- .../SchemaSettingsFieldComponent copy.tsx | 41 ------------------- .../SchemaSettingsFieldComponent.tsx | 34 ++++++++++++++- .../FilterFormItemCustom.tsx | 3 +- .../@hera/plugin-rental/src/client/index.tsx | 6 +-- 5 files changed, 46 insertions(+), 54 deletions(-) delete mode 100644 packages/plugins/@hera/plugin-core/src/client/schema-components/SchemaSettingsFieldComponent copy.tsx diff --git a/packages/plugins/@hera/plugin-core/src/client/index.tsx b/packages/plugins/@hera/plugin-core/src/client/index.tsx index d94162fbb..3998796b0 100644 --- a/packages/plugins/@hera/plugin-core/src/client/index.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/index.tsx @@ -143,6 +143,15 @@ export class PluginCoreClient extends Plugin { (item as SchemaSettingOptions).Component = AfterSuccess; } }); + + // 预览区块需要提前加进来,没法放在 afterload 中,这块后面需要重构 + const previewBlockItem = { + title: tval('preview block'), + name: 'previewBlock', + type: 'itemGroup', + children: [], + }; + this.app.schemaInitializerManager.get('popup:common:addBlock').add(previewBlockItem.name, previewBlockItem); } async registerActions() { @@ -319,13 +328,6 @@ export class PluginCoreClient extends Plugin { addCustomComponent.name, addCustomComponent, ); - const previewBlockItem = { - title: tval('preview block'), - name: 'previewBlock', - type: 'itemGroup', - children: [], - }; - this.app.schemaInitializerManager.get('RecordBlockInitializers').add(previewBlockItem.name, previewBlockItem); } async registerInterfaces() { diff --git a/packages/plugins/@hera/plugin-core/src/client/schema-components/SchemaSettingsFieldComponent copy.tsx b/packages/plugins/@hera/plugin-core/src/client/schema-components/SchemaSettingsFieldComponent copy.tsx deleted file mode 100644 index 58c41558d..000000000 --- a/packages/plugins/@hera/plugin-core/src/client/schema-components/SchemaSettingsFieldComponent copy.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import { useField, useFieldSchema, useForm } from '@formily/react'; -import { - SchemaSettingsSelectItem, - useCollection, - useCollectionField, - useCollectionManager, - useDesignable, -} from '@nocobase/client'; -import React from 'react'; - -export const SchemaSettingCollection = () => { - const fieldSchema = useFieldSchema(); - const field = useField(); - const collections = useCollectionManager(); - const options = collections?.dataSource['options']?.collections.map((value) => { - return { - label: value.name, - value: value.name, - }; - }); - const { dn } = useDesignable(); - return ( - { - fieldSchema['collectionName'] = name; - fieldSchema['name'] = 'custom.' + name; - const schema = { - ['x-uid']: fieldSchema['x-uid'], - collectionName: name, - name: 'custom.' + name, - }; - void dn.emit('patch', { schema }); - dn.refresh(); - }} - /> - ); -}; diff --git a/packages/plugins/@hera/plugin-core/src/client/schema-components/SchemaSettingsFieldComponent.tsx b/packages/plugins/@hera/plugin-core/src/client/schema-components/SchemaSettingsFieldComponent.tsx index 2a832fcc6..6d7184a9a 100644 --- a/packages/plugins/@hera/plugin-core/src/client/schema-components/SchemaSettingsFieldComponent.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/schema-components/SchemaSettingsFieldComponent.tsx @@ -1,5 +1,5 @@ import { useField, useFieldSchema } from '@formily/react'; -import { SchemaSettingsSelectItem, useDesignable } from '@nocobase/client'; +import { SchemaSettingsSelectItem, useCollectionManager, useDesignable } from '@nocobase/client'; import { useFieldComponents } from '../schema-initializer/FilterFormItemCustomInitializer/FilterFormItemCustom'; import React from 'react'; @@ -28,3 +28,35 @@ export const SchemaSettingComponent = () => { /> ); }; + +export const SchemaSettingCollection = () => { + const fieldSchema = useFieldSchema(); + const field = useField(); + const collections = useCollectionManager(); + const options = collections?.dataSource['options']?.collections.map((value) => { + return { + label: value.name, + value: value.name, + }; + }); + const { dn } = useDesignable(); + return ( + { + fieldSchema['collectionName'] = name; + fieldSchema['name'] = 'custom.' + name; + const schema = { + ['x-uid']: fieldSchema['x-uid'], + collectionName: name, + name: 'custom.' + name, + }; + void dn.emit('patch', { schema }); + dn.refresh(); + }} + /> + ); +}; diff --git a/packages/plugins/@hera/plugin-core/src/client/schema-initializer/FilterFormItemCustomInitializer/FilterFormItemCustom.tsx b/packages/plugins/@hera/plugin-core/src/client/schema-initializer/FilterFormItemCustomInitializer/FilterFormItemCustom.tsx index 5c5dcef57..cfc1cb8b7 100644 --- a/packages/plugins/@hera/plugin-core/src/client/schema-initializer/FilterFormItemCustomInitializer/FilterFormItemCustom.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/schema-initializer/FilterFormItemCustomInitializer/FilterFormItemCustom.tsx @@ -34,8 +34,7 @@ import { EditFormulaTitleField, EditTitle, EditTitleField } from '../../schema-s import _ from 'lodash'; import { SchemaSettingsRemove } from '../../components/FormFilter/SchemaSettingsRemove'; import { useTranslation } from '../../locale'; -import { SchemaSettingComponent } from '../../schema-components/SchemaSettingsFieldComponent'; -import { SchemaSettingCollection } from '../../schema-components/SchemaSettingsFieldComponent copy'; +import { SchemaSettingComponent, SchemaSettingCollection } from '../../schema-components/SchemaSettingsFieldComponent'; export const useFieldComponents = () => { const { t } = useTranslation(); diff --git a/packages/plugins/@hera/plugin-rental/src/client/index.tsx b/packages/plugins/@hera/plugin-rental/src/client/index.tsx index 0c529eb65..15d245b8b 100644 --- a/packages/plugins/@hera/plugin-rental/src/client/index.tsx +++ b/packages/plugins/@hera/plugin-rental/src/client/index.tsx @@ -118,7 +118,7 @@ export class PluginRentalClient extends Plugin { return name === 'settlements'; }, }); - this.app.schemaInitializerManager.addItem('RecordBlockInitializers', 'previewBlock.record', { + this.app.schemaInitializerManager.addItem('popup:common:addBlock', 'previewBlock.record', { key: 'record', type: 'item', title: tval('record'), @@ -127,7 +127,7 @@ export class PluginRentalClient extends Plugin { usePdfPath: '{{ useRecordPdfPath }}', target: 'record', }); - this.app.schemaInitializerManager.addItem('RecordBlockInitializers', 'previewBlock.waybill', { + this.app.schemaInitializerManager.addItem('popup:common:addBlock', 'previewBlock.waybill', { key: 'waybill', type: 'item', title: tval('waybill'), @@ -136,7 +136,7 @@ export class PluginRentalClient extends Plugin { usePdfPath: '{{ useWaybillPdfPath }}', target: 'waybill', }); - this.app.schemaInitializerManager.addItem('RecordBlockInitializers', 'previewBlock.settlement', { + this.app.schemaInitializerManager.addItem('popup:common:addBlock', 'previewBlock.settlement', { key: 'settlement', type: 'item', title: tval('settlement'),