@camunda/ccma-saas-frontend 0.17.3 → 0.17.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/components/c4-actionable-notification/c4-actionable-notification.js +1 -1
- package/lib/esm/components/c4-cluster-list/c4-cluster-list.js +22 -2
- package/lib/esm/components/c4-cluster-list/c4-cluster-list.mocks.js +2 -1
- package/lib/esm/components/c4-cluster-list/c4-cluster-list.types.d.ts +26 -0
- package/lib/esm/components/c4-cluster-list/cluster-list-filters.d.ts +22 -0
- package/lib/esm/components/c4-cluster-list/cluster-list-filters.js +118 -0
- package/lib/esm/components/c4-data-table/c4-data-table.d.ts +13 -1
- package/lib/esm/components/c4-data-table/c4-data-table.js +101 -24
- package/lib/esm/widgets/clusters/c4-clusters-page.js +17 -1
- package/lib/esm/widgets/clusters/c4-clusters-page.types.d.ts +3 -1
- package/package.json +1 -1
|
@@ -54,5 +54,5 @@ export function C4ActionableNotification(props) {
|
|
|
54
54
|
}, children: _jsxs(C3ResponsiveStack, { alignItems: 'center', justifyContent: 'space-between', children: [_jsxs(C3ResponsiveStack, { orientation: props?.orientation ?? 'horizontal', gap: 1, children: [_jsx("span", { className: 'cds--actionable-notification__title', children: props.title }), _jsx("p", { children: props.subtitle })] }), buttonSlot] }) })] }));
|
|
55
55
|
}
|
|
56
56
|
const { kind, title, subtitle, actionButtonLabel, onActionButtonClick, hideCloseButton, onCloseButtonClick, secondaryActionButtonLabel, onSecondaryActionButtonClick, } = props;
|
|
57
|
-
return (
|
|
57
|
+
return (_jsx(Alert, { variant: kindToAlertVariant(kind), title: typeof title === 'string' ? title : undefined, description: subtitle, dismissible: !hideCloseButton, onDismiss: onCloseButtonClick, children: _jsxs("div", { className: 'flex flex-wrap gap-4', children: [actionButtonLabel ? (_jsx(Button, { variant: 'link', className: 'h-auto p-0', onClick: onActionButtonClick, children: actionButtonLabel })) : undefined, secondaryActionButtonLabel && onSecondaryActionButtonClick ? (_jsx(Button, { variant: 'link', className: 'h-auto p-0', onClick: onSecondaryActionButtonClick, children: secondaryActionButtonLabel })) : undefined] }) }));
|
|
58
58
|
}
|
|
@@ -9,6 +9,7 @@ import { C4DataTable } from '../c4-data-table/c4-data-table.js';
|
|
|
9
9
|
import { C4InlineNotification } from '../c4-inline-notification/c4-inline-notification.js';
|
|
10
10
|
import { C4LinkButton } from '../c4-link-button/c4-link-button.js';
|
|
11
11
|
import { C4PageTemplate } from '../c4-page-template/c4-page-template.js';
|
|
12
|
+
import { buildClusterListFilters } from './cluster-list-filters.js';
|
|
12
13
|
// ds-only column-width hints (see `docs/c4-carbon-compat.md`) so the Status
|
|
13
14
|
// column has room for its icon + label and doesn't wrap on narrower (~14")
|
|
14
15
|
// viewports, while Generation/Region — the widest columns, which can carry
|
|
@@ -52,6 +53,21 @@ export const C4ClusterList = ({ clusters, loading, urls, permissions, onNavigate
|
|
|
52
53
|
stableClustersRef.current = nextClusters;
|
|
53
54
|
return nextClusters;
|
|
54
55
|
})();
|
|
56
|
+
// `stableClusters` keeps its row objects and updates them in place, so the
|
|
57
|
+
// table cannot see a changed status, generation or tag on its own. This
|
|
58
|
+
// signature of the fields the search and filters read makes it re-filter.
|
|
59
|
+
const rowsSignature = stableClusters
|
|
60
|
+
.map((cluster) => JSON.stringify([
|
|
61
|
+
cluster.id,
|
|
62
|
+
cluster.name,
|
|
63
|
+
cluster.status,
|
|
64
|
+
cluster.generation,
|
|
65
|
+
cluster.generationName,
|
|
66
|
+
cluster.type,
|
|
67
|
+
cluster.region,
|
|
68
|
+
cluster.tags,
|
|
69
|
+
]))
|
|
70
|
+
.join('\n');
|
|
55
71
|
const readPageSelect = useCallback(() => {
|
|
56
72
|
return (tableContainerRef.current?.querySelector(PAGE_NUMBER_SELECTOR) ?? null);
|
|
57
73
|
}, []);
|
|
@@ -330,7 +346,7 @@ export const C4ClusterList = ({ clusters, loading, urls, permissions, onNavigate
|
|
|
330
346
|
const type = filter.row.type.toLowerCase();
|
|
331
347
|
const region = filter.row.region.toLowerCase();
|
|
332
348
|
const status = filter.row.status.toLowerCase();
|
|
333
|
-
const tagsIncludeSearchTerm = filter.row.tags.some((tag) => {
|
|
349
|
+
const tagsIncludeSearchTerm = (filter.row.tags ?? []).some((tag) => {
|
|
334
350
|
return tag
|
|
335
351
|
.toLowerCase()
|
|
336
352
|
.includes(filter.searchTerm?.toLowerCase());
|
|
@@ -338,6 +354,10 @@ export const C4ClusterList = ({ clusters, loading, urls, permissions, onNavigate
|
|
|
338
354
|
return ([name, generation, type, region, status].some((value) => value.includes(filter.searchTerm?.toLowerCase())) || tagsIncludeSearchTerm);
|
|
339
355
|
},
|
|
340
356
|
},
|
|
357
|
+
// ds mode only: carbon keeps its search-only toolbar.
|
|
358
|
+
...(isDsMode
|
|
359
|
+
? buildClusterListFilters(clusters, translations.filters)
|
|
360
|
+
: []),
|
|
341
361
|
];
|
|
342
362
|
if (permissions.canCreateCluster) {
|
|
343
363
|
toolbar.push({
|
|
@@ -440,7 +460,7 @@ export const C4ClusterList = ({ clusters, loading, urls, permissions, onNavigate
|
|
|
440
460
|
paddingBlockEnd: 'var(--cds-spacing-07)',
|
|
441
461
|
}, children: [_jsx("p", { style: { color: 'var(--cds-text-secondary)' }, children: translations.emptyState.noClusters }), permissions.canCreateCluster && (_jsx("div", { style: { marginTop: 'var(--cds-spacing-05)' }, children: _jsx(Button, { kind: 'primary', onClick: () => onNavigate(urls.createCluster), disabled: permissions.createClusterButtonDisabled, children: translations.createButton }) }))] })));
|
|
442
462
|
}
|
|
443
|
-
return (_jsx("div", { ref: tableContainerRef, children: _jsx(C4DataTable, { headers: headerData, isLoading: loading, toolbar: toolbar, actions: actions, data: stableClusters, queryPrefix: 'cluster-list', options: {
|
|
463
|
+
return (_jsx("div", { ref: tableContainerRef, children: _jsx(C4DataTable, { headers: headerData, isLoading: loading, toolbar: toolbar, actions: actions, data: stableClusters, rowsSignature: rowsSignature, queryPrefix: 'cluster-list', options: {
|
|
444
464
|
pageSize: DEFAULT_PAGE_SIZE,
|
|
445
465
|
pageSizes: [10, DEFAULT_PAGE_SIZE, 50, 100],
|
|
446
466
|
} }) }));
|
|
@@ -19,6 +19,7 @@ export const mockClusters = [
|
|
|
19
19
|
id: 'cluster-2',
|
|
20
20
|
name: 'Development Cluster',
|
|
21
21
|
generation: 'Camunda 8.4 - update available',
|
|
22
|
+
generationName: 'Camunda 8.4',
|
|
22
23
|
type: 'Development',
|
|
23
24
|
region: 'eu-central-1',
|
|
24
25
|
status: 'creating',
|
|
@@ -84,7 +85,7 @@ export const defaultProps = {
|
|
|
84
85
|
translations: {
|
|
85
86
|
title: 'Clusters',
|
|
86
87
|
createButton: 'Create cluster',
|
|
87
|
-
searchLabel: 'Search',
|
|
88
|
+
searchLabel: 'Search clusters…',
|
|
88
89
|
// Not exercised by any story: `emptyStateContent` is always supplied
|
|
89
90
|
// where `clusters` is empty (see c4-cluster-list.tsx `renderDataTable`),
|
|
90
91
|
// so this fallback copy never renders. Present only to satisfy the
|
|
@@ -2,7 +2,13 @@ import type { C4WidgetScope } from '../../widgets/c4-widget-scope.types.js';
|
|
|
2
2
|
export interface ClusterListItem {
|
|
3
3
|
id: string;
|
|
4
4
|
name: string;
|
|
5
|
+
/** The generation label shown in the table, e.g. with an update hint. */
|
|
5
6
|
generation: string;
|
|
7
|
+
/**
|
|
8
|
+
* The generation name without any suffix, for the generation filter. Falls
|
|
9
|
+
* back to `generation` when not set.
|
|
10
|
+
*/
|
|
11
|
+
generationName?: string;
|
|
6
12
|
type: string;
|
|
7
13
|
region: string;
|
|
8
14
|
status: 'healthy' | 'unhealthy' | 'creating' | 'updating' | 'waitingForInput' | 'suspended' | 'resuming' | 'deleting' | string;
|
|
@@ -60,6 +66,26 @@ export interface C4ClusterListProps {
|
|
|
60
66
|
title: string;
|
|
61
67
|
createButton: string;
|
|
62
68
|
searchLabel: string;
|
|
69
|
+
/**
|
|
70
|
+
* ds mode only. Labels of the status, generation and tag filters. Each has
|
|
71
|
+
* the "all" option label and the accessible name of the select. English
|
|
72
|
+
* defaults apply when not set.
|
|
73
|
+
*/
|
|
74
|
+
filters?: {
|
|
75
|
+
status: {
|
|
76
|
+
all: string;
|
|
77
|
+
label: string;
|
|
78
|
+
unknown: string;
|
|
79
|
+
};
|
|
80
|
+
generation: {
|
|
81
|
+
all: string;
|
|
82
|
+
label: string;
|
|
83
|
+
};
|
|
84
|
+
tags: {
|
|
85
|
+
all: string;
|
|
86
|
+
label: string;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
63
89
|
emptyState: {
|
|
64
90
|
noClusters: string;
|
|
65
91
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { C3DataTableToolbarProps } from '@camunda/camunda-composite-components';
|
|
2
|
+
import type { C4ClusterListProps, ClusterListItem } from './c4-cluster-list.types.js';
|
|
3
|
+
type FilterLabels = NonNullable<C4ClusterListProps['translations']['filters']>;
|
|
4
|
+
/** A row as the data table renders it, with its required `originalIndex`. */
|
|
5
|
+
type ClusterRow = ClusterListItem & {
|
|
6
|
+
originalIndex: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The value of the "all" option of every filter. Option IDs carry a filter
|
|
10
|
+
* prefix (see `optionId`), so no status, generation or tag, such as a custom
|
|
11
|
+
* tag named "all", can equal it.
|
|
12
|
+
*/
|
|
13
|
+
export declare const ALL_FILTER_VALUE = "all";
|
|
14
|
+
export declare const DEFAULT_CLUSTER_LIST_FILTER_LABELS: FilterLabels;
|
|
15
|
+
/**
|
|
16
|
+
* The status, generation and tag filters of the cluster list, in the order of
|
|
17
|
+
* the environment filters in Hub. The options come from the clusters in the
|
|
18
|
+
* list, and a filter with no options is left out. Filters combine with AND,
|
|
19
|
+
* and each one matches a single value.
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildClusterListFilters(clusters: ClusterListItem[], labels?: FilterLabels): C3DataTableToolbarProps<ClusterRow>[];
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
|
|
3
|
+
* under one or more contributor license agreements. Licensed under a commercial license.
|
|
4
|
+
* You may not use this file except in compliance with the commercial license.
|
|
5
|
+
*/
|
|
6
|
+
import { normalizeClusterStatus } from '../c4-cluster-overview/applications.js';
|
|
7
|
+
/**
|
|
8
|
+
* The value of the "all" option of every filter. Option IDs carry a filter
|
|
9
|
+
* prefix (see `optionId`), so no status, generation or tag, such as a custom
|
|
10
|
+
* tag named "all", can equal it.
|
|
11
|
+
*/
|
|
12
|
+
export const ALL_FILTER_VALUE = 'all';
|
|
13
|
+
function optionId(filterId, value) {
|
|
14
|
+
return `${filterId}:${value}`;
|
|
15
|
+
}
|
|
16
|
+
const UNKNOWN_STATUS = 'unknown';
|
|
17
|
+
/** A status the table shows as raw text, which the status column type lists. */
|
|
18
|
+
const DELETING_STATUS = 'deleting';
|
|
19
|
+
export const DEFAULT_CLUSTER_LIST_FILTER_LABELS = {
|
|
20
|
+
status: {
|
|
21
|
+
all: 'All statuses',
|
|
22
|
+
label: 'Filter by status',
|
|
23
|
+
unknown: 'Unknown',
|
|
24
|
+
},
|
|
25
|
+
generation: { all: 'All generations', label: 'Filter by generation' },
|
|
26
|
+
tags: { all: 'All tags', label: 'Filter by tag' },
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The order and labels of the status options. They follow the status labels
|
|
30
|
+
* of the table, without the trailing ellipsis of the ongoing states.
|
|
31
|
+
*/
|
|
32
|
+
const STATUS_OPTIONS = [
|
|
33
|
+
{ value: 'healthy', label: 'Healthy' },
|
|
34
|
+
{ value: 'unhealthy', label: 'Unhealthy' },
|
|
35
|
+
{ value: 'suspended', label: 'Paused' },
|
|
36
|
+
{ value: 'resuming', label: 'Resuming' },
|
|
37
|
+
{ value: 'creating', label: 'Creating' },
|
|
38
|
+
{ value: 'updating', label: 'Updating' },
|
|
39
|
+
{ value: 'restoring', label: 'Restoring' },
|
|
40
|
+
{ value: 'waitingForInput', label: 'Waiting' },
|
|
41
|
+
{ value: 'maintenance', label: 'Maintenance' },
|
|
42
|
+
{ value: DELETING_STATUS, label: 'Deleting' },
|
|
43
|
+
];
|
|
44
|
+
function statusOf(row) {
|
|
45
|
+
const known = normalizeClusterStatus(row.status);
|
|
46
|
+
if (known) {
|
|
47
|
+
return known;
|
|
48
|
+
}
|
|
49
|
+
return row.status?.trim().toLowerCase() === DELETING_STATUS
|
|
50
|
+
? DELETING_STATUS
|
|
51
|
+
: UNKNOWN_STATUS;
|
|
52
|
+
}
|
|
53
|
+
function tagsOf(row) {
|
|
54
|
+
return row.tags ?? [];
|
|
55
|
+
}
|
|
56
|
+
function generationOf(row) {
|
|
57
|
+
return row.generationName ?? row.generation;
|
|
58
|
+
}
|
|
59
|
+
function filterWithAll(id, labels, options, matches) {
|
|
60
|
+
const prefix = optionId(id, '');
|
|
61
|
+
return {
|
|
62
|
+
id,
|
|
63
|
+
type: 'singleSelect',
|
|
64
|
+
label: labels.label,
|
|
65
|
+
defaultValue: ALL_FILTER_VALUE,
|
|
66
|
+
items: [
|
|
67
|
+
{ id: ALL_FILTER_VALUE, label: labels.all },
|
|
68
|
+
...options.map((option) => ({
|
|
69
|
+
id: optionId(id, option.value),
|
|
70
|
+
label: option.label,
|
|
71
|
+
})),
|
|
72
|
+
],
|
|
73
|
+
// A pure function of the row and the selection: the value comes from the
|
|
74
|
+
// option ID itself. The table falls back to the "all" option when the
|
|
75
|
+
// selected option is gone, so a stale ID does not reach this predicate.
|
|
76
|
+
filter: ({ row, selectedItem }) => {
|
|
77
|
+
const selected = String(selectedItem);
|
|
78
|
+
if (selected === ALL_FILTER_VALUE || !selected.startsWith(prefix)) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
return matches(row, selected.slice(prefix.length));
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The status, generation and tag filters of the cluster list, in the order of
|
|
87
|
+
* the environment filters in Hub. The options come from the clusters in the
|
|
88
|
+
* list, and a filter with no options is left out. Filters combine with AND,
|
|
89
|
+
* and each one matches a single value.
|
|
90
|
+
*/
|
|
91
|
+
export function buildClusterListFilters(clusters, labels = DEFAULT_CLUSTER_LIST_FILTER_LABELS) {
|
|
92
|
+
const statuses = new Set(clusters.map(statusOf));
|
|
93
|
+
const statusOptions = [
|
|
94
|
+
...STATUS_OPTIONS.filter((option) => statuses.has(option.value)),
|
|
95
|
+
...(statuses.has(UNKNOWN_STATUS)
|
|
96
|
+
? [{ value: UNKNOWN_STATUS, label: labels.status.unknown }]
|
|
97
|
+
: []),
|
|
98
|
+
];
|
|
99
|
+
const generationOptions = [
|
|
100
|
+
...new Set(clusters.map(generationOf).filter(Boolean)),
|
|
101
|
+
]
|
|
102
|
+
.sort((a, b) => b.localeCompare(a, undefined, { numeric: true }))
|
|
103
|
+
.map((generation) => ({ value: generation, label: generation }));
|
|
104
|
+
const tagOptions = [...new Set(clusters.flatMap(tagsOf).filter(Boolean))]
|
|
105
|
+
.sort((a, b) => a.localeCompare(b))
|
|
106
|
+
.map((tag) => ({ value: tag, label: tag }));
|
|
107
|
+
const filters = [];
|
|
108
|
+
if (statusOptions.length > 0) {
|
|
109
|
+
filters.push(filterWithAll('status', labels.status, statusOptions, (row, value) => statusOf(row) === value));
|
|
110
|
+
}
|
|
111
|
+
if (generationOptions.length > 0) {
|
|
112
|
+
filters.push(filterWithAll('generation', labels.generation, generationOptions, (row, value) => generationOf(row) === value));
|
|
113
|
+
}
|
|
114
|
+
if (tagOptions.length > 0) {
|
|
115
|
+
filters.push(filterWithAll('tags', labels.tags, tagOptions, (row, value) => tagsOf(row).includes(value)));
|
|
116
|
+
}
|
|
117
|
+
return filters;
|
|
118
|
+
}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
import { type C3DataTableProps, type RowBaseProps } from '@camunda/camunda-composite-components';
|
|
2
2
|
import { type JSX } from 'react';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* The props of `C4DataTable`: the c3 props, plus `rowsSignature`.
|
|
5
|
+
*/
|
|
6
|
+
export type C4DataTableProps<T extends RowBaseProps> = C3DataTableProps<T> & {
|
|
7
|
+
/**
|
|
8
|
+
* ds mode only. A string that changes whenever a row field that the
|
|
9
|
+
* toolbar filters read changes. Pass it when the rows are mutated in place
|
|
10
|
+
* (same `data` array, same row objects), so the filtered rows follow the
|
|
11
|
+
* new values. Not needed when a change gives a new `data` array.
|
|
12
|
+
*/
|
|
13
|
+
rowsSignature?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function C4DataTable<T extends RowBaseProps>(props: C4DataTableProps<T>): JSX.Element;
|
|
@@ -5,7 +5,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
5
5
|
* You may not use this file except in compliance with the commercial license.
|
|
6
6
|
*/
|
|
7
7
|
import { C3DataTable, } from '@camunda/camunda-composite-components';
|
|
8
|
-
import { Button, DataTable, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,
|
|
8
|
+
import { Button, DataTable, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, MultiSelect, SearchInput, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@camunda/design-system';
|
|
9
9
|
import { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
|
|
10
10
|
import { useC4DesignSystem } from '../../runtime/c4-console-runtime-context.js';
|
|
11
11
|
/**
|
|
@@ -140,8 +140,34 @@ function toRowActions(actionsRef) {
|
|
|
140
140
|
};
|
|
141
141
|
});
|
|
142
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* The value a single select applies: its state when that is one of its
|
|
145
|
+
* options, else its default. A selection whose option is gone (e.g. the last
|
|
146
|
+
* row with that value changed) thus falls back to the default instead of
|
|
147
|
+
* matching nothing.
|
|
148
|
+
*/
|
|
149
|
+
function singleSelectValue(item, raw) {
|
|
150
|
+
const isOption = typeof raw === 'string' &&
|
|
151
|
+
(item.items === undefined || item.items.some((option) => option.id === raw));
|
|
152
|
+
if (isOption) {
|
|
153
|
+
return raw;
|
|
154
|
+
}
|
|
155
|
+
return item.defaultValue != null ? String(item.defaultValue) : undefined;
|
|
156
|
+
}
|
|
143
157
|
// Items that filter rows (search/singleSelect/multiSelect); button/menuButton
|
|
144
158
|
// do not.
|
|
159
|
+
/**
|
|
160
|
+
* Flex sizing of the ds toolbar filters. The row wraps on its items' base
|
|
161
|
+
* widths, so the bases are small enough for the search, the filters and the
|
|
162
|
+
* buttons to share one row on a normal page. Each item then grows to its
|
|
163
|
+
* Hub width: the search up to 24rem, a select up to 11rem (`w-44`). On a
|
|
164
|
+
* narrow screen the row still wraps. The DS stylesheet has no utility classes
|
|
165
|
+
* for these flex values, so they are inline.
|
|
166
|
+
*/
|
|
167
|
+
const TOOLBAR_ITEM_FLEX = {
|
|
168
|
+
search: { flex: '1 1 10rem', maxWidth: '24rem', minWidth: 0 },
|
|
169
|
+
singleSelect: { flex: '1 1 8rem', maxWidth: '11rem', minWidth: 0 },
|
|
170
|
+
};
|
|
145
171
|
function keepRow(row, items, state) {
|
|
146
172
|
return items.every((item) => {
|
|
147
173
|
if (item.type === 'search') {
|
|
@@ -152,8 +178,10 @@ function keepRow(row, items, state) {
|
|
|
152
178
|
: item.filter({ row, searchTerm });
|
|
153
179
|
}
|
|
154
180
|
if (item.type === 'singleSelect') {
|
|
155
|
-
|
|
156
|
-
|
|
181
|
+
// Same value as the rendered select: the default applies to a select
|
|
182
|
+
// with no seeded state (it joined the toolbar after mount) and to a
|
|
183
|
+
// selection whose option is gone.
|
|
184
|
+
const value = singleSelectValue(item, state[item.id]) ?? '';
|
|
157
185
|
return !value || !item.filter
|
|
158
186
|
? true
|
|
159
187
|
: item.filter({ row, selectedItem: value });
|
|
@@ -209,18 +237,46 @@ function C4DataTableDs(props) {
|
|
|
209
237
|
return initial;
|
|
210
238
|
});
|
|
211
239
|
const setValue = (key, value) => setFilterState((prev) => ({ ...prev, [key]: value }));
|
|
212
|
-
// Stable signature of the filtering toolbar items (their `type` + `id
|
|
213
|
-
//
|
|
214
|
-
//
|
|
215
|
-
//
|
|
216
|
-
//
|
|
217
|
-
//
|
|
240
|
+
// Stable signature of the filtering toolbar items (their `type` + `id`, and
|
|
241
|
+
// the option IDs of a single select, because a selection whose option is
|
|
242
|
+
// gone falls back to the default). It only changes when the toolbar's
|
|
243
|
+
// filtering shape changes — not on every render — and captures every input
|
|
244
|
+
// that can alter `keepRow`'s result other than the row data and the filter
|
|
245
|
+
// state (a filter's predicate is a pure function of the row and the current
|
|
246
|
+
// selection, so its closure identity is irrelevant). It is what gates the
|
|
247
|
+
// memo below against stale results.
|
|
218
248
|
const filterSignature = allToolbarItems
|
|
219
249
|
.filter((item) => item.type === 'search' ||
|
|
220
250
|
item.type === 'singleSelect' ||
|
|
221
251
|
item.type === 'multiSelect')
|
|
222
|
-
.map((item) =>
|
|
252
|
+
.map((item) => item.type === 'singleSelect'
|
|
253
|
+
? `${item.type}:${item.id}:${(item.items ?? []).map((option) => option.id).join(',')}`
|
|
254
|
+
: `${item.type}:${item.id}`)
|
|
223
255
|
.join('|');
|
|
256
|
+
// Drop a single-select selection whose option is gone, so that it does not
|
|
257
|
+
// come back if the option reappears later. Until then the select already
|
|
258
|
+
// shows and applies its default (see `singleSelectValue`).
|
|
259
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: allToolbarItems is rebuilt every render; filterSignature carries its options
|
|
260
|
+
useEffect(() => {
|
|
261
|
+
setFilterState((prev) => {
|
|
262
|
+
let next = prev;
|
|
263
|
+
for (const item of allToolbarItems) {
|
|
264
|
+
if (item.type !== 'singleSelect') {
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
const raw = prev[item.id];
|
|
268
|
+
if (typeof raw === 'string' &&
|
|
269
|
+
item.items !== undefined &&
|
|
270
|
+
!item.items.some((option) => option.id === raw)) {
|
|
271
|
+
if (next === prev) {
|
|
272
|
+
next = { ...prev };
|
|
273
|
+
}
|
|
274
|
+
delete next[item.id];
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return next;
|
|
278
|
+
});
|
|
279
|
+
}, [filterSignature]);
|
|
224
280
|
// Debounced snapshot of the live filter state. Search inputs read from this so
|
|
225
281
|
// that typing does not re-scan the whole dataset on every keystroke; discrete
|
|
226
282
|
// filters (single/multi select) keep applying immediately (see below).
|
|
@@ -259,37 +315,57 @@ function C4DataTableDs(props) {
|
|
|
259
315
|
// reference changes; an unconditional `.filter()` would hand it a brand-new
|
|
260
316
|
// array on every parent re-render (e.g. when a per-row API call resolves),
|
|
261
317
|
// snapping the table back to page 1 and unmounting any open row action
|
|
262
|
-
// menu.
|
|
263
|
-
//
|
|
264
|
-
//
|
|
265
|
-
// subsumes it; depending on the array directly would defeat the memo and
|
|
266
|
-
// reintroduce the reset.
|
|
318
|
+
// menu. `allToolbarItems` itself is rebuilt on every render, so it is
|
|
319
|
+
// intentionally not a dependency — `filterSignature` subsumes it; depending
|
|
320
|
+
// on the array directly would defeat the memo and reintroduce the reset.
|
|
267
321
|
// `effectiveFilterState` and `allToolbarItems` are used in the body but are
|
|
268
322
|
// intentionally not dependencies: `effectiveFilterKey` subsumes the effective
|
|
269
323
|
// filter contents (including the debounced search term) and `filterSignature`
|
|
270
324
|
// subsumes the toolbar shape. Depending on the objects directly would rebuild
|
|
271
325
|
// the array on every render — snapping TanStack back to page 1 and re-scanning
|
|
272
326
|
// the whole dataset on every keystroke.
|
|
327
|
+
// `rowsSignature` re-runs the filter when a consumer that mutates its rows in
|
|
328
|
+
// place (see c4-cluster-list) changes a filtered field.
|
|
273
329
|
// biome-ignore lint/correctness/useExhaustiveDependencies: effectiveFilterState/allToolbarItems are subsumed by effectiveFilterKey + filterSignature (see comment above)
|
|
274
|
-
const
|
|
330
|
+
const nextFilteredData = useMemo(() => allToolbarItems.length
|
|
275
331
|
? data.filter((row) => keepRow(row, allToolbarItems, effectiveFilterState))
|
|
276
|
-
: data, [data, effectiveFilterKey, filterSignature]);
|
|
332
|
+
: data, [data, effectiveFilterKey, filterSignature, props.rowsSignature]);
|
|
333
|
+
// A re-run of the filter for the same `data` array that keeps the same row
|
|
334
|
+
// objects in the same order (e.g. a status changed in place, with no filter
|
|
335
|
+
// on that field) returns the previous array. A new array there would send
|
|
336
|
+
// the table back to page 1 and close an open row action menu. A new `data`
|
|
337
|
+
// array still gives a new reference.
|
|
338
|
+
const previousFilteredRef = useRef(undefined);
|
|
339
|
+
const filteredData = useMemo(() => {
|
|
340
|
+
const previous = previousFilteredRef.current;
|
|
341
|
+
if (previous !== undefined &&
|
|
342
|
+
previous.data === data &&
|
|
343
|
+
previous.rows.length === nextFilteredData.length &&
|
|
344
|
+
previous.rows.every((row, index) => row === nextFilteredData[index])) {
|
|
345
|
+
return previous.rows;
|
|
346
|
+
}
|
|
347
|
+
previousFilteredRef.current = { data, rows: nextFilteredData };
|
|
348
|
+
return nextFilteredData;
|
|
349
|
+
}, [data, nextFilteredData]);
|
|
277
350
|
const renderToolbarItem = (item) => {
|
|
278
351
|
switch (item.type) {
|
|
279
352
|
case 'search': {
|
|
280
353
|
const raw = filterState[item.id];
|
|
281
354
|
const searchValue = typeof raw === 'string' ? raw : '';
|
|
282
|
-
|
|
355
|
+
// The DS `SearchInput` shows a search icon before the placeholder,
|
|
356
|
+
// as in the Hub toolbars, and a clear button once there is a value.
|
|
357
|
+
return (_jsx("div", { style: TOOLBAR_ITEM_FLEX.search, children: _jsx(SearchInput, { className: 'w-full', placeholder: item.label ?? 'Search', "aria-label": item.label ?? 'Search', value: searchValue, onChange: (event) => setValue(item.id, event.target.value) }) }, item.id));
|
|
283
358
|
}
|
|
284
359
|
case 'singleSelect': {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
360
|
+
// A select that joins the toolbar after mount (e.g. once its options
|
|
361
|
+
// are known), or whose selected option is gone, shows its default.
|
|
362
|
+
const value = singleSelectValue(item, filterState[item.id]);
|
|
363
|
+
return (_jsx("div", { style: TOOLBAR_ITEM_FLEX.singleSelect, children: _jsxs(Select, { value: value, onValueChange: (next) => setValue(item.id, next), disabled: item.disabled, children: [_jsx(SelectTrigger, { "aria-label": item.label, className: 'w-full', children: _jsx(SelectValue, { placeholder: item.label }) }), _jsx(SelectContent, { children: item.items?.map((option) => (_jsx(SelectItem, { value: option.id, children: option.label }, option.id))) })] }) }, item.id));
|
|
288
364
|
}
|
|
289
365
|
case 'multiSelect': {
|
|
290
366
|
const raw = filterState[item.id];
|
|
291
367
|
const value = Array.isArray(raw) ? raw : [];
|
|
292
|
-
return (_jsx(MultiSelect, { id: item.id, "aria-label": item.label ?? 'Filter', placeholder: item.label ?? 'Filter', className: 'w-64', options: (item.items ?? []).map((option) => ({
|
|
368
|
+
return (_jsx(MultiSelect, { id: item.id, "aria-label": item.label ?? 'Filter', placeholder: item.label ?? 'Filter', className: 'w-64 shrink-0', options: (item.items ?? []).map((option) => ({
|
|
293
369
|
value: option.id,
|
|
294
370
|
label: option.label,
|
|
295
371
|
})), value: value, onValueChange: (next) => setValue(item.id, next) }, item.id));
|
|
@@ -311,7 +387,7 @@ function C4DataTableDs(props) {
|
|
|
311
387
|
item.type === 'singleSelect' ||
|
|
312
388
|
item.type === 'multiSelect');
|
|
313
389
|
const buttons = items.filter((item) => item.type === 'button' || item.type === 'menuButton');
|
|
314
|
-
return (_jsxs("div", { className: 'flex flex-wrap items-center gap-2', children: [filters.map(renderToolbarItem), buttons.length > 0 && (_jsx("div", { className: 'ml-auto flex items-center gap-2', children: buttons.map(renderToolbarItem) }))] }, rowIndex));
|
|
390
|
+
return (_jsxs("div", { className: 'flex flex-wrap items-center gap-2', children: [filters.map(renderToolbarItem), buttons.length > 0 && (_jsx("div", { className: 'ml-auto flex shrink-0 items-center gap-2', children: buttons.map(renderToolbarItem) }))] }, rowIndex));
|
|
315
391
|
};
|
|
316
392
|
const hasHeading = title !== undefined || description !== undefined;
|
|
317
393
|
const hasExpansion = data.some((row) => row.expansion !== undefined);
|
|
@@ -327,5 +403,6 @@ function C4DataTableDs(props) {
|
|
|
327
403
|
}
|
|
328
404
|
export function C4DataTable(props) {
|
|
329
405
|
const designSystem = useC4DesignSystem();
|
|
330
|
-
|
|
406
|
+
const { rowsSignature: _rowsSignature, ...c3Props } = props;
|
|
407
|
+
return designSystem === 'ds' ? (_jsx(C4DataTableDs, { ...props })) : (_jsx(C3DataTable, { ...c3Props }));
|
|
331
408
|
}
|
|
@@ -146,7 +146,22 @@ function buildDefaultTranslations(t) {
|
|
|
146
146
|
return {
|
|
147
147
|
title: translate('c4console:clusters.list.title', 'Clusters'),
|
|
148
148
|
createButton: translate('c4console:clusters.list.createButton', 'Create new cluster'),
|
|
149
|
-
searchLabel: translate('c4console:clusters.list.searchLabel', 'Search'),
|
|
149
|
+
searchLabel: translate('c4console:clusters.list.searchLabel', 'Search clusters…'),
|
|
150
|
+
filters: {
|
|
151
|
+
status: {
|
|
152
|
+
all: translate('c4console:clusters.list.filters.status.all', 'All statuses'),
|
|
153
|
+
label: translate('c4console:clusters.list.filters.status.label', 'Filter by status'),
|
|
154
|
+
unknown: translate('c4console:clusters.list.filters.status.unknown', 'Unknown'),
|
|
155
|
+
},
|
|
156
|
+
generation: {
|
|
157
|
+
all: translate('c4console:clusters.list.filters.generation.all', 'All generations'),
|
|
158
|
+
label: translate('c4console:clusters.list.filters.generation.label', 'Filter by generation'),
|
|
159
|
+
},
|
|
160
|
+
tags: {
|
|
161
|
+
all: translate('c4console:clusters.list.filters.tags.all', 'All tags'),
|
|
162
|
+
label: translate('c4console:clusters.list.filters.tags.label', 'Filter by tag'),
|
|
163
|
+
},
|
|
164
|
+
},
|
|
150
165
|
emptyState: {
|
|
151
166
|
noClusters: translate('c4console:clusters.list.emptyState.noClusters', 'No clusters found.'),
|
|
152
167
|
},
|
|
@@ -378,6 +393,7 @@ export const C4ClustersPage = observer(({ orgId, scope = 'cluster', gettingStart
|
|
|
378
393
|
const clusterWithLoad = {
|
|
379
394
|
...item,
|
|
380
395
|
generation: generationLabel,
|
|
396
|
+
generationName: item.generation,
|
|
381
397
|
currentClusterLoad: clusterLoad,
|
|
382
398
|
};
|
|
383
399
|
return clusterWithLoad;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ClusterListPermissions } from '../../components/c4-cluster-list/c4-cluster-list.types.js';
|
|
1
|
+
import type { C4ClusterListProps, ClusterListPermissions } from '../../components/c4-cluster-list/c4-cluster-list.types.js';
|
|
2
2
|
import type { C4WidgetScope } from '../c4-widget-scope.types.js';
|
|
3
3
|
export type C4ClustersNavigateEvent = {
|
|
4
4
|
kind: 'clusterDetails';
|
|
@@ -16,6 +16,8 @@ export interface C4ClustersPageTranslations {
|
|
|
16
16
|
title: string;
|
|
17
17
|
createButton: string;
|
|
18
18
|
searchLabel: string;
|
|
19
|
+
/** ds mode only. See `C4ClusterListProps['translations']['filters']`. */
|
|
20
|
+
filters?: C4ClusterListProps['translations']['filters'];
|
|
19
21
|
emptyState: {
|
|
20
22
|
noClusters: string;
|
|
21
23
|
};
|