From 350652a515f1cb0a51ec8ebecab19505febb0a26 Mon Sep 17 00:00:00 2001 From: Katherine Date: Sun, 19 May 2024 10:01:46 +0800 Subject: [PATCH] fix: the inherited field should be able to be set as the title field (#4394) --- .../Configuration/CollectionFields.tsx | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-data-source-manager/src/client/component/MainDataSourceManager/Configuration/CollectionFields.tsx b/packages/plugins/@nocobase/plugin-data-source-manager/src/client/component/MainDataSourceManager/Configuration/CollectionFields.tsx index b957c0626..c7035f686 100644 --- a/packages/plugins/@nocobase/plugin-data-source-manager/src/client/component/MainDataSourceManager/Configuration/CollectionFields.tsx +++ b/packages/plugins/@nocobase/plugin-data-source-manager/src/client/component/MainDataSourceManager/Configuration/CollectionFields.tsx @@ -219,13 +219,14 @@ const CurrentFields = (props) => { const InheritFields = (props) => { const compile = useCompile(); const { getInterface } = useCollectionManager_deprecated(); - const { resource, targetKey } = props.collectionResource || {}; + const { targetKey } = props.collectionResource || {}; const parentRecord = useRecord(); const [loadingRecord, setLoadingRecord] = React.useState(null); const { t } = useTranslation(); const { refreshCM, isTitleField } = useCollectionManager_deprecated(); const { [targetKey]: filterByTk, titleField, name } = parentRecord; const ctx = useContext(CollectionListContext); + const api = useAPIClient(); const columns: TableColumnProps[] = [ { @@ -246,20 +247,19 @@ const InheritFields = (props) => { dataIndex: 'titleField', title: t('Title field'), render(_, record) { - const handleChange = (checked) => { + const handleChange = async (checked) => { setLoadingRecord(record); - resource - .update({ filterByTk, values: { titleField: checked ? record.name : 'id' } }) - .then(async () => { - await props.refreshAsync(); - setLoadingRecord(null); - refreshCM(); - ctx?.refresh?.(); - }) - .catch((err) => { - setLoadingRecord(null); - console.error(err); - }); + + await api.request({ + url: `collections:update?filterByTk=${filterByTk}`, + method: 'post', + data: { titleField: checked ? record.name : 'id' }, + }); + message.success(t('Saved successfully')); + await props.refreshAsync(); + setLoadingRecord(null); + refreshCM(); + ctx?.refresh?.(); }; return isTitleField(record) ? (