@camunda/ccma-saas-frontend 0.40.0 → 0.41.0

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.
@@ -0,0 +1,7 @@
1
+ import type { JSX } from 'react';
2
+ import type { C4ClusterDiskUsageProps } from './c4-cluster-disk-usage.types.js';
3
+ type Text = C4ClusterDiskUsageProps['text'];
4
+ /** formatGib gives bytes as GiB with one decimal at most. */
5
+ export declare const formatGib: (bytes: number, text: Text) => string;
6
+ export declare const C4ClusterDiskUsage: ({ secondary, primary, isLoading, hasError, history, text, }: C4ClusterDiskUsageProps) => JSX.Element;
7
+ export {};
@@ -0,0 +1,209 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { DsCard, DsHeading, DsText, Stack } from '../../ui/index.js';
3
+ import { C4SegmentedControl } from '../c4-segmented-control/c4-segmented-control.js';
4
+ import { DsLineChart } from '../shared-charts/ds-line-chart.js';
5
+ import { getDsSeriesToken } from '../shared-charts/recharts-tokens.js';
6
+ const GIB = 1024 ** 3;
7
+ /**
8
+ * formatGibValue gives a GiB value with at most `digits` decimals, for
9
+ * example "6.5 GiB". The text gives the locale and the unit.
10
+ */
11
+ const formatGibValue = (gib, text, digits) => text.sizeLabel(new Intl.NumberFormat(text.locale, {
12
+ maximumFractionDigits: digits,
13
+ }).format(gib));
14
+ /** formatGib gives bytes as GiB with one decimal at most. */
15
+ export const formatGib = (bytes, text) => formatGibValue(bytes / GIB, text, 1);
16
+ const formatTime = (value, locale, options) => {
17
+ const date = new Date(String(value));
18
+ return Number.isNaN(date.getTime())
19
+ ? String(value)
20
+ : Intl.DateTimeFormat(locale, options).format(date);
21
+ };
22
+ const formatHour = (locale) => (value) => formatTime(value, locale, { hour: '2-digit', minute: '2-digit' });
23
+ // The daily buckets are UTC days, so the label reads the date in UTC.
24
+ const formatDay = (locale) => (value) => formatTime(value, locale, { month: 'short', day: '2-digit', timeZone: 'UTC' });
25
+ // The tooltip of the hourly range needs the day too, not only the hour.
26
+ const formatDayHour = (locale) => (value) => formatTime(value, locale, {
27
+ month: 'short',
28
+ day: '2-digit',
29
+ hour: '2-digit',
30
+ minute: '2-digit',
31
+ });
32
+ const toGib = (bytes) => Math.round((bytes / GIB) * 100) / 100;
33
+ const volumeKey = (storage, pvc) => `${storage}/${pvc}`;
34
+ /**
35
+ * The names of the volumes: the row name ("Disk 1") and the line name of the
36
+ * chart ("Primary storage, disk 1"). The number is the trailing number of the
37
+ * pvc, counted from 1. Two pvcs of one storage with the same number (for
38
+ * example `data-0` and `logs-0`) would share one line, so those keep the pvc
39
+ * name, and so does a pvc with no trailing number.
40
+ */
41
+ const volumeNames = (volumes, text) => {
42
+ const diskNumber = (pvc) => {
43
+ const index = /-(\d+)$/.exec(pvc)?.[1];
44
+ return index === undefined ? undefined : Number(index) + 1;
45
+ };
46
+ const pvcsByNumber = new Map();
47
+ for (const { storage, pvc } of volumes) {
48
+ const number = diskNumber(pvc);
49
+ if (number !== undefined) {
50
+ const key = `${storage}/${number}`;
51
+ pvcsByNumber.set(key, (pvcsByNumber.get(key) ?? new Set()).add(pvc));
52
+ }
53
+ }
54
+ const names = new Map();
55
+ for (const { storage, pvc } of volumes) {
56
+ const title = storage === 'secondary' ? text.secondaryTitle : text.primaryTitle;
57
+ const number = diskNumber(pvc);
58
+ const isUnique = number !== undefined &&
59
+ pvcsByNumber.get(`${storage}/${number}`)?.size === 1;
60
+ names.set(volumeKey(storage, pvc), {
61
+ row: isUnique ? text.diskLabel(number) : pvc,
62
+ line: isUnique
63
+ ? text.diskLineLabel(title, number)
64
+ : text.volumeLineLabel(title, pvc),
65
+ });
66
+ }
67
+ return names;
68
+ };
69
+ /**
70
+ * lineSummaries gives the first and the last value of each chart line, in
71
+ * time order.
72
+ */
73
+ const lineSummaries = (dataPoints, text) => {
74
+ const byLine = new Map();
75
+ for (const point of dataPoints) {
76
+ byLine.set(point.group, [...(byLine.get(point.group) ?? []), point]);
77
+ }
78
+ return [...byLine.entries()]
79
+ .sort(([a], [b]) => a.localeCompare(b))
80
+ .map(([line, points]) => {
81
+ const ordered = [...points].sort((a, b) => a.date.localeCompare(b.date));
82
+ return text.historyLineSummary(line, formatGibValue(ordered[0]?.value ?? 0, text, 2), formatGibValue(ordered.at(-1)?.value ?? 0, text, 2));
83
+ })
84
+ .join('. ');
85
+ };
86
+ const HistoryChart = ({ history, names, text, }) => {
87
+ const options = [
88
+ { id: '24h', label: text.range24h },
89
+ { id: '7d', label: text.range7d },
90
+ { id: '30d', label: text.range30d },
91
+ ];
92
+ const dataPoints = history.points.map((point) => ({
93
+ group: names.get(volumeKey(point.storage, point.pvc))?.line ?? point.pvc,
94
+ date: new Date(point.ts).toISOString(),
95
+ value: toGib(point.usedBytes),
96
+ }));
97
+ const is24h = history.range === '24h';
98
+ const pointsByLine = new Map();
99
+ for (const { group } of dataPoints) {
100
+ pointsByLine.set(group, (pointsByLine.get(group) ?? 0) + 1);
101
+ }
102
+ const hasShortLine = [...pointsByLine.values()].some((count) => count < 2);
103
+ return (_jsxs(Stack, { gap: 3, children: [_jsx("div", {
104
+ // The DS has no width prop for the segmented control: without a cap, it
105
+ // stretches over the whole card.
106
+ style: { maxWidth: '16rem' }, children: _jsx(C4SegmentedControl, { options: options, value: history.range, onChange: (id) => history.onRangeChange(id), ariaLabel: text.rangeLabel }) }), history.isLoading ? (_jsx(DsText, { role: 'status', children: text.loadingLabel })) : history.hasError ? (_jsx(DsText, { role: 'alert', children: text.historyErrorLabel })) : dataPoints.length === 0 ? (_jsx(DsText, { children: text.historyEmptyLabel })) : (_jsx("div", { role: 'img', "aria-label": lineSummaries(dataPoints, text), children: _jsx(DsLineChart, { dataPoints: dataPoints, axes: { titleLeft: '', titleBottom: '' }, height: 240,
107
+ // A line of one point has no stroke: the dot shows it.
108
+ dots: hasShortLine, tickFormatter: is24h ? formatHour(text.locale) : formatDay(text.locale), tooltipLabelFormatter: is24h ? formatDayHour(text.locale) : formatDay(text.locale), valueFormatter: (value) => formatGibValue(value, text, 2) }) })), _jsx(DsText, { variant: 'helper', children: text.historyCaption })] }));
109
+ };
110
+ /** From these used percentages, the bar turns amber and red (as in Control). */
111
+ const WARN_PERCENT = 75;
112
+ const FULL_PERCENT = 90;
113
+ const barColor = (percent, normal) => percent >= FULL_PERCENT
114
+ ? 'var(--danger-border-strong)'
115
+ : percent >= WARN_PERCENT
116
+ ? 'var(--warning-action-default)'
117
+ : normal;
118
+ /**
119
+ * The DS Progress has one fixed fill colour, so the state colour needs this
120
+ * bar. The inline styles hold the dynamic width and colour.
121
+ */
122
+ const UsageBar = ({ percent, color, label, valueLabel, }) => (
123
+ // biome-ignore lint/a11y/useSemanticElements: <meter> has no state colour
124
+ _jsx("div", { role: 'meter', "aria-label": label, "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": percent, "aria-valuetext": valueLabel,
125
+ // Dynamic track: the DS has no static class for it.
126
+ style: {
127
+ height: '0.625rem',
128
+ borderRadius: '999px',
129
+ overflow: 'hidden',
130
+ background: 'var(--primary-background-strong)',
131
+ }, children: _jsx("div", {
132
+ // Dynamic width and state colour: no DS class carries a runtime value.
133
+ style: {
134
+ width: `${percent}%`,
135
+ height: '100%',
136
+ borderRadius: '999px',
137
+ background: barColor(percent, color),
138
+ } }) }));
139
+ /**
140
+ * The colour of a chart line. It repeats the rule of `DsLineChart`: the line
141
+ * names sorted, then `getDsSeriesToken(index)`. A change there changes this.
142
+ */
143
+ const lineColors = (lines) => new Map([...new Set(lines)]
144
+ .sort()
145
+ .map((line, index) => [line, `var(--${getDsSeriesToken(index)})`]));
146
+ const VolumeList = ({ volumes, storage, names, colors, text, hasHistory, }) => (_jsx(Stack, { gap: 4, children: volumes.map((volume) => {
147
+ const percent = volume.limitBytes === undefined || volume.limitBytes <= 0
148
+ ? undefined
149
+ : Math.round((volume.usedBytes / volume.limitBytes) * 100);
150
+ const volumeName = names.get(volumeKey(storage, volume.pvc));
151
+ const name = volumeName?.row ?? volume.pvc;
152
+ const dot = volumeName === undefined ? undefined : colors.get(volumeName.line);
153
+ const status = percent === undefined || percent < WARN_PERCENT
154
+ ? undefined
155
+ : percent >= FULL_PERCENT
156
+ ? text.statusNearlyFull
157
+ : text.statusFillingUp;
158
+ const usage = percent === undefined || volume.limitBytes === undefined
159
+ ? text.usageNoLimitLabel(formatGib(volume.usedBytes, text))
160
+ : text.usageLabel(formatGib(volume.usedBytes, text), formatGib(volume.limitBytes, text), percent);
161
+ const label = status === undefined ? usage : text.usageStatusLabel(usage, status);
162
+ return (_jsxs(Stack, { gap: 2, children: [_jsxs("div", {
163
+ // The DS has no row layout with a name on the left, the usage on
164
+ // the right and wrapping when narrow.
165
+ style: {
166
+ display: 'flex',
167
+ justifyContent: 'space-between',
168
+ alignItems: 'center',
169
+ gap: '0.75rem',
170
+ flexWrap: 'wrap',
171
+ }, children: [_jsxs("span", {
172
+ // The DS has no inline layout to align the dot with the name.
173
+ style: {
174
+ display: 'inline-flex',
175
+ alignItems: 'center',
176
+ gap: '0.5rem',
177
+ }, children: [dot === undefined ? undefined : (_jsx("span", { "aria-hidden": true,
178
+ // The dot has the colour of the line in the chart.
179
+ style: {
180
+ width: '0.625rem',
181
+ height: '0.625rem',
182
+ borderRadius: '999px',
183
+ background: dot,
184
+ } })), _jsx(DsText, { children: name })] }), _jsx("span", {
185
+ // The DS has no tabular figures: percents line up in rows.
186
+ style: {
187
+ fontVariantNumeric: 'tabular-nums',
188
+ fontWeight: 600,
189
+ }, children: _jsx(DsText, { children: label }) })] }), status === undefined || !hasHistory ? undefined : (_jsx(DsText, { variant: 'helper', children: text.growthHint })), percent === undefined ? undefined : (_jsx(UsageBar, { percent: Math.min(percent, 100), color: dot ?? 'var(--chart-sky)', label: name, valueLabel: label }))] }, `${storage}-${volume.pvc}`));
190
+ }) }));
191
+ export const C4ClusterDiskUsage = ({ secondary, primary, isLoading, hasError, history, text, }) => {
192
+ const names = volumeNames([
193
+ ...primary.map(({ pvc }) => ({ storage: 'primary', pvc })),
194
+ ...secondary.map(({ pvc }) => ({ storage: 'secondary', pvc })),
195
+ ...(history?.points ?? []),
196
+ ], text);
197
+ const colors = lineColors((history?.points ?? []).flatMap(({ storage, pvc }) => names.get(volumeKey(storage, pvc))?.line ?? []));
198
+ const card = (title, storage, volumes) => (_jsx(DsCard, { children: _jsx("section", { "aria-label": title,
199
+ // The card has no horizontal padding of its own.
200
+ style: { padding: '0 1rem' }, children: _jsxs(Stack, { gap: 4, children: [_jsx(DsHeading, { as: 'h3', variant: 'heading-xs', children: title }), isLoading ? (_jsx(DsText, { role: 'status', children: text.loadingLabel })) : hasError ? (_jsx(DsText, { role: 'alert', children: text.errorLabel })) : volumes.length === 0 ? (_jsx(DsText, { children: text.emptyLabel })) : (_jsx(VolumeList, { volumes: volumes, storage: storage, names: names, colors: colors, text: text, hasHistory: history !== undefined }))] }) }) }));
201
+ return (_jsxs(Stack, { gap: 5, children: [_jsxs(Stack, { gap: 2, children: [_jsx(DsHeading, { as: 'h2', variant: 'heading-sm', children: text.title }), _jsx(DsText, { variant: 'body-subtle', children: text.subtitle })] }), _jsxs("div", {
202
+ // The DS has no responsive grid: two cards side by side, or one when
203
+ // narrow.
204
+ style: {
205
+ display: 'grid',
206
+ gridTemplateColumns: 'repeat(auto-fit, minmax(min(20rem, 100%), 1fr))',
207
+ gap: '1rem',
208
+ }, children: [card(text.primaryTitle, 'primary', primary), card(text.secondaryTitle, 'secondary', secondary)] }), history ? (_jsx("section", { "aria-label": text.historyTitle, children: _jsxs(Stack, { gap: 3, children: [_jsx(DsHeading, { as: 'h3', variant: 'heading-xs', children: text.historyTitle }), _jsx(HistoryChart, { history: history, names: names, text: text })] }) })) : undefined] }));
209
+ };
@@ -0,0 +1,76 @@
1
+ export interface C4ClusterDiskVolumeItem {
2
+ pvc: string;
3
+ usedBytes: number;
4
+ /** Absent when no limit is known for the volume. */
5
+ limitBytes?: number;
6
+ }
7
+ export type C4DiskHistoryRange = '24h' | '7d' | '30d';
8
+ export interface C4DiskHistoryPoint {
9
+ /** The storage of the volume. It names the line of the chart. */
10
+ storage: 'secondary' | 'primary';
11
+ /** The volume (PVC), one line of the chart. */
12
+ pvc: string;
13
+ /** Start of the hour or of the UTC day, in milliseconds. */
14
+ ts: number;
15
+ usedBytes: number;
16
+ }
17
+ export interface C4ClusterDiskHistory {
18
+ range: C4DiskHistoryRange;
19
+ onRangeChange: (range: C4DiskHistoryRange) => void;
20
+ points: C4DiskHistoryPoint[];
21
+ isLoading: boolean;
22
+ hasError: boolean;
23
+ }
24
+ export interface C4ClusterDiskUsageProps {
25
+ secondary: C4ClusterDiskVolumeItem[];
26
+ primary: C4ClusterDiskVolumeItem[];
27
+ isLoading: boolean;
28
+ hasError: boolean;
29
+ /** The trend over time. Without it, the card shows the newest reading. */
30
+ history?: C4ClusterDiskHistory;
31
+ text: {
32
+ /** The locale of the numbers and dates, for example "en-US". */
33
+ locale: string;
34
+ /** A size with its unit. Receives the formatted number: "6.5 GiB". */
35
+ sizeLabel: (amount: string) => string;
36
+ /** The line name of a volume with no number, e.g. "Primary, data". */
37
+ volumeLineLabel: (storage: string, pvc: string) => string;
38
+ title: string;
39
+ subtitle: string;
40
+ secondaryTitle: string;
41
+ primaryTitle: string;
42
+ emptyLabel: string;
43
+ errorLabel: string;
44
+ loadingLabel: string;
45
+ /** For example "6 GiB of 64 GiB (9%)". Receives the formatted values. */
46
+ usageLabel: (used: string, limit: string, percent: number) => string;
47
+ /** For example "6 GiB, limit unavailable". */
48
+ usageNoLimitLabel: (used: string) => string;
49
+ /** The short name of a volume in the list, for example "Disk 1". */
50
+ diskLabel: (disk: number) => string;
51
+ /** The line name of a volume, for example "Primary storage, disk 1". */
52
+ diskLineLabel: (storage: string, disk: number) => string;
53
+ /** The state word of a volume at 75% or more, for example "filling up". */
54
+ statusFillingUp: string;
55
+ /** The state word of a volume at 90% or more, for example "nearly full". */
56
+ statusNearlyFull: string;
57
+ /** The hint under a volume at 75% or more. */
58
+ growthHint: string;
59
+ /**
60
+ * The usage with its state word, for example "6 GiB of 64 GiB (9%),
61
+ * filling up".
62
+ */
63
+ usageStatusLabel: (usage: string, status: string) => string;
64
+ historyTitle: string;
65
+ /** For example "Each line is one volume, in GiB." */
66
+ historyCaption: string;
67
+ /** The text of one chart line, for example "Disk 1: 12 GiB to 12.6 GiB". */
68
+ historyLineSummary: (line: string, from: string, to: string) => string;
69
+ historyEmptyLabel: string;
70
+ historyErrorLabel: string;
71
+ rangeLabel: string;
72
+ range24h: string;
73
+ range7d: string;
74
+ range30d: string;
75
+ };
76
+ }
@@ -0,0 +1,6 @@
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
+ export {};
@@ -21,6 +21,14 @@ export interface DsLineChartProps {
21
21
  zoomBar?: {
22
22
  enabled: boolean;
23
23
  };
24
+ /** Label of an x tick. Defaults to the short month and day. */
25
+ tickFormatter?: (value: unknown) => string;
26
+ /** Label of the tooltip. Defaults to `tickFormatter` when that is given. */
27
+ tooltipLabelFormatter?: (value: unknown) => string;
28
+ /** Value in the tooltip, for example with a unit. Defaults to the number. */
29
+ valueFormatter?: (value: number) => string;
30
+ /** Draw a dot at each point. Needed to see a line of one point. */
31
+ dots?: boolean;
24
32
  }
