From 5f3b695bba94e92b38c80173fccbd7310d768f43 Mon Sep 17 00:00:00 2001 From: Jeff Puzzo Date: Tue, 21 May 2024 16:27:16 -0400 Subject: [PATCH] [RHOAIENG-7439] Pipeline version is not visible for some runs in the run table list --- .../apiHooks/useAllPipelineVersions.ts | 4 +- .../pipelines/apiHooks/usePipelines.ts | 48 ++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/frontend/src/concepts/pipelines/apiHooks/useAllPipelineVersions.ts b/frontend/src/concepts/pipelines/apiHooks/useAllPipelineVersions.ts index eaef59dac6..060b40bbdf 100644 --- a/frontend/src/concepts/pipelines/apiHooks/useAllPipelineVersions.ts +++ b/frontend/src/concepts/pipelines/apiHooks/useAllPipelineVersions.ts @@ -4,7 +4,7 @@ import { usePipelinesAPI } from '~/concepts/pipelines/context'; import usePipelineQuery from '~/concepts/pipelines/apiHooks/usePipelineQuery'; import { PipelineListPaged, PipelineOptions } from '~/concepts/pipelines/types'; import { FetchState, NotReadyError } from '~/utilities/useFetchState'; -import usePipelines from '~/concepts/pipelines/apiHooks/usePipelines'; +import { useAllPipelines } from '~/concepts/pipelines/apiHooks/usePipelines'; import { useDeepCompareMemoize } from '~/utilities/useDeepCompareMemoize'; /** @@ -15,7 +15,7 @@ export const useAllPipelineVersions = ( refreshRate = 0, ): FetchState> => { const { api } = usePipelinesAPI(); - const [{ items: pipelines }, pipelinesLoaded] = usePipelines(); + const [{ items: pipelines }, pipelinesLoaded] = useAllPipelines(); const pipelineIds = useDeepCompareMemoize(pipelines.map((pipeline) => pipeline.pipeline_id)); return usePipelineQuery( diff --git a/frontend/src/concepts/pipelines/apiHooks/usePipelines.ts b/frontend/src/concepts/pipelines/apiHooks/usePipelines.ts index aef8bddf99..c9446956c2 100644 --- a/frontend/src/concepts/pipelines/apiHooks/usePipelines.ts +++ b/frontend/src/concepts/pipelines/apiHooks/usePipelines.ts @@ -2,8 +2,14 @@ import * as React from 'react'; import { FetchState, NotReadyError } from '~/utilities/useFetchState'; import { PipelineKFv2 } from '~/concepts/pipelines/kfTypes'; import usePipelineQuery from '~/concepts/pipelines/apiHooks/usePipelineQuery'; -import { PipelineListPaged, PipelineOptions } from '~/concepts/pipelines/types'; +import { + ListPipelines, + PipelineListPaged, + PipelineOptions, + PipelineParams, +} from '~/concepts/pipelines/types'; import { usePipelinesAPI } from '~/concepts/pipelines/context'; +import { K8sAPIOptions } from '~/k8sTypes'; const usePipelines = ( options?: PipelineOptions, @@ -43,4 +49,44 @@ export const useSafePipelines = ( ); }; +async function getAllPipelines( + opts: K8sAPIOptions, + params: PipelineParams | undefined, + listPipelines: ListPipelines, +): Promise { + const result = await listPipelines(opts, params); + let allPipelines = result.pipelines ?? []; + + if (result.next_page_token) { + const nextPipelines = await getAllPipelines( + opts, + { pageToken: result.next_page_token }, + listPipelines, + ); + allPipelines = allPipelines.concat(nextPipelines); + } + + return allPipelines; +} + +export const useAllPipelines = ( + options?: PipelineOptions, + refreshRate?: number, +): FetchState> => { + const { api } = usePipelinesAPI(); + + return usePipelineQuery( + React.useCallback( + async (opts, params) => { + const allPipelines = await getAllPipelines(opts, params, api.listPipelines); + + return { items: allPipelines }; + }, + [api.listPipelines], + ), + options, + refreshRate, + ); +}; + export default usePipelines;