From fd2b867c1842608bf55ab8b2aa26028591a17444 Mon Sep 17 00:00:00 2001 From: ytkimirti Date: Fri, 3 May 2024 16:29:22 +0300 Subject: [PATCH] fix: pagination not reseting after filter changes --- .../components/databrowser/components/sidebar/index.tsx | 2 ++ .../components/databrowser/hooks/useFetchPaginatedKeys.ts | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/react-databrowser/src/components/databrowser/components/sidebar/index.tsx b/packages/react-databrowser/src/components/databrowser/components/sidebar/index.tsx index c441951..b9e8fc4 100644 --- a/packages/react-databrowser/src/components/databrowser/components/sidebar/index.tsx +++ b/packages/react-databrowser/src/components/databrowser/components/sidebar/index.tsx @@ -44,10 +44,12 @@ export function Sidebar({ onDataKeyChange, selectedDataKey }: Props) { direction, handleSearch, refreshSearch, + resetPagination, searchInputRef, } = useFetchPaginatedKeys(selectedDataType); const handleDataTypeChange = (dataType?: RedisDataTypeUnion) => { + resetPagination(); setSelectedDataType(dataType); }; diff --git a/packages/react-databrowser/src/components/databrowser/hooks/useFetchPaginatedKeys.ts b/packages/react-databrowser/src/components/databrowser/hooks/useFetchPaginatedKeys.ts index aa2d437..3eb8582 100644 --- a/packages/react-databrowser/src/components/databrowser/hooks/useFetchPaginatedKeys.ts +++ b/packages/react-databrowser/src/components/databrowser/hooks/useFetchPaginatedKeys.ts @@ -1,7 +1,7 @@ import { queryClient } from "@/lib/clients"; import { useDatabrowser } from "@/store"; import { RedisDataTypes, type RedisDataTypeUnion } from "@/types"; -import { useCallback, useMemo, useRef, useState } from "react"; +import { useCallback, useRef, useState } from "react"; import { useQuery } from "@tanstack/react-query"; import { useDebounce } from "./useDebounce"; import type { Redis } from "@upstash/redis"; @@ -192,6 +192,10 @@ export const useFetchPaginatedKeys = (dataType?: RedisDataTypeUnion) => { [currentPage], ); + const resetPagination = () => { + setCurrentPage(0); + }; + // If user doesn't pass any asterisk we add two of them to end and start const handleSearch = (query: string) => { setSearchTerm(!query.includes("*") ? `*${query}*` : query); @@ -215,6 +219,7 @@ export const useFetchPaginatedKeys = (dataType?: RedisDataTypeUnion) => { isLoading, error, data: data?.keys, + resetPagination, handlePageChange, handleSearch, refreshSearch,