From fda30fd519a2c4793af8e86aa04452a630fcaabd Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Tue, 2 Jan 2024 17:36:28 +0800 Subject: [PATCH] fix: dateformat setting should support sub-table/table block (#3297) * fix: dateformat should effect immediately in sub-table * refactor: dateformat setting for sub-table/table block * refactor: dateformat setting for sub-table/table block * refactor: schemaSettingsDateFormat --- .../antd/form-item/FormItem.Settings.tsx | 4 ++-- .../antd/table-v2/Table.Column.Designer.tsx | 4 ++-- .../client/src/schema-settings/SchemaSettings.tsx | 11 +++++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/form-item/FormItem.Settings.tsx b/packages/core/client/src/schema-component/antd/form-item/FormItem.Settings.tsx index 50b5487c9..63c66a968 100644 --- a/packages/core/client/src/schema-component/antd/form-item/FormItem.Settings.tsx +++ b/packages/core/client/src/schema-component/antd/form-item/FormItem.Settings.tsx @@ -11,7 +11,7 @@ import { Collection, useCollection, useCollectionManager } from '../../../collec import { useRecord } from '../../../record-provider'; import { generalSettingsItems } from '../../../schema-items/GeneralSettings'; import { - SchemaSettingsDataFormat, + SchemaSettingsDateFormat, SchemaSettingsDataScope, SchemaSettingsDefaultValue, SchemaSettingsSortingRule, @@ -732,7 +732,7 @@ export const formItemSettings = new SchemaSettings({ }, { name: 'dateFormat', - Component: SchemaSettingsDataFormat, + Component: SchemaSettingsDateFormat, useVisible() { const collectionField = useCollectionField(); const isDateField = ['datetime', 'createdAt', 'updatedAt'].includes(collectionField?.interface); diff --git a/packages/core/client/src/schema-component/antd/table-v2/Table.Column.Designer.tsx b/packages/core/client/src/schema-component/antd/table-v2/Table.Column.Designer.tsx index 2ab8b105e..099e4f938 100644 --- a/packages/core/client/src/schema-component/antd/table-v2/Table.Column.Designer.tsx +++ b/packages/core/client/src/schema-component/antd/table-v2/Table.Column.Designer.tsx @@ -6,7 +6,7 @@ import { useFormBlockContext } from '../../../block-provider'; import { useCollectionManager } from '../../../collection-manager'; import { GeneralSchemaDesigner, - SchemaSettingsDataFormat, + SchemaSettingsDateFormat, SchemaSettingsDataScope, SchemaSettingsDefaultValue, SchemaSettingsDivider, @@ -392,7 +392,7 @@ export const TableColumnDesigner = (props) => { }} /> )} - {isDateField && } + {isDateField && } {isSubTableColumn && !field?.readPretty && ['obo', 'oho', 'o2o', 'o2m', 'm2m', 'm2o'].includes(collectionField?.interface) && ( diff --git a/packages/core/client/src/schema-settings/SchemaSettings.tsx b/packages/core/client/src/schema-settings/SchemaSettings.tsx index 20a490936..236dad184 100644 --- a/packages/core/client/src/schema-settings/SchemaSettings.tsx +++ b/packages/core/client/src/schema-settings/SchemaSettings.tsx @@ -1428,10 +1428,9 @@ export const SchemaSettingsEnableChildCollections = function EnableChildCollecti ); }; -export const SchemaSettingsDataFormat = function DateFormatConfig(props: { fieldSchema: Schema }) { +export const SchemaSettingsDateFormat = function DateFormatConfig(props: { fieldSchema: Schema }) { const { fieldSchema } = props; const field = useField(); - const form = useForm(); const { dn } = useDesignable(); const { t } = useTranslation(); const { getCollectionJoinField } = useCollectionManager(); @@ -1561,8 +1560,12 @@ export const SchemaSettingsDataFormat = function DateFormatConfig(props: { field }; schema['x-component-props'] = fieldSchema['x-component-props']; field.componentProps = fieldSchema['x-component-props']; - field.query(`.*.${fieldSchema.name}`).forEach((f) => { - f.componentProps = fieldSchema['x-component-props']; + //子表格/表格区块 + const parts = (field.path.entire as string).split('.'); + parts.pop(); + const modifiedString = parts.join('.'); + field.query(`${modifiedString}.*[0:].${fieldSchema.name}`).forEach((f) => { + f.setComponentProps({ ...data }); }); dn.emit('patch', { schema,