fix: the inherited field should be able to be set as the title field (#4394)

This commit is contained in:
Katherine 2024-05-19 10:01:46 +08:00 committed by GitHub
parent 144338be90
commit 350652a515
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<any>[] = [
{
@ -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) ? (