mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 11:12:20 +08:00
fix: collection fields should refreshed after editing sync from database (#4224)
* fix: collection fields table should refreshed after editing collection field * fix: bug
This commit is contained in:
parent
a5a270d641
commit
0602bb9ab8
@ -190,7 +190,7 @@ export const EditFieldAction = (props) => {
|
|||||||
return (
|
return (
|
||||||
record?.fields ||
|
record?.fields ||
|
||||||
getCollection(record.collectionName)
|
getCollection(record.collectionName)
|
||||||
.options.fields.filter((v) => {
|
?.options.fields.filter((v) => {
|
||||||
return ['string', 'bigInt', 'integer'].includes(v.type);
|
return ['string', 'bigInt', 'integer'].includes(v.type);
|
||||||
})
|
})
|
||||||
.map((k) => {
|
.map((k) => {
|
||||||
|
@ -111,15 +111,7 @@ const getIsOverriding = (currentFields, record) => {
|
|||||||
return flag;
|
return flag;
|
||||||
};
|
};
|
||||||
export const OverridingFieldAction = (props) => {
|
export const OverridingFieldAction = (props) => {
|
||||||
const {
|
const { scope, getContainer, item: record, parentItem: parentRecord, children, currentCollection } = props;
|
||||||
scope,
|
|
||||||
getContainer,
|
|
||||||
item: record,
|
|
||||||
parentItem: parentRecord,
|
|
||||||
children,
|
|
||||||
currentCollection,
|
|
||||||
handleRefresh,
|
|
||||||
} = props;
|
|
||||||
const { target, through } = record;
|
const { target, through } = record;
|
||||||
const { getInterface, getCurrentCollectionFields, getChildrenCollections, collections } =
|
const { getInterface, getCurrentCollectionFields, getChildrenCollections, collections } =
|
||||||
useCollectionManager_deprecated();
|
useCollectionManager_deprecated();
|
||||||
@ -175,7 +167,6 @@ export const OverridingFieldAction = (props) => {
|
|||||||
await form.reset();
|
await form.reset();
|
||||||
await refreshCM();
|
await refreshCM();
|
||||||
await refresh();
|
await refresh();
|
||||||
handleRefresh?.();
|
|
||||||
ctx.setVisible(false);
|
ctx.setVisible(false);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -57,6 +57,11 @@ const resourceActionProps = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const CollectionFieldsProvider = (props) => {
|
||||||
|
return <ResourceActionProvider {...resourceActionProps}>{props.children}</ResourceActionProvider>;
|
||||||
|
};
|
||||||
|
|
||||||
const indentStyle = css`
|
const indentStyle = css`
|
||||||
.ant-table {
|
.ant-table {
|
||||||
margin-left: -16px !important;
|
margin-left: -16px !important;
|
||||||
@ -86,8 +91,6 @@ const tableContainer = css`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const titlePrompt = 'Default title for each record';
|
const titlePrompt = 'Default title for each record';
|
||||||
const RefreshContext = createContext(null);
|
|
||||||
|
|
||||||
const CurrentFields = (props) => {
|
const CurrentFields = (props) => {
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const { getInterface } = useCollectionManager_deprecated();
|
const { getInterface } = useCollectionManager_deprecated();
|
||||||
@ -101,7 +104,7 @@ const CurrentFields = (props) => {
|
|||||||
const targetTemplate = getTemplate(template);
|
const targetTemplate = getTemplate(template);
|
||||||
const columns: TableColumnProps<any>[] = [
|
const columns: TableColumnProps<any>[] = [
|
||||||
{
|
{
|
||||||
dataIndex: ['uiSchema', 'rawTitle'],
|
dataIndex: ['uiSchema', 'title'],
|
||||||
title: t('Field display name'),
|
title: t('Field display name'),
|
||||||
render: (value) => <div style={{ marginLeft: 7 }}>{compile(value)}</div>,
|
render: (value) => <div style={{ marginLeft: 7 }}>{compile(value)}</div>,
|
||||||
},
|
},
|
||||||
@ -265,11 +268,9 @@ const InheritFields = (props) => {
|
|||||||
dataIndex: 'actions',
|
dataIndex: 'actions',
|
||||||
title: t('Actions'),
|
title: t('Actions'),
|
||||||
render: function Render(_, record) {
|
render: function Render(_, record) {
|
||||||
const { handleRefresh } = useContext(RefreshContext);
|
|
||||||
const overrideProps = {
|
const overrideProps = {
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
currentCollection: name,
|
currentCollection: name,
|
||||||
handleRefresh,
|
|
||||||
};
|
};
|
||||||
const viewCollectionProps = {
|
const viewCollectionProps = {
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
@ -297,20 +298,19 @@ const InheritFields = (props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CollectionFields = () => {
|
const CollectionFieldsInternal = () => {
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const field = useField<Field>();
|
const field = useField<Field>();
|
||||||
const { name, template } = useRecord();
|
const { name, template } = useRecord();
|
||||||
const {
|
const {
|
||||||
data: { database },
|
data: { database },
|
||||||
} = useCurrentAppInfo();
|
} = useCurrentAppInfo();
|
||||||
const { getInterface, getInheritCollections, getCollection, getCurrentCollectionFields, getTemplate } =
|
const { getInterface, getInheritCollections, getCollection, getTemplate } = useCollectionManager_deprecated();
|
||||||
useCollectionManager_deprecated();
|
|
||||||
const form = useMemo(() => createForm(), []);
|
const form = useMemo(() => createForm(), []);
|
||||||
const f = useAttach(form.createArrayField({ ...field.props, basePath: '' }));
|
const f = useAttach(form.createArrayField({ ...field.props, basePath: '' }));
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const collectionResource = useResourceContext();
|
const collectionResource = useResourceContext();
|
||||||
const { refreshAsync } = useContext(ResourceActionContext);
|
const { refreshAsync, data } = useContext(ResourceActionContext);
|
||||||
const targetTemplate = getTemplate(template);
|
const targetTemplate = getTemplate(template);
|
||||||
const inherits = getInheritCollections(name);
|
const inherits = getInheritCollections(name);
|
||||||
|
|
||||||
@ -349,8 +349,7 @@ export const CollectionFields = () => {
|
|||||||
title: t('Actions'),
|
title: t('Actions'),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
const fields = data?.data || [];
|
||||||
const fields = getCurrentCollectionFields(name);
|
|
||||||
const groups = {
|
const groups = {
|
||||||
pf: [],
|
pf: [],
|
||||||
association: [],
|
association: [],
|
||||||
@ -427,65 +426,64 @@ export const CollectionFields = () => {
|
|||||||
);
|
);
|
||||||
const addProps = { type: 'primary', database };
|
const addProps = { type: 'primary', database };
|
||||||
const syncProps = { type: 'primary' };
|
const syncProps = { type: 'primary' };
|
||||||
const [refresh, setRefresh] = useState(false);
|
|
||||||
|
|
||||||
const handleRefresh = () => {
|
|
||||||
setRefresh(!refresh);
|
|
||||||
};
|
|
||||||
return (
|
return (
|
||||||
<RefreshContext.Provider value={{ refresh, handleRefresh }}>
|
<FormContext.Provider value={form}>
|
||||||
<ResourceActionProvider {...resourceActionProps}>
|
<FieldContext.Provider value={f}>
|
||||||
<FormContext.Provider value={form}>
|
<Space
|
||||||
<FieldContext.Provider value={f}>
|
align={'end'}
|
||||||
<Space
|
className={css`
|
||||||
align={'end'}
|
justify-content: flex-end;
|
||||||
className={css`
|
display: flex;
|
||||||
justify-content: flex-end;
|
margin-bottom: 16px;
|
||||||
display: flex;
|
`}
|
||||||
margin-bottom: 16px;
|
>
|
||||||
`}
|
<Action {...deleteProps} />
|
||||||
>
|
<SyncFieldsAction {...syncProps} />
|
||||||
<Action {...deleteProps} />
|
<SyncSQLFieldsAction refreshCMList={refreshAsync} />
|
||||||
<SyncFieldsAction {...syncProps} />
|
<SchemaComponent
|
||||||
<SyncSQLFieldsAction refreshCMList={refreshAsync} />
|
schema={{
|
||||||
<SchemaComponent
|
type: 'object',
|
||||||
schema={{
|
properties: {
|
||||||
type: 'object',
|
...targetTemplate.configureActions,
|
||||||
properties: {
|
},
|
||||||
...targetTemplate.configureActions,
|
}}
|
||||||
},
|
/>
|
||||||
}}
|
<AddCollectionField {...addProps} />
|
||||||
/>
|
</Space>
|
||||||
<AddCollectionField {...addProps} />
|
<Table
|
||||||
</Space>
|
rowKey={'key'}
|
||||||
<Table
|
columns={columns}
|
||||||
rowKey={'key'}
|
dataSource={dataSource.filter((d) => d.fields.length)}
|
||||||
columns={columns}
|
pagination={false}
|
||||||
dataSource={dataSource.filter((d) => d.fields.length)}
|
className={tableContainer}
|
||||||
pagination={false}
|
expandable={{
|
||||||
className={tableContainer}
|
defaultExpandAllRows: true,
|
||||||
expandable={{
|
defaultExpandedRowKeys: dataSource.map((d) => d.key),
|
||||||
defaultExpandAllRows: true,
|
expandedRowRender: (record) =>
|
||||||
defaultExpandedRowKeys: dataSource.map((d) => d.key),
|
record.inherit ? (
|
||||||
expandedRowRender: (record) =>
|
<InheritFields
|
||||||
record.inherit ? (
|
fields={record.fields}
|
||||||
<InheritFields
|
collectionResource={collectionResource}
|
||||||
fields={record.fields}
|
refreshAsync={refreshAsync}
|
||||||
collectionResource={collectionResource}
|
/>
|
||||||
refreshAsync={refreshAsync}
|
) : (
|
||||||
/>
|
<CurrentFields
|
||||||
) : (
|
fields={record.fields}
|
||||||
<CurrentFields
|
collectionResource={collectionResource}
|
||||||
fields={record.fields}
|
refreshAsync={refreshAsync}
|
||||||
collectionResource={collectionResource}
|
/>
|
||||||
refreshAsync={refreshAsync}
|
),
|
||||||
/>
|
}}
|
||||||
),
|
/>
|
||||||
}}
|
</FieldContext.Provider>
|
||||||
/>
|
</FormContext.Provider>
|
||||||
</FieldContext.Provider>
|
);
|
||||||
</FormContext.Provider>
|
};
|
||||||
</ResourceActionProvider>
|
|
||||||
</RefreshContext.Provider>
|
export const CollectionFields = () => {
|
||||||
|
return (
|
||||||
|
<CollectionFieldsProvider>
|
||||||
|
<CollectionFieldsInternal />
|
||||||
|
</CollectionFieldsProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user