refactor: useFieldModeOptions (#2612)

* refactor: useFieldModeOptions

* refactor: code improve

* refactor: code improve
This commit is contained in:
katherinehhh 2023-09-08 09:40:34 +08:00 committed by GitHub
parent f82b466aaa
commit 0d465f4d71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 6 deletions

View File

@ -1,4 +1,4 @@
import { useField, useFieldSchema } from '@formily/react'; import { useField, useFieldSchema, useForm } from '@formily/react';
import { useMemo } from 'react'; import { useMemo } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useCollection, useCollectionManager } from '../../collection-manager'; import { useCollection, useCollectionManager } from '../../collection-manager';
@ -8,7 +8,8 @@ export const useFieldModeOptions = (props?) => {
const currentFieldSchema = useFieldSchema(); const currentFieldSchema = useFieldSchema();
const fieldSchema = props?.fieldSchema || currentFieldSchema; const fieldSchema = props?.fieldSchema || currentFieldSchema;
const field = useField(); const field = useField();
const isReadPretty = field.readPretty; const form = useForm();
const isReadPretty = field.readPretty && form.readPretty;
const isSubTableField = props?.fieldSchema; const isSubTableField = props?.fieldSchema;
const { getField } = useCollection(); const { getField } = useCollection();
const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']); const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);

View File

@ -47,6 +47,7 @@ import {
getInheritCollections, getInheritCollections,
getPopupContainer, getPopupContainer,
useGCMTranslation, useGCMTranslation,
cleanGraphContainer,
} from './utils'; } from './utils';
const { drop, groupBy, last, maxBy, minBy, take, uniq } = lodash; const { drop, groupBy, last, maxBy, minBy, take, uniq } = lodash;
@ -628,7 +629,6 @@ export const GraphDrawPage = React.memo(() => {
targetGraph.selectedCollections = queryString; targetGraph.selectedCollections = queryString;
}; };
const handleConnectionParents = (collections) => { const handleConnectionParents = (collections) => {
console.log(collections);
let data = targetGraph.selectedCollections.split(',') || []; let data = targetGraph.selectedCollections.split(',') || [];
data = data.concat(collections); data = data.concat(collections);
const queryString = uniq(data).toString(); const queryString = uniq(data).toString();
@ -1079,6 +1079,9 @@ export const GraphDrawPage = React.memo(() => {
} else { } else {
!selectedCollections && renderInitGraphCollection(collections); !selectedCollections && renderInitGraphCollection(collections);
} }
return () => {
cleanGraphContainer();
};
}, [searchParams, collectionList]); }, [searchParams, collectionList]);
const loadCollections = async () => { const loadCollections = async () => {

View File

@ -30,9 +30,6 @@ export const SelectCollectionsAction = (props) => {
getPopupContainer={getPopupContainer} getPopupContainer={getPopupContainer}
mode="multiple" mode="multiple"
allowClear allowClear
onSearch={(value) => {
console.log(value);
}}
options={collectionOptions} options={collectionOptions}
onChange={handleChange} onChange={handleChange}
style={{ minWidth: 200, position: 'fixed', margin: '24px', zIndex: 1000, maxWidth: '60%' }} style={{ minWidth: 200, position: 'fixed', margin: '24px', zIndex: 1000, maxWidth: '60%' }}

View File

@ -552,3 +552,7 @@ export const getPopupContainer = () => {
} }
return (graphContainer = document.getElementById('graph_container')); return (graphContainer = document.getElementById('graph_container'));
}; };
export const cleanGraphContainer = () => {
graphContainer = null;
};