Skip to content

Commit

Permalink
show correct artifact run node details on artifact side drawer panel
Browse files Browse the repository at this point in the history
  • Loading branch information
DaoDaoNoCode committed Jun 6, 2024
1 parent 78b9cd9 commit d3b9012
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,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 @@ -46,9 +46,7 @@ const getArtifactPipelineTask = (
*/
const getInputArtifacts = (
groupId: string | undefined,
status: PipelineTaskRunStatus | undefined,
inputArtifacts: InputOutputDefinitionArtifacts | undefined,
artifactData: Artifact | undefined,
) => {
if (!inputArtifacts) {
return [];
Expand All @@ -58,9 +56,8 @@ const getInputArtifacts = (
createArtifactNode(
idForTaskArtifact(groupId, '', artifactKey),
artifactKey,
getArtifactPipelineTask(artifactKey, artifactType, artifactData),
getArtifactPipelineTask(artifactKey, artifactType),
undefined,
translateStatusForNode(status?.state),
artifactType.schemaTitle,
),
);
Expand All @@ -69,27 +66,41 @@ const getInputArtifacts = (
const getTaskArtifacts = (
groupId: string | undefined,
taskId: string,
status: PipelineTaskRunStatus | undefined,
componentRef: string,
componentArtifactMap: ComponentArtifactMap,
artifactData: Artifact | undefined,
artifacts: Artifact[] | undefined,
events: Event[] | undefined,
executions: Execution[] | undefined,
): 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 @@ -101,10 +112,10 @@ const getNodesForTasks = (
componentArtifactMap: ComponentArtifactMap,
taskArtifactMap: TaskArtifactMap,
runDetails?: RunDetailsKF,
executions?: Execution[] | null,
executions?: Execution[],
inputArtifacts?: InputOutputDefinitionArtifacts,
events?: Event[],
artifacts?: Artifact[] | undefined,
artifacts?: Artifact[],
): [nestedNodes: PipelineNodeModelExpanded[], children: string[]] => {
const nodes: PipelineNodeModelExpanded[] = [];
const children: string[] = [];
Expand Down Expand Up @@ -139,33 +150,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 @@ -190,6 +191,8 @@ const getNodesForTasks = (
runDetails,
executions,
component?.inputDefinitions?.artifacts,
events,
artifacts,
);

const itemNode = createGroupNode(
Expand All @@ -213,9 +216,9 @@ const getNodesForTasks = (
export const usePipelineTaskTopology = (
spec?: PipelineSpecVariable,
runDetails?: RunDetailsKF,
executions?: Execution[] | null,
executions?: Execution[],
events?: Event[],
artifacts?: Artifact[] | undefined,
artifacts?: Artifact[],
): PipelineNodeModelExpanded[] =>
React.useMemo(() => {
if (!spec) {
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/concepts/topology/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const createArtifactNode = (
label: string,
pipelineTask: PipelineTask,
runAfterTasks?: string[],
runStatus?: RunStatus,
artifactType?: string,
): PipelineNodeModelExpanded => ({
id,
Expand All @@ -50,7 +49,6 @@ export const createArtifactNode = (
data: {
pipelineTask,
artifactType,
runStatus,
},
});

Expand Down

0 comments on commit d3b9012

Please sign in to comment.