Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pro:search): selecting option after remote search overides value #1935

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/pro/search/src/segments/CreateSelectSegment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function createSelectSegment(
name: 'select',
inputClassName: [`${prefixCls}-select-segment-input`],
containerClassName: [`${prefixCls}-select-segment-container`],
parse: input => parseInput(input, config, locale.allSelected),
parse: (input, _, getCacheData) => parseInput(input, config, locale.allSelected, getCacheData),
format: (value, states, getCacheData, setCacheData) =>
formatValue(value, states, getCacheData, setCacheData, config, locale.allSelected),
panelRenderer,
Expand All @@ -81,14 +81,18 @@ function parseInput(
input: string,
config: SelectSearchField['fieldConfig'],
allSelected: string,
getCacheData: (dataKey: string) => any,
): VKey | VKey[] | undefined {
const { concludeAllSelected, separator, dataSource, multiple } = config
const trimedInput = input.trim()

const cachedData = getCacheData(dataSourceCacheKey)
const mergedDataSource = cachedData ? mergeData(cachedData, dataSource) : dataSource

const keys =
concludeAllSelected && trimedInput === allSelected
? dataSource.map(data => data.key)
: getKeyByLabels(dataSource, trimedInput.split(separator ?? defaultSeparator))
? mergedDataSource.map(data => data.key)
: getKeyByLabels(mergedDataSource, trimedInput.split(separator ?? defaultSeparator))

return multiple ? (keys.length > 0 ? keys : undefined) : keys[0]
}
Expand Down
Loading