Skip to content

Commit

Permalink
fix: added fallback for reason
Browse files Browse the repository at this point in the history
Signed-off-by: James <[email protected]>
  • Loading branch information
james-union committed Apr 19, 2023
1 parent 334c560 commit 6d93cb0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from 'models/Execution/types';
import { Routes } from 'routes/routes';
import { PaginatedEntityResponse } from 'models/AdminEntity/types';
import { compareTimestampsAscending, timestampToDate } from 'common/utils';
import { timestampToDate } from 'common';
import { formatDateUTC } from 'common/formatters';

export function isSingleTaskExecution(execution: Execution) {
Expand All @@ -29,18 +29,21 @@ export function getExecutionBackLink(execution: Execution): string {
export function getTaskExecutionDetailReasons(
taskExecutionDetails?: PaginatedEntityResponse<TaskExecution>,
): (string | null | undefined)[] {
const reasons = (
taskExecutionDetails?.entities.map(
taskExecution => taskExecution.closure.reasons || [],
) || []
)
.flat()
.sort((a, b) => {
if (!a || !a.occurredAt) return -1;
if (!b || !b.occurredAt) return 1;
return compareTimestampsAscending(a.occurredAt, b.occurredAt);
});
return reasons.map(reason => reason.message);
let reasons: string[] = [];
taskExecutionDetails?.entities.forEach(taskExecution => {
if (taskExecution.closure.reasons)
reasons = reasons.concat(
taskExecution.closure.reasons.map(
reason =>
(reason.occurredAt
? formatDateUTC(timestampToDate(reason.occurredAt)) + ' '
: '') + reason.message,
),
);
else if (taskExecution.closure.reason)
reasons.push(taskExecution.closure.reason);
});
return reasons;
}

export function isChildGroupsFetched(
Expand Down
1 change: 1 addition & 0 deletions packages/console/src/models/Execution/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export interface TaskExecutionClosure extends Admin.ITaskExecutionClosure {
startedAt?: Protobuf.ITimestamp;
eventVersion?: number;
reasons?: Admin.IReason[];
reason?: string;
}

/** Execution data */
Expand Down

0 comments on commit 6d93cb0

Please sign in to comment.