fix(client): cannot read properties of undefined (reading 'interface') (#1245)

This commit is contained in:
chenos 2022-12-14 17:27:50 +08:00
parent 26e27c814b
commit 63581688e9

View File

@ -1,7 +1,7 @@
import { useFieldSchema } from "@formily/react";
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { useCollectionManager, useCollection } from "../../collection-manager";
import { useFieldSchema } from '@formily/react';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useCollection, useCollectionManager } from '../../collection-manager';
export const useFieldComponentOptions = () => {
const { getCollectionJoinField } = useCollectionManager();
@ -11,11 +11,11 @@ export const useFieldComponentOptions = () => {
const { t } = useTranslation();
const fieldComponentOptions = useMemo(() => {
if (
!['o2o', 'oho', 'obo', 'o2m', 'linkTo', 'm2o', 'm2m']
.includes(collectionField.interface)
)
if (!collectionField || !collectionField?.interface) {
return;
}
if (!['o2o', 'oho', 'obo', 'o2m', 'linkTo', 'm2o', 'm2m'].includes(collectionField.interface)) return;
switch (collectionField.interface) {
case 'o2m':
@ -31,7 +31,7 @@ export const useFieldComponentOptions = () => {
return [
{ label: t('Record picker'), value: 'CollectionField' },
{ label: t('Select'), value: 'AssociationSelect' },
]
];
default:
return [
@ -39,7 +39,6 @@ export const useFieldComponentOptions = () => {
{ label: t('Subform'), value: 'FormField' },
{ label: t('Select'), value: 'AssociationSelect' },
];
}
}, [t, collectionField?.interface]);