-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathevent-details-section.svelte
More file actions
171 lines (160 loc) · 5.11 KB
/
event-details-section.svelte
File metadata and controls
171 lines (160 loc) · 5.11 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
<script lang="ts">
import { page } from '$app/state';
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 { EventGroup } from '$lib/models/event-groups/event-groups';
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 type { CombinedAttributes } from '$lib/utilities/format-event-attributes';
import { formatDistanceAbbreviated } from '$lib/utilities/format-time';
import {
displayLinkType,
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';
import MetadataDecoder from './metadata-decoder.svelte';
let {
event,
group,
attributes,
detailFields,
linkFields,
}: {
event: WorkflowEvent;
group?: EventGroup;
attributes: CombinedAttributes;
detailFields: [string, unknown][];
linkFields: [string, unknown][];
} = $props();
const { namespace, workflow, run } = $derived(page.params);
const displayName = $derived(
isLocalActivityMarkerEvent(event)
? translate('events.category.local-activity')
: spaceBetweenCapitalLetters(event.name),
);
const durationSinceLastEvent = $derived.by(() => {
if (!group) return '';
const eventIndex = group.eventList.findIndex((evt) => evt.id === event.id);
if (eventIndex === -1 || eventIndex === 0) return '';
const previousEvent = group.eventList[eventIndex - 1];
return formatDistanceAbbreviated({
start: event.eventTime,
end: previousEvent.eventTime,
includeMilliseconds: true,
});
});
</script>
<div class="mb-2 flex w-full 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>
<div class="flex flex-col items-end gap-0 font-mono text-sm leading-4">
<Timestamp as="p" dateTime={event.eventTime} />
{#if durationSinceLastEvent}
<p class="font-medium text-secondary">+{durationSinceLastEvent}</p>
{/if}
</div>
</div>
{#if event?.links?.length}
{#each event.links as link}
{@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 font-medium text-secondary">
{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>
{@const nsHref = routeForNamespace({
namespace: link.workflowEvent.namespace,
})}
<div class="flex items-start gap-4">
<p class="min-w-56 text-sm font-medium text-secondary">
{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={nsHref} class="whitespace-pre-line"
>{link.workflowEvent.namespace}</Link
>
</Copyable>
</div>
{/each}
{/if}
{#if event?.userMetadata?.summary}
<div class="flex items-start gap-4">
<p class="min-w-56 text-sm font-medium text-secondary">Summary</p>
<p class="whitespace-pre-line">
<MetadataDecoder
value={event.userMetadata.summary}
let:decodedValue
fallback={translate('events.decode-failed')}
>
{decodedValue}
</MetadataDecoder>
</p>
</div>
{/if}
{#each detailFields as [key, value] (key)}
<div class="flex items-start gap-4">
<p class="min-w-56 text-sm font-medium text-secondary">
{format(key)}
</p>
<p class="whitespace-pre-line break-all">
{#if shouldDisplayAsTime(key)}
<Timestamp dateTime={value} />
{:else}
{value}
{/if}
</p>
</div>
{/each}
{#each linkFields as [key, value] (key)}
<div class="flex items-start gap-4">
<p class="min-w-56 text-sm font-medium text-secondary">
{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>
{/each}