25
33
  /**
26
34
  * Line chart, rendered with the `@camunda/design-system` `LineChart`.
@@ -28,4 +36,4 @@ export interface DsLineChartProps {
28
36
  * zoom/brush or axis-title API, so the `zoomBar`/`axes` props are accepted
29
37
  * to keep call sites unchanged, but only the chart title is shown.
30
38
  */
31
- export declare function DsLineChart({ title, dataPoints, thresholds, height, }: DsLineChartProps): JSX.Element;
39
+ export declare function DsLineChart({ title, dataPoints, thresholds, height, tickFormatter, tooltipLabelFormatter, valueFormatter, dots, }: DsLineChartProps): JSX.Element;
@@ -47,7 +47,7 @@ function pivotByDate(dataPoints) {
47
47
  * zoom/brush or axis-title API, so the `zoomBar`/`axes` props are accepted
48
48
  * to keep call sites unchanged, but only the chart title is shown.
49
49
  */
50
- export function DsLineChart({ title, dataPoints, thresholds, height = 400, }) {
50
+ export function DsLineChart({ title, dataPoints, thresholds, height = 400, tickFormatter, tooltipLabelFormatter, valueFormatter, dots, }) {
51
51
  const { rows, keyByGroup } = useMemo(() => pivotByDate(dataPoints), [dataPoints]);
52
52
  // Iterate the map, so that every config key is a key the map produced.
53
53
  const config = useMemo(() => Object.fromEntries([...keyByGroup].map(([group, seriesKey], index) => [
@@ -63,5 +63,5 @@ export function DsLineChart({ title, dataPoints, thresholds, height = 400, }) {
63
63
  fontSize: 14,
64
64
  marginBottom: 8,
65
65
  color: 'var(--neutral-foreground-strong)',
66
- }, children: title })), _jsx("div", { style: { height }, children: _jsx(LineChart, { className: 'h-full w-full', data: rows, categoryKey: 'date', config: config, curve: 'monotone', connectNulls: true, referenceLines: referenceLines, tickFormatter: formatDate }) })] }));
66
+ }, children: title })), _jsx("div", { style: { height }, children: _jsx(LineChart, { className: 'h-full w-full', data: rows, categoryKey: 'date', config: config, curve: 'monotone', connectNulls: true, referenceLines: referenceLines, dots: dots, tickFormatter: tickFormatter ?? formatDate, tooltipLabelFormatter: tooltipLabelFormatter ?? tickFormatter, valueFormatter: valueFormatter }) })] }));
67
67
  }
