From fbbd90ca3cf403857c4f7392309437e8e371276d Mon Sep 17 00:00:00 2001 From: Rairn <958414905@qq.com> Date: Tue, 16 May 2023 20:16:45 +0800 Subject: [PATCH] chore: avoid error --- .../antd/association-field/Editable.tsx | 16 ++++++++-------- .../antd/association-field/hooks.ts | 16 ++++++++++------ .../AssociationFilter.Item.tsx | 9 ++++++--- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/association-field/Editable.tsx b/packages/core/client/src/schema-component/antd/association-field/Editable.tsx index 506c62e2f..29b11762d 100644 --- a/packages/core/client/src/schema-component/antd/association-field/Editable.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/Editable.tsx @@ -1,15 +1,15 @@ import { observer, useField, useFieldSchema, useForm } from '@formily/react'; -import React, { useEffect, useState } from 'react'; +import React from 'react'; +import { SchemaComponentOptions } from '../../'; +import { useAssociationCreateActionProps as useCAP } from '../../../block-provider/hooks'; import { AssociationFieldProvider } from './AssociationFieldProvider'; +import { AssociationSelect } from './AssociationSelect'; +import { InternalFileManager } from './FileManager'; import { InternalNester } from './InternalNester'; import { InternalPicker } from './InternalPicker'; -import { AssociationSelect } from './AssociationSelect'; -import { useAssociationCreateActionProps as useCAP } from '../../../block-provider/hooks'; -import { SchemaComponentOptions } from '../../'; import { InternalSubTable } from './InternalSubTable'; -import { InternalFileManager } from './FileManager'; +import { CreateRecordAction } from './components/CreateRecordAction'; import { useAssociationFieldContext } from './hooks'; -import {CreateRecordAction} from './components/CreateRecordAction' const EditableAssociationField = observer((props: any) => { const { multiple } = props; @@ -25,7 +25,7 @@ const EditableAssociationField = observer((props: any) => { async onClick() { await onClick(); const { data } = actionField.data?.data?.data || {}; - if (['m2m', 'o2m'].includes(collectionField.interface) && multiple !== false) { + if (['m2m', 'o2m'].includes(collectionField?.interface) && multiple !== false) { const values = JSON.parse(JSON.stringify(form.values[fieldSchema.name] || [])); values.push({ ...data, @@ -45,7 +45,7 @@ const EditableAssociationField = observer((props: any) => { }; }; return ( - + {currentMode === 'Picker' && } {currentMode === 'Nester' && } {currentMode === 'Select' && } diff --git a/packages/core/client/src/schema-component/antd/association-field/hooks.ts b/packages/core/client/src/schema-component/antd/association-field/hooks.ts index 0844e93c0..0ac0da19b 100644 --- a/packages/core/client/src/schema-component/antd/association-field/hooks.ts +++ b/packages/core/client/src/schema-component/antd/association-field/hooks.ts @@ -2,12 +2,12 @@ import { GeneralField } from '@formily/core'; import { useFieldSchema } from '@formily/react'; import cloneDeep from 'lodash/cloneDeep'; import { useCallback, useContext, useMemo } from 'react'; -import { useDesignable } from '../../hooks'; import { mergeFilter } from '../../../block-provider/SharedFilterProvider'; -import { AssociationFieldContext } from './context'; -import { useRecord } from '../../../record-provider'; -import { isInFilterFormBlock } from '../../../filter-provider'; import { useCollection, useCollectionManager } from '../../../collection-manager'; +import { isInFilterFormBlock } from '../../../filter-provider'; +import { useRecord } from '../../../record-provider'; +import { useDesignable } from '../../hooks'; +import { AssociationFieldContext } from './context'; export const useInsertSchema = (component) => { const fieldSchema = useFieldSchema(); @@ -72,7 +72,7 @@ export default function useServiceOptions(props) { return mergeFilter( [ mergeFilter([ - isOToAny && !isInFilterFormBlock(fieldSchema) + isOToAny && !isInFilterFormBlock(fieldSchema) && collectionField?.foreignKey ? { [collectionField.foreignKey]: { $is: null, @@ -81,7 +81,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/association-filter/AssociationFilter.Item.tsx b/packages/core/client/src/schema-component/antd/association-filter/AssociationFilter.Item.tsx index 4681452a6..5996bc8e5 100644 --- a/packages/core/client/src/schema-component/antd/association-filter/AssociationFilter.Item.tsx +++ b/packages/core/client/src/schema-component/antd/association-filter/AssociationFilter.Item.tsx @@ -6,9 +6,9 @@ import cls from 'classnames'; import React, { ChangeEvent, MouseEvent, useMemo, useState } from 'react'; import { SortableItem } from '../../common'; import { useCompile, useDesigner, useProps } from '../../hooks'; +import { EllipsisWithTooltip } from '../input'; import { getLabelFormatValue, useLabelUiSchema } from '../record-picker'; import { AssociationFilter } from './AssociationFilter'; -import { EllipsisWithTooltip } from '../input'; const { Panel } = Collapse; @@ -32,7 +32,10 @@ export const AssociationFilterItem = (props) => { const [searchVisible, setSearchVisible] = useState(false); - const defaultActiveKeyCollapse = useMemo(() => (defaultCollapse ? [collectionField.name] : []), []); + const defaultActiveKeyCollapse = useMemo( + () => (defaultCollapse && collectionField?.name ? [collectionField.name] : []), + [], + ); const valueKey = _valueKey || collectionField?.targetKey || 'id'; const labelKey = _labelKey || fieldSchema['x-component-props']?.fieldNames?.label || valueKey; @@ -79,7 +82,7 @@ export const AssociationFilterItem = (props) => { _handleSearchInput(e); }; - const title = fieldSchema.title ?? collectionField.uiSchema?.title; + const title = fieldSchema.title ?? collectionField?.uiSchema?.title; const labelUiSchema = useLabelUiSchema(collectionField, fieldNames?.title || 'label'); return (