refactor: collection template support configureActions (#3123)

This commit is contained in:
katherinehhh 2023-12-01 11:27:38 +08:00 committed by GitHub
parent 8983eed330
commit 4f9696035a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View File

@ -6,7 +6,7 @@ import React, { useContext, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useCurrentAppInfo } from '../../appInfo';
import { RecordProvider, useRecord } from '../../record-provider';
import { Action, useAttach, useCompile } from '../../schema-component';
import { Action, useAttach, useCompile, SchemaComponent } from '../../schema-component';
import { Input } from '../../schema-component/antd/input';
import {
isDeleteButtonDisabled,
@ -61,9 +61,9 @@ const CurrentFields = (props) => {
const { t } = useTranslation();
const { setState } = useResourceActionContext();
const { resource, targetKey } = props.collectionResource || {};
const { [targetKey]: filterByTk, titleField } = useRecord();
const { [targetKey]: filterByTk, titleField, template } = useRecord();
const [loadingRecord, setLoadingRecord] = React.useState<any>(null);
const { refreshCM, isTitleField } = useCollectionManager();
const { refreshCM, isTitleField, getTemplate } = useCollectionManager();
const columns: TableColumnProps<any>[] = [
{
@ -269,17 +269,18 @@ const InheritFields = (props) => {
export const CollectionFields = () => {
const compile = useCompile();
const field = useField<Field>();
const { name } = useRecord();
const { name, template } = useRecord();
const {
data: { database },
} = useCurrentAppInfo();
const { getInterface, getInheritCollections, getCollection, getCurrentCollectionFields } = useCollectionManager();
const { getInterface, getInheritCollections, getCollection, getCurrentCollectionFields, getTemplate } =
useCollectionManager();
const form = useMemo(() => createForm(), []);
const f = useAttach(form.createArrayField({ ...field.props, basePath: '' }));
const { t } = useTranslation();
const collectionResource = useResourceContext();
const { refreshAsync } = useContext(ResourceActionContext);
const targetTemplate = getTemplate(template);
const inherits = getInheritCollections(name);
const columns: TableColumnProps<any>[] = [
@ -428,6 +429,14 @@ export const CollectionFields = () => {
<Action {...deleteProps} />
<SyncFieldsAction {...syncProps} />
<SyncSQLFieldsAction refreshCMList={refreshAsync} />
<SchemaComponent
schema={{
type: 'object',
properties: {
...targetTemplate.configureActions,
},
}}
/>
<AddCollectionField {...addProps} />
</Space>
<Table

View File

@ -18,6 +18,8 @@ export interface ICollectionTemplate {
divider?: boolean;
/** 模板描述 */
description?: string;
/**配置字段中的操作按钮 */
configureActions?: Record<string, ISchema>;
}
interface AvailableFieldInterfacesInclude {