@@ -851,5 +851,34 @@
851
851
  "reopenTransferButton": "Reopen transfer",
852
852
  "progressText": "This cluster has no actions until the migration ends. To cancel the migration, delete the cluster.",
853
853
  "deleteButton": "Delete cluster"
854
+ },
855
+ "diskUsage": {
856
+ "locale": "en-US",
857
+ "size": "{{amount}} GiB",
858
+ "volumeLine": "{{storage}}, {{pvc}}",
859
+ "title": "Disk usage",
860
+ "subtitle": "The newest reading of each volume, against its storage limit.",
861
+ "secondaryTitle": "Secondary storage",
862
+ "primaryTitle": "Primary storage",
863
+ "empty": "No data yet",
864
+ "error": "Couldn't load disk usage. Reload the page to try again.",
865
+ "loading": "Loading…",
866
+ "usage": "{{used}} of {{limit}} ({{percent}}%)",
867
+ "usageNoLimit": "{{used}}, limit unavailable",
868
+ "disk": "Disk {{disk}}",
869
+ "diskLine": "{{storage}}, disk {{disk}}",
870
+ "statusFillingUp": "filling up",
871
+ "statusNearlyFull": "nearly full",
872
+ "growthHint": "Check how fast it grows in the history below.",
873
+ "usageStatus": "{{usage}}, {{status}}",
874
+ "historyTitle": "Over time",
875
+ "historyCaption": "Each line is one volume, in GiB.",
876
+ "historyLineSummary": "{{line}}: {{from}} to {{to}}",
877
+ "historyEmpty": "No history yet",
878
+ "historyError": "Couldn't load the history. Reload the page to try again.",
879
+ "rangeLabel": "Time range",
880
+ "range24h": "24 hours",
881
+ "range7d": "7 days",
882
+ "range30d": "30 days"
854
883
  }
