From a464556c9075c40fc4acca6a9a3ff7d372cbb5cc Mon Sep 17 00:00:00 2001 From: Ashique Ansari Date: Thu, 14 Sep 2023 23:32:46 +0530 Subject: [PATCH] fix pipeline run to show jobs details --- .../content/createRun/useRunFormData.ts | 44 +++++++++++-------- .../pipelines/context/PipelinesContext.tsx | 11 ++--- .../context/useJobRelatedInformation.ts | 2 +- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/frontend/src/concepts/pipelines/content/createRun/useRunFormData.ts b/frontend/src/concepts/pipelines/content/createRun/useRunFormData.ts index 71e3522a4b..09f6b95bec 100644 --- a/frontend/src/concepts/pipelines/content/createRun/useRunFormData.ts +++ b/frontend/src/concepts/pipelines/content/createRun/useRunFormData.ts @@ -9,6 +9,7 @@ import { RunType, RunTypeOption, ScheduledType, + RunParam, } from '~/concepts/pipelines/content/createRun/types'; import { DateTimeKF, @@ -18,12 +19,9 @@ import { PipelineRunKF, ResourceReferenceKF, } from '~/concepts/pipelines/kfTypes'; -import { - getPipelineCoreResourcePipelineReference, - getPipelineCoreResourceJobReference, -} from '~/concepts/pipelines/content/tables/utils'; + +import { getPipelineCoreResourcePipelineReference } from '~/concepts/pipelines/content/tables/utils'; import usePipelineById from '~/concepts/pipelines/apiHooks/usePipelineById'; -import usePipelineRunJobById from '~/concepts/pipelines/apiHooks/usePipelineRunJobById'; import { UpdateObjectAtPropAndValue } from '~/pages/projects/types'; import { FetchState } from '~/utilities/useFetchState'; import { ValueOf } from '~/typeHelpers'; @@ -38,6 +36,9 @@ const isPipelineRunJob = ( runOrJob?: PipelineRunJobKF | PipelineRunKF, ): runOrJob is PipelineRunJobKF => !!(runOrJob as PipelineRunJobKF)?.trigger; +const isPipeline = (pipeline?: unknown): pipeline is PipelineKF => + !!(pipeline as PipelineKF)?.default_version; + const useUpdateData = ( setFunction: UpdateObjectAtPropAndValue, run: T | null = null, @@ -64,18 +65,22 @@ const useUpdatePipelineRun = ( setFunction: UpdateObjectAtPropAndValue, initialData?: PipelineRunKF | PipelineRunJobKF, ) => { - const reference = getPipelineCoreResourceJobReference(initialData); - const [pipelineRunJob] = usePipelineRunJobById(reference?.key.id); + const { getJobInformation } = usePipelinesAPI(); + const { data: pipelineRunJob, loading } = getJobInformation(initialData); + const updatedSetFunction = React.useCallback>( - (key, resource) => { - setFunction(key, resource); - const nameDesc: ValueOf = { - name: initialData?.name ? `Duplicate of ${initialData.name}` : '', - description: pipelineRunJob?.description ?? initialData?.description ?? '', - }; - setFunction('nameDesc', nameDesc); + (key, pipeline) => { + if (!loading && isPipeline(pipeline)) { + setFunction(key, pipeline); + setFunction('params', getParams(pipeline)); + const nameDesc: ValueOf = { + name: initialData?.name ? `Duplicate of ${initialData.name}` : '', + description: pipelineRunJob?.description ?? initialData?.description ?? '', + }; + setFunction('nameDesc', nameDesc); + } }, - [setFunction, initialData, pipelineRunJob], + [setFunction, initialData, pipelineRunJob, loading], ); return useUpdateData( @@ -195,6 +200,11 @@ export const useUpdateRunType = ( }, [setFunction, initialData]); }; +const getParams = (pipeline?: PipelineKF): RunParam[] | undefined => + pipeline + ? (pipeline.parameters || []).map((p) => ({ label: p.name, value: p.value ?? '' })) + : undefined; + const useRunFormData = ( initialData?: PipelineRunKF | PipelineRunJobKF, lastPipeline?: PipelineKF, @@ -211,9 +221,7 @@ const useRunFormData = ( pipeline: lastPipeline ?? null, // experiment: null, runType: { type: RunTypeOption.ONE_TRIGGER }, - params: lastPipeline - ? (lastPipeline.parameters || []).map((p) => ({ label: p.name, value: p.value ?? '' })) - : undefined, + params: getParams(lastPipeline), }); const setFunction = objState[1]; useUpdatePipeline(setFunction, initialData); diff --git a/frontend/src/concepts/pipelines/context/PipelinesContext.tsx b/frontend/src/concepts/pipelines/context/PipelinesContext.tsx index 388f0e1671..0a9003de5f 100644 --- a/frontend/src/concepts/pipelines/context/PipelinesContext.tsx +++ b/frontend/src/concepts/pipelines/context/PipelinesContext.tsx @@ -9,7 +9,6 @@ import { StackItem, } from '@patternfly/react-core'; import { ProjectKind } from '~/k8sTypes'; -import { PipelineCoreResourceKF, PipelineRunJobKF } from '~/concepts/pipelines/kfTypes'; import { byName, ProjectsContext } from '~/concepts/projects/ProjectsContext'; import DeletePipelineServerModal from '~/concepts/pipelines/content/DeletePipelineServerModal'; import { ConfigurePipelinesServerModal } from '~/concepts/pipelines/content/configurePipelinesServer/ConfigurePipelinesServerModal'; @@ -22,12 +21,8 @@ import useAPIState, { APIState } from './useAPIState'; import usePipelineNamespaceCR, { dspaLoaded, hasServerTimedOut } from './usePipelineNamespaceCR'; import usePipelinesAPIRoute from './usePipelinesAPIRoute'; -type JobStatus = { - loading: boolean; - data: PipelineRunJobKF | null; -}; +type GetJobInformationType = ReturnType['getJobInformation']; -type GetJobInformation = (resource: PipelineCoreResourceKF) => JobStatus; type PipelineContext = { hasCR: boolean; crInitializing: boolean; @@ -38,7 +33,7 @@ type PipelineContext = { refreshState: () => Promise; refreshAPIState: () => void; apiState: APIState; - getJobInformation: GetJobInformation; + getJobInformation: GetJobInformationType; }; const PipelinesContext = React.createContext({ @@ -137,7 +132,7 @@ type UsePipelinesAPI = APIState & { * Allows agnostic functionality to request all watched API to be reacquired. * Triggering this will invalidate the memo for API - pay attention to only calling it once per need. */ - getJobInformation: GetJobInformation; + getJobInformation: GetJobInformationType; refreshAllAPI: () => void; }; diff --git a/frontend/src/concepts/pipelines/context/useJobRelatedInformation.ts b/frontend/src/concepts/pipelines/context/useJobRelatedInformation.ts index 1589c015ad..7db2a2f9ef 100644 --- a/frontend/src/concepts/pipelines/context/useJobRelatedInformation.ts +++ b/frontend/src/concepts/pipelines/context/useJobRelatedInformation.ts @@ -8,7 +8,7 @@ type JobStatus = { data: PipelineRunJobKF | null; }; -export type GetJobInformation = (resource: PipelineCoreResourceKF) => JobStatus; +export type GetJobInformation = (resource?: PipelineCoreResourceKF) => JobStatus; const useJobRelatedInformation = (apiState: APIState): { getJobInformation: GetJobInformation } => { const [jobStorage, setJobStorage] = React.useState<{ [jobId: string]: JobStatus }>({});