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';
|
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 CurrentFields = (props) => {
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const { getInterface } = useCollectionManager();
|
const { getInterface } = useCollectionManager();
|
||||||
@ -67,7 +61,7 @@ const CurrentFields = (props) => {
|
|||||||
const { resource, targetKey } = props.collectionResource || {};
|
const { resource, targetKey } = props.collectionResource || {};
|
||||||
const { [targetKey]: filterByTk, titleField } = useRecord();
|
const { [targetKey]: filterByTk, titleField } = useRecord();
|
||||||
const [loadingRecord, setLoadingRecord] = React.useState<any>(null);
|
const [loadingRecord, setLoadingRecord] = React.useState<any>(null);
|
||||||
const { refreshCM } = useCollectionManager();
|
const { refreshCM, isTitleField } = useCollectionManager();
|
||||||
|
|
||||||
const columns: TableColumnProps<any>[] = [
|
const columns: TableColumnProps<any>[] = [
|
||||||
{
|
{
|
||||||
@ -173,7 +167,7 @@ const InheritFields = (props) => {
|
|||||||
const { [targetKey]: filterByTk, titleField, name } = useRecord();
|
const { [targetKey]: filterByTk, titleField, name } = useRecord();
|
||||||
const [loadingRecord, setLoadingRecord] = React.useState(null);
|
const [loadingRecord, setLoadingRecord] = React.useState(null);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { refreshCM } = useCollectionManager();
|
const { refreshCM, isTitleField } = useCollectionManager();
|
||||||
|
|
||||||
const columns: TableColumnProps<any>[] = [
|
const columns: TableColumnProps<any>[] = [
|
||||||
{
|
{
|
||||||
|
@ -264,6 +264,15 @@ export const useCollectionManager = () => {
|
|||||||
return getInheritChain(collectionName);
|
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 {
|
return {
|
||||||
service,
|
service,
|
||||||
interfaces,
|
interfaces,
|
||||||
@ -302,9 +311,7 @@ export const useCollectionManager = () => {
|
|||||||
}
|
}
|
||||||
return collectionField;
|
return collectionField;
|
||||||
},
|
},
|
||||||
getInterface(name: string) {
|
getInterface,
|
||||||
return interfaces[name] ? clone(interfaces[name]) : null;
|
|
||||||
},
|
|
||||||
getTemplate(name = 'general') {
|
getTemplate(name = 'general') {
|
||||||
return templates[name] ? clone(templates[name] || templates['general']) : null;
|
return templates[name] ? clone(templates[name] || templates['general']) : null;
|
||||||
},
|
},
|
||||||
@ -328,5 +335,6 @@ export const useCollectionManager = () => {
|
|||||||
},
|
},
|
||||||
getAllCollectionsInheritChain,
|
getAllCollectionsInheritChain,
|
||||||
getInheritCollectionsChain,
|
getInheritCollectionsChain,
|
||||||
|
isTitleField,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -13,7 +13,6 @@ import {
|
|||||||
useCollectionManager,
|
useCollectionManager,
|
||||||
useSortFields,
|
useSortFields,
|
||||||
} from '../../../collection-manager';
|
} from '../../../collection-manager';
|
||||||
import { isTitleField } from '../../../collection-manager/Configuration/CollectionFields';
|
|
||||||
import { GeneralSchemaItems } from '../../../schema-items';
|
import { GeneralSchemaItems } from '../../../schema-items';
|
||||||
import { GeneralSchemaDesigner, SchemaSettings, isPatternDisabled, isShowDefaultValue } from '../../../schema-settings';
|
import { GeneralSchemaDesigner, SchemaSettings, isPatternDisabled, isShowDefaultValue } from '../../../schema-settings';
|
||||||
import { useIsShowMultipleSwitch } from '../../../schema-settings/hooks/useIsShowMultipleSwitch';
|
import { useIsShowMultipleSwitch } from '../../../schema-settings/hooks/useIsShowMultipleSwitch';
|
||||||
@ -95,7 +94,8 @@ interface AssociationSelectInterface {
|
|||||||
export const AssociationSelect = InternalAssociationSelect as unknown as AssociationSelectInterface;
|
export const AssociationSelect = InternalAssociationSelect as unknown as AssociationSelectInterface;
|
||||||
|
|
||||||
AssociationSelect.Designer = function Designer() {
|
AssociationSelect.Designer = function Designer() {
|
||||||
const { getCollectionFields, getInterface, getCollectionJoinField, getCollection } = useCollectionManager();
|
const { getCollectionFields, getInterface, getCollectionJoinField, getCollection, isTitleField } =
|
||||||
|
useCollectionManager();
|
||||||
const { getField } = useCollection();
|
const { getField } = useCollection();
|
||||||
const { form } = useFormBlockContext();
|
const { form } = useFormBlockContext();
|
||||||
const field = useField<Field>();
|
const field = useField<Field>();
|
||||||
|
@ -17,7 +17,6 @@ import {
|
|||||||
useCollectionFilterOptions,
|
useCollectionFilterOptions,
|
||||||
useCollectionManager,
|
useCollectionManager,
|
||||||
} from '../../../collection-manager';
|
} from '../../../collection-manager';
|
||||||
import { isTitleField } from '../../../collection-manager/Configuration/CollectionFields';
|
|
||||||
import { GeneralSchemaItems } from '../../../schema-items/GeneralSchemaItems';
|
import { GeneralSchemaItems } from '../../../schema-items/GeneralSchemaItems';
|
||||||
import { GeneralSchemaDesigner, SchemaSettings, isPatternDisabled, isShowDefaultValue } from '../../../schema-settings';
|
import { GeneralSchemaDesigner, SchemaSettings, isPatternDisabled, isShowDefaultValue } from '../../../schema-settings';
|
||||||
import { useIsShowMultipleSwitch } from '../../../schema-settings/hooks/useIsShowMultipleSwitch';
|
import { useIsShowMultipleSwitch } from '../../../schema-settings/hooks/useIsShowMultipleSwitch';
|
||||||
@ -159,7 +158,8 @@ export const FormItem: any = observer(
|
|||||||
|
|
||||||
FormItem.Designer = function Designer() {
|
FormItem.Designer = function Designer() {
|
||||||
let targetField;
|
let targetField;
|
||||||
const { getCollectionFields, getInterface, getCollectionJoinField, getCollection } = useCollectionManager();
|
const { getCollectionFields, getInterface, getCollectionJoinField, getCollection, isTitleField } =
|
||||||
|
useCollectionManager();
|
||||||
const { getField } = useCollection();
|
const { getField } = useCollection();
|
||||||
const { form } = useFormBlockContext();
|
const { form } = useFormBlockContext();
|
||||||
const ctx = useBlockRequestContext();
|
const ctx = useBlockRequestContext();
|
||||||
|
@ -8,14 +8,13 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { GeneralSchemaDesigner, SchemaSettings } from '../..';
|
import { GeneralSchemaDesigner, SchemaSettings } from '../..';
|
||||||
import { mergeFilter } from '../../../block-provider';
|
import { mergeFilter } from '../../../block-provider';
|
||||||
import { useCollectionFilterOptions, useCollectionManager } from '../../../collection-manager';
|
import { useCollectionFilterOptions, useCollectionManager } from '../../../collection-manager';
|
||||||
import { isTitleField } from '../../../collection-manager/Configuration/CollectionFields';
|
|
||||||
import { removeNullCondition, useCompile, useDesignable } from '../../../schema-component';
|
import { removeNullCondition, useCompile, useDesignable } from '../../../schema-component';
|
||||||
import { ITemplate } from '../../../schema-component/antd/form-v2/Templates';
|
import { ITemplate } from '../../../schema-component/antd/form-v2/Templates';
|
||||||
import { FilterDynamicComponent } from '../../../schema-component/antd/table-v2/FilterDynamicComponent';
|
import { FilterDynamicComponent } from '../../../schema-component/antd/table-v2/FilterDynamicComponent';
|
||||||
|
|
||||||
export const Designer = observer(
|
export const Designer = observer(
|
||||||
() => {
|
() => {
|
||||||
const { getCollectionFields, getCollectionField, getCollection } = useCollectionManager();
|
const { getCollectionFields, getCollectionField, getCollection, isTitleField } = useCollectionManager();
|
||||||
const field = useField<Field>();
|
const field = useField<Field>();
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
Loading…
Reference in New Issue
Block a user