fix: hook error in isTitleField
(#2471)
* fix: hook error in `isTitleField` * fix: error
This commit is contained in:
parent
aa6facac97
commit
efa153e92e
@ -53,12 +53,6 @@ const tableContainer = css`
|
||||
|
||||
const titlePrompt = 'Default title for each record';
|
||||
|
||||
// 是否可以作为标题字段
|
||||
export const isTitleField = (field) => {
|
||||
const { getInterface } = useCollectionManager();
|
||||
return !field.isForeignKey && getInterface(field.interface)?.titleUsable;
|
||||
};
|
||||
|
||||
const CurrentFields = (props) => {
|
||||
const compile = useCompile();
|
||||
const { getInterface } = useCollectionManager();
|
||||
@ -67,7 +61,7 @@ const CurrentFields = (props) => {
|
||||
const { resource, targetKey } = props.collectionResource || {};
|
||||
const { [targetKey]: filterByTk, titleField } = useRecord();
|
||||
const [loadingRecord, setLoadingRecord] = React.useState<any>(null);
|
||||
const { refreshCM } = useCollectionManager();
|
||||
const { refreshCM, isTitleField } = useCollectionManager();
|
||||
|
||||
const columns: TableColumnProps<any>[] = [
|
||||
{
|
||||
@ -173,7 +167,7 @@ const InheritFields = (props) => {
|
||||
const { [targetKey]: filterByTk, titleField, name } = useRecord();
|
||||
const [loadingRecord, setLoadingRecord] = React.useState(null);
|
||||
const { t } = useTranslation();
|
||||
const { refreshCM } = useCollectionManager();
|
||||
const { refreshCM, isTitleField } = useCollectionManager();
|
||||
|
||||
const columns: TableColumnProps<any>[] = [
|
||||
{
|
||||
|
@ -264,6 +264,15 @@ export const useCollectionManager = () => {
|
||||
return getInheritChain(collectionName);
|
||||
};
|
||||
|
||||
const getInterface = (name: string) => {
|
||||
return interfaces[name] ? clone(interfaces[name]) : null;
|
||||
};
|
||||
|
||||
// 是否可以作为标题字段
|
||||
const isTitleField = (field) => {
|
||||
return !field.isForeignKey && getInterface(field.interface)?.titleUsable;
|
||||
};
|
||||
|
||||
return {
|
||||
service,
|
||||
interfaces,
|
||||
@ -302,9 +311,7 @@ export const useCollectionManager = () => {
|
||||
}
|
||||
return collectionField;
|
||||
},
|
||||
getInterface(name: string) {
|
||||
return interfaces[name] ? clone(interfaces[name]) : null;
|
||||
},
|
||||
getInterface,
|
||||
getTemplate(name = 'general') {
|
||||
return templates[name] ? clone(templates[name] || templates['general']) : null;
|
||||
},
|
||||
@ -328,5 +335,6 @@ export const useCollectionManager = () => {
|
||||
},
|
||||
getAllCollectionsInheritChain,
|
||||
getInheritCollectionsChain,
|
||||
isTitleField,
|
||||
};
|
||||
};
|
||||
|
@ -13,7 +13,6 @@ import {
|
||||
useCollectionManager,
|
||||
useSortFields,
|
||||
} from '../../../collection-manager';
|
||||
import { isTitleField } from '../../../collection-manager/Configuration/CollectionFields';
|
||||
import { GeneralSchemaItems } from '../../../schema-items';
|
||||
import { GeneralSchemaDesigner, SchemaSettings, isPatternDisabled, isShowDefaultValue } from '../../../schema-settings';
|
||||
import { useIsShowMultipleSwitch } from '../../../schema-settings/hooks/useIsShowMultipleSwitch';
|
||||
@ -95,7 +94,8 @@ interface AssociationSelectInterface {
|
||||
export const AssociationSelect = InternalAssociationSelect as unknown as AssociationSelectInterface;
|
||||
|
||||
AssociationSelect.Designer = function Designer() {
|
||||
const { getCollectionFields, getInterface, getCollectionJoinField, getCollection } = useCollectionManager();
|
||||
const { getCollectionFields, getInterface, getCollectionJoinField, getCollection, isTitleField } =
|
||||
useCollectionManager();
|
||||
const { getField } = useCollection();
|
||||
const { form } = useFormBlockContext();
|
||||
const field = useField<Field>();
|
||||
|
@ -17,7 +17,6 @@ import {
|
||||
useCollectionFilterOptions,
|
||||
useCollectionManager,
|
||||
} from '../../../collection-manager';
|
||||
import { isTitleField } from '../../../collection-manager/Configuration/CollectionFields';
|
||||
import { GeneralSchemaItems } from '../../../schema-items/GeneralSchemaItems';
|
||||
import { GeneralSchemaDesigner, SchemaSettings, isPatternDisabled, isShowDefaultValue } from '../../../schema-settings';
|
||||
import { useIsShowMultipleSwitch } from '../../../schema-settings/hooks/useIsShowMultipleSwitch';
|
||||
@ -159,7 +158,8 @@ export const FormItem: any = observer(
|
||||
|
||||
FormItem.Designer = function Designer() {
|
||||
let targetField;
|
||||
const { getCollectionFields, getInterface, getCollectionJoinField, getCollection } = useCollectionManager();
|
||||
const { getCollectionFields, getInterface, getCollectionJoinField, getCollection, isTitleField } =
|
||||
useCollectionManager();
|
||||
const { getField } = useCollection();
|
||||
const { form } = useFormBlockContext();
|
||||
const ctx = useBlockRequestContext();
|
||||
|
@ -8,14 +8,13 @@ import { useTranslation } from 'react-i18next';
|
||||
import { GeneralSchemaDesigner, SchemaSettings } from '../..';
|
||||
import { mergeFilter } from '../../../block-provider';
|
||||
import { useCollectionFilterOptions, useCollectionManager } from '../../../collection-manager';
|
||||
import { isTitleField } from '../../../collection-manager/Configuration/CollectionFields';
|
||||
import { removeNullCondition, useCompile, useDesignable } from '../../../schema-component';
|
||||
import { ITemplate } from '../../../schema-component/antd/form-v2/Templates';
|
||||
import { FilterDynamicComponent } from '../../../schema-component/antd/table-v2/FilterDynamicComponent';
|
||||
|
||||
export const Designer = observer(
|
||||
() => {
|
||||
const { getCollectionFields, getCollectionField, getCollection } = useCollectionManager();
|
||||
const { getCollectionFields, getCollectionField, getCollection, isTitleField } = useCollectionManager();
|
||||
const field = useField<Field>();
|
||||
const fieldSchema = useFieldSchema();
|
||||
const { t } = useTranslation();
|
||||
|
Loading…
Reference in New Issue
Block a user