-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathevent-card.svelte
More file actions
258 lines (245 loc) · 7.74 KB
/
event-card.svelte
File metadata and controls
258 lines (245 loc) · 7.74 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<script lang="ts">
import { page } from '$app/state';
import Payload from '$lib/components/payload.svelte';
import Timestamp from '$lib/components/timestamp.svelte';
import Copyable from '$lib/holocene/copyable/index.svelte';
import Link from '$lib/holocene/link.svelte';
import { translate } from '$lib/i18n/translate';
import type { EventLink as ELink } from '$lib/types';
import { type Payload as RawPayload } from '$lib/types';
import type { WorkflowEvent } from '$lib/types/events';
import { getEventLinkHref } from '$lib/utilities/event-link-href';
import {
format,
spaceBetweenCapitalLetters,
} from '$lib/utilities/format-camel-case';
import { formatAttributes } from '$lib/utilities/format-event-attributes';
import {
displayLinkType,
getCodeBlockValue,
getStackTrace,
shouldDisplayAsTime,
} from '$lib/utilities/get-single-attribute-for-event';
import { isLocalActivityMarkerEvent } from '$lib/utilities/is-event-type';
import {
routeForEventHistoryEvent,
routeForNamespace,
} from '$lib/utilities/route-for';
import EventDetailsLink from './event-details-link.svelte';
let { event }: { event: WorkflowEvent } = $props();
const { namespace, workflow, run } = $derived(page.params);
const displayName = $derived(
isLocalActivityMarkerEvent(event)
? translate('events.category.local-activity')
: spaceBetweenCapitalLetters(event.name),
);
const attributes = $derived.by(() => {
const attrs = formatAttributes(event);
if (event?.principal?.name) attrs.principalName = event.principal.name;
if (event?.principal?.type) attrs.principalType = event.principal.type;
return attrs;
});
const fields = $derived(Object.entries(attributes));
const payloadFields = $derived(
fields.filter(
([_key, value]) =>
typeof value === 'object' && Object.keys(value).length > 0,
),
);
const linkFields = $derived(
fields.filter(
([key, _value]) => displayLinkType(key, attributes) !== 'none',
),
);
const hiddenDetailFields = $derived.by(() => {
if (event.category === 'activity')
return ['scheduledEventId', 'startedEventId', 'namespaceId'];
if (event.category === 'child-workflow')
return ['initiatedEventId', 'startedEventId', 'namespaceId'];
return ['namespaceId'];
});
const detailFields = $derived(
fields.filter(
([key, value]) =>
typeof value !== 'object' &&
displayLinkType(key, attributes) === 'none' &&
!hiddenDetailFields.includes(key) &&
(key !== 'namespace' ||
(key === 'namespace' && page.params.namespace !== value)),
),
);
</script>
<div
class="surface-primary flex flex-1 cursor-default flex-col gap-2 border-b border-subtle p-4"
>
<div class="flex flex-wrap items-center justify-between gap-2">
<div class="flex items-center gap-2 text-base">
<Link
href={routeForEventHistoryEvent({
eventId: event.id,
run,
workflow,
namespace,
})}>{event.id}</Link
>
<p class="font-medium">
{displayName}
</p>
</div>
<Timestamp as="p" class="text-sm" dateTime={event.eventTime} />
</div>
<div class="flex flex-col gap-1 xl:flex-row">
<div class="flex w-full flex-col gap-1 xl:w-1/2">
{#if event?.links?.length}
{@render eventLinks(event.links)}
{/if}
{#if event?.userMetadata?.summary}
{@render eventSummary(event.userMetadata.summary)}
{/if}
{#each detailFields as [key, value] (key)}
{@render details(key, value)}
{/each}
{#each linkFields as [key, value] (key)}
{@render link(key, value)}
{/each}
</div>
{#if payloadFields.length}
<div class="flex w-full flex-col gap-1 xl:w-1/2">
{#each payloadFields as [key, value] (key)}
{@render payloads(key, value)}
{/each}
</div>
{/if}
</div>
</div>
{#snippet eventLink(link: ELink)}
{@const href = getEventLinkHref(link)}
{@const value = href.split('workflows/')?.[1] || href}
<div class="flex items-start gap-4">
<p class="min-w-56 text-sm text-secondary/80">
{translate('nexus.link')}
</p>
<Copyable
copyIconTitle={translate('common.copy-icon-title')}
copySuccessIconTitle={translate('common.copy-success-icon-title')}
content={value}
>
<Link {href} class="whitespace-pre-line">{value}</Link>
</Copyable>
</div>
{/snippet}
{#snippet eventNamespaceLink(link: ELink)}
{@const href = routeForNamespace({ namespace: link.workflowEvent.namespace })}
<div class="flex items-start gap-4">
<p class="min-w-56 text-sm text-secondary/80">
{translate('nexus.link-namespace')}
</p>
<Copyable
copyIconTitle={translate('common.copy-icon-title')}
copySuccessIconTitle={translate('common.copy-success-icon-title')}
content={link.workflowEvent.namespace}
>
<Link {href} class="whitespace-pre-line"
>{link.workflowEvent.namespace}</Link
>
</Copyable>
</div>
{/snippet}
{#snippet eventLinks(links: ELink[])}
{#each links as link (link)}
{@render eventLink(link)}
{@render eventNamespaceLink(link)}
{/each}
{/snippet}
{#snippet eventSummary(value: RawPayload)}
<div class="flex items-start gap-4">
<p class="min-w-56 text-sm text-secondary/80">Summary</p>
<p class="whitespace-pre-line">
<Payload
{value}
mode="summary"
fallback={translate('events.decode-failed')}
/>
</p>
</div>
{/snippet}
{#snippet payloads(key, value)}
{@const codeBlockValue = getCodeBlockValue(value)}
{@const stackTrace = getStackTrace(codeBlockValue)}
<div>
<p class="mb-1 min-w-56 text-sm text-secondary/80">
{format(key)}
</p>
{#if value?.payloads}
<Payload
{value}
key="payloads"
maxHeight={384}
copyIconTitle={translate('common.copy-icon-title')}
copySuccessIconTitle={translate('common.copy-success-icon-title')}
/>
{:else if key === 'searchAttributes'}
<Payload
key="searchAttributes"
value={{ searchAttributes: codeBlockValue }}
maxHeight={384}
copyIconTitle={translate('common.copy-icon-title')}
copySuccessIconTitle={translate('common.copy-success-icon-title')}
/>
{:else}
<Payload
value={codeBlockValue}
maxHeight={384}
copyIconTitle={translate('common.copy-icon-title')}
copySuccessIconTitle={translate('common.copy-success-icon-title')}
/>
{/if}
</div>
{#if stackTrace}
<div>
<p class="mb-1 min-w-56 text-sm text-secondary/80">
{translate('workflows.call-stack-tab')}
</p>
<Payload
value={stackTrace}
language="text"
maxHeight={384}
copyIconTitle={translate('common.copy-icon-title')}
copySuccessIconTitle={translate('common.copy-success-icon-title')}
/>
</div>
{/if}
{/snippet}
{#snippet link(key, value)}
<div class="flex items-start gap-4">
<p class="min-w-56 text-sm text-secondary/80">
{format(key)}
</p>
<Copyable
copyIconTitle={translate('common.copy-icon-title')}
copySuccessIconTitle={translate('common.copy-success-icon-title')}
content={String(value)}
>
<EventDetailsLink
value={String(value)}
{attributes}
type={displayLinkType(key, attributes)}
class="whitespace-pre-line"
/>
</Copyable>
</div>
{/snippet}
{#snippet details(key, value)}
<div class="flex items-start gap-4">
<p class="min-w-56 text-sm text-secondary/80">
{format(key)}
</p>
<p class="whitespace-pre-line break-all">
{#if shouldDisplayAsTime(key)}
<Timestamp dateTime={value} />
{:else}
{value}
{/if}
</p>
</div>
{/snippet}