fix: select options (#2101)

This commit is contained in:
katherinehhh 2023-06-23 12:00:59 +08:00 committed by GitHub
parent bdcbe7392f
commit 480e499f67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,18 +1,18 @@
import { LoadingOutlined } from '@ant-design/icons'; import { LoadingOutlined } from '@ant-design/icons';
import { connect, mapProps, mapReadPretty, useField, useFieldSchema, useForm } from '@formily/react'; import { connect, mapProps, mapReadPretty, useField, useFieldSchema, useForm } from '@formily/react';
import { SelectProps, Tag, Empty, Divider } from 'antd'; import { Divider, SelectProps, Tag } from 'antd';
import { uniqBy } from 'lodash';
import flat from 'flat'; import flat from 'flat';
import { uniqBy } from 'lodash';
import moment from 'moment'; import moment from 'moment';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { ResourceActionOptions, useRequest } from '../../../api-client'; import { ResourceActionOptions, useRequest } from '../../../api-client';
import { useBlockRequestContext } from '../../../block-provider/BlockProvider';
import { mergeFilter } from '../../../block-provider/SharedFilterProvider'; import { mergeFilter } from '../../../block-provider/SharedFilterProvider';
import { useCollection, useCollectionManager } from '../../../collection-manager'; import { useCollection, useCollectionManager } from '../../../collection-manager';
import { Select, defaultFieldNames } from '../select';
import { ReadPretty } from './ReadPretty';
import { useBlockRequestContext } from '../../../block-provider/BlockProvider';
import { getInnermostKeyAndValue } from '../../common/utils/uitls'; import { getInnermostKeyAndValue } from '../../common/utils/uitls';
import { parseVariables, extractFilterfield, generatePattern, extractValuesByPattern } from './utils'; import { defaultFieldNames, Select } from '../select';
import { ReadPretty } from './ReadPretty';
import { extractFilterfield, extractValuesByPattern, generatePattern, parseVariables } from './utils';
const EMPTY = 'N/A'; const EMPTY = 'N/A';
export type RemoteSelectProps<P = any> = SelectProps<P, any> & { export type RemoteSelectProps<P = any> = SelectProps<P, any> & {
@ -229,8 +229,10 @@ const InternalRemoteSelect = connect(
if (!data?.data?.length) { if (!data?.data?.length) {
return value != null ? (Array.isArray(value) ? value : [value]) : []; return value != null ? (Array.isArray(value) ? value : [value]) : [];
} }
return uniqBy(data?.data || [], fieldNames.value); const valueOptions = (value != null && (Array.isArray(value) ? value : [value])) || [];
return uniqBy(data?.data?.concat(valueOptions) || [], fieldNames.value);
}, [data?.data, value]); }, [data?.data, value]);
const onDropdownVisibleChange = (visible) => { const onDropdownVisibleChange = (visible) => {
setOpen(visible); setOpen(visible);
searchData.current = null; searchData.current = null;