Skip to content

Commit

Permalink
Added load more resource from tekton results on scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
lokanandaprabhu committed Oct 21, 2024
1 parent fdc4fa0 commit 203a42a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
29 changes: 27 additions & 2 deletions src/components/pipelineRuns-list/PipelineRunsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const PipelineRunsList: React.FC<PipelineRunsListProps> = ({
PLRsForKind,
}) => {
const { t } = useTranslation('plugin__pipelines-console-plugin');
const loadMoreRef = React.useRef<HTMLDivElement | null>(null);
const { ns } = useParams();
namespace = namespace || ns;
const columns = usePipelineRunsColumns(namespace, repositoryPLRs);
Expand All @@ -44,12 +45,35 @@ const PipelineRunsList: React.FC<PipelineRunsListProps> = ({
? 5
: 4;

const [pipelineRuns, pipelineRunsLoaded, pipelineRunsLoadError] =
useGetPipelineRuns(namespace, { name: PLRsForName, kind: PLRsForKind });
const [
pipelineRuns,
pipelineRunsLoaded,
pipelineRunsLoadError,
nextPageToken,
] = useGetPipelineRuns(namespace, { name: PLRsForName, kind: PLRsForKind });
const [data, filteredData, onFilterChange] = useListPageFilter(
pipelineRuns,
filters,
);

// Once OCPBUGS-43538 ticket is closed, use onRowsRendered prop in VirtualizedTable for load more on scroll
React.useEffect(() => {
if (!loadMoreRef.current || !pipelineRunsLoaded) return;

const observer = new IntersectionObserver((entries) => {
const entry = entries[0];
if (entry.isIntersecting && nextPageToken) {
nextPageToken();
}
});

observer.observe(loadMoreRef.current);

return () => {
observer.disconnect();
};
}, [nextPageToken, pipelineRunsLoaded]);

return (
<ListPageBody>
<ListPageFilter
Expand Down Expand Up @@ -88,6 +112,7 @@ const PipelineRunsList: React.FC<PipelineRunsListProps> = ({
sortColumnIndex={sortColumnIndex}
sortDirection={SortByDirection.desc}
/>
<div ref={loadMoreRef}></div>
</ListPageBody>
);
};
Expand Down
25 changes: 24 additions & 1 deletion src/components/pipelines-tasks/TaskRunsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,39 @@ const TaskRunsList: React.FC<TaskRunsListPageProps> = ({
...props
}) => {
const { t } = useTranslation('plugin__pipelines-console-plugin');
const loadMoreRef = React.useRef<HTMLDivElement | null>(null);
const [columns, activeColumns] = useTaskColumns();
const params = useParams();
const { ns: namespace } = params;
const ns = namespace === ALL_NAMESPACES_KEY ? '-' : namespace;
const sortColumnIndex = !namespace ? 6 : 5;
const parentName = props?.obj?.metadata?.name;
const [taskRuns, loaded, loadError] = useTaskRuns(ns, parentName);
const [taskRuns, loaded, loadError, nextPageToken] = useTaskRuns(
ns,
parentName,
);
const [staticData, filteredData, onFilterChange] = useListPageFilter(
taskRuns,
useTaskRunsFilters(),
);

// Once OCPBUGS-43538 ticket is closed, use onRowsRendered prop in VirtualizedTable for load more on scroll
React.useEffect(() => {
if (!loadMoreRef.current || !loaded) return;

const observer = new IntersectionObserver((entries) => {
const entry = entries[0];
if (entry.isIntersecting && nextPageToken) {
nextPageToken();
}
});

observer.observe(loadMoreRef.current);

return () => {
observer.disconnect();
};
}, [nextPageToken, loaded]);
return (
<>
<ListPageBody>
Expand Down Expand Up @@ -175,6 +197,7 @@ const TaskRunsList: React.FC<TaskRunsListPageProps> = ({
sortColumnIndex={sortColumnIndex}
sortDirection={SortByDirection.desc}
/>
<div ref={loadMoreRef}></div>
</ListPageBody>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/utils/tekton-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export const createTektonResultsUrl = async (
MINIMUM_PAGE_SIZE,
Math.min(
MAXIMUM_PAGE_SIZE,
options?.limit >= 0 ? options.limit : options?.pageSize ?? 30,
options?.limit >= 0 ? options.limit : options?.pageSize ?? 50,
),
)}`,
...(nextPageToken ? { page_token: nextPageToken } : {}),
Expand Down

0 comments on commit 203a42a

Please sign in to comment.