|
1
|
import { HttpTypes } from "@medusajs/types" |
|
2
|
import { TFunction } from "i18next" |
|
3
|
import { |
|
4
|
STEP_ERROR_STATES, |
|
5
|
STEP_INACTIVE_STATES, |
|
6
|
STEP_IN_PROGRESS_STATES, |
|
7
|
TRANSACTION_ERROR_STATES, |
|
8
|
TRANSACTION_IN_PROGRESS_STATES, |
|
9
|
} from "./constants" |
|
10
|
import { TransactionState, TransactionStepState } from "./types" |
|
11
|
|
|
12
|
export const adminExecutionKey = { |
|
13
|
detail: (id: string) => ["workflow_executions", "detail", id], |
|
14
|
list: (query?: HttpTypes.AdminGetWorkflowExecutionsParams) => [ |
|
15
|
"workflow_executions", |
|
16
|
"list", |
|
17
|
{ query }, |
|
18
|
], |
|
19
|
} |
|
20
|
|
|
21
|
export const getTransactionStateColor = ( |
|
22
|
state: TransactionState |
|
23
|
): "green" | "orange" | "red" => { |
|
24
|
let statusColor: "green" | "red" | "orange" = "green" |
|
25
|
|
|
26
|
if (TRANSACTION_ERROR_STATES.includes(state)) { |
|
27
|
statusColor = "red" |
|
28
|
} |
|
29
|
|
|
30
|
if (TRANSACTION_IN_PROGRESS_STATES.includes(state)) { |
|
31
|
statusColor = "orange" |
|
32
|
} |
|
33
|
|
|
34
|
return statusColor |
|
35
|
} |
|
36
|
|
|
37
|
export const getTransactionState = ( |
|
38
|
t: TFunction<"translation", any>, |
|
39
|
state: TransactionState |
|
40
|
) => { |
|
41
|
switch (state) { |
|
42
|
case TransactionState.DONE: |
|
43
|
return t("workflowExecutions.state.done") |
|
44
|
case TransactionState.FAILED: |
|
45
|
return t("workflowExecutions.state.failed") |
|
46
|
case TransactionState.REVERTED: |
|
47
|
return t("workflowExecutions.state.reverted") |
|
48
|
case TransactionState.INVOKING: |
|
49
|
return t("workflowExecutions.state.invoking") |
|
50
|
case TransactionState.WAITING_TO_COMPENSATE: |
|
51
|
return t("workflowExecutions.transaction.state.waitingToCompensate") |
|
52
|
case TransactionState.COMPENSATING: |
|
53
|
return t("workflowExecutions.state.compensating") |
|
54
|
case TransactionState.NOT_STARTED: |
|
55
|
return t("workflowExecutions.state.notStarted") |
|
56
|
} |
|
57
|
} |
|
58
|
|
|
59
|
export const getStepStateColor = (state: TransactionStepState) => { |
|
60
|
let statusColor: "green" | "red" | "orange" | "grey" = "green" |
|
61
|
|
|
62
|
if (STEP_ERROR_STATES.includes(state)) { |
|
63
|
statusColor = "red" |
|
64
|
} |
|
65
|
|
|
66
|
if (STEP_INACTIVE_STATES.includes(state)) { |
|
67
|
statusColor = "grey" |
|
68
|
} |
|
69
|
|
|
70
|
if (STEP_IN_PROGRESS_STATES.includes(state)) { |
|
71
|
statusColor = "orange" |
|
72
|
} |
|
73
|
|
|
74
|
return statusColor |
|
75
|
} |
|
76
|
|
|
77
|
export const getStepState = ( |
|
78
|
t: TFunction<"translation", any>, |
|
79
|
state: TransactionStepState |
|
80
|
) => { |
|
81
|
switch (state) { |
|
82
|
case TransactionStepState.DONE: |
|
83
|
return t("workflowExecutions.state.done") |
|
84
|
case TransactionStepState.FAILED: |
|
85
|
return t("workflowExecutions.state.failed") |
|
86
|
case TransactionStepState.REVERTED: |
|
87
|
return t("workflowExecutions.state.reverted") |
|
88
|
case TransactionStepState.INVOKING: |
|
89
|
return t("workflowExecutions.state.invoking") |
|
90
|
case TransactionStepState.COMPENSATING: |
|
91
|
return t("workflowExecutions.state.compensating") |
|
92
|
case TransactionStepState.NOT_STARTED: |
|
93
|
return t("workflowExecutions.state.notStarted") |
|
94
|
case TransactionStepState.SKIPPED: |
|
95
|
return t("workflowExecutions.step.state.skipped") |
|
96
|
case TransactionStepState.SKIPPED_FAILURE: |
|
97
|
return t("workflowExecutions.step.state.skippedFailure") |
|
98
|
case TransactionStepState.DORMANT: |
|
99
|
return t("workflowExecutions.step.state.dormant") |
|
100
|
case TransactionStepState.TIMEOUT: |
|
101
|
return t("workflowExecutions.step.state.timeout") |
|
102
|
} |
|
103
|
} |