Skip to content

Commit

Permalink
fix: find task by id or taskReferenceName
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudakatux authored and jpbelval committed Dec 20, 2024
1 parent 45ab448 commit 29ffc0b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ui/src/pages/execution/RightPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function RightPanel({
const taskResult =
selectedNode?.data?.task?.executionData?.status === "PENDING"
? pendingTaskSelection(selectedNode?.data?.task)
: taskWithLatestIteration(execution?.tasks, selectedTask?.ref);
: taskWithLatestIteration(execution?.tasks, selectedTask);

const dfOptions = useMemo(
() => dag && dag.getSiblings(selectedTask),
Expand Down
28 changes: 19 additions & 9 deletions ui/src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function astToQuery(node) {

return `${wrapper ? "(" : ""}${clauses.join(` ${combinator} `)}${
wrapper ? ")" : ""
}`;
}`;
} else {
return "";
}
Expand Down Expand Up @@ -99,16 +99,24 @@ export function getBasename() {
return _.isEmpty(basename) ? "/" : basename;
}

export const taskWithLatestIteration = (tasksList, taskReferenceName) => {
const filteredTasks = tasksList?.filter(
(task) =>
task?.workflowTask?.taskReferenceName === taskReferenceName ||
task?.referenceTaskName === taskReferenceName
);
export const taskWithLatestIteration = (tasksList = [], selectedTask) => {
const taskReferenceName = selectedTask?.ref;

const findTaskByReferenceName = (task) =>
task?.workflowTask?.taskReferenceName === taskReferenceName ||
task?.referenceTaskName === taskReferenceName;

const findTaskById = (task) => task?.taskId === selectedTask?.id;

// If reference name is not provided, use taskId to find the task
const findTask = selectedTask?.ref == null ? findTaskById : findTaskByReferenceName;

const filteredTasks = tasksList?.filter(findTask);

if (filteredTasks && filteredTasks.length === 1) {
// task without any retry/iteration
return _nth(filteredTasks, 0);
const targetTask = _nth(filteredTasks, 0);
return targetTask;
} else if (filteredTasks && filteredTasks.length > 1) {
const result = filteredTasks.reduce(
(acc, task, idx) => {
Expand All @@ -121,9 +129,11 @@ export const taskWithLatestIteration = (tasksList, taskReferenceName) => {
);

if (result?.idx > -1) {
return _nth(filteredTasks, result.idx);
const targetTask = _nth(filteredTasks, result.idx);
return targetTask;
}
}

return undefined;
};

Expand Down

0 comments on commit 29ffc0b

Please sign in to comment.