Skip to content

Commit

Permalink
Merge pull request #2831 from jpuzz0/RHOAIENG-7439
Browse files Browse the repository at this point in the history
[RHOAIENG-7439] Pipeline version is not visible for some runs in the run table list
  • Loading branch information
openshift-merge-bot[bot] authored May 22, 2024
2 parents 1c223b6 + 5f3b695 commit cd34c2c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -15,7 +15,7 @@ export const useAllPipelineVersions = (
refreshRate = 0,
): FetchState<PipelineListPaged<PipelineVersionKFv2>> => {
const { api } = usePipelinesAPI();
const [{ items: pipelines }, pipelinesLoaded] = usePipelines();
const [{ items: pipelines }, pipelinesLoaded] = useAllPipelines();
const pipelineIds = useDeepCompareMemoize(pipelines.map((pipeline) => pipeline.pipeline_id));

return usePipelineQuery<PipelineVersionKFv2>(
Expand Down
48 changes: 47 additions & 1 deletion frontend/src/concepts/pipelines/apiHooks/usePipelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -43,4 +49,44 @@ export const useSafePipelines = (
);
};

async function getAllPipelines(
opts: K8sAPIOptions,
params: PipelineParams | undefined,
listPipelines: ListPipelines,
): Promise<PipelineKFv2[]> {
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<PipelineListPaged<PipelineKFv2>> => {
const { api } = usePipelinesAPI();

return usePipelineQuery<PipelineKFv2>(
React.useCallback(
async (opts, params) => {
const allPipelines = await getAllPipelines(opts, params, api.listPipelines);

return { items: allPipelines };
},
[api.listPipelines],
),
options,
refreshRate,
);
};

export default usePipelines;

0 comments on commit cd34c2c

Please sign in to comment.