chore: avoid errors generated by collectionField
This commit is contained in:
parent
8ba90b126f
commit
2e4636a8ca
@ -29,7 +29,7 @@ export const useCollection = () => {
|
|||||||
return {
|
return {
|
||||||
...collection,
|
...collection,
|
||||||
resource,
|
resource,
|
||||||
getField(name: SchemaKey): CollectionFieldOptions {
|
getField(name: SchemaKey): CollectionFieldOptions | null {
|
||||||
const fields = totalFields as any[];
|
const fields = totalFields as any[];
|
||||||
return fields?.find((field) => field.name === name);
|
return fields?.find((field) => field.name === name);
|
||||||
},
|
},
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import { RecursionField, observer, useField, useFieldSchema } from '@formily/react';
|
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 { differenceBy, unionBy } from 'lodash';
|
||||||
import React, { useContext, useEffect, useState } from 'react';
|
import React, { useContext, useEffect, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import {
|
import {
|
||||||
FormProvider,
|
FormProvider,
|
||||||
RecordPickerContext,
|
RecordPickerContext,
|
||||||
@ -17,9 +16,8 @@ import {
|
|||||||
import { CollectionProvider } from '../../../collection-manager';
|
import { CollectionProvider } from '../../../collection-manager';
|
||||||
import { useCompile } from '../../hooks';
|
import { useCompile } from '../../hooks';
|
||||||
import { ActionContext } from '../action';
|
import { ActionContext } from '../action';
|
||||||
import { useFieldNames, useInsertSchema } from './hooks';
|
import { useAssociationFieldContext, useFieldNames, useInsertSchema } from './hooks';
|
||||||
import schema from './schema';
|
import schema from './schema';
|
||||||
import { useAssociationFieldContext } from './hooks';
|
|
||||||
import { flatData, getLabelFormatValue, useLabelUiSchema } from './util';
|
import { flatData, getLabelFormatValue, useLabelUiSchema } from './util';
|
||||||
|
|
||||||
const useTableSelectorProps = () => {
|
const useTableSelectorProps = () => {
|
||||||
@ -173,7 +171,7 @@ export const InternalPicker = observer((props: any) => {
|
|||||||
</Input.Group>
|
</Input.Group>
|
||||||
<ActionContext.Provider value={{ openMode: 'drawer', visible: visibleSelector, setVisible: setVisibleSelector }}>
|
<ActionContext.Provider value={{ openMode: 'drawer', visible: visibleSelector, setVisible: setVisibleSelector }}>
|
||||||
<RecordPickerProvider {...pickerProps}>
|
<RecordPickerProvider {...pickerProps}>
|
||||||
<CollectionProvider name={collectionField.target}>
|
<CollectionProvider name={collectionField?.target}>
|
||||||
<FormProvider>
|
<FormProvider>
|
||||||
<TableSelectorParamsProvider params={{ filter: getFilter() }}>
|
<TableSelectorParamsProvider params={{ filter: getFilter() }}>
|
||||||
<SchemaComponentOptions scope={{ usePickActionProps, useTableSelectorProps }}>
|
<SchemaComponentOptions scope={{ usePickActionProps, useTableSelectorProps }}>
|
||||||
|
@ -8,10 +8,9 @@ import { FormProvider } from '../../core';
|
|||||||
import { useCompile } from '../../hooks';
|
import { useCompile } from '../../hooks';
|
||||||
import { ActionContext, useActionContext } from '../action';
|
import { ActionContext, useActionContext } from '../action';
|
||||||
import { EllipsisWithTooltip } from '../input/EllipsisWithTooltip';
|
import { EllipsisWithTooltip } from '../input/EllipsisWithTooltip';
|
||||||
import { useFieldNames, useInsertSchema } from './hooks';
|
import { useAssociationFieldContext, useFieldNames, useInsertSchema } from './hooks';
|
||||||
import schema from './schema';
|
import schema from './schema';
|
||||||
import { getLabelFormatValue, useLabelUiSchema } from './util';
|
import { getLabelFormatValue, useLabelUiSchema } from './util';
|
||||||
import { useAssociationFieldContext } from './hooks';
|
|
||||||
|
|
||||||
interface IEllipsisWithTooltipRef {
|
interface IEllipsisWithTooltipRef {
|
||||||
setPopoverVisible: (boolean) => void;
|
setPopoverVisible: (boolean) => void;
|
||||||
@ -99,13 +98,13 @@ export const ReadPrettyInternalViewer: React.FC = observer((props: any) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<BlockAssociationContext.Provider value={`${collectionField.collectionName}.${collectionField.name}`}>
|
<BlockAssociationContext.Provider value={`${collectionField?.collectionName}.${collectionField?.name}`}>
|
||||||
<CollectionProvider name={collectionField.target ?? collectionField.targetCollection}>
|
<CollectionProvider name={collectionField?.target ?? collectionField?.targetCollection}>
|
||||||
<EllipsisWithTooltip ellipsis={true} ref={ellipsisWithTooltipRef}>
|
<EllipsisWithTooltip ellipsis={true} ref={ellipsisWithTooltipRef}>
|
||||||
{renderRecords()}
|
{renderRecords()}
|
||||||
</EllipsisWithTooltip>
|
</EllipsisWithTooltip>
|
||||||
<ActionContext.Provider
|
<ActionContext.Provider
|
||||||
value={{ visible, setVisible, openMode: 'drawer', snapshot: collectionField.interface === 'snapshot' }}
|
value={{ visible, setVisible, openMode: 'drawer', snapshot: collectionField?.interface === 'snapshot' }}
|
||||||
>
|
>
|
||||||
{renderRecordProvider()}
|
{renderRecordProvider()}
|
||||||
</ActionContext.Provider>
|
</ActionContext.Provider>
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import { RecursionField, observer, useField, useFieldSchema } from '@formily/react';
|
import { RecursionField, observer, useField, useFieldSchema } from '@formily/react';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { CollectionProvider } from '../../../../collection-manager';
|
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 { CreateAction } from '../../../../schema-initializer/components';
|
||||||
|
import { ActionContext, useActionContext } from '../../action';
|
||||||
|
import { useAssociationFieldContext, useInsertSchema } from '../hooks';
|
||||||
import schema from '../schema';
|
import schema from '../schema';
|
||||||
|
|
||||||
export const CreateRecordAction = observer((props) => {
|
export const CreateRecordAction = observer((props) => {
|
||||||
@ -14,14 +13,14 @@ export const CreateRecordAction = observer((props) => {
|
|||||||
const insertAddNewer = useInsertSchema('AddNewer');
|
const insertAddNewer = useInsertSchema('AddNewer');
|
||||||
const { options: collectionField } = useAssociationFieldContext();
|
const { options: collectionField } = useAssociationFieldContext();
|
||||||
const [visibleAddNewer, setVisibleAddNewer] = useState(false);
|
const [visibleAddNewer, setVisibleAddNewer] = useState(false);
|
||||||
const [currentCollection, setCurrentCollection] = useState(collectionField.target);
|
const [currentCollection, setCurrentCollection] = useState(collectionField?.target);
|
||||||
const addbuttonClick = (name) => {
|
const addbuttonClick = (name) => {
|
||||||
insertAddNewer(schema.AddNewer);
|
insertAddNewer(schema.AddNewer);
|
||||||
setVisibleAddNewer(true);
|
setVisibleAddNewer(true);
|
||||||
setCurrentCollection(name);
|
setCurrentCollection(name);
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<CollectionProvider name={collectionField.target}>
|
<CollectionProvider name={collectionField?.target}>
|
||||||
<CreateAction {...props} onClick={(arg) => addbuttonClick(arg)} />
|
<CreateAction {...props} onClick={(arg) => addbuttonClick(arg)} />
|
||||||
<ActionContext.Provider value={{ ...ctx, visible: visibleAddNewer, setVisible: setVisibleAddNewer }}>
|
<ActionContext.Provider value={{ ...ctx, visible: visibleAddNewer, setVisible: setVisibleAddNewer }}>
|
||||||
<CollectionProvider name={currentCollection}>
|
<CollectionProvider name={currentCollection}>
|
||||||
|
@ -44,7 +44,7 @@ export default function useServiceOptions(props) {
|
|||||||
return mergeFilter(
|
return mergeFilter(
|
||||||
[
|
[
|
||||||
mergeFilter([
|
mergeFilter([
|
||||||
isOToAny && !isInFilterFormBlock(fieldSchema)
|
isOToAny && !isInFilterFormBlock(fieldSchema) && collectionField?.foreignKey
|
||||||
? {
|
? {
|
||||||
[collectionField.foreignKey]: {
|
[collectionField.foreignKey]: {
|
||||||
$is: null,
|
$is: null,
|
||||||
@ -53,7 +53,11 @@ export default function useServiceOptions(props) {
|
|||||||
: null,
|
: null,
|
||||||
params?.filter,
|
params?.filter,
|
||||||
]),
|
]),
|
||||||
isOToAny && sourceValue !== undefined && sourceValue !== null && !isInFilterFormBlock(fieldSchema)
|
isOToAny &&
|
||||||
|
sourceValue !== undefined &&
|
||||||
|
sourceValue !== null &&
|
||||||
|
!isInFilterFormBlock(fieldSchema) &&
|
||||||
|
collectionField?.foreignKey
|
||||||
? {
|
? {
|
||||||
[collectionField.foreignKey]: {
|
[collectionField.foreignKey]: {
|
||||||
$eq: sourceValue,
|
$eq: sourceValue,
|
||||||
|
@ -5,7 +5,7 @@ import { uid } from '@formily/shared';
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useFilterByTk, useFormBlockContext } from '../../../block-provider';
|
import { useFormBlockContext } from '../../../block-provider';
|
||||||
import { useCollection, useCollectionManager } from '../../../collection-manager';
|
import { useCollection, useCollectionManager } from '../../../collection-manager';
|
||||||
import { SchemaSettings, isPatternDisabled } from '../../../schema-settings';
|
import { SchemaSettings, isPatternDisabled } from '../../../schema-settings';
|
||||||
import { useCompile, useDesignable, useFieldModeOptions } from '../../hooks';
|
import { useCompile, useDesignable, useFieldModeOptions } from '../../hooks';
|
||||||
@ -344,11 +344,11 @@ export const EditDefaultValue = () => {
|
|||||||
title: t('Set default value'),
|
title: t('Set default value'),
|
||||||
properties: {
|
properties: {
|
||||||
default: {
|
default: {
|
||||||
...collectionField.uiSchema,
|
...collectionField?.uiSchema,
|
||||||
name: 'default',
|
name: 'default',
|
||||||
title: t('Default value'),
|
title: t('Default value'),
|
||||||
'x-decorator': 'FormItem',
|
'x-decorator': 'FormItem',
|
||||||
default: fieldSchema.default || collectionField.defaultValue,
|
default: fieldSchema.default || collectionField?.defaultValue,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} as ISchema
|
} as ISchema
|
||||||
@ -536,7 +536,7 @@ export const EditTitleField = () => {
|
|||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
|
const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
|
||||||
const targetFields = collectionField?.target
|
const targetFields = collectionField?.target
|
||||||
? getCollectionFields(collectionField.target)
|
? getCollectionFields(collectionField?.target)
|
||||||
: getCollectionFields(collectionField?.targetCollection) ?? [];
|
: getCollectionFields(collectionField?.targetCollection) ?? [];
|
||||||
const options = targetFields
|
const options = targetFields
|
||||||
.filter((field) => !field?.target && field.type !== 'boolean')
|
.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.RemainsTheSame}>{t('Remains the same')}</Select.Option>
|
||||||
<Select.Option value={BulkEditFormItemValueType.ChangedTo}>{t('Changed to')}</Select.Option>
|
<Select.Option value={BulkEditFormItemValueType.ChangedTo}>{t('Changed to')}</Select.Option>
|
||||||
<Select.Option value={BulkEditFormItemValueType.Clear}>{t('Clear')}</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.Option value={BulkEditFormItemValueType.AddAttach}>{t('Add attach')}</Select.Option>
|
||||||
)}
|
)}
|
||||||
</Select>
|
</Select>
|
||||||
{/* XXX: Not a best practice */}
|
{/* XXX: Not a best practice */}
|
||||||
{[BulkEditFormItemValueType.ChangedTo, BulkEditFormItemValueType.AddAttach].includes(type) &&
|
{[BulkEditFormItemValueType.ChangedTo, BulkEditFormItemValueType.AddAttach].includes(type) &&
|
||||||
collectionField.interface !== 'checkbox' && (
|
collectionField?.interface !== 'checkbox' && (
|
||||||
<CollectionField {...props} value={value} onChange={valueChangeHandler} style={{ minWidth: 150 }} />
|
<CollectionField {...props} value={value} onChange={valueChangeHandler} style={{ minWidth: 150 }} />
|
||||||
// <SchemaComponent
|
// <SchemaComponent
|
||||||
// schema={collectionSchema}
|
// schema={collectionSchema}
|
||||||
@ -146,7 +146,7 @@ export const BulkEditField = (props: any) => {
|
|||||||
// />
|
// />
|
||||||
)}
|
)}
|
||||||
{[BulkEditFormItemValueType.ChangedTo, BulkEditFormItemValueType.AddAttach].includes(type) &&
|
{[BulkEditFormItemValueType.ChangedTo, BulkEditFormItemValueType.AddAttach].includes(type) &&
|
||||||
collectionField.interface === 'checkbox' && <Checkbox checked={value} onChange={valueChangeHandler} />}
|
collectionField?.interface === 'checkbox' && <Checkbox checked={value} onChange={valueChangeHandler} />}
|
||||||
</Space>
|
</Space>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -13,7 +13,7 @@ const ReadPretty = (props) => {
|
|||||||
const form = useForm();
|
const form = useForm();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!field.title && collectionField?.uiSchema?.title) {
|
if (!field.title && collectionField?.uiSchema?.title) {
|
||||||
field.title = collectionField.uiSchema.title;
|
field.title = collectionField?.uiSchema.title;
|
||||||
}
|
}
|
||||||
}, collectionField?.title);
|
}, collectionField?.title);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user