-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathworkflows-summary-configurable-table.svelte
More file actions
178 lines (164 loc) · 5.78 KB
/
workflows-summary-configurable-table.svelte
File metadata and controls
178 lines (164 loc) · 5.78 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
<script lang="ts">
import { page } from '$app/stores';
import TableEmptyState from '$lib/components/workflow/workflows-summary-configurable-table/table-empty-state.svelte';
import Button from '$lib/holocene/button.svelte';
import FeatureTag from '$lib/holocene/feature-tag.svelte';
import Icon from '$lib/holocene/icon/icon.svelte';
import PaginatedTable from '$lib/holocene/table/paginated-table/api-paginated.svelte';
import Tooltip from '$lib/holocene/tooltip.svelte';
import { translate } from '$lib/i18n/translate';
import {
fetchAllChildWorkflows,
fetchPaginatedWorkflows,
} from '$lib/services/workflow-service';
import { configurableTableColumns } from '$lib/stores/configurable-table-columns';
import { viewFeature } from '$lib/stores/new-feature-tags';
import { tableDensity } from '$lib/stores/table-density';
import { refresh, workflowCount } from '$lib/stores/workflows';
import type { WorkflowExecution } from '$lib/types/workflows';
import { exportWorkflows } from '$lib/utilities/export-workflows';
import TableBodyCell from './workflows-summary-configurable-table/table-body-cell.svelte';
import TableHeaderCell from './workflows-summary-configurable-table/table-header-cell.svelte';
import TableHeaderRow from './workflows-summary-configurable-table/table-header-row.svelte';
import TableRow from './workflows-summary-configurable-table/table-row.svelte';
export let onClickConfigure: () => void;
$: ({ namespace } = $page.params);
$: baseColumns = $configurableTableColumns?.[namespace]?.workflows ?? [];
$: query = $page.url.searchParams.get('query');
$: hasVersioningFilter =
query?.includes('TemporalWorkerDeploymentVersion') ?? false;
$: hasVersioningBehaviorColumn = baseColumns.some(
(col) => col.label === 'Versioning Behavior',
);
$: columns =
hasVersioningFilter && !hasVersioningBehaviorColumn
? [...baseColumns, { label: 'Versioning Behavior' }]
: baseColumns;
let childrenIds: {
workflowId: string;
runId: string;
children: WorkflowExecution[];
}[] = [];
const clearChildren = () => {
childrenIds = [];
};
$: ($refresh, query, clearChildren());
const viewChildren = async (workflow: WorkflowExecution) => {
if (childrenActive(workflow)) {
childrenIds = childrenIds.filter(
(id) => id.workflowId !== workflow.id && id.runId !== workflow.runId,
);
} else {
const children = await fetchAllChildWorkflows(
namespace,
workflow.id,
workflow.runId,
);
childrenIds = [
{ workflowId: workflow.id, runId: workflow.runId, children },
...childrenIds,
];
}
};
$: childrenActive = (workflow: WorkflowExecution) => {
return childrenIds.find(
(id) => id.workflowId === workflow.id && id.runId === workflow.runId,
);
};
$: onFetch = () => fetchPaginatedWorkflows(namespace, query);
$: compact = $tableDensity === 'compact';
const setTableDensity = () => {
$tableDensity = compact ? 'comfortable' : 'compact';
viewFeature('tableDensity');
};
</script>
{#key [namespace, query, $refresh]}
<PaginatedTable
total={$workflowCount.count}
{onFetch}
let:visibleItems
aria-label={translate('common.workflows')}
pageSizeSelectLabel={translate('common.per-page')}
nextButtonLabel={translate('common.next')}
previousButtonLabel={translate('common.previous')}
emptyStateMessage={translate('workflows.empty-state-title')}
maxHeight="var(--panel-h)"
>
<caption class="sr-only" slot="caption">
{translate('common.workflows')}
</caption>
<TableHeaderRow
columnsCount={columns.length}
empty={visibleItems.length === 0}
slot="headers"
let:visibleItems
workflows={visibleItems}
>
{#each columns as column}
<TableHeaderCell {column} />
{/each}
</TableHeaderRow>
{#each visibleItems as workflow (`${workflow.id}:${workflow.runId}`)}
<TableRow
{workflow}
{viewChildren}
childCount={childrenActive(workflow)?.children.length}
>
{#each columns as column}
<TableBodyCell {workflow} {column} />
{/each}
</TableRow>
{#if childrenActive(workflow)}
{#each childrenActive(workflow).children as child (`${child.id}:${child.runId}`)}
<TableRow workflow={child} child>
{#each columns as column}
<TableBodyCell workflow={child} {column} />
{/each}
</TableRow>
{/each}
{/if}
{/each}
<svelte:fragment slot="empty">
<TableEmptyState>
<slot name="cloud" slot="cloud" />
</TableEmptyState>
</svelte:fragment>
<svelte:fragment slot="actions-end-additional" let:visibleItems let:page>
<Tooltip
text={compact
? translate('common.dense')
: translate('common.comfortable')}
top
>
<FeatureTag feature="tableDensity" alpha />
<Button
on:click={setTableDensity}
data-testid="table-density-button"
size="xs"
variant="ghost"
leadingIcon={compact ? 'table-dense' : 'table-comfy'}
></Button>
</Tooltip>
<Tooltip text={translate('common.download-json')} top>
<Button
on:click={() => exportWorkflows(visibleItems, page)}
data-testid="export-history-button"
size="xs"
variant="ghost"
>
<Icon name="download" />
</Button>
</Tooltip>
<Tooltip text="Configure Columns" top>
<Button
on:click={onClickConfigure}
data-testid="workflows-summary-table-configuration-button"
size="xs"
variant="ghost"
>
<Icon name="settings" />
</Button>
</Tooltip>
</svelte:fragment>
</PaginatedTable>
{/key}