From 0269a1ff7dee6bdb1624bf9540e65a4e919c4edf Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Mon, 25 Mar 2024 16:25:41 +0800 Subject: [PATCH] fix(Details): block template (#3807) * fix: add 'Details' in condition * fix: block template --- .../core/client/src/block-provider/BlockProvider.tsx | 4 +++- .../details-multi/multiDataDetailsBlockSettings.tsx | 3 ++- .../details-single/singleDataDetailsBlockSettings.ts | 3 ++- .../blocks/data-blocks/form/createFormBlockSettings.tsx | 6 ++++-- .../blocks/data-blocks/form/editFormBlockSettings.ts | 3 ++- .../data-blocks/grid-card/gridCardBlockSettings.ts | 3 ++- .../modules/blocks/data-blocks/list/listBlockSettings.ts | 3 ++- .../blocks/data-blocks/table/tableBlockSettings.tsx | 3 ++- .../collapse/filterCollapseBlockSettings.ts | 3 ++- .../blocks/filter-blocks/form/filterFormBlockSettings.ts | 3 ++- .../AssociationFilter.BlockDesigner.tsx | 3 ++- .../src/schema-component/antd/form-v2/Form.Settings.tsx | 9 ++++++--- .../antd/grid-card/GridCard.Designer.tsx | 3 ++- .../src/schema-component/antd/list/List.Designer.tsx | 3 ++- .../antd/table-v2/TableBlockDesigner.tsx | 3 ++- packages/core/client/src/schema-initializer/utils.ts | 9 +++++++++ .../core/client/src/schema-settings/SchemaSettings.tsx | 4 ++-- .../src/client/calendar/Calender.Settings.tsx | 3 ++- .../plugin-map/src/client/block/MapBlock.Settings.tsx | 3 ++- 19 files changed, 52 insertions(+), 22 deletions(-) diff --git a/packages/core/client/src/block-provider/BlockProvider.tsx b/packages/core/client/src/block-provider/BlockProvider.tsx index da97a5c09..80c9f344e 100644 --- a/packages/core/client/src/block-provider/BlockProvider.tsx +++ b/packages/core/client/src/block-provider/BlockProvider.tsx @@ -330,7 +330,9 @@ export const useParamsFromRecord = () => { const { fields } = useCollection_deprecated(); const fieldSchema = useFieldSchema(); const { getCollectionJoinField } = useCollectionManager_deprecated(); - const collectionField = getCollectionJoinField(fieldSchema?.['x-decorator-props']?.resource); + const collectionField = getCollectionJoinField( + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association, + ); const filterFields = fields .filter((v) => { return ['boolean', 'date', 'integer', 'radio', 'sort', 'string', 'time', 'uid', 'uuid'].includes(v.type); diff --git a/packages/core/client/src/modules/blocks/data-blocks/details-multi/multiDataDetailsBlockSettings.tsx b/packages/core/client/src/modules/blocks/data-blocks/details-multi/multiDataDetailsBlockSettings.tsx index d4a8601ef..8b52f5907 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/details-multi/multiDataDetailsBlockSettings.tsx +++ b/packages/core/client/src/modules/blocks/data-blocks/details-multi/multiDataDetailsBlockSettings.tsx @@ -177,7 +177,8 @@ export const multiDataDetailsBlockSettings = new SchemaSettings({ useComponentProps() { const { name } = useCollection_deprecated(); const fieldSchema = useFieldSchema(); - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; return { componentName: 'Details', collectionName: name, diff --git a/packages/core/client/src/modules/blocks/data-blocks/details-single/singleDataDetailsBlockSettings.ts b/packages/core/client/src/modules/blocks/data-blocks/details-single/singleDataDetailsBlockSettings.ts index cd130c554..c2bfdda96 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/details-single/singleDataDetailsBlockSettings.ts +++ b/packages/core/client/src/modules/blocks/data-blocks/details-single/singleDataDetailsBlockSettings.ts @@ -16,7 +16,8 @@ export const singleDataDetailsBlockSettings = new SchemaSettings({ useComponentProps() { const { name } = useCollection_deprecated(); const fieldSchema = useFieldSchema(); - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; return { insertAdjacentPosition: 'beforeEnd', componentName: 'ReadPrettyFormItem', diff --git a/packages/core/client/src/modules/blocks/data-blocks/form/createFormBlockSettings.tsx b/packages/core/client/src/modules/blocks/data-blocks/form/createFormBlockSettings.tsx index 0e7551ed9..c93d35087 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/form/createFormBlockSettings.tsx +++ b/packages/core/client/src/modules/blocks/data-blocks/form/createFormBlockSettings.tsx @@ -51,7 +51,8 @@ export const creationFormBlockSettings = new SchemaSettings({ useComponentProps() { const { name } = useCollection_deprecated(); const fieldSchema = useFieldSchema(); - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; return { componentName: 'FormItem', collectionName: name, @@ -117,7 +118,8 @@ export const createFormBlockSettings = new SchemaSettings({ useComponentProps() { const { name } = useCollection_deprecated(); const fieldSchema = useFieldSchema(); - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; return { componentName: 'FormItem', collectionName: name, diff --git a/packages/core/client/src/modules/blocks/data-blocks/form/editFormBlockSettings.ts b/packages/core/client/src/modules/blocks/data-blocks/form/editFormBlockSettings.ts index 134fa5235..f12f6a9a8 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/form/editFormBlockSettings.ts +++ b/packages/core/client/src/modules/blocks/data-blocks/form/editFormBlockSettings.ts @@ -50,7 +50,8 @@ export const editFormBlockSettings = new SchemaSettings({ useComponentProps() { const { name } = useCollection_deprecated(); const fieldSchema = useFieldSchema(); - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; return { componentName: 'FormItem', collectionName: name, diff --git a/packages/core/client/src/modules/blocks/data-blocks/grid-card/gridCardBlockSettings.ts b/packages/core/client/src/modules/blocks/data-blocks/grid-card/gridCardBlockSettings.ts index 11938ba5b..ce626c00c 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/grid-card/gridCardBlockSettings.ts +++ b/packages/core/client/src/modules/blocks/data-blocks/grid-card/gridCardBlockSettings.ts @@ -257,7 +257,8 @@ export const gridCardBlockSettings = new SchemaSettings({ useComponentProps() { const { name } = useCollection_deprecated(); const fieldSchema = useFieldSchema(); - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; return { componentName: 'GridCard', diff --git a/packages/core/client/src/modules/blocks/data-blocks/list/listBlockSettings.ts b/packages/core/client/src/modules/blocks/data-blocks/list/listBlockSettings.ts index 32b4b179b..627700a88 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/list/listBlockSettings.ts +++ b/packages/core/client/src/modules/blocks/data-blocks/list/listBlockSettings.ts @@ -196,7 +196,8 @@ export const listBlockSettings = new SchemaSettings({ useComponentProps() { const { name } = useCollection_deprecated(); const fieldSchema = useFieldSchema(); - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; return { componentName: 'List', diff --git a/packages/core/client/src/modules/blocks/data-blocks/table/tableBlockSettings.tsx b/packages/core/client/src/modules/blocks/data-blocks/table/tableBlockSettings.tsx index 3d9cdd7dc..2e8b96699 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/table/tableBlockSettings.tsx +++ b/packages/core/client/src/modules/blocks/data-blocks/table/tableBlockSettings.tsx @@ -359,7 +359,8 @@ export const tableBlockSettings = new SchemaSettings({ useComponentProps() { const { name } = useCollection_deprecated(); const fieldSchema = useFieldSchema(); - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; return { componentName: 'Table', collectionName: name, diff --git a/packages/core/client/src/modules/blocks/filter-blocks/collapse/filterCollapseBlockSettings.ts b/packages/core/client/src/modules/blocks/filter-blocks/collapse/filterCollapseBlockSettings.ts index 68d8b5263..0ad5faaec 100644 --- a/packages/core/client/src/modules/blocks/filter-blocks/collapse/filterCollapseBlockSettings.ts +++ b/packages/core/client/src/modules/blocks/filter-blocks/collapse/filterCollapseBlockSettings.ts @@ -22,7 +22,8 @@ export const filterCollapseBlockSettings = new SchemaSettings({ useComponentProps() { const { name } = useCollection_deprecated(); const fieldSchema = useFieldSchema(); - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; return { componentName: 'FilterCollapse', diff --git a/packages/core/client/src/modules/blocks/filter-blocks/form/filterFormBlockSettings.ts b/packages/core/client/src/modules/blocks/filter-blocks/form/filterFormBlockSettings.ts index 707e9aa67..46761790e 100644 --- a/packages/core/client/src/modules/blocks/filter-blocks/form/filterFormBlockSettings.ts +++ b/packages/core/client/src/modules/blocks/filter-blocks/form/filterFormBlockSettings.ts @@ -23,7 +23,8 @@ export const filterFormBlockSettings = new SchemaSettings({ useComponentProps() { const { name } = useCollection_deprecated(); const fieldSchema = useFieldSchema(); - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; return { componentName: 'FilterFormItem', collectionName: name, diff --git a/packages/core/client/src/schema-component/antd/association-filter/AssociationFilter.BlockDesigner.tsx b/packages/core/client/src/schema-component/antd/association-filter/AssociationFilter.BlockDesigner.tsx index 387d31e92..2bf44589e 100644 --- a/packages/core/client/src/schema-component/antd/association-filter/AssociationFilter.BlockDesigner.tsx +++ b/packages/core/client/src/schema-component/antd/association-filter/AssociationFilter.BlockDesigner.tsx @@ -18,7 +18,8 @@ export const AssociationFilterBlockDesigner = () => { const template = useSchemaTemplate(); const fieldSchema = useFieldSchema(); const { t } = useTranslation(); - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; return ( diff --git a/packages/core/client/src/schema-component/antd/form-v2/Form.Settings.tsx b/packages/core/client/src/schema-component/antd/form-v2/Form.Settings.tsx index 55c57c97f..d6e033988 100644 --- a/packages/core/client/src/schema-component/antd/form-v2/Form.Settings.tsx +++ b/packages/core/client/src/schema-component/antd/form-v2/Form.Settings.tsx @@ -62,7 +62,8 @@ export const formSettings = new SchemaSettings({ useComponentProps() { const { name } = useCollection_deprecated(); const fieldSchema = useFieldSchema(); - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; return { componentName: 'FormItem', collectionName: name, @@ -103,7 +104,8 @@ export const readPrettyFormSettings = new SchemaSettings({ useComponentProps() { const { name } = useCollection_deprecated(); const fieldSchema = useFieldSchema(); - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; return { insertAdjacentPosition: 'beforeEnd', componentName: 'ReadPrettyFormItem', @@ -294,7 +296,8 @@ export const formDetailsSettings = new SchemaSettings({ useComponentProps() { const { name } = useCollection_deprecated(); const fieldSchema = useFieldSchema(); - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; return { componentName: 'Details', collectionName: name, diff --git a/packages/core/client/src/schema-component/antd/grid-card/GridCard.Designer.tsx b/packages/core/client/src/schema-component/antd/grid-card/GridCard.Designer.tsx index ce216ba07..d48bc8a01 100644 --- a/packages/core/client/src/schema-component/antd/grid-card/GridCard.Designer.tsx +++ b/packages/core/client/src/schema-component/antd/grid-card/GridCard.Designer.tsx @@ -39,7 +39,8 @@ export const GridCardDesigner = () => { const sortFields = useSortFields(name); const record = useRecord(); const defaultSort = fieldSchema?.['x-decorator-props']?.params?.sort || []; - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; const columnCount = field.decoratorProps.columnCount || defaultColumnCount; const columnCountSchema = useMemo(() => { diff --git a/packages/core/client/src/schema-component/antd/list/List.Designer.tsx b/packages/core/client/src/schema-component/antd/list/List.Designer.tsx index 65f4859dd..ed8de4bcf 100644 --- a/packages/core/client/src/schema-component/antd/list/List.Designer.tsx +++ b/packages/core/client/src/schema-component/antd/list/List.Designer.tsx @@ -35,7 +35,8 @@ export const ListDesigner = () => { const sortFields = useSortFields(name); const record = useRecord(); const defaultSort = fieldSchema?.['x-decorator-props']?.params?.sort || []; - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; const sort = defaultSort?.map((item: string) => { return item.startsWith('-') ? { diff --git a/packages/core/client/src/schema-component/antd/table-v2/TableBlockDesigner.tsx b/packages/core/client/src/schema-component/antd/table-v2/TableBlockDesigner.tsx index 947440c26..c823057da 100644 --- a/packages/core/client/src/schema-component/antd/table-v2/TableBlockDesigner.tsx +++ b/packages/core/client/src/schema-component/antd/table-v2/TableBlockDesigner.tsx @@ -78,7 +78,8 @@ export const TableBlockDesigner = () => { const { dn } = useDesignable(); const defaultSort = fieldSchema?.['x-decorator-props']?.params?.sort || []; - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; const supportTemplate = !fieldSchema?.['x-decorator-props']?.disableTemplate; const sort = defaultSort?.map((item: string) => { return item?.startsWith('-') diff --git a/packages/core/client/src/schema-initializer/utils.ts b/packages/core/client/src/schema-initializer/utils.ts index 36ec4d353..6b7adf2c0 100644 --- a/packages/core/client/src/schema-initializer/utils.ts +++ b/packages/core/client/src/schema-initializer/utils.ts @@ -1685,6 +1685,15 @@ function useAssociationFields({ const targetCollection = cm.getCollection(field.target); const title = `${compile(field.uiSchema.title || field.name)} -> ${compile(targetCollection.title)}`; const templates = getTemplatesByCollection(dataSource, field.target).filter((template) => { + // 针对弹窗中的详情区块 + if (componentName === 'ReadPrettyFormItem') { + if (['hasOne', 'belongsTo'].includes(field.type)) { + return template.componentName === 'ReadPrettyFormItem'; + } else { + return template.componentName === 'Details'; + } + } + return ( componentName && template.componentName === componentName && diff --git a/packages/core/client/src/schema-settings/SchemaSettings.tsx b/packages/core/client/src/schema-settings/SchemaSettings.tsx index cbea0aee2..b32307f7e 100644 --- a/packages/core/client/src/schema-settings/SchemaSettings.tsx +++ b/packages/core/client/src/schema-settings/SchemaSettings.tsx @@ -291,7 +291,7 @@ export const SchemaSettingsTemplate = function Template(props) { const findGridSchema = (fieldSchema) => { return fieldSchema.reduceProperties((buf, s) => { - if (s['x-component'] === 'FormV2') { + if (s['x-component'] === 'FormV2' || s['x-component'] === 'Details') { const f = s.reduceProperties((buf, s) => { if (s['x-component'] === 'Grid' || s['x-component'] === 'BlockTemplate') { return s; @@ -308,7 +308,7 @@ const findGridSchema = (fieldSchema) => { const findBlockTemplateSchema = (fieldSchema) => { return fieldSchema.reduceProperties((buf, s) => { - if (s['x-component'] === 'FormV2') { + if (s['x-component'] === 'FormV2' || s['x-component'] === 'Details') { const f = s.reduceProperties((buf, s) => { if (s['x-component'] === 'BlockTemplate') { return s; diff --git a/packages/plugins/@nocobase/plugin-calendar/src/client/calendar/Calender.Settings.tsx b/packages/plugins/@nocobase/plugin-calendar/src/client/calendar/Calender.Settings.tsx index 0180f9792..2e3260b09 100644 --- a/packages/plugins/@nocobase/plugin-calendar/src/client/calendar/Calender.Settings.tsx +++ b/packages/plugins/@nocobase/plugin-calendar/src/client/calendar/Calender.Settings.tsx @@ -205,7 +205,8 @@ export const calendarBlockSettings = new SchemaSettings({ useComponentProps() { const { name } = useCollection(); const fieldSchema = useFieldSchema(); - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; return { componentName: 'Calendar', collectionName: name, diff --git a/packages/plugins/@nocobase/plugin-map/src/client/block/MapBlock.Settings.tsx b/packages/plugins/@nocobase/plugin-map/src/client/block/MapBlock.Settings.tsx index a396d73b5..2244bc7ec 100644 --- a/packages/plugins/@nocobase/plugin-map/src/client/block/MapBlock.Settings.tsx +++ b/packages/plugins/@nocobase/plugin-map/src/client/block/MapBlock.Settings.tsx @@ -230,7 +230,8 @@ export const mapBlockSettings = new SchemaSettings({ useComponentProps() { const { name } = useCollection(); const fieldSchema = useFieldSchema(); - const defaultResource = fieldSchema?.['x-decorator-props']?.resource; + const defaultResource = + fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association; return { componentName: 'Map', collectionName: name,