refactor: remoteSelect support non object value (#2375)

This commit is contained in:
katherinehhh 2023-08-04 11:00:30 +08:00 committed by GitHub
parent 5480167827
commit 45a5cdc643
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -199,7 +199,7 @@ const InternalRemoteSelect = connect(
}, },
}, },
{ {
manual, manual: manual && Object.prototype.toString.call(value) === '[object Object]',
debounceWait: wait, debounceWait: wait,
}, },
); );
@ -254,7 +254,8 @@ const InternalRemoteSelect = connect(
if (!data?.data?.length) { if (!data?.data?.length) {
return v != null ? (Array.isArray(v) ? v : [v]) : []; return v != null ? (Array.isArray(v) ? v : [v]) : [];
} }
const valueOptions = (v != null && (Array.isArray(v) ? v : [v])) || []; const valueOptions =
(v != null && (Array.isArray(v) ? v : [{ ...v, [fieldNames.value]: v[fieldNames.value] || v }])) || [];
return uniqBy(data?.data?.concat(valueOptions) || [], fieldNames.value); return uniqBy(data?.data?.concat(valueOptions) || [], fieldNames.value);
}, [value, defaultValue, data?.data, fieldNames.value]); }, [value, defaultValue, data?.data, fieldNames.value]);
@ -324,7 +325,7 @@ const InternalRemoteSelect = connect(
mapReadPretty(ReadPretty), mapReadPretty(ReadPretty),
); );
export const RemoteSelect = InternalRemoteSelect as unknown as typeof InternalRemoteSelect & { export const RemoteSelect = (InternalRemoteSelect as unknown) as typeof InternalRemoteSelect & {
ReadPretty: typeof ReadPretty; ReadPretty: typeof ReadPretty;
}; };