855
884
  }
@@ -54,6 +54,8 @@ export { C4ClusterDetailsIpWhitelist } from './components/c4-cluster-details-ip-
54
54
  export type { C4ClusterDetailsIpWhitelistProps, IpWhitelistItem, } from './components/c4-cluster-details-ip-whitelist/c4-cluster-details-ip-whitelist.types.js';
55
55
  export { C4ClusterDetailsSecureConnectivity } from './components/c4-cluster-details-secure-connectivity/c4-cluster-details-secure-connectivity.js';
56
56
  export type { C4ClusterDetailsSecureConnectivityProps, C4ClusterDetailsSecureConnectivityStatus, C4SecureConnectivityPrivateEndpoint, } from './components/c4-cluster-details-secure-connectivity/c4-cluster-details-secure-connectivity.types.js';
57
+ export { C4ClusterDiskUsage } from './components/c4-cluster-disk-usage/c4-cluster-disk-usage.js';
58
+ export type { C4ClusterDiskHistory, C4ClusterDiskUsageProps, C4ClusterDiskVolumeItem, C4DiskHistoryPoint, C4DiskHistoryRange, } from './components/c4-cluster-disk-usage/c4-cluster-disk-usage.types.js';
57
59
  export { C4ClusterExpiryTag } from './components/c4-cluster-list/c4-cluster-expiry-tag.js';
