Skip to content

Commit

Permalink
refactor: reuse formatStrategyValues
Browse files Browse the repository at this point in the history
  • Loading branch information
aojunhao123 committed Nov 21, 2024
1 parent ff9f216 commit a5625a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,

React.useEffect(() => {
if (searchValue) {
setSearchExpandedKeys(getAllKeys(treeData, fieldNames));
setSearchExpandedKeys(getAllKeys(memoTreeData, fieldNames));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [searchValue]);
Expand Down
20 changes: 7 additions & 13 deletions src/TreeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,15 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
extra: { triggerValue?: SafeKey; selected?: boolean },
source: SelectSource,
) => {
const formattedKeyList = formatStrategyValues(
newRawValues,
mergedShowCheckedStrategy,
keyEntities,
mergedFieldNames,
);

// if multiple and maxCount is set, check if exceed maxCount
if (mergedMultiple && maxCount !== undefined) {
const formattedKeyList = formatStrategyValues(
newRawValues,
mergedShowCheckedStrategy,
keyEntities,
mergedFieldNames,
);

if (formattedKeyList.length > maxCount) {
return;
}
Expand All @@ -441,12 +441,6 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
if (onChange) {
let eventValues: SafeKey[] = newRawValues;
if (treeConduction) {
const formattedKeyList = formatStrategyValues(
newRawValues,
mergedShowCheckedStrategy,
keyEntities,
mergedFieldNames,
);
eventValues = formattedKeyList.map(key => {
const entity = valueEntities.get(key);
return entity ? entity.node[mergedFieldNames.value] : key;
Expand Down

0 comments on commit a5625a1

Please sign in to comment.