Skip to content

Commit 14b0032

Browse files
Merge pull request #161 from lokanandaprabhu/feature/SRVKP-6638
SRVKP-6638: PipelineRuns List page doesn't fetch next page data on scroll
2 parents 1adac09 + 5bbdaf4 commit 14b0032

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

src/components/pipelineRuns-list/PipelineRunsList.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import * as React from 'react';
2+
import { useTranslation } from 'react-i18next';
3+
import { useParams } from 'react-router-dom-v5-compat';
24
import { SortByDirection } from '@patternfly/react-table';
35
import {
46
ListPageBody,
@@ -11,8 +13,7 @@ import { usePipelineRunsFilters } from './usePipelineRunsFilters';
1113
import { PipelineRunKind } from '../../types';
1214
import { useGetPipelineRuns } from '../hooks/useTektonResult';
1315
import PipelineRunsRow from './PipelineRunsRow';
14-
import { useTranslation } from 'react-i18next';
15-
import { useParams } from 'react-router-dom-v5-compat';
16+
import { useLoadMoreOnScroll } from '../utils/tekton-results';
1617

1718
import './PipelineRunsList.scss';
1819

@@ -32,6 +33,7 @@ const PipelineRunsList: React.FC<PipelineRunsListProps> = ({
3233
PLRsForKind,
3334
}) => {
3435
const { t } = useTranslation('plugin__pipelines-console-plugin');
36+
const loadMoreRef = React.useRef<HTMLDivElement | null>(null);
3537
const { ns } = useParams();
3638
namespace = namespace || ns;
3739
const columns = usePipelineRunsColumns(namespace, repositoryPLRs);
@@ -44,12 +46,19 @@ const PipelineRunsList: React.FC<PipelineRunsListProps> = ({
4446
? 5
4547
: 4;
4648

47-
const [pipelineRuns, pipelineRunsLoaded, pipelineRunsLoadError] =
48-
useGetPipelineRuns(namespace, { name: PLRsForName, kind: PLRsForKind });
49+
const [
50+
pipelineRuns,
51+
pipelineRunsLoaded,
52+
pipelineRunsLoadError,
53+
nextPageToken,
54+
] = useGetPipelineRuns(namespace, { name: PLRsForName, kind: PLRsForKind });
4955
const [data, filteredData, onFilterChange] = useListPageFilter(
5056
pipelineRuns,
5157
filters,
5258
);
59+
60+
useLoadMoreOnScroll(loadMoreRef, nextPageToken, pipelineRunsLoaded);
61+
5362
return (
5463
<ListPageBody>
5564
<ListPageFilter
@@ -88,6 +97,7 @@ const PipelineRunsList: React.FC<PipelineRunsListProps> = ({
8897
sortColumnIndex={sortColumnIndex}
8998
sortDirection={SortByDirection.desc}
9099
/>
100+
<div ref={loadMoreRef}></div>
91101
</ListPageBody>
92102
);
93103
};

src/components/pipelines-tasks/TaskRunsList.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { TaskRunModel } from '../../models';
1919
import { ALL_NAMESPACES_KEY, TektonResourceLabel } from '../../consts';
2020
import { getReferenceForModel } from '../pipelines-overview/utils';
2121
import { useTaskRunsFilters } from './useTaskRunsFilters';
22+
import { useLoadMoreOnScroll } from '../utils/tekton-results';
2223

2324
interface TaskRunsListPageProps {
2425
showTitle?: boolean;
@@ -107,17 +108,24 @@ const TaskRunsList: React.FC<TaskRunsListPageProps> = ({
107108
...props
108109
}) => {
109110
const { t } = useTranslation('plugin__pipelines-console-plugin');
111+
const loadMoreRef = React.useRef<HTMLDivElement | null>(null);
110112
const [columns, activeColumns] = useTaskColumns();
111113
const params = useParams();
112114
const { ns: namespace } = params;
113115
const ns = namespace === ALL_NAMESPACES_KEY ? '-' : namespace;
114116
const sortColumnIndex = !namespace ? 6 : 5;
115117
const parentName = props?.obj?.metadata?.name;
116-
const [taskRuns, loaded, loadError] = useTaskRuns(ns, parentName);
118+
const [taskRuns, loaded, loadError, nextPageToken] = useTaskRuns(
119+
ns,
120+
parentName,
121+
);
117122
const [staticData, filteredData, onFilterChange] = useListPageFilter(
118123
taskRuns,
119124
useTaskRunsFilters(),
120125
);
126+
127+
useLoadMoreOnScroll(loadMoreRef, nextPageToken, loaded);
128+
121129
return (
122130
<>
123131
<ListPageBody>
@@ -175,6 +183,7 @@ const TaskRunsList: React.FC<TaskRunsListPageProps> = ({
175183
sortColumnIndex={sortColumnIndex}
176184
sortDirection={SortByDirection.desc}
177185
/>
186+
<div ref={loadMoreRef}></div>
178187
</ListPageBody>
179188
</>
180189
);

src/components/utils/tekton-results.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
k8sGet,
88
} from '@openshift-console/dynamic-plugin-sdk';
99
import _ from 'lodash';
10+
import { RefObject, useEffect } from 'react';
1011
import {
1112
ALL_NAMESPACES_KEY,
1213
DELETED_RESOURCE_IN_K8S_ANNOTATION,
@@ -281,7 +282,7 @@ export const createTektonResultsUrl = async (
281282
MINIMUM_PAGE_SIZE,
282283
Math.min(
283284
MAXIMUM_PAGE_SIZE,
284-
options?.limit >= 0 ? options.limit : options?.pageSize ?? 30,
285+
options?.limit >= 0 ? options.limit : options?.pageSize ?? 50,
285286
),
286287
)}`,
287288
...(nextPageToken ? { page_token: nextPageToken } : {}),
@@ -491,3 +492,24 @@ export const getTaskRunLog = async (taskRunPath: string): Promise<string> => {
491492
)}`;
492493
return consoleProxyFetchLog({ url, method: 'GET', allowInsecure: true });
493494
};
495+
496+
export const useLoadMoreOnScroll = (
497+
loadMoreRef: RefObject<HTMLElement>,
498+
nextPageToken: (() => void) | null,
499+
loaded: boolean,
500+
) => {
501+
useEffect(() => {
502+
if (!loadMoreRef.current || !loaded) return;
503+
504+
const observer = new IntersectionObserver((entries) => {
505+
const entry = entries[0];
506+
if (entry.isIntersecting && nextPageToken) {
507+
nextPageToken();
508+
}
509+
});
510+
observer.observe(loadMoreRef.current);
511+
return () => {
512+
observer.disconnect();
513+
};
514+
}, [nextPageToken, loaded, loadMoreRef]);
515+
};

0 commit comments

Comments
 (0)