mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 07:25:15 +00:00
refactor: code improve
This commit is contained in:
parent
9a375cd0b2
commit
c7abcd927e
@ -5,7 +5,7 @@ import { InternalNester } from './InternalNester';
|
|||||||
import { InternalPicker } from './InternalPicker';
|
import { InternalPicker } from './InternalPicker';
|
||||||
import { AssociationSelect } from './AssociationSelect';
|
import { AssociationSelect } from './AssociationSelect';
|
||||||
import { useAssociationCreateActionProps as useCAP } from '../../../block-provider/hooks';
|
import { useAssociationCreateActionProps as useCAP } from '../../../block-provider/hooks';
|
||||||
import { useCollection, useCollectionManager } from '../../../collection-manager';
|
import { useCollectionManager } from '../../../collection-manager';
|
||||||
import { SchemaComponentOptions } from '../../';
|
import { SchemaComponentOptions } from '../../';
|
||||||
import { InternalSubTable } from './InternalSubTable';
|
import { InternalSubTable } from './InternalSubTable';
|
||||||
import { InternalFileManager } from './FileManager';
|
import { InternalFileManager } from './FileManager';
|
||||||
@ -18,9 +18,8 @@ export const Editable = observer((props: any) => {
|
|||||||
const field: any = useField();
|
const field: any = useField();
|
||||||
const form = useForm();
|
const form = useForm();
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const { getField } = useCollection();
|
const { getCollection, getCollectionJoinField } = useCollectionManager();
|
||||||
const { getCollection } = useCollectionManager();
|
const collectionField = getCollectionJoinField(fieldSchema?.['x-collection-field']);
|
||||||
const collectionField = getField(field.props.name);
|
|
||||||
const isFileCollection = getCollection(collectionField?.target)?.template === 'file';
|
const isFileCollection = getCollection(collectionField?.target)?.template === 'file';
|
||||||
const [currentMode, setCurrentMode] = useState(props.mode || (isFileCollection ? 'FileManager' : 'Select'));
|
const [currentMode, setCurrentMode] = useState(props.mode || (isFileCollection ? 'FileManager' : 'Select'));
|
||||||
const useCreateActionProps = () => {
|
const useCreateActionProps = () => {
|
||||||
|
@ -2,7 +2,7 @@ import { RecursionField, observer, useField, useFieldSchema } from '@formily/rea
|
|||||||
import { toArr } from '@formily/shared';
|
import { toArr } from '@formily/shared';
|
||||||
import React, { Fragment, useRef, useState } from 'react';
|
import React, { Fragment, useRef, useState } from 'react';
|
||||||
import { BlockAssociationContext, WithoutTableFieldResource } from '../../../block-provider';
|
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 { RecordProvider, useRecord } from '../../../record-provider';
|
||||||
import { FormProvider } from '../../core';
|
import { FormProvider } from '../../core';
|
||||||
import { useCompile } from '../../hooks';
|
import { useCompile } from '../../hooks';
|
||||||
@ -32,8 +32,7 @@ export const ReadPrettyInternalViewer: React.FC = observer((props: any) => {
|
|||||||
const fieldNames = useFieldNames(props);
|
const fieldNames = useFieldNames(props);
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const insertViewer = useInsertSchema('Viewer');
|
const insertViewer = useInsertSchema('Viewer');
|
||||||
const { getField } = useCollection();
|
const collectionField = getCollectionJoinField(fieldSchema?.['x-collection-field']);
|
||||||
const collectionField = getField(fieldSchema.name) || getCollectionJoinField(fieldSchema?.['x-collection-field']);
|
|
||||||
const [record, setRecord] = useState({});
|
const [record, setRecord] = useState({});
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const labelUiSchema = useLabelUiSchema(collectionField, fieldNames?.label || 'label');
|
const labelUiSchema = useLabelUiSchema(collectionField, fieldNames?.label || 'label');
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { useField, observer } from '@formily/react';
|
import { useFieldSchema, observer } from '@formily/react';
|
||||||
import { AssociationFieldProvider } from './AssociationFieldProvider';
|
import { AssociationFieldProvider } from './AssociationFieldProvider';
|
||||||
import { InternalNester } from './InternalNester';
|
import { InternalNester } from './InternalNester';
|
||||||
import { ReadPrettyInternalViewer } from './InternalViewer';
|
import { ReadPrettyInternalViewer } from './InternalViewer';
|
||||||
import { useCollection, useCollectionManager } from '../../../collection-manager';
|
import { useCollectionManager } from '../../../collection-manager';
|
||||||
import { InternalSubTable } from './InternalSubTable';
|
import { InternalSubTable } from './InternalSubTable';
|
||||||
import { FileManageReadPretty } from './FileManager';
|
import { FileManageReadPretty } from './FileManager';
|
||||||
|
|
||||||
export const ReadPretty = observer((props: any) => {
|
export const ReadPretty = observer((props: any) => {
|
||||||
const field: any = useField();
|
const fieldSchema = useFieldSchema();
|
||||||
const { getField } = useCollection();
|
const { getCollection, getCollectionJoinField } = useCollectionManager();
|
||||||
const { getCollection } = useCollectionManager();
|
const collectionField = getCollectionJoinField(fieldSchema?.['x-collection-field']);
|
||||||
const collectionField = getField(field.props.name);
|
|
||||||
const isFileCollection = getCollection(collectionField?.target)?.template === 'file';
|
const isFileCollection = getCollection(collectionField?.target)?.template === 'file';
|
||||||
const [currentMode, setCurrentMode] = useState(props.mode || (isFileCollection ? 'FileManager' : 'Select'));
|
const [currentMode, setCurrentMode] = useState(props.mode || (isFileCollection ? 'FileManager' : 'Select'));
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user