@camunda/ccma-saas-frontend 0.3.1 → 0.4.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.
- package/lib/esm/components/c4-activity-graph/c4-activity-graph.d.ts +2 -2
- package/lib/esm/components/c4-activity-graph/c4-activity-graph.js +90 -73
- package/lib/esm/components/c4-advanced-search-filters/c4-advanced-search-filters.js +13 -13
- package/lib/esm/components/c4-billing-page/elements/current-usage-metrics.js +7 -1
- package/lib/esm/components/c4-charts-dashboard/c4-charts-dashboard.d.ts +1 -1
- package/lib/esm/components/c4-charts-dashboard/c4-charts-dashboard.js +31 -25
- package/lib/esm/components/c4-cluster-details-activity/c4-cluster-details-activity.js +11 -8
- package/lib/esm/components/c4-cluster-details-clients/c4-cluster-details-clients.d.ts +1 -1
- package/lib/esm/components/c4-cluster-details-clients/c4-cluster-details-clients.js +21 -20
- package/lib/esm/components/c4-cluster-details-secure-connectivity/c4-cluster-details-secure-connectivity.js +10 -2
- package/lib/esm/components/c4-cluster-overview/applications.js +7 -1
- package/lib/esm/components/c4-cluster-tag-selector/c4-cluster-tag-selector.js +7 -1
- package/lib/esm/components/c4-data-table/c4-data-table.js +58 -4
- package/lib/esm/components/c4-data-table/c4-data-table.spec.js +52 -1
- package/lib/esm/components/c4-management-activity/c4-management-activity.d.ts +1 -1
- package/lib/esm/components/c4-management-activity/c4-management-activity.js +9 -4
- package/lib/esm/components/c4-management-settings/c4-management-settings.d.ts +1 -1
- package/lib/esm/components/c4-management-settings/c4-management-settings.js +9 -5
- package/lib/esm/components/c4-stackdriver-links/c4-stackdriver-links.js +3 -4
- package/lib/esm/components/c4-usage-history/c4-usage-history.d.ts +1 -1
- package/lib/esm/components/c4-usage-history/c4-usage-history.js +5 -2
- package/lib/esm/components/c4-usage-history/elements/usage-history-charts.d.ts +2 -2
- package/lib/esm/components/c4-usage-history/elements/usage-history-charts.js +6 -2
- package/lib/esm/components/c4-usage-metrics-per-cluster/c4-usage-metrics-per-cluster.d.ts +1 -1
- package/lib/esm/components/c4-usage-metrics-per-cluster/c4-usage-metrics-per-cluster.js +14 -8
- package/lib/esm/runtime/c4-console-data-context.d.ts +17 -5
- package/lib/esm/runtime/c4-console-data-context.js +40 -15
- package/lib/esm/runtime/c4-console-data-context.spec.d.ts +1 -0
- package/lib/esm/runtime/c4-console-data-context.spec.js +354 -0
- package/lib/esm/runtime/c4-console-data-context.types.d.ts +6 -0
- package/lib/esm/runtime/c4-console-data-store.d.ts +11 -0
- package/lib/esm/runtime/c4-console-data-store.js +74 -34
- package/lib/esm/runtime/c4-console-data-store.nav.spec.js +1 -0
- package/lib/esm/runtime/c4-console-data-store.spec.js +147 -1
- package/lib/esm/runtime/c4-user-notifications-context.spec.js +2 -0
- package/lib/esm/runtime/nav/use-webapp-nav-data.js +11 -3
- package/lib/esm/runtime/to-api-config.d.ts +1 -1
- package/lib/esm/runtime/to-api-config.js +6 -0
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-connector-secrets-tab.d.ts +3 -1
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-connector-secrets-tab.js +6 -1
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-hot-backups-tab.d.ts +3 -1
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-hot-backups-tab.js +5 -1
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-overview-tab.d.ts +3 -1
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-overview-tab.js +5 -1
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-secure-connectivity-tab.d.ts +3 -1
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-secure-connectivity-tab.js +5 -1
- package/lib/esm/widgets/clusters/c4-clusters-page.spec.js +1 -1
- package/lib/esm/widgets/connector-management/c4-connector-management.shared.js +12 -3
- package/lib/esm/widgets/dashboard/c4-dashboard-app.js +24 -6
- package/package.json +7 -4
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
|
|
4
|
+
* under one or more contributor license agreements. Licensed under a commercial license.
|
|
5
|
+
* You may not use this file except in compliance with the commercial license.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Characterization tests for the C4 console data layer.
|
|
9
|
+
*
|
|
10
|
+
* These pin the *observable contract* of `C4ConsoleDataProvider` /
|
|
11
|
+
* `useC4ConsoleData` — the public API surface, that reads return the right
|
|
12
|
+
* data, that consumers update when their data changes (fetch resolves, SSE
|
|
13
|
+
* patches the cache), request dedup, error surfacing, and initialState seeding.
|
|
14
|
+
*
|
|
15
|
+
* They intentionally do NOT assert render counts or that a consumer re-renders
|
|
16
|
+
* on *unrelated* changes: reducing that over-rendering is a planned improvement,
|
|
17
|
+
* so pinning it here would be counter-productive. The goal is that everything
|
|
18
|
+
* below stays green across a reactivity refactor of the provider.
|
|
19
|
+
*/
|
|
20
|
+
import { SseEntity, SseType } from '@camunda/ccma-shared-types';
|
|
21
|
+
import { act, render, renderHook, screen, waitFor, } from '@testing-library/react';
|
|
22
|
+
import { observer } from 'mobx-react-lite';
|
|
23
|
+
import { useEffect } from 'react';
|
|
24
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
25
|
+
import { C4ConsoleDataProvider, useC4ConsoleData, } from './c4-console-data-context.js';
|
|
26
|
+
import { C4ConsoleRuntimeProvider } from './c4-console-runtime-context.js';
|
|
27
|
+
vi.mock('@camunda/ccma-api', () => ({
|
|
28
|
+
AuditLoggerService: { getAudit: vi.fn() },
|
|
29
|
+
ConsoleClusterService: { getClusters: vi.fn() },
|
|
30
|
+
EarlyAccessFeaturesService: { getForOrg: vi.fn() },
|
|
31
|
+
ExternalAccountsService: { getMyOrganizations: vi.fn() },
|
|
32
|
+
ExternalConsoleService: { getOrgClusters: vi.fn() },
|
|
33
|
+
GenerationService: {
|
|
34
|
+
getUpgradableMulti: vi.fn(),
|
|
35
|
+
getGeneration: vi.fn(),
|
|
36
|
+
upgradeCluster: vi.fn(),
|
|
37
|
+
},
|
|
38
|
+
HdpService: { getClusterCapacity: vi.fn() },
|
|
39
|
+
HttpError: class HttpError extends Error {
|
|
40
|
+
},
|
|
41
|
+
OrganizationMembersService: { getMembers: vi.fn() },
|
|
42
|
+
OrgsService: { getOrgInfo: vi.fn(), getMyOrgs: vi.fn(), getOwner: vi.fn() },
|
|
43
|
+
// toApiConfig wires this in as `getDynamicHeaders` on every request config;
|
|
44
|
+
// Vitest's ESM mock throws on any access to an export the factory omits.
|
|
45
|
+
correlationHeaders: () => ({}),
|
|
46
|
+
}));
|
|
47
|
+
import { ConsoleClusterService, ExternalConsoleService, } from '@camunda/ccma-api';
|
|
48
|
+
import { useC4ClusterNavEntries } from './nav/use-webapp-nav-data.js';
|
|
49
|
+
const runtime = {
|
|
50
|
+
stage: 'dev',
|
|
51
|
+
auth: { getAccessToken: async () => 'token' },
|
|
52
|
+
backendUrls: {},
|
|
53
|
+
};
|
|
54
|
+
const cacheEntry = (data) => ({
|
|
55
|
+
data,
|
|
56
|
+
isLoading: false,
|
|
57
|
+
error: null,
|
|
58
|
+
lastFetched: null,
|
|
59
|
+
});
|
|
60
|
+
const wrapper = (initialState) => ({ children }) => (_jsx(C4ConsoleRuntimeProvider, { config: runtime, children: _jsx(C4ConsoleDataProvider, { initialState: initialState, children: children }) }));
|
|
61
|
+
beforeEach(() => {
|
|
62
|
+
vi.clearAllMocks();
|
|
63
|
+
});
|
|
64
|
+
describe('useC4ConsoleData — public API surface', () => {
|
|
65
|
+
// Pins the client interface: every documented action/getter must remain
|
|
66
|
+
// present with the same name so a refactor cannot silently drop or rename one.
|
|
67
|
+
const ACTION_MEMBERS = [
|
|
68
|
+
'fetchClusters',
|
|
69
|
+
'fetchOrgInfo',
|
|
70
|
+
'fetchOrgOwner',
|
|
71
|
+
'fetchEarlyAccessFeatures',
|
|
72
|
+
'fetchMembers',
|
|
73
|
+
'fetchAudits',
|
|
74
|
+
'fetchClusterCapacity',
|
|
75
|
+
'fetchMyOrgs',
|
|
76
|
+
'fetchWebappClusters',
|
|
77
|
+
'fetchUpgradableGenerations',
|
|
78
|
+
'fetchGenerationDetails',
|
|
79
|
+
'upgradeClusterGeneration',
|
|
80
|
+
'upsertCluster',
|
|
81
|
+
'setOrgInfo',
|
|
82
|
+
'setEarlyAccessFeatures',
|
|
83
|
+
'invalidateClusters',
|
|
84
|
+
'invalidateClusterCapacity',
|
|
85
|
+
'invalidateMembers',
|
|
86
|
+
'invalidateAudits',
|
|
87
|
+
'invalidateMyOrgs',
|
|
88
|
+
'invalidateWebappClusters',
|
|
89
|
+
'invalidateAll',
|
|
90
|
+
'getClusters',
|
|
91
|
+
'getOrgInfo',
|
|
92
|
+
'getOrgOwner',
|
|
93
|
+
'getEarlyAccessFeatures',
|
|
94
|
+
'getMembers',
|
|
95
|
+
'getAudits',
|
|
96
|
+
'getClusterCapacity',
|
|
97
|
+
'getMyOrgs',
|
|
98
|
+
'getWebappClusters',
|
|
99
|
+
'getSseEntityVersion',
|
|
100
|
+
'getUpgradableGenerations',
|
|
101
|
+
'getGenerationDetails',
|
|
102
|
+
];
|
|
103
|
+
const GETTER_MEMBERS = [
|
|
104
|
+
'clusters',
|
|
105
|
+
'orgInfo',
|
|
106
|
+
'orgOwner',
|
|
107
|
+
'earlyAccessFeatures',
|
|
108
|
+
'members',
|
|
109
|
+
'audits',
|
|
110
|
+
'clusterCapacity',
|
|
111
|
+
'myOrgs',
|
|
112
|
+
'webappClusters',
|
|
113
|
+
'upgradableGenerations',
|
|
114
|
+
'generationDetails',
|
|
115
|
+
];
|
|
116
|
+
it('exposes every documented action as a function', () => {
|
|
117
|
+
const { result } = renderHook(() => useC4ConsoleData(), {
|
|
118
|
+
wrapper: wrapper(),
|
|
119
|
+
});
|
|
120
|
+
for (const member of ACTION_MEMBERS) {
|
|
121
|
+
expect(typeof result.current[member], `${member} should be a function`).toBe('function');
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
it('exposes every documented data collection getter', () => {
|
|
125
|
+
const { result } = renderHook(() => useC4ConsoleData(), {
|
|
126
|
+
wrapper: wrapper(),
|
|
127
|
+
});
|
|
128
|
+
for (const member of GETTER_MEMBERS) {
|
|
129
|
+
expect(result.current[member], `${member} should be defined`).toBeDefined();
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
it('throws when used outside the provider', () => {
|
|
133
|
+
const spy = vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
134
|
+
expect(() => renderHook(() => useC4ConsoleData())).toThrow(/must be used within C4ConsoleDataProvider/);
|
|
135
|
+
spy.mockRestore();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
describe('useC4ConsoleData — seeded reads (initialState)', () => {
|
|
139
|
+
it('returns seeded clusters via both the getter and the collection', () => {
|
|
140
|
+
const { result } = renderHook(() => useC4ConsoleData(), {
|
|
141
|
+
wrapper: wrapper({
|
|
142
|
+
clusters: { 'org-1': cacheEntry([{ uuid: 'c1', name: 'Prod' }]) },
|
|
143
|
+
}),
|
|
144
|
+
});
|
|
145
|
+
expect(result.current.getClusters('org-1')).toEqual([
|
|
146
|
+
{ uuid: 'c1', name: 'Prod' },
|
|
147
|
+
]);
|
|
148
|
+
expect(result.current.clusters['org-1']?.data).toEqual([
|
|
149
|
+
{ uuid: 'c1', name: 'Prod' },
|
|
150
|
+
]);
|
|
151
|
+
expect(result.current.clusters['org-1']?.isLoading).toBe(false);
|
|
152
|
+
});
|
|
153
|
+
it('returns seeded webapp clusters, orgs and cluster capacity', () => {
|
|
154
|
+
const { result } = renderHook(() => useC4ConsoleData(), {
|
|
155
|
+
wrapper: wrapper({
|
|
156
|
+
webappClusters: {
|
|
157
|
+
'org-1': cacheEntry([{ uuid: 'c1', name: 'Prod' }]),
|
|
158
|
+
},
|
|
159
|
+
myOrgs: cacheEntry([{ uuid: 'org-1', name: 'Acme' }]),
|
|
160
|
+
clusterCapacity: { 'org-1': new Map([['c1', 0.42]]) },
|
|
161
|
+
}),
|
|
162
|
+
});
|
|
163
|
+
expect(result.current.getWebappClusters('org-1')).toEqual([
|
|
164
|
+
{ uuid: 'c1', name: 'Prod' },
|
|
165
|
+
]);
|
|
166
|
+
expect(result.current.getMyOrgs()).toEqual([
|
|
167
|
+
{ uuid: 'org-1', name: 'Acme' },
|
|
168
|
+
]);
|
|
169
|
+
expect(result.current.myOrgs.data).toEqual([
|
|
170
|
+
{ uuid: 'org-1', name: 'Acme' },
|
|
171
|
+
]);
|
|
172
|
+
expect(result.current.getClusterCapacity('org-1', 'c1')).toBe(0.42);
|
|
173
|
+
});
|
|
174
|
+
it('returns undefined for orgs that were never seeded or fetched', () => {
|
|
175
|
+
const { result } = renderHook(() => useC4ConsoleData(), {
|
|
176
|
+
wrapper: wrapper(),
|
|
177
|
+
});
|
|
178
|
+
expect(result.current.getClusters('missing')).toBeUndefined();
|
|
179
|
+
expect(result.current.clusters.missing).toBeUndefined();
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
// A minimal consumer that reads clusters and records how many times it rendered.
|
|
183
|
+
// Wrapped in `observer` — the required pattern for components that read data
|
|
184
|
+
// from useC4ConsoleData during render (the context value is now stable, so
|
|
185
|
+
// reactivity comes from MobX tracking, not from the context value changing).
|
|
186
|
+
const ClustersConsumer = observer(function ClustersConsumer({ orgId, autofetch, renderSpy, }) {
|
|
187
|
+
const data = useC4ConsoleData();
|
|
188
|
+
renderSpy?.();
|
|
189
|
+
// Emulate a real widget's mount-time fetch (in an effect, so it runs after
|
|
190
|
+
// the provider's layout effect has injected the runtime config).
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
if (autofetch) {
|
|
193
|
+
void data.fetchClusters(orgId);
|
|
194
|
+
}
|
|
195
|
+
}, [autofetch, data, orgId]);
|
|
196
|
+
const clusters = data.getClusters(orgId);
|
|
197
|
+
return (_jsx("ul", { children: (clusters ?? []).map((cluster) => (_jsx("li", { children: cluster.name }, cluster.uuid))) }));
|
|
198
|
+
});
|
|
199
|
+
describe('C4ConsoleDataProvider — reactivity (the core contract)', () => {
|
|
200
|
+
it('updates a consumer when a fetch resolves', async () => {
|
|
201
|
+
vi.mocked(ConsoleClusterService.getClusters).mockResolvedValue([
|
|
202
|
+
{ uuid: 'c1', name: 'Fetched Cluster' },
|
|
203
|
+
]);
|
|
204
|
+
render(_jsx(ClustersConsumer, { orgId: 'org-1', autofetch: true }), {
|
|
205
|
+
wrapper: wrapper(),
|
|
206
|
+
});
|
|
207
|
+
// Nothing rendered until the fetch resolves...
|
|
208
|
+
expect(screen.queryByText('Fetched Cluster')).not.toBeInTheDocument();
|
|
209
|
+
// ...then the consumer re-renders with the fetched data.
|
|
210
|
+
expect(await screen.findByText('Fetched Cluster')).toBeInTheDocument();
|
|
211
|
+
});
|
|
212
|
+
it('updates a consumer when an SSE clusterchange patches the cache', async () => {
|
|
213
|
+
render(_jsx(ClustersConsumer, { orgId: 'org-1' }), {
|
|
214
|
+
wrapper: wrapper({
|
|
215
|
+
clusters: { 'org-1': cacheEntry([{ uuid: 'c1', name: 'Old Name' }]) },
|
|
216
|
+
}),
|
|
217
|
+
});
|
|
218
|
+
expect(screen.getByText('Old Name')).toBeInTheDocument();
|
|
219
|
+
act(() => {
|
|
220
|
+
window.dispatchEvent(new CustomEvent('clusterchange', {
|
|
221
|
+
detail: {
|
|
222
|
+
org: 'org-1',
|
|
223
|
+
entity: SseEntity.CLUSTER,
|
|
224
|
+
type: SseType.UPDATED,
|
|
225
|
+
clusterId: 'c1',
|
|
226
|
+
payload: { cluster: { uuid: 'c1', name: 'New Name' } },
|
|
227
|
+
},
|
|
228
|
+
}));
|
|
229
|
+
});
|
|
230
|
+
expect(await screen.findByText('New Name')).toBeInTheDocument();
|
|
231
|
+
expect(screen.queryByText('Old Name')).not.toBeInTheDocument();
|
|
232
|
+
});
|
|
233
|
+
it('exposes a changing SSE entity version for effect-based consumers', () => {
|
|
234
|
+
const { result } = renderHook(() => useC4ConsoleData(), {
|
|
235
|
+
wrapper: wrapper({
|
|
236
|
+
clusters: { 'org-1': cacheEntry([{ uuid: 'c1', name: 'Old Name' }]) },
|
|
237
|
+
}),
|
|
238
|
+
});
|
|
239
|
+
const before = result.current.getSseEntityVersion('org-1', SseEntity.CLUSTER, 'c1');
|
|
240
|
+
act(() => {
|
|
241
|
+
window.dispatchEvent(new CustomEvent('clusterchange', {
|
|
242
|
+
detail: {
|
|
243
|
+
org: 'org-1',
|
|
244
|
+
entity: SseEntity.CLUSTER,
|
|
245
|
+
type: SseType.UPDATED,
|
|
246
|
+
clusterId: 'c1',
|
|
247
|
+
payload: { cluster: { uuid: 'c1', name: 'New Name' } },
|
|
248
|
+
},
|
|
249
|
+
}));
|
|
250
|
+
});
|
|
251
|
+
const after = result.current.getSseEntityVersion('org-1', SseEntity.CLUSTER, 'c1');
|
|
252
|
+
expect(after).not.toBe(before);
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
describe('C4ConsoleDataProvider — fine-grained reactivity (the improvement)', () => {
|
|
256
|
+
it('does not re-render an observer reading org B when org A changes', () => {
|
|
257
|
+
const orgARenders = vi.fn();
|
|
258
|
+
const orgBRenders = vi.fn();
|
|
259
|
+
render(_jsxs(_Fragment, { children: [_jsx(ClustersConsumer, { orgId: 'org-a', renderSpy: orgARenders }), _jsx(ClustersConsumer, { orgId: 'org-b', renderSpy: orgBRenders })] }), {
|
|
260
|
+
wrapper: wrapper({
|
|
261
|
+
clusters: {
|
|
262
|
+
'org-a': cacheEntry([{ uuid: 'a1', name: 'A One' }]),
|
|
263
|
+
'org-b': cacheEntry([{ uuid: 'b1', name: 'B One' }]),
|
|
264
|
+
},
|
|
265
|
+
}),
|
|
266
|
+
});
|
|
267
|
+
const orgBRendersBeforeChange = orgBRenders.mock.calls.length;
|
|
268
|
+
const orgARendersBeforeChange = orgARenders.mock.calls.length;
|
|
269
|
+
act(() => {
|
|
270
|
+
window.dispatchEvent(new CustomEvent('clusterchange', {
|
|
271
|
+
detail: {
|
|
272
|
+
org: 'org-a',
|
|
273
|
+
entity: SseEntity.CLUSTER,
|
|
274
|
+
type: SseType.UPDATED,
|
|
275
|
+
clusterId: 'a1',
|
|
276
|
+
payload: { cluster: { uuid: 'a1', name: 'A Two' } },
|
|
277
|
+
},
|
|
278
|
+
}));
|
|
279
|
+
});
|
|
280
|
+
// Org A's consumer re-rendered with the new data...
|
|
281
|
+
expect(screen.getByText('A Two')).toBeInTheDocument();
|
|
282
|
+
expect(orgARenders.mock.calls.length).toBeGreaterThan(orgARendersBeforeChange);
|
|
283
|
+
// ...but org B's consumer did not re-render at all.
|
|
284
|
+
expect(orgBRenders.mock.calls.length).toBe(orgBRendersBeforeChange);
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
describe('public data hooks stay reactive for non-observer callers', () => {
|
|
288
|
+
it('re-renders a non-observer caller of useC4ClusterNavEntries when data loads', async () => {
|
|
289
|
+
vi.mocked(ExternalConsoleService.getOrgClusters).mockResolvedValue([
|
|
290
|
+
{
|
|
291
|
+
uuid: 'c1',
|
|
292
|
+
name: 'Prod',
|
|
293
|
+
endpoints: { operate: 'https://c1.operate' },
|
|
294
|
+
status: { operate: 'Healthy' },
|
|
295
|
+
},
|
|
296
|
+
]);
|
|
297
|
+
// renderHook's default wrapper is a plain (non-observer) component; the
|
|
298
|
+
// hook must still re-render it when the auto-fetch resolves. This is the
|
|
299
|
+
// external contract that the useObserver bridge preserves.
|
|
300
|
+
const { result } = renderHook(() => useC4ClusterNavEntries('org-1'), {
|
|
301
|
+
wrapper: wrapper(),
|
|
302
|
+
});
|
|
303
|
+
expect(result.current).toHaveLength(0);
|
|
304
|
+
await waitFor(() => expect(result.current).toHaveLength(1));
|
|
305
|
+
expect(result.current[0].cluster).toMatchObject({
|
|
306
|
+
uuid: 'c1',
|
|
307
|
+
name: 'Prod',
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
describe('C4ConsoleDataProvider — dedup, errors and cache hits', () => {
|
|
312
|
+
it('dedupes concurrent fetches from two consumers into one request', async () => {
|
|
313
|
+
let resolveFetch = () => undefined;
|
|
314
|
+
vi.mocked(ConsoleClusterService.getClusters).mockImplementation(() => new Promise((resolve) => {
|
|
315
|
+
resolveFetch = resolve;
|
|
316
|
+
}));
|
|
317
|
+
render(_jsxs(_Fragment, { children: [_jsx(ClustersConsumer, { orgId: 'org-1', autofetch: true }), _jsx(ClustersConsumer, { orgId: 'org-1', autofetch: true })] }), { wrapper: wrapper() });
|
|
318
|
+
await waitFor(() => {
|
|
319
|
+
expect(ConsoleClusterService.getClusters).toHaveBeenCalledTimes(1);
|
|
320
|
+
});
|
|
321
|
+
act(() => {
|
|
322
|
+
resolveFetch([{ uuid: 'c1', name: 'Shared' }]);
|
|
323
|
+
});
|
|
324
|
+
expect(await screen.findAllByText('Shared')).toHaveLength(2);
|
|
325
|
+
expect(ConsoleClusterService.getClusters).toHaveBeenCalledTimes(1);
|
|
326
|
+
});
|
|
327
|
+
it('surfaces a fetch error on the cache entry without throwing', async () => {
|
|
328
|
+
vi.mocked(ConsoleClusterService.getClusters).mockRejectedValue(new Error('boom'));
|
|
329
|
+
const { result } = renderHook(() => useC4ConsoleData(), {
|
|
330
|
+
wrapper: wrapper(),
|
|
331
|
+
});
|
|
332
|
+
await act(async () => {
|
|
333
|
+
await result.current.fetchClusters('org-1');
|
|
334
|
+
});
|
|
335
|
+
await waitFor(() => {
|
|
336
|
+
expect(result.current.clusters['org-1']?.error).toBeInstanceOf(Error);
|
|
337
|
+
});
|
|
338
|
+
expect(result.current.clusters['org-1']?.isLoading).toBe(false);
|
|
339
|
+
});
|
|
340
|
+
it('does not fetch when the cache is already seeded (non-force)', async () => {
|
|
341
|
+
const { result } = renderHook(() => useC4ConsoleData(), {
|
|
342
|
+
wrapper: wrapper({
|
|
343
|
+
clusters: { 'org-1': cacheEntry([{ uuid: 'c1', name: 'Prod' }]) },
|
|
344
|
+
}),
|
|
345
|
+
});
|
|
346
|
+
await act(async () => {
|
|
347
|
+
await result.current.fetchClusters('org-1');
|
|
348
|
+
});
|
|
349
|
+
expect(ConsoleClusterService.getClusters).not.toHaveBeenCalled();
|
|
350
|
+
expect(result.current.getClusters('org-1')).toEqual([
|
|
351
|
+
{ uuid: 'c1', name: 'Prod' },
|
|
352
|
+
]);
|
|
353
|
+
});
|
|
354
|
+
});
|
|
@@ -25,6 +25,7 @@ export interface C4ConsoleDataState {
|
|
|
25
25
|
earlyAccessFeatures: OrgCache<any[]>;
|
|
26
26
|
members: OrgCache<any[]>;
|
|
27
27
|
audits: OrgCache<any[]>;
|
|
28
|
+
clients: OrgCache<any[]>;
|
|
28
29
|
clusterCapacity: Record<string, Map<string, number>>;
|
|
29
30
|
/** Organizations of the current user (external API). Single cache entry. */
|
|
30
31
|
myOrgs: CacheState<ExternalOrganizationDto[]>;
|
|
@@ -54,6 +55,9 @@ export interface C4ConsoleDataState {
|
|
|
54
55
|
fetchAudits: (orgId: string, options?: {
|
|
55
56
|
force?: boolean;
|
|
56
57
|
}) => Promise<void>;
|
|
58
|
+
fetchClients: (orgId: string, options?: {
|
|
59
|
+
force?: boolean;
|
|
60
|
+
}) => Promise<void>;
|
|
57
61
|
fetchClusterCapacity: (orgId: string, clusterIds: string[], options?: {
|
|
58
62
|
force?: boolean;
|
|
59
63
|
}) => Promise<void>;
|
|
@@ -82,6 +86,7 @@ export interface C4ConsoleDataState {
|
|
|
82
86
|
invalidateClusterCapacity: (orgId: string) => void;
|
|
83
87
|
invalidateMembers: (orgId: string) => void;
|
|
84
88
|
invalidateAudits: (orgId: string) => void;
|
|
89
|
+
invalidateClients: (orgId: string) => void;
|
|
85
90
|
invalidateMyOrgs: () => void;
|
|
86
91
|
invalidateWebappClusters: (orgId: string) => void;
|
|
87
92
|
invalidateAll: (orgId: string) => void;
|
|
@@ -96,6 +101,7 @@ export interface C4ConsoleDataState {
|
|
|
96
101
|
getEarlyAccessFeatures: (orgId: string) => any[] | undefined;
|
|
97
102
|
getMembers: (orgId: string) => any[] | undefined;
|
|
98
103
|
getAudits: (orgId: string) => any[] | undefined;
|
|
104
|
+
getClients: (orgId: string) => any[] | undefined;
|
|
99
105
|
getClusterCapacity: (orgId: string, clusterId: string) => number | undefined;
|
|
100
106
|
getMyOrgs: () => ExternalOrganizationDto[] | undefined;
|
|
101
107
|
getWebappClusters: (orgId: string) => ExternalClusterDto[] | undefined;
|
|
@@ -38,6 +38,12 @@ export declare const ConsoleDataStore: import("mobx-state-tree").IModelType<{
|
|
|
38
38
|
error: import("mobx-state-tree").IMaybeNull<import("mobx-state-tree").IType<any, any, any>>;
|
|
39
39
|
lastFetched: import("mobx-state-tree").IMaybeNull<import("mobx-state-tree").IType<number | Date, number, Date>>;
|
|
40
40
|
}, {}, import("mobx-state-tree")._NotCustomized, import("mobx-state-tree")._NotCustomized>>;
|
|
41
|
+
clients: import("mobx-state-tree").IMapType<import("mobx-state-tree").IModelType<{
|
|
42
|
+
data: import("mobx-state-tree").IType<any, any, any>;
|
|
43
|
+
isLoading: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<boolean>, [undefined]>;
|
|
44
|
+
error: import("mobx-state-tree").IMaybeNull<import("mobx-state-tree").IType<any, any, any>>;
|
|
45
|
+
lastFetched: import("mobx-state-tree").IMaybeNull<import("mobx-state-tree").IType<number | Date, number, Date>>;
|
|
46
|
+
}, {}, import("mobx-state-tree")._NotCustomized, import("mobx-state-tree")._NotCustomized>>;
|
|
41
47
|
clusterCapacity: import("mobx-state-tree").IMapType<import("mobx-state-tree").IType<Map<string, number>, Map<string, number>, Map<string, number>>>;
|
|
42
48
|
upgradableGenerations: import("mobx-state-tree").IMapType<import("mobx-state-tree").IModelType<{
|
|
43
49
|
data: import("mobx-state-tree").IType<any, any, any>;
|
|
@@ -96,6 +102,7 @@ export declare const ConsoleDataStore: import("mobx-state-tree").IModelType<{
|
|
|
96
102
|
getEarlyAccessFeatures(orgId: string): any[] | undefined;
|
|
97
103
|
getMembers(orgId: string): any[] | undefined;
|
|
98
104
|
getAudits(orgId: string): any[] | undefined;
|
|
105
|
+
getClients(orgId: string): any[] | undefined;
|
|
99
106
|
getClusterCapacity(orgId: string, clusterId: string): number | undefined;
|
|
100
107
|
getUpgradableGenerations(fromGenerationUuid: string, clusterId?: string): UpgradableGenerationsDto | undefined;
|
|
101
108
|
getGenerationDetails(generationUuid: string): any | undefined;
|
|
@@ -114,6 +121,7 @@ export declare const ConsoleDataStore: import("mobx-state-tree").IModelType<{
|
|
|
114
121
|
invalidateClusterCapacity(orgId: string): void;
|
|
115
122
|
invalidateMembers(orgId: string): void;
|
|
116
123
|
invalidateAudits(orgId: string): void;
|
|
124
|
+
invalidateClients(orgId: string): void;
|
|
117
125
|
invalidateMyOrgs(): void;
|
|
118
126
|
invalidateWebappClusters(orgId: string): void;
|
|
119
127
|
invalidateAll(orgId: string): void;
|
|
@@ -155,6 +163,9 @@ export declare const ConsoleDataStore: import("mobx-state-tree").IModelType<{
|
|
|
155
163
|
fetchAudits: (orgId: string, options?: {
|
|
156
164
|
force?: boolean;
|
|
157
165
|
} | undefined) => Promise<void>;
|
|
166
|
+
fetchClients: (orgId: string, options?: {
|
|
167
|
+
force?: boolean;
|
|
168
|
+
} | undefined) => Promise<void>;
|
|
158
169
|
fetchClusterCapacity: (orgId: string, clusterIds: string[], options?: {
|
|
159
170
|
force?: boolean;
|
|
160
171
|
} | undefined) => Promise<void>;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* under one or more contributor license agreements. Licensed under a commercial license.
|
|
4
4
|
* You may not use this file except in compliance with the commercial license.
|
|
5
5
|
*/
|
|
6
|
-
import { AuditLoggerService, ConsoleClusterService, EarlyAccessFeaturesService, ExternalAccountsService, ExternalConsoleService, GenerationService, HdpService, HttpError, OrganizationMembersService, OrgsService, } from '@camunda/ccma-api';
|
|
6
|
+
import { AuditLoggerService, ConsoleApiClientsService, ConsoleClusterService, EarlyAccessFeaturesService, ExternalAccountsService, ExternalConsoleService, GenerationService, HdpService, HttpError, OrganizationMembersService, OrgsService, } from '@camunda/ccma-api';
|
|
7
7
|
import { SseEntity, SseType, } from '@camunda/ccma-shared-types';
|
|
8
8
|
import { flow, types } from 'mobx-state-tree';
|
|
9
9
|
import { toApiConfig } from './to-api-config.js';
|
|
@@ -100,6 +100,7 @@ export const ConsoleDataStore = types
|
|
|
100
100
|
earlyAccessFeatures: types.map(CacheStateModel),
|
|
101
101
|
members: types.map(CacheStateModel),
|
|
102
102
|
audits: types.map(CacheStateModel),
|
|
103
|
+
clients: types.map(CacheStateModel),
|
|
103
104
|
clusterCapacity: types.map(types.frozen()),
|
|
104
105
|
// Caches keyed by arbitrary string keys (e.g., generationUuid)
|
|
105
106
|
upgradableGenerations: types.map(CacheStateModel),
|
|
@@ -159,6 +160,10 @@ export const ConsoleDataStore = types
|
|
|
159
160
|
const cached = self.audits.get(orgId);
|
|
160
161
|
return cached?.data;
|
|
161
162
|
},
|
|
163
|
+
getClients(orgId) {
|
|
164
|
+
const cached = self.clients.get(orgId);
|
|
165
|
+
return cached?.data;
|
|
166
|
+
},
|
|
162
167
|
getClusterCapacity(orgId, clusterId) {
|
|
163
168
|
const map = self.clusterCapacity.get(orgId);
|
|
164
169
|
return map?.get(clusterId);
|
|
@@ -247,6 +252,9 @@ export const ConsoleDataStore = types
|
|
|
247
252
|
invalidateAudits(orgId) {
|
|
248
253
|
self.audits.delete(orgId);
|
|
249
254
|
},
|
|
255
|
+
invalidateClients(orgId) {
|
|
256
|
+
self.clients.delete(orgId);
|
|
257
|
+
},
|
|
250
258
|
invalidateMyOrgs() {
|
|
251
259
|
self.myOrgs = null;
|
|
252
260
|
},
|
|
@@ -260,6 +268,7 @@ export const ConsoleDataStore = types
|
|
|
260
268
|
self.earlyAccessFeatures.delete(orgId);
|
|
261
269
|
self.members.delete(orgId);
|
|
262
270
|
self.audits.delete(orgId);
|
|
271
|
+
self.clients.delete(orgId);
|
|
263
272
|
self.clusterCapacity.delete(orgId);
|
|
264
273
|
self.webappClusters.delete(orgId);
|
|
265
274
|
},
|
|
@@ -745,6 +754,42 @@ export const ConsoleDataStore = types
|
|
|
745
754
|
});
|
|
746
755
|
}
|
|
747
756
|
}),
|
|
757
|
+
fetchClients: flow(function* (orgId, options) {
|
|
758
|
+
if (!self.runtime) {
|
|
759
|
+
throw new Error('Runtime config not set');
|
|
760
|
+
}
|
|
761
|
+
const cached = self.clients.get(orgId);
|
|
762
|
+
if (!options?.force && cached && !cached.isLoading && cached.data) {
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
self.clients.set(orgId, {
|
|
766
|
+
data: cached?.data,
|
|
767
|
+
isLoading: true,
|
|
768
|
+
error: null,
|
|
769
|
+
lastFetched: cached?.lastFetched ?? null,
|
|
770
|
+
});
|
|
771
|
+
try {
|
|
772
|
+
const apiConfig = toApiConfig(self.runtime);
|
|
773
|
+
const clientsList = yield ConsoleApiClientsService.getAll({
|
|
774
|
+
params: { orgId },
|
|
775
|
+
config: apiConfig,
|
|
776
|
+
});
|
|
777
|
+
self.clients.set(orgId, {
|
|
778
|
+
data: clientsList,
|
|
779
|
+
isLoading: false,
|
|
780
|
+
error: null,
|
|
781
|
+
lastFetched: new Date(),
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
catch (error) {
|
|
785
|
+
self.clients.set(orgId, {
|
|
786
|
+
data: cached?.data,
|
|
787
|
+
isLoading: false,
|
|
788
|
+
error: error,
|
|
789
|
+
lastFetched: cached?.lastFetched ?? null,
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
}),
|
|
748
793
|
fetchClusterCapacity: flow(function* (orgId, clusterIds, options) {
|
|
749
794
|
if (!self.runtime) {
|
|
750
795
|
throw new Error('Runtime config not set');
|
|
@@ -764,40 +809,33 @@ export const ConsoleDataStore = types
|
|
|
764
809
|
try {
|
|
765
810
|
const apiConfig = toApiConfig(self.runtime);
|
|
766
811
|
const loadMap = new Map();
|
|
767
|
-
// Fetch capacity for
|
|
768
|
-
//
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
const point = match ?? points[0];
|
|
786
|
-
if (!point) {
|
|
787
|
-
continue;
|
|
788
|
-
}
|
|
789
|
-
// The HDP capacity API returns a data point with min/max/avg.
|
|
790
|
-
// The UI treats `avg` as the current load for the "latest" operation.
|
|
791
|
-
const rawValue = point?.avg ?? point?.current?.value ?? point?.value ?? undefined;
|
|
792
|
-
const numericValue = parseFiniteNumber(rawValue);
|
|
793
|
-
if (numericValue === undefined) {
|
|
794
|
-
continue;
|
|
795
|
-
}
|
|
796
|
-
loadMap.set(clusterId, numericValue);
|
|
812
|
+
// Fetch capacity for all clusters in a single batched request.
|
|
813
|
+
// The HDP `latest` operation accepts the full `clusterIds` array and
|
|
814
|
+
// returns one data point per cluster, each tagged with its `clusterId`
|
|
815
|
+
// (see accounts-backend getLatestCapacity). This replaces the previous
|
|
816
|
+
// per-cluster serial loop, which issued one HTTP round-trip per cluster.
|
|
817
|
+
const latest = yield HdpService.getClusterCapacity({
|
|
818
|
+
params: {
|
|
819
|
+
orgId,
|
|
820
|
+
clusterIds,
|
|
821
|
+
operation: 'latest',
|
|
822
|
+
},
|
|
823
|
+
config: apiConfig,
|
|
824
|
+
});
|
|
825
|
+
const points = Array.isArray(latest) ? latest : [];
|
|
826
|
+
for (const point of points) {
|
|
827
|
+
const clusterId = point?.clusterId;
|
|
828
|
+
if (!clusterId) {
|
|
829
|
+
continue;
|
|
797
830
|
}
|
|
798
|
-
|
|
799
|
-
|
|
831
|
+
// The HDP capacity API returns a data point with min/max/avg.
|
|
832
|
+
// The UI treats `avg` as the current load for the "latest" operation.
|
|
833
|
+
const rawValue = point?.avg ?? point?.current?.value ?? point?.value ?? undefined;
|
|
834
|
+
const numericValue = parseFiniteNumber(rawValue);
|
|
835
|
+
if (numericValue === undefined) {
|
|
836
|
+
continue;
|
|
800
837
|
}
|
|
838
|
+
loadMap.set(clusterId, numericValue);
|
|
801
839
|
}
|
|
802
840
|
self.clusterCapacity.set(orgId, loadMap);
|
|
803
841
|
self.clusterCapacityLastRefreshMs.set(orgId, Date.now());
|
|
@@ -923,7 +961,9 @@ export const ConsoleDataStore = types
|
|
|
923
961
|
}
|
|
924
962
|
case SseEntity.CONSOLE_API_CLIENT: {
|
|
925
963
|
self.bumpSseEntityVersion(orgId, SseEntity.CONSOLE_API_CLIENT, clusterId);
|
|
926
|
-
|
|
964
|
+
if (self.clients.has(orgId)) {
|
|
965
|
+
void self.fetchClients(orgId, { force: true });
|
|
966
|
+
}
|
|
927
967
|
break;
|
|
928
968
|
}
|
|
929
969
|
default: {
|