Skip to content

Commit 2855c76

Browse files
authored
Event History and Workflow Run store refactor (#1051)
* WIP: removing workflowRun and eventHistory stores * WIP refactor * Move up layout logic to +layout, add back stores, need to figure out worker query page logic * Use page params for params to query * Use stores, not props to be consistent * More refactoring, move fetchEvents to event history instead of the page layout * Remove unused file and bump version * Bump back down to 2.2.0
1 parent aba6e8d commit 2855c76

23 files changed

+147
-230
lines changed

Diff for: src/lib/components/event/event-empty-row.svelte

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
<script lang="ts">
22
import EmptyState from '$lib/holocene/empty-state.svelte';
3+
import Loading from '$lib/holocene/loading.svelte';
4+
5+
export let loading = false;
36
</script>
47

58
<tr class="row">
69
<td class="table-cell" colspan="6">
7-
<EmptyState
8-
title="No Events Match"
9-
content="There are no events that match your filters or selected view. Adjust your filters or view to see your events."
10-
/>
10+
{#if loading}
11+
<Loading />
12+
{:else}
13+
<EmptyState
14+
title="No Events Match"
15+
content="There are no events that match your filters or selected view. Adjust your filters or view to see your events."
16+
/>
17+
{/if}
1118
</td>
1219
</tr>
1320

Diff for: src/lib/components/event/event-history-timeline-container.svelte

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import Badge from '$lib/holocene/badge.svelte';
1717
import { groupEvents } from '$lib/models/event-groups';
1818
19-
$: isRunning = $workflowRun.workflow?.isRunning;
19+
$: ({ workflow } = $workflowRun);
20+
21+
$: isRunning = workflow?.isRunning;
2022
2123
let showEventTypeFilter = false;
2224
let eventTypeValue = '';

Diff for: src/lib/components/event/event-summary.svelte

+43-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,58 @@
11
<script lang="ts">
22
import { page } from '$app/stores';
3-
import { eventFilterSort, expandAllEvents } from '$lib/stores/event-view';
4-
import { eventHistory } from '$lib/stores/events';
3+
import {
4+
eventFilterSort,
5+
type EventSortOrder,
6+
expandAllEvents,
7+
} from '$lib/stores/event-view';
58
import { refresh } from '$lib/stores/workflow-run';
9+
import { eventHistory } from '$lib/stores/events';
610
711
import EventSummaryTable from '$lib/components/event/event-summary-table.svelte';
812
import EventSummaryRow from '$lib/components/event/event-summary-row.svelte';
913
import EventEmptyRow from './event-empty-row.svelte';
1014
import { groupEvents } from '$lib/models/event-groups';
1115
import Pagination from '$lib/holocene/pagination.svelte';
16+
import { fetchAllEvents } from '$lib/services/events-service';
1217
13-
export let events: CommonHistoryEvent[];
1418
export let compact = false;
1519
20+
$: ({ namespace, workflow: workflowId, run: runId } = $page.params);
21+
22+
let fullHistory: CommonHistoryEvent[] = [];
23+
let loading: boolean = true;
24+
25+
const resetFullHistory = () => {
26+
fullHistory = [];
27+
loading = true;
28+
};
29+
30+
const fetchEvents = async (
31+
namespace: string,
32+
workflowId: string,
33+
runId: string,
34+
sort: EventSortOrder,
35+
) => {
36+
const { settings, user } = $page.data;
37+
resetFullHistory();
38+
fullHistory = await fetchAllEvents({
39+
namespace,
40+
workflowId,
41+
runId,
42+
settings,
43+
accessToken: user?.accessToken,
44+
sort: compact ? 'ascending' : sort,
45+
});
46+
loading = false;
47+
};
48+
49+
$: $refresh, fetchEvents(namespace, workflowId, runId, $eventFilterSort);
50+
1651
function handleExpandChange(event: CustomEvent) {
1752
$expandAllEvents = event.detail.expanded;
1853
}
1954
20-
const getEvents = (
55+
const getEventsOrGroups = (
2156
items: CommonHistoryEvent[],
2257
category: string,
2358
): IterableEvent[] => {
@@ -33,10 +68,10 @@
3368
$eventFilterSort === 'descending' && !compact
3469
? $eventHistory?.end
3570
: $eventHistory?.start;
36-
$: currentEvents = events.length ? events : intialEvents;
71+
$: currentEvents = fullHistory.length ? fullHistory : intialEvents;
3772
$: initialItem = currentEvents?.[0];
38-
$: items = getEvents(currentEvents, category);
39-
$: updating = currentEvents.length && !events.length;
73+
$: items = getEventsOrGroups(currentEvents, category);
74+
$: updating = currentEvents.length && !fullHistory.length;
4075
</script>
4176

4277
{#key [$eventFilterSort, category, $refresh]}
@@ -60,7 +95,7 @@
6095
onRowClick={() => setActiveRowIndex(index)}
6196
/>
6297
{:else}
63-
<EventEmptyRow />
98+
<EventEmptyRow {loading} />
6499
{/each}
65100
</EventSummaryTable>
66101
</Pagination>

Diff for: src/lib/components/workflow/pending-activities.svelte

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
} from '$lib/utilities/format-event-attributes';
1717
import { toTimeDifference } from '$lib/utilities/to-time-difference';
1818
19-
$: pendingActivities = $workflowRun.workflow?.pendingActivities;
19+
$: ({ workflow } = $workflowRun);
20+
$: pendingActivities = workflow?.pendingActivities;
2021
2122
$: href = routeForPendingActivities({
2223
namespace: $page.params.namespace,
@@ -25,7 +26,7 @@
2526
});
2627
2728
$: canceled = ['Terminated', 'TimedOut', 'Canceled'].includes(
28-
$workflowRun.workflow?.status,
29+
workflow?.status,
2930
);
3031
</script>
3132

Diff for: src/lib/components/workflow/workflow-relationships.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script lang="ts">
22
import { page } from '$app/stores';
3-
import { eventHistory } from '$lib/stores/events';
4-
import { workflowRun } from '$lib/stores/workflow-run';
53
import { routeForEventHistory } from '$lib/utilities/route-for';
4+
import { workflowRun } from '$lib/stores/workflow-run';
5+
import { eventHistory } from '$lib/stores/events';
66
77
import Accordion from '$lib/holocene/accordion.svelte';
88
import Badge from '$lib/holocene/badge.svelte';

Diff for: src/lib/components/workflow/workflow-stack-trace-error.svelte

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<script lang="ts">
22
import EmptyState from '$lib/holocene/empty-state.svelte';
33
4-
import type { GetPollersResponse } from '$lib/services/pollers-service';
5-
6-
export let workflow: WorkflowExecution;
7-
export let workers: GetPollersResponse;
4+
import { workflowRun } from '$lib/stores/workflow-run';
85
6+
$: ({ workflow, workers } = $workflowRun);
97
$: runningWithNoWorkers = workflow.isRunning && !workers?.pollers?.length;
108
</script>
119

Diff for: src/lib/components/workflow/workflow-summary.svelte

+10-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
1111
import Accordion from '$lib/holocene/accordion.svelte';
1212
import WorkflowDetail from '$lib/components/workflow/workflow-detail.svelte';
13+
14+
$: ({ workflow } = $workflowRun);
1315
</script>
1416

1517
<Accordion
@@ -26,40 +28,36 @@
2628
<div class="col-span-1 md:col-span-2">
2729
<h3 class="font-medium">Workflow Type</h3>
2830
<div class="h-0.5 rounded-full bg-gray-900" />
29-
<WorkflowDetail content={$workflowRun.workflow?.name} copyable />
30-
<WorkflowDetail
31-
title="Run ID"
32-
content={$workflowRun.workflow?.runId}
33-
copyable
34-
/>
31+
<WorkflowDetail content={workflow?.name} copyable />
32+
<WorkflowDetail title="Run ID" content={workflow?.runId} copyable />
3533
</div>
3634
<div class="col-span-1">
3735
<h3 class="font-medium">Task Queue</h3>
3836
<div class="h-0.5 rounded-full bg-gray-900" />
3937
<WorkflowDetail
40-
content={$workflowRun.workflow?.taskQueue}
38+
content={workflow?.taskQueue}
4139
href={routeForWorkers({
4240
namespace: $page.params.namespace,
43-
workflow: $workflowRun.workflow?.id,
44-
run: $workflowRun.workflow?.runId,
41+
workflow: workflow?.id,
42+
run: workflow?.runId,
4543
})}
4644
copyable
4745
/>
4846
<WorkflowDetail
4947
title="State Transitions"
50-
content={$workflowRun.workflow?.stateTransitionCount}
48+
content={workflow?.stateTransitionCount}
5149
/>
5250
</div>
5351
<div class="col-span-1">
5452
<h3 class="font-medium">Start & Close Time</h3>
5553
<div class="h-0.5 rounded-full bg-gray-900" />
5654
<WorkflowDetail
5755
title="Start Time"
58-
content={formatDate($workflowRun.workflow?.startTime, $timeFormat)}
56+
content={formatDate(workflow?.startTime, $timeFormat)}
5957
/>
6058
<WorkflowDetail
6159
title="Close Time"
62-
content={formatDate($workflowRun.workflow?.endTime, $timeFormat)}
60+
content={formatDate(workflow?.endTime, $timeFormat)}
6361
/>
6462
</div>
6563
</div>

Diff for: src/lib/layouts/workflow-header.svelte

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
<script lang="ts">
2-
import Badge from '$lib/holocene/badge.svelte';
3-
import Icon from '$lib/holocene/icon/icon.svelte';
42
import { onDestroy, onMount } from 'svelte';
53
import { fly } from 'svelte/transition';
64
75
import { autoRefreshWorkflow } from '$lib/stores/event-view';
86
import { workflowsQuery, workflowsSearch } from '$lib/stores/workflows';
9-
import { workflowRun, refresh } from '$lib/stores/workflow-run';
7+
import { refresh, workflowRun } from '$lib/stores/workflow-run';
108
import { eventHistory } from '$lib/stores/events';
119
1210
import {
@@ -19,8 +17,8 @@
1917
} from '$lib/utilities/route-for';
2018
import { toListWorkflowQuery } from '$lib/utilities/query/list-workflow-query';
2119
22-
import type { GetPollersResponse } from '$lib/services/pollers-service';
23-
20+
import Badge from '$lib/holocene/badge.svelte';
21+
import Icon from '$lib/holocene/icon/icon.svelte';
2422
import WorkflowStatus from '$lib/components/workflow-status.svelte';
2523
import WorkflowActions from '$lib/components/workflow-actions.svelte';
2624
import Tab from '$lib/holocene/tab.svelte';
@@ -31,8 +29,8 @@
3129
import { isCancelInProgress } from '$lib/utilities/cancel-in-progress';
3230
3331
export let namespace: string;
34-
export let workflow: WorkflowExecution;
35-
export let workers: GetPollersResponse;
32+
33+
$: ({ workflow, workers } = $workflowRun);
3634
3735
export let terminateEnabled: boolean = false;
3836
export let cancelEnabled: boolean = false;

Diff for: src/lib/layouts/workflow-history-layout.svelte

+3-29
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<script lang="ts">
22
import { page } from '$app/stores';
3-
import { workflowRun, refresh } from '$lib/stores/workflow-run';
43
import { eventViewType } from '$lib/stores/event-view';
5-
import { eventHistory } from '$lib/stores/events';
6-
import { fetchStartAndEndEvents } from '$lib/services/events-service';
74
import { getWorkflowStartedCompletedAndTaskFailedEvents } from '$lib/utilities/get-started-completed-and-task-failed-events';
85
import { exportHistory } from '$lib/utilities/export-history';
6+
import { workflowRun } from '$lib/stores/workflow-run';
7+
import { eventHistory } from '$lib/stores/events';
98
109
import ToggleButton from '$lib/holocene/toggle-button/toggle-button.svelte';
1110
import ToggleButtons from '$lib/holocene/toggle-button/toggle-buttons.svelte';
@@ -20,31 +19,9 @@
2019
2120
let showShortcuts = false;
2221
23-
$: namespace = $page.params.namespace;
24-
$: workflowId = $page.params.workflow;
25-
$: runId = $page.params.run;
26-
27-
$: $refresh, getStartAndEndEvents(namespace, workflowId, runId);
28-
2922
$: workflowEvents =
3023
getWorkflowStartedCompletedAndTaskFailedEvents($eventHistory);
3124
32-
const getStartAndEndEvents = async (
33-
namespace: string,
34-
workflowId: string,
35-
runId: string,
36-
) => {
37-
const { settings, user } = $page.data;
38-
const events = await fetchStartAndEndEvents({
39-
namespace,
40-
workflowId,
41-
runId,
42-
settings,
43-
accessToken: user?.accessToken,
44-
});
45-
$eventHistory = events;
46-
};
47-
4825
const onViewClick = (view: EventView) => {
4926
if ($page.url.searchParams.get('page')) {
5027
$page.url.searchParams.delete('page');
@@ -56,10 +33,7 @@
5633
<section class="flex flex-col gap-4">
5734
<WorkflowSummary />
5835
<WorkflowRelationships />
59-
<WorkflowStackTraceError
60-
workflow={$workflowRun.workflow}
61-
workers={$workflowRun.workers}
62-
/>
36+
<WorkflowStackTraceError />
6337
<WorkflowTypedError error={workflowEvents.error} />
6438
<PendingActivities />
6539
<section class="flex w-full" data-cy="inputs-results">

0 commit comments

Comments
 (0)