diff --git a/packages/core/client/src/collection-manager/hooks/useCollection.ts b/packages/core/client/src/collection-manager/hooks/useCollection.ts index 15699b77b..1b4d47005 100644 --- a/packages/core/client/src/collection-manager/hooks/useCollection.ts +++ b/packages/core/client/src/collection-manager/hooks/useCollection.ts @@ -29,7 +29,7 @@ export const useCollection = () => { return { ...collection, resource, - getField(name: SchemaKey): CollectionFieldOptions { + getField(name: SchemaKey): CollectionFieldOptions | null { const fields = totalFields as any[]; return fields?.find((field) => field.name === name); }, diff --git a/packages/core/client/src/schema-component/antd/association-field/InternalPicker.tsx b/packages/core/client/src/schema-component/antd/association-field/InternalPicker.tsx index 6f6ae6172..5c5d72394 100644 --- a/packages/core/client/src/schema-component/antd/association-field/InternalPicker.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/InternalPicker.tsx @@ -1,8 +1,7 @@ import { RecursionField, observer, useField, useFieldSchema } from '@formily/react'; -import { Button, Input, Select } from 'antd'; +import { Input, Select } from 'antd'; import { differenceBy, unionBy } from 'lodash'; import React, { useContext, useEffect, useState } from 'react'; -import { useTranslation } from 'react-i18next'; import { FormProvider, RecordPickerContext, @@ -17,9 +16,8 @@ import { import { CollectionProvider } from '../../../collection-manager'; import { useCompile } from '../../hooks'; import { ActionContext } from '../action'; -import { useFieldNames, useInsertSchema } from './hooks'; +import { useAssociationFieldContext, useFieldNames, useInsertSchema } from './hooks'; import schema from './schema'; -import { useAssociationFieldContext } from './hooks'; import { flatData, getLabelFormatValue, useLabelUiSchema } from './util'; const useTableSelectorProps = () => { @@ -173,7 +171,7 @@ export const InternalPicker = observer((props: any) => { - + diff --git a/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx b/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx index 85057bc74..9f70e6042 100644 --- a/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx @@ -8,10 +8,9 @@ import { FormProvider } from '../../core'; import { useCompile } from '../../hooks'; import { ActionContext, useActionContext } from '../action'; import { EllipsisWithTooltip } from '../input/EllipsisWithTooltip'; -import { useFieldNames, useInsertSchema } from './hooks'; +import { useAssociationFieldContext, useFieldNames, useInsertSchema } from './hooks'; import schema from './schema'; import { getLabelFormatValue, useLabelUiSchema } from './util'; -import { useAssociationFieldContext } from './hooks'; interface IEllipsisWithTooltipRef { setPopoverVisible: (boolean) => void; @@ -99,13 +98,13 @@ export const ReadPrettyInternalViewer: React.FC = observer((props: any) => { return (
- - + + {renderRecords()} {renderRecordProvider()} diff --git a/packages/core/client/src/schema-component/antd/association-field/components/CreateRecordAction.tsx b/packages/core/client/src/schema-component/antd/association-field/components/CreateRecordAction.tsx index 6e6e948c4..cd5afa7e4 100644 --- a/packages/core/client/src/schema-component/antd/association-field/components/CreateRecordAction.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/components/CreateRecordAction.tsx @@ -1,10 +1,9 @@ import { RecursionField, observer, useField, useFieldSchema } from '@formily/react'; import React, { useState } from 'react'; import { CollectionProvider } from '../../../../collection-manager'; -import { ActionContext, useActionContext } from '../../action'; -import { useAssociationFieldContext } from '../hooks'; -import { useInsertSchema } from '../hooks'; import { CreateAction } from '../../../../schema-initializer/components'; +import { ActionContext, useActionContext } from '../../action'; +import { useAssociationFieldContext, useInsertSchema } from '../hooks'; import schema from '../schema'; export const CreateRecordAction = observer((props) => { @@ -14,14 +13,14 @@ export const CreateRecordAction = observer((props) => { const insertAddNewer = useInsertSchema('AddNewer'); const { options: collectionField } = useAssociationFieldContext(); const [visibleAddNewer, setVisibleAddNewer] = useState(false); - const [currentCollection, setCurrentCollection] = useState(collectionField.target); + const [currentCollection, setCurrentCollection] = useState(collectionField?.target); const addbuttonClick = (name) => { insertAddNewer(schema.AddNewer); setVisibleAddNewer(true); setCurrentCollection(name); }; return ( - + addbuttonClick(arg)} /> diff --git a/packages/core/client/src/schema-component/antd/association-select/useServiceOptions.ts b/packages/core/client/src/schema-component/antd/association-select/useServiceOptions.ts index bf5d04fc9..3e729fc6e 100644 --- a/packages/core/client/src/schema-component/antd/association-select/useServiceOptions.ts +++ b/packages/core/client/src/schema-component/antd/association-select/useServiceOptions.ts @@ -44,7 +44,7 @@ export default function useServiceOptions(props) { return mergeFilter( [ mergeFilter([ - isOToAny && !isInFilterFormBlock(fieldSchema) + isOToAny && !isInFilterFormBlock(fieldSchema) && collectionField?.foreignKey ? { [collectionField.foreignKey]: { $is: null, @@ -53,7 +53,11 @@ export default function useServiceOptions(props) { : null, params?.filter, ]), - isOToAny && sourceValue !== undefined && sourceValue !== null && !isInFilterFormBlock(fieldSchema) + isOToAny && + sourceValue !== undefined && + sourceValue !== null && + !isInFilterFormBlock(fieldSchema) && + collectionField?.foreignKey ? { [collectionField.foreignKey]: { $eq: sourceValue, diff --git a/packages/core/client/src/schema-component/antd/form-item/SchemaSettingOptions.tsx b/packages/core/client/src/schema-component/antd/form-item/SchemaSettingOptions.tsx index 1183fc73c..19ca25dc8 100644 --- a/packages/core/client/src/schema-component/antd/form-item/SchemaSettingOptions.tsx +++ b/packages/core/client/src/schema-component/antd/form-item/SchemaSettingOptions.tsx @@ -5,7 +5,7 @@ import { uid } from '@formily/shared'; import _ from 'lodash'; import React from 'react'; import { useTranslation } from 'react-i18next'; -import { useFilterByTk, useFormBlockContext } from '../../../block-provider'; +import { useFormBlockContext } from '../../../block-provider'; import { useCollection, useCollectionManager } from '../../../collection-manager'; import { SchemaSettings, isPatternDisabled } from '../../../schema-settings'; import { useCompile, useDesignable, useFieldModeOptions } from '../../hooks'; @@ -344,11 +344,11 @@ export const EditDefaultValue = () => { title: t('Set default value'), properties: { default: { - ...collectionField.uiSchema, + ...collectionField?.uiSchema, name: 'default', title: t('Default value'), 'x-decorator': 'FormItem', - default: fieldSchema.default || collectionField.defaultValue, + default: fieldSchema.default || collectionField?.defaultValue, }, }, } as ISchema @@ -536,7 +536,7 @@ export const EditTitleField = () => { const compile = useCompile(); const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']); const targetFields = collectionField?.target - ? getCollectionFields(collectionField.target) + ? getCollectionFields(collectionField?.target) : getCollectionFields(collectionField?.targetCollection) ?? []; const options = targetFields .filter((field) => !field?.target && field.type !== 'boolean') diff --git a/packages/core/client/src/schema-initializer/components/BulkEditField.tsx b/packages/core/client/src/schema-initializer/components/BulkEditField.tsx index 855197637..db4ff6a04 100644 --- a/packages/core/client/src/schema-initializer/components/BulkEditField.tsx +++ b/packages/core/client/src/schema-initializer/components/BulkEditField.tsx @@ -131,13 +131,13 @@ export const BulkEditField = (props: any) => { {t('Remains the same')} {t('Changed to')} {t('Clear')} - {['subTable', 'linkTo', 'm2m', 'o2m', 'o2o', 'oho', 'obo', 'm2o'].includes(collectionField.interface) && ( + {['subTable', 'linkTo', 'm2m', 'o2m', 'o2o', 'oho', 'obo', 'm2o'].includes(collectionField?.interface) && ( {t('Add attach')} )} {/* XXX: Not a best practice */} {[BulkEditFormItemValueType.ChangedTo, BulkEditFormItemValueType.AddAttach].includes(type) && - collectionField.interface !== 'checkbox' && ( + collectionField?.interface !== 'checkbox' && ( // { // /> )} {[BulkEditFormItemValueType.ChangedTo, BulkEditFormItemValueType.AddAttach].includes(type) && - collectionField.interface === 'checkbox' && } + collectionField?.interface === 'checkbox' && } ); }; diff --git a/packages/plugins/map/src/client/components/ReadPretty.tsx b/packages/plugins/map/src/client/components/ReadPretty.tsx index b9ac54c2f..ce81b2425 100644 --- a/packages/plugins/map/src/client/components/ReadPretty.tsx +++ b/packages/plugins/map/src/client/components/ReadPretty.tsx @@ -13,7 +13,7 @@ const ReadPretty = (props) => { const form = useForm(); useEffect(() => { if (!field.title && collectionField?.uiSchema?.title) { - field.title = collectionField.uiSchema.title; + field.title = collectionField?.uiSchema.title; } }, collectionField?.title);