58
60
  export { C4ClusterList } from './components/c4-cluster-list/c4-cluster-list.js';
59
61
  export type { C4ClusterListProps, ClusterListItem, ClusterListNotification, ClusterListPermissions, ClusterListUrls, } from './components/c4-cluster-list/c4-cluster-list.types.js';
package/lib/esm/index.js CHANGED
@@ -30,6 +30,7 @@ export { C4ClusterDetailsHotBackups } from './components/c4-cluster-details-hot-
30
30
  export { C4ClusterDetailsHotBackupsRestore } from './components/c4-cluster-details-hot-backups-restore/c4-cluster-details-hot-backups-restore.js';
31
31
  export { C4ClusterDetailsIpWhitelist } from './components/c4-cluster-details-ip-whitelist/c4-cluster-details-ip-whitelist.js';
32
32
  export { C4ClusterDetailsSecureConnectivity } from './components/c4-cluster-details-secure-connectivity/c4-cluster-details-secure-connectivity.js';
33
+ export { C4ClusterDiskUsage } from './components/c4-cluster-disk-usage/c4-cluster-disk-usage.js';
33
34
  export { C4ClusterExpiryTag } from './components/c4-cluster-list/c4-cluster-expiry-tag.js';
34
35
  export { C4ClusterList } from './components/c4-cluster-list/c4-cluster-list.js';
35
36
  export { DEFAULT_CLUSTER_EXPIRY_TAG_COPY, getClusterExpiryRemaining, getClusterExpiryTag, } from './components/c4-cluster-list/cluster-expiry-tag.js';
