fix(RemoteSelect): fix 'N/A' issue (#5878)

This commit is contained in:
Zeke Zhang 2024-12-13 09:00:57 +08:00 committed by GitHub
parent 753e911ac4
commit e94eab7680
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,13 +15,13 @@ import { uniqBy } from 'lodash';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { ResourceActionOptions, useRequest } from '../../../api-client';
import { useCollection_deprecated, useCollectionManager_deprecated } from '../../../collection-manager';
import { mergeFilter } from '../../../filter-provider/utils';
import { useCompile } from '../../hooks';
import { FieldNames, Select, SelectProps, defaultFieldNames } from '../select';
import { ReadPretty } from './ReadPretty';
import { useDataSourceHeaders } from '../../../data-source/utils';
import { useDataSourceKey } from '../../../data-source/data-source/DataSourceProvider';
import { useDataSourceHeaders } from '../../../data-source/utils';
import { mergeFilter } from '../../../filter-provider/utils';
import { withDynamicSchemaProps } from '../../../hoc/withDynamicSchemaProps';
import { useCompile } from '../../hooks';
import { defaultFieldNames, FieldNames, Select, SelectProps } from '../select';
import { ReadPretty } from './ReadPretty';
const EMPTY = 'N/A';
export type RemoteSelectProps<P = any> = SelectProps<P, any> & {
@ -234,10 +234,15 @@ const InternalRemoteSelect = withDynamicSchemaProps(
return v != null ? (Array.isArray(v) ? v : [v]) : [];
}
const valueOptions =
(v != null && (Array.isArray(v) ? v : [{ ...v, [fieldNames.value]: v[fieldNames.value] || v }])) || [];
(v != null &&
(Array.isArray(v)
? v.map((item) => ({ ...item, [fieldNames.value]: item[fieldNames.value] || item }))
: [{ ...v, [fieldNames.value]: v[fieldNames.value] || v }])) ||
[];
const filtered = typeof optionFilter === 'function' ? data.data.filter(optionFilter) : data.data;
return uniqBy(filtered.concat(valueOptions ?? []), fieldNames.value);
}, [value, defaultValue, data?.data, fieldNames.value, optionFilter]);
const onDropdownVisibleChange = (visible) => {
setOpen(visible);
searchData.current = null;
@ -246,6 +251,7 @@ const InternalRemoteSelect = withDynamicSchemaProps(
}
firstRun.current = true;
};
return (
<Select
open={open}