@@ -16,15 +16,16 @@ import {
1616import { SkeletonTable } from "@patternfly/react-component-groups" ;
1717import { LabelGroup } from "@patternfly/react-core" ;
1818import { ExternalLinkAltIcon } from "@patternfly/react-icons" ;
19- import { useInfiniteQuery } from "@tanstack/react-query" ;
19+ import { useQuery } from "@tanstack/react-query" ;
2020import { Link } from "@tanstack/react-router" ;
2121import { PipelineRun } from "../../apiDefinitions" ;
2222import { pipelinesQueryOptions } from "../../queries/pipeline/pipelinesQuery" ;
2323import coprLogo from "../../static/copr.ico" ;
2424import kojiLogo from "../../static/koji.ico" ;
2525import { ErrorConnection } from "../errors/ErrorConnection" ;
2626import { ForgeIcon , ForgeIconByForge } from "../icons/ForgeIcon" ;
27- import { LoadMore } from "../shared/LoadMore" ;
27+ import { PackitPagination } from "../shared/PackitPagination" ;
28+ import { PackitPaginationContext } from "../shared/PackitPaginationContext" ;
2829import { Timestamp } from "../shared/Timestamp" ;
2930import { StatusLabel } from "../statusLabels/StatusLabel" ;
3031import { SyncReleaseTargetStatusLabel } from "../statusLabels/SyncReleaseTargetStatusLabel" ;
@@ -104,24 +105,20 @@ const columnNames = {
104105 external : "External" ,
105106} ;
106107export function PipelinesTable ( ) {
107- const {
108- isLoading,
109- isError,
110- fetchNextPage,
111- data,
112- isFetchingNextPage,
113- hasNextPage,
114- } = useInfiniteQuery ( pipelinesQueryOptions ( ) ) ;
115-
116- // 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
117- const rows = useMemo ( ( ) => ( data ? data . pages . flat ( ) : [ ] ) , [ data ] ) ;
108+ const [ page , setPage ] = useState ( 1 ) ;
109+ const [ perPage , setPerPage ] = useState ( 10 ) ;
110+ const value = { page, setPage, perPage, setPerPage } ;
111+
112+ const { isLoading, isError, data } = useQuery (
113+ pipelinesQueryOptions ( page , perPage ) ,
114+ ) ;
118115
119116 const mappedRows = useMemo (
120117 ( ) =>
121- rows
122- . filter ( ( run ) => run . trigger )
118+ data
119+ ? .filter ( ( run ) => run . trigger )
123120 . map ( ( run ) => < PipelinesTableTr key = { run . merged_run_id } run = { run } /> ) ,
124- [ columnNames , rows ] ,
121+ [ columnNames , data ] ,
125122 ) ;
126123
127124 const TableHeads = [
@@ -142,30 +139,24 @@ export function PipelinesTable() {
142139 return < ErrorConnection /> ;
143140 }
144141
145- if ( isLoading ) {
146- return (
147- < SkeletonTable
148- variant = { TableVariant . compact }
149- rows = { 10 }
150- columns = { TableHeads }
151- />
152- ) ;
153- }
154-
155142 return (
156- < >
157- < Table aria-label = "Pipeline runs" variant = { TableVariant . compact } >
158- < Thead >
159- < Tr > { TableHeads } </ Tr >
160- </ Thead >
161- < Tbody > { mappedRows } </ Tbody >
162- </ Table >
163- < LoadMore
164- isFetchingNextPage = { isFetchingNextPage }
165- hasNextPage = { hasNextPage }
166- fetchNextPage = { ( ) => void fetchNextPage ( ) }
167- />
168- </ >
143+ < PackitPaginationContext . Provider value = { value } >
144+ < PackitPagination />
145+ { isLoading ? (
146+ < SkeletonTable
147+ variant = { TableVariant . compact }
148+ rows = { perPage }
149+ columns = { TableHeads }
150+ />
151+ ) : (
152+ < Table aria-label = "Pipeline runs" variant = { TableVariant . compact } >
153+ < Thead >
154+ < Tr > { TableHeads } </ Tr >
155+ </ Thead >
156+ < Tbody > { mappedRows } </ Tbody >
157+ </ Table >
158+ ) }
159+ </ PackitPaginationContext . Provider >
169160 ) ;
170161}
171162
0 commit comments