@@ -0,0 +1,37 @@
1
+ import type { RequestBaseParamsConfig } from '@camunda/ccma-api';
2
+ import type { HdpDiskVolume } from '@camunda/ccma-shared-types';
3
+ export type ClusterDiskHistoryRange = '24h' | '7d' | '30d';
4
+ export interface ClusterDiskHistoryPoint {
5
+ /** The storage that the volume belongs to. */
6
+ storage: 'secondary' | 'primary';
7
+ /** The volume (PVC) that the reading belongs to. */
8
+ pvc: string;
9
+ /** Start of the hour (24h) or of the UTC day (7d, 30d), in milliseconds. */
10
+ ts: number;
11
+ /** The used bytes of the volume. */
12
+ usedBytes: number;
13
+ }
14
+ export interface ClusterDiskHistory {
15
+ points: ClusterDiskHistoryPoint[];
16
+ isLoading: boolean;
17
+ /** True when a read failed. Then `points` is empty. */
18
+ hasError: boolean;
19
+ }
20
+ /**
21
+ * keepRange drops the rows outside the window of the range. HDP gives 30 days
22
+ * for `per-day`, so the 7d view cuts by timestamp: a missed day must not widen
23
+ * the window.
24
+ */
25
+ export declare const keepRange: (points: HdpDiskVolume[], range: ClusterDiskHistoryRange, now: number) => HdpDiskVolume[];
26
+ /**
27
+ * useClusterDiskHistory reads the used bytes of each volume of the secondary
28
+ * and the primary storage over a range: hourly for `24h`, daily for
29
+ * `7d` and `30d`. With `enabled` false it reads nothing.
30
+ */
31
+ export declare const useClusterDiskHistory: (options: {
32
+ config: RequestBaseParamsConfig;
33
+ orgId: string;
34
+ clusterId: string;
35
+ range: ClusterDiskHistoryRange;
36
+ enabled: boolean;
37
+ }) => ClusterDiskHistory;
@@ -0,0 +1,64 @@
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 { HdpService } from '@camunda/ccma-api';
7
+ import { useEffect, useState } from 'react';
8
+ const DISKS = ['elasticsearch', 'zeebe'];
9
+ const DAY_MS = 24 * 60 * 60 * 1000;
10
+ /**
11
+ * keepRange drops the rows outside the window of the range. HDP gives 30 days
12
+ * for `per-day`, so the 7d view cuts by timestamp: a missed day must not widen
13
+ * the window.
14
+ */
15
+ export const keepRange = (points, range, now) => range === '7d'
16
+ ? points.filter((point) => point.ts >= now - 7 * DAY_MS)
17
+ : points;
18
+ /**
19
+ * useClusterDiskHistory reads the used bytes of each volume of the secondary
20
+ * and the primary storage over a range: hourly for `24h`, daily for
21
+ * `7d` and `30d`. With `enabled` false it reads nothing.
22
+ */
23
+ export const useClusterDiskHistory = (options) => {
24
+ const { config, orgId, clusterId, range, enabled } = options;
25
+ const [state, setState] = useState({
26
+ points: [],
27
+ // True from the start: a flag that arrives after mount reads as loading
28
+ // in its first render, not as "no data". Disabled hides it below.
29
+ isLoading: true,
30
+ hasError: false,
31
+ });
32
+ useEffect(() => {
33
+ if (!enabled) {
34
+ return;
35
+ }
36
+ let cancelled = false;
37
+ setState({ points: [], isLoading: true, hasError: false });
38
+ const operation = range === '24h' ? 'volumes-24h' : 'volumes-per-day';
39
+ Promise.all(DISKS.map(async (disk) => {
40
+ const rows = await HdpService.getClusterDiskVolumes({
41
+ config,
42
+ params: { orgId, clusterId, disk, operation },
43
+ });
44
+ return keepRange(rows, range, Date.now()).map((row) => ({
45
+ storage: disk === 'elasticsearch' ? 'secondary' : 'primary',
46
+ pvc: row.pvc,
47
+ ts: row.ts,
48
+ usedBytes: row.usedBytes,
49
+ }));
50
+ })).then((series) => {
51
+ if (!cancelled) {
52
+ setState({ points: series.flat(), isLoading: false, hasError: false });
53
+ }
54
+ }, () => {
55
+ if (!cancelled) {
56
+ setState({ points: [], isLoading: false, hasError: true });
57
+ }
58
+ });
59
+ return () => {
60
+ cancelled = true;
61
+ };
62
+ }, [config, orgId, clusterId, range, enabled]);
63
+ return { ...state, isLoading: enabled && state.isLoading };
64
+ };
@@ -0,0 +1,24 @@
1
+ import type { RequestBaseParamsConfig } from '@camunda/ccma-api';
2
+ import type { HdpDiskVolume } from '@camunda/ccma-shared-types';
3
+ /** The flag that shows the disk usage of a cluster to customers. */
4
+ export declare const CLUSTER_DISK_USAGE_FLAG = "console.showDiskUsageToCustomers";
5
+ export interface ClusterDiskVolumes {
6
+ /** The volumes of the secondary storage (Elasticsearch). */
7
+ secondary: HdpDiskVolume[];
8
+ /** The volumes of the primary storage (Zeebe). */
9
+ primary: HdpDiskVolume[];
10
+ isLoading: boolean;
11
+ /** True when a read failed. Then the lists can be empty. */
12
+ hasError: boolean;
13
+ }
14
+ /**
15
+ * useClusterDiskVolumes reads each volume of the secondary and the primary
16
+ * storage of a cluster in the newest hour of HDP. With `enabled` false it
17
+ * reads nothing.
18
+ */
19
+ export declare const useClusterDiskVolumes: (options: {
20
+ config: RequestBaseParamsConfig;
21
+ orgId: string;
22
+ clusterId: string;
23
+ enabled: boolean;
24
+ }) => ClusterDiskVolumes;
@@ -0,0 +1,58 @@
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 { HdpService } from '@camunda/ccma-api';
7
+ import { useEffect, useState } from 'react';
8
+ /** The flag that shows the disk usage of a cluster to customers. */
9
+ export const CLUSTER_DISK_USAGE_FLAG = 'console.showDiskUsageToCustomers';
10
+ const DISKS = {
11
+ secondary: 'elasticsearch',
12
+ primary: 'zeebe',
13
+ };
14
+ /**
15
+ * useClusterDiskVolumes reads each volume of the secondary and the primary
16
+ * storage of a cluster in the newest hour of HDP. With `enabled` false it
17
+ * reads nothing.
18
+ */
19
+ export const useClusterDiskVolumes = (options) => {
20
+ const { config, orgId, clusterId, enabled } = options;
21
+ const [state, setState] = useState({
22
+ secondary: [],
23
+ primary: [],
24
+ // True from the start: a flag that arrives after mount reads as loading
25
+ // in its first render, not as "no data". Disabled hides it below.
26
+ isLoading: true,
27
+ hasError: false,
28
+ });
29
+ useEffect(() => {
30
+ if (!enabled) {
31
+ return;
32
+ }
33
+ let cancelled = false;
34
+ setState({ secondary: [], primary: [], isLoading: true, hasError: false });
35
+ const read = (disk) => HdpService.getClusterDiskVolumes({
36
+ config,
37
+ params: { orgId, clusterId, disk },
38
+ });
39
+ Promise.all([read(DISKS.secondary), read(DISKS.primary)]).then(([secondary, primary]) => {
40
+ if (!cancelled) {
41
+ setState({ secondary, primary, isLoading: false, hasError: false });
42
+ }
43
+ }, () => {
44
+ if (!cancelled) {
45
+ setState({
46
+ secondary: [],
47
+ primary: [],
48
+ isLoading: false,
49
+ hasError: true,
50
+ });
51
+ }
52
+ });
53
+ return () => {
54
+ cancelled = true;
55
+ };
56
+ }, [config, orgId, clusterId, enabled]);
57
+ return { ...state, isLoading: enabled && state.isLoading };
58
+ };
@@ -9,6 +9,7 @@ import { useC4ConsoleRuntime } from '../../../runtime/c4-console-runtime-context
9
9
  import { useCliExtrasApi } from '../../../runtime/use-cli-extras-api.js';
