Skip to content

Commit

Permalink
fix pipeline run to show jobs details
Browse files Browse the repository at this point in the history
  • Loading branch information
uidoyen committed Sep 14, 2023
1 parent cf7548e commit a464556
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
44 changes: 26 additions & 18 deletions frontend/src/concepts/pipelines/content/createRun/useRunFormData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
RunType,
RunTypeOption,
ScheduledType,
RunParam,
} from '~/concepts/pipelines/content/createRun/types';
import {
DateTimeKF,
Expand All @@ -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';
Expand All @@ -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 = <T extends PipelineCoreResourceKF>(
setFunction: UpdateObjectAtPropAndValue<RunFormData>,
run: T | null = null,
Expand All @@ -64,18 +65,22 @@ const useUpdatePipelineRun = (
setFunction: UpdateObjectAtPropAndValue<RunFormData>,
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<UpdateObjectAtPropAndValue<RunFormData>>(
(key, resource) => {
setFunction(key, resource);
const nameDesc: ValueOf<RunFormData> = {
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<RunFormData> = {
name: initialData?.name ? `Duplicate of ${initialData.name}` : '',
description: pipelineRunJob?.description ?? initialData?.description ?? '',
};
setFunction('nameDesc', nameDesc);
}
},
[setFunction, initialData, pipelineRunJob],
[setFunction, initialData, pipelineRunJob, loading],
);

return useUpdateData(
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down
11 changes: 3 additions & 8 deletions frontend/src/concepts/pipelines/context/PipelinesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<typeof useJobRelatedInformation>['getJobInformation'];

type GetJobInformation = (resource: PipelineCoreResourceKF) => JobStatus;
type PipelineContext = {
hasCR: boolean;
crInitializing: boolean;
Expand All @@ -38,7 +33,7 @@ type PipelineContext = {
refreshState: () => Promise<undefined>;
refreshAPIState: () => void;
apiState: APIState;
getJobInformation: GetJobInformation;
getJobInformation: GetJobInformationType;
};

const PipelinesContext = React.createContext<PipelineContext>({
Expand Down Expand Up @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>({});
Expand Down

0 comments on commit a464556

Please sign in to comment.