11// Copyright Contributors to the Packit project.
22// SPDX-License-Identifier: MIT
33
4- import { useMemo } from "react" ;
4+ import { useState } from "react" ;
55
66import {
77 Table ,
@@ -14,7 +14,7 @@ import {
1414} from "@patternfly/react-table" ;
1515
1616import { SkeletonTable } from "@patternfly/react-component-groups" ;
17- import { useInfiniteQuery } from "@tanstack/react-query" ;
17+ import { useQuery } from "@tanstack/react-query" ;
1818import { ErrorConnection } from "../../components/errors/ErrorConnection" ;
1919import { Timestamp } from "../../components/shared/Timestamp" ;
2020import {
@@ -23,10 +23,15 @@ import {
2323} from "../../components/trigger/TriggerLink" ;
2424import { bodhiUpdatesQueryOptions } from "../../queries/bodhi/bodhiUpdatesQuery" ;
2525import { ForgeIcon , ForgeIconByForge } from "../icons/ForgeIcon" ;
26- import { LoadMore } from "../shared/LoadMore" ;
26+ import { PackitPagination } from "../shared/PackitPagination" ;
27+ import { PackitPaginationContext } from "../shared/PackitPaginationContext" ;
2728import { StatusLabel } from "../statusLabels/StatusLabel" ;
2829
2930const BodhiUpdatesTable = ( ) => {
31+ const [ page , setPage ] = useState ( 1 ) ;
32+ const [ perPage , setPerPage ] = useState ( 10 ) ;
33+ const value = { page, setPage, perPage, setPerPage } ;
34+
3035 // Headings
3136 const columnNames = {
3237 forge : "Forge" ,
@@ -36,17 +41,9 @@ const BodhiUpdatesTable = () => {
3641 bodhiUpdate : "Bodhi Update" ,
3742 } ;
3843
39- const {
40- isLoading,
41- isError,
42- fetchNextPage,
43- data,
44- isFetchingNextPage,
45- hasNextPage,
46- } = useInfiniteQuery ( bodhiUpdatesQueryOptions ( ) ) ;
47-
48- // Create a memoization of all the data when we flatten it out. Ideally one should render all the pages separately so that rendering will be done faster
49- const rows = useMemo ( ( ) => ( data ? data . pages . flat ( ) : [ ] ) , [ data ] ) ;
44+ const { isLoading, isError, data } = useQuery (
45+ bodhiUpdatesQueryOptions ( page , perPage ) ,
46+ ) ;
5047
5148 const TableHeads = [
5249 < Th key = { columnNames . forge } >
@@ -71,70 +68,64 @@ const BodhiUpdatesTable = () => {
7168 return < ErrorConnection /> ;
7269 }
7370
74- if ( isLoading ) {
75- return (
76- < SkeletonTable
77- variant = { TableVariant . compact }
78- rows = { 10 }
79- columns = { TableHeads }
80- />
81- ) ;
82- }
83-
8471 return (
85- < >
86- < Table aria-label = "Bodhi updates" variant = { TableVariant . compact } >
87- < Thead >
88- < Tr > { TableHeads } </ Tr >
89- </ Thead >
90- < Tbody >
91- { rows . map ( ( bodhi_update ) => (
92- < Tr key = { bodhi_update . packit_id } >
93- < Td dataLabel = { columnNames . forge } >
94- { bodhi_update . project_url ? (
95- < ForgeIcon url = { bodhi_update . project_url } />
96- ) : (
97- < ForgeIconByForge />
98- ) }
99- </ Td >
100- < Td dataLabel = { columnNames . trigger } >
101- < strong >
102- < TriggerLink trigger = { bodhi_update } >
103- < TriggerSuffix trigger = { bodhi_update } />
104- </ TriggerLink >
105- </ strong >
106- </ Td >
107- < Td dataLabel = { columnNames . branch } >
108- < StatusLabel
109- target = { bodhi_update . branch }
110- status = { bodhi_update . status }
111- link = { `/jobs/bodhi/${ bodhi_update . packit_id } ` }
112- />
113- </ Td >
114- < Td dataLabel = { columnNames . timeProcessed } >
115- < Timestamp stamp = { bodhi_update . submitted_time } />
116- </ Td >
117- < Td dataLabel = { columnNames . bodhiUpdate } >
118- < strong >
119- < a
120- href = { bodhi_update . web_url ?? "" }
121- target = "_blank"
122- rel = "noreferrer"
123- >
124- { bodhi_update . alias }
125- </ a >
126- </ strong >
127- </ Td >
128- </ Tr >
129- ) ) }
130- </ Tbody >
131- </ Table >
132- < LoadMore
133- isFetchingNextPage = { isFetchingNextPage }
134- hasNextPage = { hasNextPage }
135- fetchNextPage = { ( ) => void fetchNextPage ( ) }
136- />
137- </ >
72+ < PackitPaginationContext . Provider value = { value } >
73+ < PackitPagination />
74+ { isLoading ? (
75+ < SkeletonTable
76+ variant = { TableVariant . compact }
77+ rows = { 10 }
78+ columns = { TableHeads }
79+ />
80+ ) : (
81+ < Table aria-label = "Bodhi updates" variant = { TableVariant . compact } >
82+ < Thead >
83+ < Tr > { TableHeads } </ Tr >
84+ </ Thead >
85+ < Tbody >
86+ { data ?. map ( ( bodhi_update ) => (
87+ < Tr key = { bodhi_update . packit_id } >
88+ < Td dataLabel = { columnNames . forge } >
89+ { bodhi_update . project_url ? (
90+ < ForgeIcon url = { bodhi_update . project_url } />
91+ ) : (
92+ < ForgeIconByForge />
93+ ) }
94+ </ Td >
95+ < Td dataLabel = { columnNames . trigger } >
96+ < strong >
97+ < TriggerLink trigger = { bodhi_update } >
98+ < TriggerSuffix trigger = { bodhi_update } />
99+ </ TriggerLink >
100+ </ strong >
101+ </ Td >
102+ < Td dataLabel = { columnNames . branch } >
103+ < StatusLabel
104+ target = { bodhi_update . branch }
105+ status = { bodhi_update . status }
106+ link = { `/jobs/bodhi/${ bodhi_update . packit_id } ` }
107+ />
108+ </ Td >
109+ < Td dataLabel = { columnNames . timeProcessed } >
110+ < Timestamp stamp = { bodhi_update . submitted_time } />
111+ </ Td >
112+ < Td dataLabel = { columnNames . bodhiUpdate } >
113+ < strong >
114+ < a
115+ href = { bodhi_update . web_url ?? "" }
116+ target = "_blank"
117+ rel = "noreferrer"
118+ >
119+ { bodhi_update . alias }
120+ </ a >
121+ </ strong >
122+ </ Td >
123+ </ Tr >
124+ ) ) }
125+ </ Tbody >
126+ </ Table >
127+ ) }
128+ </ PackitPaginationContext . Provider >
138129 ) ;
139130} ;
140131
0 commit comments