mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-02 12:18:15 +08:00
fix: collection support title field setting (#4322)
This commit is contained in:
parent
31b410dd69
commit
086984cb90
@ -10,8 +10,8 @@
|
|||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import { createForm, Field } from '@formily/core';
|
import { createForm, Field } from '@formily/core';
|
||||||
import { FieldContext, FormContext, useField } from '@formily/react';
|
import { FieldContext, FormContext, useField } from '@formily/react';
|
||||||
import { Space, Switch, Table, TableColumnProps, Tag, Tooltip } from 'antd';
|
import { Space, Switch, Table, TableColumnProps, Tag, Tooltip, message } from 'antd';
|
||||||
import React, { useContext, useMemo, createContext, useState } from 'react';
|
import React, { useContext, useMemo, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import {
|
import {
|
||||||
Action,
|
Action,
|
||||||
@ -36,6 +36,7 @@ import {
|
|||||||
useResourceActionContext,
|
useResourceActionContext,
|
||||||
useResourceContext,
|
useResourceContext,
|
||||||
ViewCollectionField,
|
ViewCollectionField,
|
||||||
|
useAPIClient,
|
||||||
} from '@nocobase/client';
|
} from '@nocobase/client';
|
||||||
|
|
||||||
import { collection } from './schemas/collectionFields';
|
import { collection } from './schemas/collectionFields';
|
||||||
@ -96,12 +97,16 @@ const CurrentFields = (props) => {
|
|||||||
const { getInterface } = useCollectionManager_deprecated();
|
const { getInterface } = useCollectionManager_deprecated();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { setState } = useResourceActionContext();
|
const { setState } = useResourceActionContext();
|
||||||
const { resource, targetKey } = props.collectionResource || {};
|
const { targetKey } = props.collectionResource || {};
|
||||||
const parentRecordData = useRecord();
|
const parentRecordData = useRecord();
|
||||||
const [loadingRecord, setLoadingRecord] = React.useState<any>(null);
|
const [loadingRecord, setLoadingRecord] = React.useState<any>(null);
|
||||||
const { refreshCM, isTitleField, getTemplate } = useCollectionManager_deprecated();
|
const { refreshCM, isTitleField, getTemplate } = useCollectionManager_deprecated();
|
||||||
const { [targetKey]: filterByTk, titleField, template } = parentRecordData;
|
const { [targetKey]: filterByTk, titleField: targetTitleField, template } = parentRecordData;
|
||||||
|
const [titleField, setTitleField] = useState(targetTitleField);
|
||||||
|
|
||||||
const targetTemplate = getTemplate(template);
|
const targetTemplate = getTemplate(template);
|
||||||
|
const api = useAPIClient();
|
||||||
|
|
||||||
const columns: TableColumnProps<any>[] = [
|
const columns: TableColumnProps<any>[] = [
|
||||||
{
|
{
|
||||||
dataIndex: ['uiSchema', 'title'],
|
dataIndex: ['uiSchema', 'title'],
|
||||||
@ -121,19 +126,18 @@ const CurrentFields = (props) => {
|
|||||||
dataIndex: 'titleField',
|
dataIndex: 'titleField',
|
||||||
title: t('Title field'),
|
title: t('Title field'),
|
||||||
render: function Render(_, record) {
|
render: function Render(_, record) {
|
||||||
const handleChange = (checked) => {
|
const handleChange = async (checked) => {
|
||||||
setLoadingRecord(record);
|
setLoadingRecord(record);
|
||||||
resource
|
await api.request({
|
||||||
.update({ filterByTk, values: { titleField: checked ? record.name : 'id' } })
|
url: `collections:update?filterByTk=${filterByTk}`,
|
||||||
.then(async () => {
|
method: 'post',
|
||||||
await props.refreshAsync();
|
data: { titleField: checked ? record.name : 'id' },
|
||||||
setLoadingRecord(null);
|
});
|
||||||
refreshCM();
|
message.success(t('Saved successfully'));
|
||||||
})
|
setTitleField(checked ? record.name : 'id');
|
||||||
.catch((err) => {
|
await props.refreshAsync();
|
||||||
setLoadingRecord(null);
|
setLoadingRecord(null);
|
||||||
console.error(err);
|
refreshCM();
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return isTitleField(record) ? (
|
return isTitleField(record) ? (
|
||||||
|
Loading…
Reference in New Issue
Block a user