refactor: code improve

This commit is contained in:
katherinehhh 2023-05-11 17:18:24 +08:00
parent 9a375cd0b2
commit c7abcd927e
3 changed files with 10 additions and 13 deletions

View File

@ -5,7 +5,7 @@ import { InternalNester } from './InternalNester';
import { InternalPicker } from './InternalPicker';
import { AssociationSelect } from './AssociationSelect';
import { useAssociationCreateActionProps as useCAP } from '../../../block-provider/hooks';
import { useCollection, useCollectionManager } from '../../../collection-manager';
import { useCollectionManager } from '../../../collection-manager';
import { SchemaComponentOptions } from '../../';
import { InternalSubTable } from './InternalSubTable';
import { InternalFileManager } from './FileManager';
@ -18,9 +18,8 @@ export const Editable = observer((props: any) => {
const field: any = useField();
const form = useForm();
const fieldSchema = useFieldSchema();
const { getField } = useCollection();
const { getCollection } = useCollectionManager();
const collectionField = getField(field.props.name);
const { getCollection, getCollectionJoinField } = useCollectionManager();
const collectionField = getCollectionJoinField(fieldSchema?.['x-collection-field']);
const isFileCollection = getCollection(collectionField?.target)?.template === 'file';
const [currentMode, setCurrentMode] = useState(props.mode || (isFileCollection ? 'FileManager' : 'Select'));
const useCreateActionProps = () => {

View File

@ -2,7 +2,7 @@ import { RecursionField, observer, useField, useFieldSchema } from '@formily/rea
import { toArr } from '@formily/shared';
import React, { Fragment, useRef, useState } from 'react';
import { BlockAssociationContext, WithoutTableFieldResource } from '../../../block-provider';
import { CollectionProvider, useCollection, useCollectionManager } from '../../../collection-manager';
import { CollectionProvider, useCollectionManager } from '../../../collection-manager';
import { RecordProvider, useRecord } from '../../../record-provider';
import { FormProvider } from '../../core';
import { useCompile } from '../../hooks';
@ -32,8 +32,7 @@ export const ReadPrettyInternalViewer: React.FC = observer((props: any) => {
const fieldNames = useFieldNames(props);
const [visible, setVisible] = useState(false);
const insertViewer = useInsertSchema('Viewer');
const { getField } = useCollection();
const collectionField = getField(fieldSchema.name) || getCollectionJoinField(fieldSchema?.['x-collection-field']);
const collectionField = getCollectionJoinField(fieldSchema?.['x-collection-field']);
const [record, setRecord] = useState({});
const compile = useCompile();
const labelUiSchema = useLabelUiSchema(collectionField, fieldNames?.label || 'label');

View File

@ -1,17 +1,16 @@
import React, { useEffect, useState } from 'react';
import { useField, observer } from '@formily/react';
import { useFieldSchema, observer } from '@formily/react';
import { AssociationFieldProvider } from './AssociationFieldProvider';
import { InternalNester } from './InternalNester';
import { ReadPrettyInternalViewer } from './InternalViewer';
import { useCollection, useCollectionManager } from '../../../collection-manager';
import { useCollectionManager } from '../../../collection-manager';
import { InternalSubTable } from './InternalSubTable';
import { FileManageReadPretty } from './FileManager';
export const ReadPretty = observer((props: any) => {
const field: any = useField();
const { getField } = useCollection();
const { getCollection } = useCollectionManager();
const collectionField = getField(field.props.name);
const fieldSchema = useFieldSchema();
const { getCollection, getCollectionJoinField } = useCollectionManager();
const collectionField = getCollectionJoinField(fieldSchema?.['x-collection-field']);
const isFileCollection = getCollection(collectionField?.target)?.template === 'file';
const [currentMode, setCurrentMode] = useState(props.mode || (isFileCollection ? 'FileManager' : 'Select'));
useEffect(() => {