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(SearchTreeInfinite): adjust selected row item management #820

Merged
merged 1 commit into from
Jan 9, 2025
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
33 changes: 21 additions & 12 deletions src/widgets/views/SearchTreeInfinite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,16 @@ function SearchTreeInfiniteComp(props: SearchTreeInfiniteProps, ref: any) {
],
);

const changeSelectedRowItems = useCallback(
(newSelectedRowItems: any[]) => {
setSelectedRowItems?.(newSelectedRowItems);
onChangeSelectedRowKeys?.(newSelectedRowItems.map((item) => item.id));
},
[onChangeSelectedRowKeys, setSelectedRowItems],
);

const changeSelectedRowKeys = useCallback(
(newSelectedRowKeys: any[]) => {
(newSelectedRowKeys: number[]) => {
setSelectedRowItems?.(newSelectedRowKeys.map((id: number) => ({ id })));
onChangeSelectedRowKeys?.(newSelectedRowKeys);
},
Expand Down Expand Up @@ -460,7 +468,7 @@ function SearchTreeInfiniteComp(props: SearchTreeInfiniteProps, ref: any) {

const selectAllPromise = async () => {
if (nameSearch) {
setSelectedRowItems?.(lastAssignedResults.current);
changeSelectedRowItems(lastAssignedResults.current);
return;
}

Expand All @@ -476,7 +484,7 @@ function SearchTreeInfiniteComp(props: SearchTreeInfiniteProps, ref: any) {
totalItems: totalRows,
},
);
setSelectedRowItems?.(allRowsResults.map((id: number) => ({ id })));
changeSelectedRowItems(allRowsResults.map((id: number) => ({ id })));
};

if (mustSelectAll) {
Expand All @@ -493,9 +501,10 @@ function SearchTreeInfiniteComp(props: SearchTreeInfiniteProps, ref: any) {
selectAllPromise();
}
} else {
setSelectedRowItems?.([]);
setSelectedRowItems([]);
}
}, [
changeSelectedRowItems,
domain,
mergedParams,
model,
Expand Down Expand Up @@ -613,11 +622,11 @@ function SearchTreeInfiniteComp(props: SearchTreeInfiniteProps, ref: any) {
}, [searchParams, searchVisible]);

const refresh = useCallback(async () => {
setSelectedRowItems?.([]);
changeSelectedRowItems([]);
currentSearchParamsString.current = undefined;
await updateTotalRows();
tableRef?.current?.refresh();
}, [setSelectedRowItems, updateTotalRows]);
}, [changeSelectedRowItems, updateTotalRows]);

useImperativeHandle(ref, () => ({
refreshResults: refresh,
Expand Down Expand Up @@ -658,28 +667,28 @@ function SearchTreeInfiniteComp(props: SearchTreeInfiniteProps, ref: any) {
);

const onSearchFilterClear = useCallback(() => {
setSelectedRowItems?.([]);
changeSelectedRowItems([]);
tableRef.current?.unselectAll();
setSearchTreeNameSearch?.(undefined);
setSearchParams?.([]);
setSearchValues?.(undefined);
}, [
setSelectedRowItems,
changeSelectedRowItems,
setSearchTreeNameSearch,
setSearchParams,
setSearchValues,
]);

const onSearchFilterSubmit = useCallback(
({ params, searchValues }: any) => {
setSelectedRowItems?.([]);
changeSelectedRowItems([]);
tableRef.current?.unselectAll();
setSearchTreeNameSearch?.(undefined);
setSearchParams?.(params);
setSearchValues?.(searchValues);
},
[
setSelectedRowItems,
changeSelectedRowItems,
setSearchTreeNameSearch,
setSearchParams,
setSearchValues,
Expand Down Expand Up @@ -713,15 +722,15 @@ function SearchTreeInfiniteComp(props: SearchTreeInfiniteProps, ref: any) {

const onSideSearchFilterSubmit = useCallback(
({ params, values }: any) => {
setSelectedRowItems?.([]);
changeSelectedRowItems([]);
tableRef.current?.unselectAll();
setSearchTreeNameSearch?.(undefined);
setSearchParams?.(params);
setSearchValues?.(values);
setSearchVisible?.(false);
},
[
setSelectedRowItems,
changeSelectedRowItems,
setSearchTreeNameSearch,
setSearchParams,
setSearchValues,
Expand Down
Loading