-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathevent-details-full.svelte
More file actions
144 lines (133 loc) · 4.82 KB
/
event-details-full.svelte
File metadata and controls
144 lines (133 loc) · 4.82 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
<script lang="ts">
import { page } from '$app/state';
import type { EventGroup } from '$lib/models/event-groups/event-groups';
import type { WorkflowEvent } from '$lib/types/events';
import { formatAttributes } from '$lib/utilities/format-event-attributes';
import { displayLinkType } from '$lib/utilities/get-single-attribute-for-event';
import PendingActivityCard from '../workflow/pending-activity/pending-activity-card.svelte';
import PendingNexusOperationCard from '../workflow/pending-nexus-operation/pending-nexus-operation-card.svelte';
import EventCard from './event-card.svelte';
import EventDetailsSection from './event-details-section.svelte';
import EventPayloads from './event-payloads.svelte';
let {
group = undefined,
event = undefined,
}: { group?: EventGroup; event?: WorkflowEvent } = $props();
const pendingEvent = $derived(
group?.pendingActivity || group?.pendingNexusOperation,
);
const showEventGroup = $derived(
group && (group.eventList.length > 1 || pendingEvent),
);
const processedEvents = $derived.by(() => {
if (!group || !showEventGroup) return [];
return group.eventList.map((evt) => {
const attrs = formatAttributes(evt);
if (evt?.principal?.name) attrs.principalName = evt.principal.name;
if (evt?.principal?.type) attrs.principalType = evt.principal.type;
const fields = Object.entries(attrs);
const payloadFields = fields.filter(
([_key, value]) =>
typeof value === 'object' && Object.keys(value).length > 0,
);
const linkFields = fields.filter(
([key, _value]) => displayLinkType(key, attrs) !== 'none',
);
const hiddenDetailFields = (() => {
if (evt.category === 'activity')
return ['scheduledEventId', 'startedEventId', 'namespaceId'];
if (evt.category === 'child-workflow')
return ['initiatedEventId', 'startedEventId', 'namespaceId'];
return ['namespaceId'];
})();
const detailFields = fields.filter(
([key, value]) =>
typeof value !== 'object' &&
displayLinkType(key, attrs) === 'none' &&
!hiddenDetailFields.includes(key) &&
(key !== 'namespace' ||
(key === 'namespace' && page.params.namespace !== value)),
);
return {
event: evt,
attributes: attrs,
payloadFields,
detailFields,
linkFields,
};
});
});
const payloadKeyOrder = [
'input',
'result',
'lastFailure',
'failure',
'header',
'searchAttributes',
'memo',
];
const allPayloadFields = $derived.by(() => {
const all = processedEvents.flatMap((p) => p.payloadFields);
return all.toSorted(([a], [b]) => {
const aIndex = payloadKeyOrder.indexOf(a);
const bIndex = payloadKeyOrder.indexOf(b);
const aOrder = aIndex !== -1 ? aIndex : payloadKeyOrder.length - 1;
const bOrder = bIndex !== -1 ? bIndex : payloadKeyOrder.length - 1;
return aOrder - bOrder;
});
});
const hasAnyPayloads = $derived(allPayloadFields.length > 0);
</script>
{#if showEventGroup}
<div
class="surface-primary flex flex-col overflow-hidden border-t border-subtle"
>
{#if group?.pendingActivity}
<PendingActivityCard activity={group.pendingActivity} />
{:else if group?.pendingNexusOperation}
<PendingNexusOperationCard operation={group.pendingNexusOperation} />
{/if}
{#if hasAnyPayloads}
<div class="flex flex-col border-b border-subtle xl:flex-row">
<div class="flex w-full flex-col xl:w-1/2">
{#each processedEvents as processed, i (processed.event.id)}
<div
class="p-4 {i < processedEvents.length - 1
? 'border-b border-subtle'
: ''}"
>
<div class="flex flex-col gap-1">
<EventDetailsSection
event={processed.event}
{group}
attributes={processed.attributes}
detailFields={processed.detailFields}
linkFields={processed.linkFields}
/>
</div>
</div>
{/each}
</div>
<div class="flex w-full flex-col gap-1 p-4 xl:w-1/2">
<EventPayloads payloadFields={allPayloadFields} />
</div>
</div>
{:else}
{#each processedEvents as processed (processed.event.id)}
<div class="border-b border-subtle p-4">
<div class="flex flex-col gap-1">
<EventDetailsSection
event={processed.event}
{group}
attributes={processed.attributes}
detailFields={processed.detailFields}
linkFields={processed.linkFields}
/>
</div>
</div>
{/each}
{/if}
</div>
{:else if event}
<EventCard {event} />
{/if}