Skip to content

Commit

Permalink
[master] feat: enhance useUrlSearchParamsStatus hook with reset pageI…
Browse files Browse the repository at this point in the history
…ndex when columnFilters has changed (#4424)

feat: enhance useUrlSearchParamsStatus hook with reset pageIndex when columnFilters has changed

Signed-off-by: ya zhou <huyazhou@msn.com>
Co-authored-by: ya zhou <huyazhou@msn.com>
  • Loading branch information
ks-ci-bot and yazhouio authored Jan 8, 2025
1 parent 2d42d2b commit 8eedc78
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/shared/src/utils/table/hooks/useUrlSearchParamsStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,24 @@ const pickUrlSearchParams = (params: URLSearchParams | string, pickKeys: string[
return newParams;
};

export const useUrlSearchParamsStatus = (omitKeys: string[] = []) => {
export const useUrlSearchParamsStatus = (
omitKeys: string[] = [],
): {
state: Partial<TableState>;
setState: (state: Partial<TableState>, type: keyof TableState) => void;
params: URLSearchParams;
setParams: (params: URLSearchParams) => void;
} => {
const [params, setParams] = useSearchParams();
const paramsRef = React.useRef(params.toString());
const [state, setState] = React.useState<Partial<TableState>>(
urlParams2Status(omitUrlSearchParams(params, omitKeys)),
);

const handleState = React.useCallback((_state: Partial<TableState>) => {
const handleState = React.useCallback((_state: Partial<TableState>, type: keyof TableState) => {
if (type === 'columnFilters') {
set(_state, 'pagination.pageIndex', 0);
}
const newParams = status2UrlParams(_state, pickUrlSearchParams(paramsRef.current, omitKeys));
setState(_state);
paramsRef.current = newParams.toString();
Expand Down

0 comments on commit 8eedc78

Please sign in to comment.