chore: avoid errors generated by collectionField
This commit is contained in:
parent
8ba90b126f
commit
2e4636a8ca
@ -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);
|
||||
},
|
||||
|
@ -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) => {
|
||||
</Input.Group>
|
||||
<ActionContext.Provider value={{ openMode: 'drawer', visible: visibleSelector, setVisible: setVisibleSelector }}>
|
||||
<RecordPickerProvider {...pickerProps}>
|
||||
<CollectionProvider name={collectionField.target}>
|
||||
<CollectionProvider name={collectionField?.target}>
|
||||
<FormProvider>
|
||||
<TableSelectorParamsProvider params={{ filter: getFilter() }}>
|
||||
<SchemaComponentOptions scope={{ usePickActionProps, useTableSelectorProps }}>
|
||||
|
@ -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 (
|
||||
<div>
|
||||
<BlockAssociationContext.Provider value={`${collectionField.collectionName}.${collectionField.name}`}>
|
||||
<CollectionProvider name={collectionField.target ?? collectionField.targetCollection}>
|
||||
<BlockAssociationContext.Provider value={`${collectionField?.collectionName}.${collectionField?.name}`}>
|
||||
<CollectionProvider name={collectionField?.target ?? collectionField?.targetCollection}>
|
||||
<EllipsisWithTooltip ellipsis={true} ref={ellipsisWithTooltipRef}>
|
||||
{renderRecords()}
|
||||
</EllipsisWithTooltip>
|
||||
<ActionContext.Provider
|
||||
value={{ visible, setVisible, openMode: 'drawer', snapshot: collectionField.interface === 'snapshot' }}
|
||||
value={{ visible, setVisible, openMode: 'drawer', snapshot: collectionField?.interface === 'snapshot' }}
|
||||
>
|
||||
{renderRecordProvider()}
|
||||
</ActionContext.Provider>
|
||||
|
@ -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 (
|
||||
<CollectionProvider name={collectionField.target}>
|
||||
<CollectionProvider name={collectionField?.target}>
|
||||
<CreateAction {...props} onClick={(arg) => addbuttonClick(arg)} />
|
||||
<ActionContext.Provider value={{ ...ctx, visible: visibleAddNewer, setVisible: setVisibleAddNewer }}>
|
||||
<CollectionProvider name={currentCollection}>
|
||||
|
@ -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,
|
||||
|
@ -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')
|
||||
|
@ -131,13 +131,13 @@ export const BulkEditField = (props: any) => {
|
||||
<Select.Option value={BulkEditFormItemValueType.RemainsTheSame}>{t('Remains the same')}</Select.Option>
|
||||
<Select.Option value={BulkEditFormItemValueType.ChangedTo}>{t('Changed to')}</Select.Option>
|
||||
<Select.Option value={BulkEditFormItemValueType.Clear}>{t('Clear')}</Select.Option>
|
||||
{['subTable', 'linkTo', 'm2m', 'o2m', 'o2o', 'oho', 'obo', 'm2o'].includes(collectionField.interface) && (
|
||||
{['subTable', 'linkTo', 'm2m', 'o2m', 'o2o', 'oho', 'obo', 'm2o'].includes(collectionField?.interface) && (
|
||||
<Select.Option value={BulkEditFormItemValueType.AddAttach}>{t('Add attach')}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
{/* XXX: Not a best practice */}
|
||||
{[BulkEditFormItemValueType.ChangedTo, BulkEditFormItemValueType.AddAttach].includes(type) &&
|
||||
collectionField.interface !== 'checkbox' && (
|
||||
collectionField?.interface !== 'checkbox' && (
|
||||
<CollectionField {...props} value={value} onChange={valueChangeHandler} style={{ minWidth: 150 }} />
|
||||
// <SchemaComponent
|
||||
// schema={collectionSchema}
|
||||
@ -146,7 +146,7 @@ export const BulkEditField = (props: any) => {
|
||||
// />
|
||||
)}
|
||||
{[BulkEditFormItemValueType.ChangedTo, BulkEditFormItemValueType.AddAttach].includes(type) &&
|
||||
collectionField.interface === 'checkbox' && <Checkbox checked={value} onChange={valueChangeHandler} />}
|
||||
collectionField?.interface === 'checkbox' && <Checkbox checked={value} onChange={valueChangeHandler} />}
|
||||
</Space>
|
||||
);
|
||||
};
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user