10
10
  import { Button, CodeSnippet, DsBadge, DsCard, DsCodeBlock, DsText, Modal, Stack, TextInput, } from '../../../ui/index.js';
11
11
  import { safeTranslate } from '../../../utils/safe-translate.js';
12
+ import { C4ClusterDetailsDiskUsageSection } from './c4-cluster-details-disk-usage-section.js';
12
13
  function asByomStatusLike(value) {
13
14
  if (!value || typeof value !== 'object')
14
15
  return undefined;
@@ -252,7 +253,7 @@ export const C4ClusterDetailsByomClientsTab = (props) => {
252
253
  kind: 'openUrl',
253
254
  url: props.docLink,
254
255
  });
255
- } })), _jsx(Modal, { open: byomCreateOpen, size: 'sm', modalHeading: byomActivateOnSubmit
256
+ } })), _jsx(C4ClusterDetailsDiskUsageSection, { orgId: orgId, clusterId: clusterId, apiConfig: apiConfig, t: t }), _jsx(Modal, { open: byomCreateOpen, size: 'sm', modalHeading: byomActivateOnSubmit
256
257
  ? safeTranslate(t, 'byomClients:create.title', 'Activate monitoring endpoint')
257
258
  : safeTranslate(t, 'byomClients:create.title', 'Create new credentials'), primaryButtonText: byomActivateOnSubmit
258
259
  ? safeTranslate(t, 'byomClients:create.activate', 'Activate')
@@ -0,0 +1,17 @@
1
+ import type { RequestBaseParamsConfig } from '@camunda/ccma-api';
2
+ import type { JSX } from 'react';
3
+ type TranslateFn = (key: string, options?: Record<string, unknown>) => string;
4
+ export interface C4ClusterDetailsDiskUsageSectionProps {
5
+ orgId: string;
6
+ clusterId: string;
7
+ apiConfig: RequestBaseParamsConfig;
8
+ t: TranslateFn | undefined;
9
+ }
10
+ /**
11
+ * The disk usage of the volumes of a cluster, behind the flag
12
+ * `console.showDiskUsageToCustomers`. With the flag off, it renders nothing
13
+ * and sends no request. The component draws one card for each storage, so
14
+ * this section adds no card.
15
+ */
16
+ export declare const C4ClusterDetailsDiskUsageSection: ({ orgId, clusterId, apiConfig, t, }: C4ClusterDetailsDiskUsageSectionProps) => JSX.Element | undefined;
17
+ export {};
@@ -0,0 +1,72 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { C4ClusterDiskUsage } from '../../../components/c4-cluster-disk-usage/c4-cluster-disk-usage.js';
4
+ import { useC4FeatureFlag } from '../../../runtime/c4-console-runtime-context.js';
5
+ import { useClusterDiskHistory, } from '../../../runtime/use-cluster-disk-history.js';
6
+ import { CLUSTER_DISK_USAGE_FLAG, useClusterDiskVolumes, } from '../../../runtime/use-cluster-disk-volumes.js';
7
+ import { safeTranslate } from '../../../utils/safe-translate.js';
8
+ /**
9
+ * The disk usage of the volumes of a cluster, behind the flag
10
+ * `console.showDiskUsageToCustomers`. With the flag off, it renders nothing
11
+ * and sends no request. The component draws one card for each storage, so
12
+ * this section adds no card.
13
+ */
14
+ export const C4ClusterDetailsDiskUsageSection = ({ orgId, clusterId, apiConfig, t, }) => {
15
+ const showDiskUsage = useC4FeatureFlag(CLUSTER_DISK_USAGE_FLAG);
16
+ const diskVolumes = useClusterDiskVolumes({
17
+ config: apiConfig,
18
+ orgId,
19
+ clusterId,
20
+ enabled: showDiskUsage,
21
+ });
22
+ const [diskRange, setDiskRange] = useState('24h');
23
+ const diskHistory = useClusterDiskHistory({
24
+ config: apiConfig,
25
+ orgId,
26
+ clusterId,
27
+ range: diskRange,
28
+ enabled: showDiskUsage,
29
+ });
30
+ if (!showDiskUsage) {
31
+ return undefined;
32
+ }
33
+ return (_jsx(C4ClusterDiskUsage, { secondary: diskVolumes.secondary, primary: diskVolumes.primary, isLoading: diskVolumes.isLoading, hasError: diskVolumes.hasError, history: {
34
+ range: diskRange,
35
+ onRangeChange: setDiskRange,
36
+ points: diskHistory.points,
37
+ isLoading: diskHistory.isLoading,
38
+ hasError: diskHistory.hasError,
39
+ }, text: {
40
+ title: safeTranslate(t, 'clusterdetails:diskUsage.title', 'Disk usage'),
41
+ subtitle: safeTranslate(t, 'clusterdetails:diskUsage.subtitle', 'The newest reading of each volume, against its storage limit.'),
42
+ secondaryTitle: safeTranslate(t, 'clusterdetails:diskUsage.secondaryTitle', 'Secondary storage'),
43
+ primaryTitle: safeTranslate(t, 'clusterdetails:diskUsage.primaryTitle', 'Primary storage'),
44
+ emptyLabel: safeTranslate(t, 'clusterdetails:diskUsage.empty', 'No data yet'),
45
+ errorLabel: safeTranslate(t, 'clusterdetails:diskUsage.error', "Couldn't load disk usage. Reload the page to try again."),
46
+ loadingLabel: safeTranslate(t, 'clusterdetails:diskUsage.loading', 'Loading…'),
47
+ historyTitle: safeTranslate(t, 'clusterdetails:diskUsage.historyTitle', 'Over time'),
48
+ historyCaption: safeTranslate(t, 'clusterdetails:diskUsage.historyCaption', 'Each line is one volume, in GiB.'),
49
+ historyEmptyLabel: safeTranslate(t, 'clusterdetails:diskUsage.historyEmpty', 'No history yet'),
50
+ historyErrorLabel: safeTranslate(t, 'clusterdetails:diskUsage.historyError', "Couldn't load the history. Reload the page to try again."),
51
+ rangeLabel: safeTranslate(t, 'clusterdetails:diskUsage.rangeLabel', 'Time range'),
52
+ range24h: safeTranslate(t, 'clusterdetails:diskUsage.range24h', '24 hours'),
53
+ range7d: safeTranslate(t, 'clusterdetails:diskUsage.range7d', '7 days'),
54
+ range30d: safeTranslate(t, 'clusterdetails:diskUsage.range30d', '30 days'),
55
+ locale: safeTranslate(t, 'clusterdetails:diskUsage.locale', 'en-US'),
56
+ sizeLabel: (amount) => safeTranslate(t, 'clusterdetails:diskUsage.size', `${amount} GiB`, {
57
+ amount,
58
+ }),
59
+ volumeLineLabel: (storage, pvc) => safeTranslate(t, 'clusterdetails:diskUsage.volumeLine', `${storage}, ${pvc}`, { storage, pvc }),
60
+ usageLabel: (used, limit, percent) => safeTranslate(t, 'clusterdetails:diskUsage.usage', `${used} of ${limit} (${percent}%)`, { used, limit, percent }),
61
+ diskLabel: (disk) => safeTranslate(t, 'clusterdetails:diskUsage.disk', `Disk ${disk}`, {
62
+ disk,
63
+ }),
64
+ diskLineLabel: (storage, disk) => safeTranslate(t, 'clusterdetails:diskUsage.diskLine', `${storage}, disk ${disk}`, { storage, disk }),
65
+ statusFillingUp: safeTranslate(t, 'clusterdetails:diskUsage.statusFillingUp', 'filling up'),
66
+ statusNearlyFull: safeTranslate(t, 'clusterdetails:diskUsage.statusNearlyFull', 'nearly full'),
67
+ growthHint: safeTranslate(t, 'clusterdetails:diskUsage.growthHint', 'Check how fast it grows in the history below.'),
68
+ usageStatusLabel: (usage, status) => safeTranslate(t, 'clusterdetails:diskUsage.usageStatus', `${usage}, ${status}`, { usage, status }),
69
+ historyLineSummary: (line, from, to) => safeTranslate(t, 'clusterdetails:diskUsage.historyLineSummary', `${line}: ${from} to ${to}`, { line, from, to }),
70
+ usageNoLimitLabel: (used) => safeTranslate(t, 'clusterdetails:diskUsage.usageNoLimit', `${used}, limit unavailable`, { used }),
71
+ } }));
72
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camunda/ccma-saas-frontend",
3
- "version": "0.40.0",
3
+ "version": "0.41.0",
4
4
  "description": "Camunda Composite Components",
5
5
  "bugs": {
6
6
  "url": "https://github.com/camunda/camunda-cloud-management-apps/issues"
@@ -85,8 +85,8 @@
85
85
  "react-markdown": "^8.0.7 || ^10.0.0"
86
86
  },
87
87
  "dependencies": {
88
- "@camunda/ccma-api": "14.2.0",
89
- "@camunda/ccma-shared-types": "18.15.0",
88
+ "@camunda/ccma-api": "14.4.0",
89
+ "@camunda/ccma-shared-types": "19.1.0",
90
90
  "@pactsafe/pactsafe-react-sdk": "2.15.0",
91
91
  "cron-parser": "5.10.6",
92
92
  "mobx": "6.16.1",