From 8cd95a8c1d9d58a631708970e0a67f118f2d52bf Mon Sep 17 00:00:00 2001 From: SaniyaKalamkar <68800346+SaniyaKalamkar@users.noreply.github.com> Date: Thu, 23 Jan 2025 14:31:27 -0500 Subject: [PATCH] feat: rows/page dropbox. Fixes #1764 (#2337) --- .../partials/K8sEvents/index.tsx | 137 ++++++++++++------ 1 file changed, 90 insertions(+), 47 deletions(-) diff --git a/ui/src/components/common/SlidingSidebar/partials/K8sEvents/index.tsx b/ui/src/components/common/SlidingSidebar/partials/K8sEvents/index.tsx index e95e4496ce..4e0cbed45a 100644 --- a/ui/src/components/common/SlidingSidebar/partials/K8sEvents/index.tsx +++ b/ui/src/components/common/SlidingSidebar/partials/K8sEvents/index.tsx @@ -19,7 +19,8 @@ import { useNamespaceK8sEventsFetch } from "../../../../../utils/fetchWrappers/n import "./style.css"; -const MAX_PAGE_SIZE = 6; +const DEFAULT_PAGE_SIZE_OPTIONS = [2, 4, 6, 8, 10, 15, 20]; + const DEFAULT_FILTER_VALUE = "All"; export interface K8sEventsProps { @@ -49,6 +50,7 @@ export function K8sEvents({ useState(DEFAULT_FILTER_VALUE); const [page, setPage] = useState(1); const [totalPages, setTotalPages] = useState(0); + const [pageSize, setPageSize] = useState(6); const [typeFilter, setTypeFilter] = useState(); const [filteredEvents, setFilteredEvents] = useState([]); const { data, loading, error } = useNamespaceK8sEventsFetch({ @@ -58,7 +60,6 @@ export function K8sEvents({ vertex: selectedVertex === DEFAULT_FILTER_VALUE ? vertexId : selectedVertex, }); - // Update filtered events based on page selected and filter useEffect(() => { if (!data) { setFilteredEvents([]); @@ -75,7 +76,7 @@ export function K8sEvents({ // Break list into pages const pages = filtered.reduce((resultArray: any[], item, index) => { - const chunkIndex = Math.floor(index / MAX_PAGE_SIZE); + const chunkIndex = Math.floor(index / pageSize); if (!resultArray[chunkIndex]) { resultArray[chunkIndex] = []; } @@ -84,13 +85,11 @@ export function K8sEvents({ }, []); if (page > pages.length) { - // Reset to page 1 if current page is greater than total pages after filtering setPage(1); } - // Set filtered namespaces with current page setFilteredEvents(pages[page - 1] || []); setTotalPages(pages.length); - }, [data, page, typeFilter]); + }, [data, page, pageSize, typeFilter]); const handlePageChange = useCallback( (event: React.ChangeEvent, value: number) => { @@ -120,53 +119,96 @@ export function K8sEvents({ }, [] ); - const typeCounts = useMemo(() => { return ( - - - - Normal -
- {data?.normalCount || 0} -
-
-
- - + Normal +
+ {data?.normalCount || 0} +
+
+
+ - Warning -
- {data?.warningCount || 0} -
- -
-
+ + Warning +
+ {data?.warningCount || 0} +
+
+ + + + {} + + + + + ); - }, [data, typeFilter, handleTypeFilterChange]); + }, [data, typeFilter, pageSize, handleTypeFilterChange]); const table = useMemo(() => { if (loading) { @@ -211,7 +253,7 @@ export function K8sEvents({ > @@ -494,3 +536,4 @@ export function K8sEvents({ ); } +