-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathget-event-categorization.ts
174 lines (157 loc) · 5.54 KB
/
get-event-categorization.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import type { I18nKey } from '$lib/i18n';
import type {
EventType,
IterableEvent,
WorkflowEvents,
} from '$lib/types/events';
type Categories = typeof CATEGORIES;
export type EventTypeCategory = Categories[keyof Categories];
export const CATEGORIES = {
ACTIVITY: 'activity',
CHILD_WORKFLOW: 'child-workflow',
LOCAL_ACTIVITY: 'local-activity',
NEXUS: 'nexus',
SIGNAL: 'signal',
TIMER: 'timer',
UPDATE: 'update',
WORKFLOW: 'workflow',
OTHER: 'other',
} as const;
export const eventTypeCategorizations: Readonly<
Record<EventType, EventTypeCategory>
> = {
ActivityTaskCanceled: CATEGORIES.ACTIVITY,
ActivityTaskCancelRequested: CATEGORIES.ACTIVITY,
ActivityTaskCompleted: CATEGORIES.ACTIVITY,
ActivityTaskFailed: CATEGORIES.ACTIVITY,
ActivityTaskScheduled: CATEGORIES.ACTIVITY,
ActivityTaskStarted: CATEGORIES.ACTIVITY,
ActivityTaskTimedOut: CATEGORIES.ACTIVITY,
ChildWorkflowExecutionCanceled: CATEGORIES.CHILD_WORKFLOW,
ChildWorkflowExecutionCompleted: CATEGORIES.CHILD_WORKFLOW,
ChildWorkflowExecutionFailed: CATEGORIES.CHILD_WORKFLOW,
ChildWorkflowExecutionStarted: CATEGORIES.CHILD_WORKFLOW,
ChildWorkflowExecutionTerminated: CATEGORIES.CHILD_WORKFLOW,
ChildWorkflowExecutionTimedOut: CATEGORIES.CHILD_WORKFLOW,
StartChildWorkflowExecutionFailed: CATEGORIES.CHILD_WORKFLOW,
StartChildWorkflowExecutionInitiated: CATEGORIES.CHILD_WORKFLOW,
SignalExternalWorkflowExecutionFailed: CATEGORIES.SIGNAL,
SignalExternalWorkflowExecutionInitiated: CATEGORIES.SIGNAL,
WorkflowExecutionSignaled: CATEGORIES.SIGNAL,
ExternalWorkflowExecutionSignaled: CATEGORIES.SIGNAL,
TimerCanceled: CATEGORIES.TIMER,
TimerFired: CATEGORIES.TIMER,
TimerStarted: CATEGORIES.TIMER,
WorkflowExecutionCanceled: CATEGORIES.WORKFLOW,
WorkflowExecutionCancelRequested: CATEGORIES.WORKFLOW,
WorkflowExecutionCompleted: CATEGORIES.WORKFLOW,
WorkflowExecutionContinuedAsNew: CATEGORIES.WORKFLOW,
WorkflowExecutionFailed: CATEGORIES.WORKFLOW,
WorkflowExecutionStarted: CATEGORIES.WORKFLOW,
WorkflowExecutionTerminated: CATEGORIES.WORKFLOW,
WorkflowExecutionTimedOut: CATEGORIES.WORKFLOW,
WorkflowExecutionOptionsUpdated: CATEGORIES.WORKFLOW,
WorkflowTaskCompleted: CATEGORIES.WORKFLOW,
WorkflowTaskFailed: CATEGORIES.WORKFLOW,
WorkflowTaskScheduled: CATEGORIES.WORKFLOW,
WorkflowTaskStarted: CATEGORIES.WORKFLOW,
WorkflowTaskTimedOut: CATEGORIES.WORKFLOW,
ExternalWorkflowExecutionCancelRequested: CATEGORIES.WORKFLOW,
RequestCancelExternalWorkflowExecutionFailed: CATEGORIES.WORKFLOW,
RequestCancelExternalWorkflowExecutionInitiated: CATEGORIES.WORKFLOW,
WorkflowExecutionUpdateAccepted: CATEGORIES.UPDATE,
WorkflowExecutionUpdateCompleted: CATEGORIES.UPDATE,
WorkflowExecutionUpdateRequested: CATEGORIES.UPDATE,
WorkflowExecutionUpdateRejected: CATEGORIES.UPDATE,
WorkflowExecutionUpdateAdmitted: CATEGORIES.UPDATE,
NexusOperationScheduled: CATEGORIES.NEXUS,
NexusOperationStarted: CATEGORIES.NEXUS,
NexusOperationCompleted: CATEGORIES.NEXUS,
NexusOperationFailed: CATEGORIES.NEXUS,
NexusOperationCanceled: CATEGORIES.NEXUS,
NexusOperationTimedOut: CATEGORIES.NEXUS,
NexusOperationCancelRequested: CATEGORIES.NEXUS,
MarkerRecorded: CATEGORIES.OTHER,
UpsertWorkflowSearchAttributes: CATEGORIES.OTHER,
WorkflowPropertiesModified: CATEGORIES.OTHER,
};
export type EventTypeOption = {
label: I18nKey;
value: EventTypeCategory;
description?: I18nKey;
};
export const allEventTypeOptions: EventTypeOption[] = [
{
label: 'events.category.activity',
value: CATEGORIES.ACTIVITY,
description: 'events.category.activity-tooltip',
},
{
label: 'events.category.child-workflow',
value: CATEGORIES.CHILD_WORKFLOW,
description: 'events.category.child-workflow-tooltip',
},
{
label: 'events.category.local-activity',
value: CATEGORIES.LOCAL_ACTIVITY,
description: 'events.category.local-activity-tooltip',
},
{
label: 'events.category.signal',
value: CATEGORIES.SIGNAL,
description: 'events.category.signal-tooltip',
},
{
label: 'events.category.timer',
value: CATEGORIES.TIMER,
description: 'events.category.timer-tooltip',
},
{
label: 'events.category.update',
value: CATEGORIES.UPDATE,
description: 'events.category.update-tooltip',
},
{
label: 'events.category.nexus',
value: CATEGORIES.NEXUS,
description: 'events.category.nexus-tooltip',
},
{
label: 'events.category.workflow',
value: CATEGORIES.WORKFLOW,
description: 'events.category.workflow-tooltip',
},
{
label: 'events.category.other',
value: CATEGORIES.OTHER,
description: 'events.category.other-tooltip',
},
];
const compactEventTypes: EventTypeCategory[] = [
CATEGORIES.ACTIVITY,
CATEGORIES.LOCAL_ACTIVITY,
CATEGORIES.CHILD_WORKFLOW,
CATEGORIES.SIGNAL,
CATEGORIES.TIMER,
CATEGORIES.UPDATE,
CATEGORIES.NEXUS,
CATEGORIES.OTHER,
];
export const compactEventTypeOptions: EventTypeOption[] =
allEventTypeOptions.filter(({ value }) => compactEventTypes.includes(value));
export const getEventCategory = (eventType: EventType): EventTypeCategory => {
return eventTypeCategorizations?.[eventType] || CATEGORIES.OTHER;
};
export const isCategoryType = (value: string): value is EventTypeCategory => {
for (const category in CATEGORIES) {
if (value === CATEGORIES[category]) return true;
}
return false;
};
export const getEventsInCategory = (
events: WorkflowEvents,
category: string,
): WorkflowEvents => {
if (!isCategoryType(category)) return events;
return events.filter((event: IterableEvent) => event.category === category);
};