Skip to content

Commit

Permalink
Merge pull request #2885 from DaoDaoNoCode/jira-rhoaieng-7544
Browse files Browse the repository at this point in the history
Show correct artifact run node details on artifact side drawer panel
  • Loading branch information
openshift-merge-bot[bot] authored Jun 11, 2024
2 parents b4db549 + 7d27150 commit bc28f39
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ import {
TaskArtifactMap,
translateStatusForNode,
} from './parseUtils';
import { PipelineTask, PipelineTaskRunStatus } from './pipelineTaskTypes';
import { PipelineTask } from './pipelineTaskTypes';

const getArtifactPipelineTask = (
name: string,
artifactType: InputOutputArtifactType,
artifactData: Artifact | undefined,
artifactData?: Artifact,
): PipelineTask => ({
type: 'artifact',
name,
Expand All @@ -51,9 +51,7 @@ const getArtifactPipelineTask = (
*/
const getInputArtifacts = (
groupId: string | undefined,
status: PipelineTaskRunStatus | undefined,
inputArtifacts: InputOutputDefinitionArtifacts | undefined,
artifactData: Artifact | undefined,
) => {
if (!inputArtifacts) {
return [];
Expand All @@ -63,9 +61,8 @@ const getInputArtifacts = (
createArtifactNode(
idForTaskArtifact(groupId, '', artifactKey),
artifactKey,
getArtifactPipelineTask(artifactKey, artifactType, artifactData),
getArtifactPipelineTask(artifactKey, artifactType),
undefined,
translateStatusForNode(status?.state),
artifactType.schemaTitle,
),
);
Expand All @@ -74,27 +71,41 @@ const getInputArtifacts = (
const getTaskArtifacts = (
groupId: string | undefined,
taskId: string,
status: PipelineTaskRunStatus | undefined,
componentRef: string,
componentArtifactMap: ComponentArtifactMap,
artifactData: Artifact | undefined,
artifacts?: Artifact[],
events?: Event[] | null,
executions?: Execution[] | null,
): PipelineNodeModelExpanded[] => {
const artifactsInComponent = componentArtifactMap[componentRef];

if (!artifactsInComponent) {
return [];
}

return Object.entries(artifactsInComponent).map(([artifactKey, data]) =>
createArtifactNode(
const execution = executions?.find(
(e) => e.getCustomPropertiesMap().get('task_name')?.getStringValue() === taskId,
);

const executionEvents = events?.filter((event) => event.getExecutionId() === execution?.getId());

return Object.entries(artifactsInComponent).map(([artifactKey, data]) => {
const artifactData = artifacts?.find((artifact) => {
const artifactEvent = executionEvents?.find(
(event) => event.getArtifactId() === artifact.getId(),
);

return artifactEvent && artifact.getType() === data.schemaTitle;
});

return createArtifactNode(
idForTaskArtifact(groupId, taskId, artifactKey),
artifactKey,
getArtifactPipelineTask(artifactKey, data, artifactData),
[taskId],
translateStatusForNode(status?.state),
data.schemaTitle,
),
);
);
});
};

const getNodesForTasks = (
Expand All @@ -109,8 +120,8 @@ const getNodesForTasks = (
runDetails?: RunDetailsKF,
executions?: Execution[] | null,
inputArtifacts?: InputOutputDefinitionArtifacts,
events?: Event[],
artifacts?: Artifact[] | undefined,
events?: Event[] | null,
artifacts?: Artifact[],
): [nestedNodes: PipelineNodeModelExpanded[], children: string[]] => {
const nodes: PipelineNodeModelExpanded[] = [];
const children: string[] = [];
Expand Down Expand Up @@ -166,33 +177,23 @@ const getNodesForTasks = (
volumeMounts: parseVolumeMounts(spec.platform_spec, executorLabel),
};

const artifactData = artifacts?.find((artifact) => {
const artifactEvent = events?.find((event) => event.getArtifactId() === artifact.getId());
const artifactExecution = executions?.find(
(execution) => execution.getId() === artifactEvent?.getExecutionId(),
);

return (
artifactExecution?.getCustomPropertiesMap().get('task_name')?.getStringValue() === taskId
);
});

// Build artifact nodes with inputs from task nodes
const artifactNodes = getTaskArtifacts(
groupId,
taskId,
status,
componentRef,
componentArtifactMap,
artifactData,
artifacts,
events,
executions,
);
if (artifactNodes.length) {
nodes.push(...artifactNodes);
children.push(...artifactNodes.map((n) => n.id));
}

// Build artifact nodes without inputs
const inputArtifactNodes = getInputArtifacts(groupId, status, inputArtifacts, artifactData);
const inputArtifactNodes = getInputArtifacts(groupId, inputArtifacts);
if (inputArtifactNodes.length) {
nodes.push(...inputArtifactNodes);
children.push(...inputArtifactNodes.map((n) => n.id));
Expand All @@ -218,6 +219,8 @@ const getNodesForTasks = (
runDetails,
executions,
component?.inputDefinitions?.artifacts,
events,
artifacts,
);

const itemNode = createGroupNode(
Expand All @@ -243,7 +246,7 @@ export const usePipelineTaskTopology = (
runDetails?: RunDetailsKF,
executions?: Execution[] | null,
events?: Event[] | null,
artifacts?: Artifact[] | undefined,
artifacts?: Artifact[],
): PipelineNodeModelExpanded[] =>
React.useMemo(() => {
if (!spec) {
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/concepts/topology/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const createArtifactNode = (
label: string,
pipelineTask: PipelineTask,
runAfterTasks?: string[],
runStatus?: RunStatus,
artifactType?: string,
): PipelineNodeModelExpanded => ({
id,
Expand All @@ -47,7 +46,7 @@ export const createArtifactNode = (
data: {
pipelineTask,
artifactType,
runStatus,
runStatus: pipelineTask.metadata ? RunStatus.Succeeded : undefined,
},
});

Expand Down

0 comments on commit bc28f39

Please sign in to comment.