@camunda/ccma-saas-frontend 0.11.0 → 0.12.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.
Files changed (87) hide show
  1. package/lib/esm/components/c4-cluster-list/c4-cluster-list.d.ts +1 -1
  2. package/lib/esm/components/c4-cluster-list/c4-cluster-list.js +24 -2
  3. package/lib/esm/components/c4-cluster-list/c4-cluster-list.types.d.ts +9 -0
  4. package/lib/esm/components/c4-cluster-settings/elements/danger-zone.js +9 -1
  5. package/lib/esm/components/c4-cluster-tag-selector/c4-cluster-tag-selector.js +5 -5
  6. package/lib/esm/components/c4-clusters-empty-state/c4-clusters-empty-state.js +3 -3
  7. package/lib/esm/components/c4-convert-trial-organization-modal/c4-convert-trial-organization-modal.js +1 -11
  8. package/lib/esm/components/c4-create-alert-modal/c4-create-alert-modal.js +1 -14
  9. package/lib/esm/components/c4-create-cluster/c4-create-cluster.d.ts +1 -1
  10. package/lib/esm/components/c4-create-cluster/c4-create-cluster.js +188 -71
  11. package/lib/esm/components/c4-create-cluster/c4-create-cluster.types.d.ts +52 -0
  12. package/lib/esm/components/c4-create-cluster-api-client-modal/c4-create-cluster-api-client-modal.js +1 -11
  13. package/lib/esm/components/c4-create-connector-secret-modal/c4-create-connector-secret-modal.js +6 -13
  14. package/lib/esm/components/c4-create-console-api-client-modal/c4-create-console-api-client-modal.js +1 -11
  15. package/lib/esm/components/c4-create-ip-whitelist-modal/c4-create-ip-whitelist-modal.js +1 -18
  16. package/lib/esm/components/c4-create-trial-organization-modal/c4-create-trial-organization-modal.js +1 -11
  17. package/lib/esm/components/c4-delete-account-modal/c4-delete-account-modal.d.ts +0 -7
  18. package/lib/esm/components/c4-delete-account-modal/c4-delete-account-modal.js +1 -24
  19. package/lib/esm/components/c4-delete-organization-modal/c4-delete-organization-modal.js +1 -18
  20. package/lib/esm/components/c4-divider/c4-divider.js +12 -0
  21. package/lib/esm/components/c4-empty-state/c4-empty-state.d.ts +8 -0
  22. package/lib/esm/components/c4-empty-state/c4-empty-state.js +32 -8
  23. package/lib/esm/components/c4-file-uploader/c4-file-uploader.d.ts +36 -0
  24. package/lib/esm/components/c4-file-uploader/c4-file-uploader.js +43 -0
  25. package/lib/esm/components/c4-invite-user-to-organization-modal/c4-invite-user-to-organization-modal.js +1 -11
  26. package/lib/esm/components/c4-leave-organization-modal/c4-leave-organization-modal.js +1 -11
  27. package/lib/esm/components/c4-rename-organization-modal/c4-rename-organization-modal.js +1 -11
  28. package/lib/esm/components/c4-segmented-control/c4-segmented-control.d.ts +46 -0
  29. package/lib/esm/components/c4-segmented-control/c4-segmented-control.js +117 -0
  30. package/lib/esm/externalUrls.const.d.ts +7 -0
  31. package/lib/esm/externalUrls.const.js +11 -1
  32. package/lib/esm/i18n/c4-console-i18n.js +3 -0
  33. package/lib/esm/i18n/en/modals/apiclients.json +2 -1
  34. package/lib/esm/i18n/en/modals/clusterclients.json +2 -1
  35. package/lib/esm/i18n/en/pages/clusterdetails.json +11 -1
  36. package/lib/esm/i18n/en/pages/createcluster.json +43 -0
  37. package/lib/esm/i18n/en/pages/orgmanagement.json +3 -0
  38. package/lib/esm/index.d.ts +2 -0
  39. package/lib/esm/index.js +2 -0
  40. package/lib/esm/runtime/cluster-duplication.d.ts +10 -0
  41. package/lib/esm/runtime/cluster-duplication.js +15 -0
  42. package/lib/esm/ui/c4-password-input.js +1 -1
  43. package/lib/esm/ui/index.d.ts +1 -0
  44. package/lib/esm/ui/index.js +16 -2
  45. package/lib/esm/utils/role-labels.d.ts +1 -2
  46. package/lib/esm/utils/role-labels.js +1 -13
  47. package/lib/esm/utils/safe-translate.d.ts +4 -2
  48. package/lib/esm/utils/safe-translate.js +9 -2
  49. package/lib/esm/widgets/cluster-client-details/c4-cluster-client-details-app.js +2 -12
  50. package/lib/esm/widgets/cluster-details/c4-cluster-details-app.js +34 -23
  51. package/lib/esm/widgets/cluster-details/c4-cluster-details-app.types.d.ts +6 -0
  52. package/lib/esm/widgets/cluster-details/c4-cluster-details-page.js +7 -0
  53. package/lib/esm/widgets/cluster-details/c4-cluster-details-page.types.d.ts +3 -0
  54. package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-activity-tab.js +1 -19
  55. package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-alerts-tab.js +1 -14
  56. package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-byom-clients-tab.js +1 -18
  57. package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-clients-tab.js +1 -1
  58. package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-connector-secrets-tab.d.ts +1 -0
  59. package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-connector-secrets-tab.js +77 -28
  60. package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-hot-backups-tab.js +1 -6
  61. package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-ip-whitelist-tab.js +1 -18
  62. package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-overview-tab.js +1 -19
  63. package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-secure-connectivity-tab.js +1 -6
  64. package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-settings-tab.js +1 -16
  65. package/lib/esm/widgets/clusters/c4-clusters-page.js +72 -100
  66. package/lib/esm/widgets/clusters/c4-clusters-page.types.d.ts +7 -0
  67. package/lib/esm/widgets/connector-management/c4-connector-management-page.js +1 -9
  68. package/lib/esm/widgets/connector-management/c4-connector-management.shared.js +1 -9
  69. package/lib/esm/widgets/create-cluster/c4-create-cluster-page.d.ts +88 -1
  70. package/lib/esm/widgets/create-cluster/c4-create-cluster-page.js +285 -45
  71. package/lib/esm/widgets/create-cluster/c4-create-cluster-page.types.d.ts +9 -0
  72. package/lib/esm/widgets/dashboard/c4-dashboard-app.js +1 -18
  73. package/lib/esm/widgets/environment/c4-cluster-connector-secrets-widget.js +1 -1
  74. package/lib/esm/widgets/group-details/c4-group-details-page.js +1 -9
  75. package/lib/esm/widgets/job-worker/c4-job-worker.helpers.d.ts +1 -0
  76. package/lib/esm/widgets/job-worker/c4-job-worker.helpers.js +4 -34
  77. package/lib/esm/widgets/management/c4-management-app.js +1 -20
  78. package/lib/esm/widgets/management/c4-management-page.js +1 -9
  79. package/lib/esm/widgets/management/tabs/c4-management-api-tab.js +1 -13
  80. package/lib/esm/widgets/management/tabs/c4-management-billing-tab.js +1 -9
  81. package/lib/esm/widgets/management/tabs/c4-management-overview-tab.js +1 -13
  82. package/lib/esm/widgets/management/tabs/c4-management-pricing-tab.js +1 -8
  83. package/lib/esm/widgets/management/tabs/c4-management-settings-tab.js +1 -24
  84. package/lib/esm/widgets/management/tabs/c4-management-users-tab.js +1 -13
  85. package/lib/esm/widgets/user-account/c4-delete-account-widget.js +2 -1
  86. package/lib/esm/widgets/user-details/c4-user-details-page.js +1 -9
  87. package/package.json +3 -3
@@ -11,10 +11,20 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
11
11
  import { C4CreateCluster } from '../../components/c4-create-cluster/c4-create-cluster.js';
12
12
  import { C4PageTemplate } from '../../components/c4-page-template/c4-page-template.js';
13
13
  import { getC4CreateClusterExternalLinks, getC4TalkToAnExpertUrl, } from '../../externalUrls.const.js';
14
+ import { addC4ConsoleNotification } from '../../notifications/c4-console-notifications-handle.js';
15
+ import { useC4ConsoleAuthz } from '../../runtime/c4-console-authz.js';
14
16
  import { useC4ConsoleData } from '../../runtime/c4-console-data-context.js';
15
- import { useC4ConsoleRuntime } from '../../runtime/c4-console-runtime-context.js';
17
+ import { useC4ConsoleRuntime, useC4FeatureFlag, } from '../../runtime/c4-console-runtime-context.js';
18
+ import { CLUSTER_DUPLICATION_FLAG } from '../../runtime/cluster-duplication.js';
16
19
  import { toApiConfig } from '../../runtime/to-api-config.js';
17
20
  import { Link, Stack } from '../../ui/index.js';
21
+ import { safeTranslate } from '../../utils/safe-translate.js';
22
+ /**
23
+ * What the customer types to confirm the delete of the source cluster. It
24
+ * matches the delete modal of the cluster list, thus the two destructive
25
+ * actions of a cluster ask for the same word.
26
+ */
27
+ const DELETE_CONFIRMATION_VALUE = 'DELETE';
18
28
  function mapRegionBackups(region) {
19
29
  const rawBackups = getPathUnknown(region, ['backups']);
20
30
  if (!Array.isArray(rawBackups)) {
@@ -120,7 +130,15 @@ function getMaxReservedFromConfig(config, planTypeUuid) {
120
130
  }
121
131
  return undefined;
122
132
  }
123
- function deriveClusterUsageByPlanType(rawClusters) {
133
+ /**
134
+ * Counts the reservations that the clusters of the org use, per plan type.
135
+ *
136
+ * `excludeClusterId` leaves one cluster out of the count. A duplicate that
137
+ * replaces its source gives the reservation of the source cluster to the new
138
+ * one, thus the form must offer the plan type of a cluster that is about to
139
+ * go away.
140
+ */
141
+ function deriveClusterUsageByPlanType(rawClusters, excludeClusterId) {
124
142
  const result = {};
125
143
  if (!rawClusters) {
126
144
  return result;
@@ -129,6 +147,9 @@ function deriveClusterUsageByPlanType(rawClusters) {
129
147
  if (!isRecord(raw)) {
130
148
  continue;
131
149
  }
150
+ if (excludeClusterId && getString(raw, 'uuid') === excludeClusterId) {
151
+ continue;
152
+ }
132
153
  const planTypeUuid = getPathString(raw, ['planType', 'uuid']);
133
154
  if (!planTypeUuid) {
134
155
  continue;
@@ -168,16 +189,17 @@ function sendNavigate(onNavigate, event) {
168
189
  function resolveExternalLinks(input) {
169
190
  return getC4CreateClusterExternalLinks(input);
170
191
  }
171
- function buildCreateClusterTranslations(t) {
172
- const translate = (key, fallback) => {
173
- try {
174
- const translated = t?.(key);
175
- return translated && translated !== key ? translated : fallback;
176
- }
177
- catch {
178
- return fallback;
179
- }
180
- };
192
+ /**
193
+ * Every copy string of the page, resolved once. Exported for the test that
194
+ * holds each string against its key: a miss must give the English fallback and
195
+ * never the identifier.
196
+ */
197
+ export function buildCreateClusterTranslations(t) {
198
+ // `safeTranslate` and not a local copy: i18next answers a missing key with
199
+ // the key MINUS its namespace (`createcluster:duplicate.title` ->
200
+ // `duplicate.title`). A compare against the full key does not see that miss,
201
+ // thus the page showed the identifier instead of the fallback.
202
+ const translate = (key, fallback) => safeTranslate(t, key, fallback);
181
203
  return {
182
204
  title: translate('createcluster:title', 'Create a cluster'),
183
205
  breadcrumbsClusters: translate('createcluster:breadcrumbs.clusters', 'Clusters'),
@@ -225,6 +247,31 @@ function buildCreateClusterTranslations(t) {
225
247
  ctaSubmitting: translate('createcluster:cta.states.submitting', 'Creating cluster...'),
226
248
  ctaSuccess: translate('createcluster:cta.states.success', 'Cluster will now be created'),
227
249
  ctaError: translate('createcluster:cta.states.error', 'Error creating cluster. Please try again.'),
250
+ duplicateTitle: translate('createcluster:duplicate.title', 'Duplicate a cluster'),
251
+ duplicateNoticeTitle: translate('createcluster:duplicate.notice.title', 'Copying settings from'),
252
+ duplicateNoticeCopied: translate('createcluster:duplicate.notice.copied', 'Your connector secrets, alerts, IP allowlist, and other cluster settings carry over to the new cluster.'),
253
+ duplicateNoticeNotCopied: translate('createcluster:duplicate.notice.notCopied', 'Process data is not copied — the new cluster starts empty. Each API client is recreated with a new client ID and secret, so update your applications with the new credentials.'),
254
+ duplicateCta: translate('createcluster:duplicate.cta.create', 'Duplicate cluster'),
255
+ duplicateCtaSubmitting: translate('createcluster:duplicate.cta.states.submitting', 'Duplicating cluster...'),
256
+ duplicateCtaSuccess: translate('createcluster:duplicate.cta.states.success', 'Cluster will now be created'),
257
+ duplicateCtaError: translate('createcluster:duplicate.cta.states.error', 'Error duplicating cluster. Please try again.'),
258
+ duplicateReplaceLabel: translate('createcluster:duplicate.replace.label', 'Delete the original cluster to free up a reservation'),
259
+ duplicateReplaceDescription: translate('createcluster:duplicate.replace.description', 'Your plan has no reservations left. The new cluster is created first, then the original cluster and all of its data are deleted. This cannot be undone.'),
260
+ duplicateReplaceConfirmHeading: translate('createcluster:duplicate.replace.confirm.heading', 'Delete the original cluster?'),
261
+ duplicateReplaceConfirmBody: translate('createcluster:duplicate.replace.confirm.body', 'The original cluster and all of its data are deleted once the new cluster is created. This cannot be undone.'),
262
+ duplicateReplaceConfirmLabel: translate('createcluster:duplicate.replace.confirm.label', 'Type DELETE to confirm'),
263
+ duplicateReplaceConfirmPrimary: translate('createcluster:duplicate.replace.confirm.primary', 'Duplicate and delete'),
264
+ duplicateReplaceConfirmSecondary: translate('createcluster:duplicate.replace.confirm.secondary', 'Cancel'),
265
+ duplicateCarryOverFailedTitle: translate('createcluster:duplicate.carryOverFailed.title', 'Some settings were not copied'),
266
+ duplicateCarryOverFailedSubtitle: translate('createcluster:duplicate.carryOverFailed.subtitle', 'Your new cluster is ready, but we could not copy everything. Check these on the new cluster:'),
267
+ duplicateCarryOverClusterClients: translate('createcluster:duplicate.carryOver.clusterClients', 'API clients'),
268
+ duplicateCarryOverConnectorSecrets: translate('createcluster:duplicate.carryOver.connectorSecrets', 'connector secrets'),
269
+ duplicateCarryOverAlerts: translate('createcluster:duplicate.carryOver.alerts', 'alerts'),
270
+ duplicateCarryOverByom: translate('createcluster:duplicate.carryOver.byom', 'monitoring credentials'),
271
+ duplicateCarryOverByoidp: translate('createcluster:duplicate.carryOver.byoidp', 'identity provider secret'),
272
+ duplicateCarryOverBackupSchedule: translate('createcluster:duplicate.carryOver.backupSchedule', 'backup schedule'),
273
+ duplicateSourceNotDeletedTitle: translate('createcluster:duplicate.sourceNotDeleted.title', 'The original cluster was not deleted'),
274
+ duplicateSourceNotDeletedSubtitle: translate('createcluster:duplicate.sourceNotDeleted.subtitle', 'Your new cluster is ready, but we could not delete the original cluster. Delete it from the cluster list to free up its reservation.'),
228
275
  ctaCancel: translate('createcluster:cta.cancel', 'Cancel'),
229
276
  ctaHelpPrefix: translate('createcluster:cta.help.prefix', 'Need help?'),
230
277
  ctaHelpLabel: translate('createcluster:cta.help.label', 'Talk to an expert'),
@@ -236,9 +283,17 @@ function buildCreateClusterTranslations(t) {
236
283
  stageSleepInactivity: translate('clusterdetails:settings.tags.sleepInactivity', 'Auto-pauses after inactivity'),
237
284
  };
238
285
  }
239
- export const C4CreateClusterPage = observer(({ orgId, afterCreateModalUrl, talkToAnExpertUrl, externalLinks, onNavigate, }) => {
286
+ export const C4CreateClusterPage = observer(({ orgId, afterCreateModalUrl, talkToAnExpertUrl, externalLinks, onNavigate, duplicateOfClusterId, }) => {
240
287
  const runtime = useC4ConsoleRuntime();
241
288
  const data = useC4ConsoleData();
289
+ const authz = useC4ConsoleAuthz({ orgId });
290
+ const duplicationEnabled = useC4FeatureFlag(CLUSTER_DUPLICATION_FLAG);
291
+ // The flags arrive with a request, thus this is false on the first render
292
+ // and true on the render after. Every read below goes through this value,
293
+ // so the page makes a normal cluster while the answer is not there.
294
+ const sourceClusterId = duplicationEnabled
295
+ ? duplicateOfClusterId
296
+ : undefined;
242
297
  const resolvedTalkToAnExpertUrl = useMemo(() => talkToAnExpertUrl ??
243
298
  getC4TalkToAnExpertUrl({
244
299
  email: runtime.user?.email,
@@ -254,6 +309,12 @@ export const C4CreateClusterPage = observer(({ orgId, afterCreateModalUrl, talkT
254
309
  const [creationParametersLoading, setCreationParametersLoading] = useState(false);
255
310
  const [organizations, setOrganizations] = useState([]);
256
311
  const [organizationsLoading, setOrganizationsLoading] = useState(false);
312
+ const [sourceCluster, setSourceCluster] = useState(undefined);
313
+ const [sourceClusterLoading, setSourceClusterLoading] = useState(false);
314
+ // Set when the customer takes the offer to give the reservation of the
315
+ // source cluster to the new one. It changes the reservation count of every
316
+ // plan type, thus it lives here and not in the form.
317
+ const [replaceSource, setReplaceSource] = useState(false);
257
318
  const [apiError, setApiError] = useState(undefined);
258
319
  const selectedEncryptionRef = useRef(undefined);
259
320
  useEffect(() => {
@@ -271,8 +332,9 @@ export const C4CreateClusterPage = observer(({ orgId, afterCreateModalUrl, talkT
271
332
  setApiError(undefined);
272
333
  setCreationParametersLoading(true);
273
334
  setOrganizationsLoading(true);
335
+ setSourceClusterLoading(Boolean(sourceClusterId));
274
336
  try {
275
- const [parametersResponse, orgResponse] = await Promise.all([
337
+ const [parametersResponse, orgResponse, sourceClusterResponse] = await Promise.all([
276
338
  ConsoleClusterParametersService.getCreationParameters({
277
339
  params: { orgId },
278
340
  config: apiConfig,
@@ -281,12 +343,19 @@ export const C4CreateClusterPage = observer(({ orgId, afterCreateModalUrl, talkT
281
343
  orgUuid: orgId,
282
344
  config: apiConfig,
283
345
  }),
346
+ sourceClusterId
347
+ ? ConsoleClusterService.getCluster({
348
+ params: { orgId, clusterId: sourceClusterId },
349
+ config: apiConfig,
350
+ })
351
+ : Promise.resolve(undefined),
284
352
  ]);
285
353
  if (cancelled) {
286
354
  return;
287
355
  }
288
356
  setCreationParameters(isRecord(parametersResponse) ? parametersResponse : {});
289
357
  setOrganizations(isRecord(orgResponse) ? [orgResponse] : []);
358
+ setSourceCluster(isRecord(sourceClusterResponse) ? sourceClusterResponse : undefined);
290
359
  }
291
360
  catch (error) {
292
361
  if (cancelled) {
@@ -304,17 +373,29 @@ export const C4CreateClusterPage = observer(({ orgId, afterCreateModalUrl, talkT
304
373
  }
305
374
  setCreationParametersLoading(false);
306
375
  setOrganizationsLoading(false);
376
+ setSourceClusterLoading(false);
307
377
  }
308
378
  }
309
379
  load();
310
380
  return () => {
311
381
  cancelled = true;
312
382
  };
313
- }, [orgId, apiConfig, runtime.telemetry]);
383
+ }, [orgId, apiConfig, runtime.telemetry, sourceClusterId]);
314
384
  const clustersCache = data.clusters[orgId];
315
385
  const rawClusters = (clustersCache?.data ?? []);
316
386
  const clustersLoading = clustersCache?.isLoading ?? false;
317
- const loading = clustersLoading || creationParametersLoading || organizationsLoading;
387
+ // The feature flag arrives with a request, thus `sourceClusterId` becomes
388
+ // set one render after the page opens, and the read of the source cluster
389
+ // starts one render after that. The form seeds its fields on its first
390
+ // render alone, so it must not open before the source cluster is there.
391
+ // Either the cluster arrives, or the read fails and `apiError` replaces the
392
+ // form.
393
+ const sourceClusterPending = Boolean(sourceClusterId) && !sourceCluster;
394
+ const loading = clustersLoading ||
395
+ creationParametersLoading ||
396
+ organizationsLoading ||
397
+ sourceClusterLoading ||
398
+ (sourceClusterPending && !apiError);
318
399
  const translations = useMemo(() => {
319
400
  return buildCreateClusterTranslations(runtime.i18n?.t);
320
401
  }, [runtime.i18n?.t]);
@@ -374,8 +455,8 @@ export const C4CreateClusterPage = observer(({ orgId, afterCreateModalUrl, talkT
374
455
  ]);
375
456
  }, [organizationToSalesPlan]);
376
457
  const usageByPlanTypeUuid = useMemo(() => {
377
- return deriveClusterUsageByPlanType(rawClusters);
378
- }, [rawClusters]);
458
+ return deriveClusterUsageByPlanType(rawClusters, replaceSource ? sourceClusterId : undefined);
459
+ }, [rawClusters, replaceSource, sourceClusterId]);
379
460
  const planTypes = useMemo(() => {
380
461
  const rawPlanTypes = getPathUnknown(creationParameters, [
381
462
  'clusterPlanTypes',
@@ -587,28 +668,167 @@ export const C4CreateClusterPage = observer(({ orgId, afterCreateModalUrl, talkT
587
668
  },
588
669
  };
589
670
  }, [links.docsByok, salesPlanTypeRaw, translations]);
671
+ /**
672
+ * The channel of the source cluster comes from its generation, and not from
673
+ * the cluster itself: the form offers a generation only inside its channel,
674
+ * thus the two must agree. A generation that the org can no longer select
675
+ * is in no channel here, and the form then opens on its own defaults.
676
+ */
677
+ const sourceChannelUuid = useMemo(() => {
678
+ const generationUuid = getPathString(sourceCluster ?? {}, [
679
+ 'generation',
680
+ 'uuid',
681
+ ]);
682
+ if (!generationUuid) {
683
+ return undefined;
684
+ }
685
+ return channelsWithGenerations.find((channel) => channel.generations.some((generation) => generation.uuid === generationUuid))?.uuid;
686
+ }, [channelsWithGenerations, sourceCluster]);
687
+ const initialValues = useMemo(() => {
688
+ if (!sourceCluster) {
689
+ return undefined;
690
+ }
691
+ const name = getString(sourceCluster, 'name') ?? '';
692
+ // `(copy)` must fit, thus the name of the source cluster is cut first.
693
+ const copySuffix = ' (copy)';
694
+ const duplicateName = `${name.slice(0, MAX_LENGTH_CLUSTER_NAME - copySuffix.length)}${copySuffix}`;
695
+ return {
696
+ name: duplicateName,
697
+ description: getString(sourceCluster, 'description'),
698
+ clusterPlanType: getPathString(sourceCluster, ['planType', 'uuid']),
699
+ channel: sourceChannelUuid,
700
+ generation: getPathString(sourceCluster, ['generation', 'uuid']),
701
+ region: getString(sourceCluster, 'k8sContextUuid'),
702
+ backupRegion: getString(sourceCluster, 'backupRegionId'),
703
+ stageLabel: getPathString(sourceCluster, [
704
+ 'labels',
705
+ 'camunda',
706
+ '0',
707
+ ]),
708
+ autoUpdate: getBoolean(sourceCluster, 'autoUpdate'),
709
+ encryption: getString(sourceCluster, 'encryption'),
710
+ numberOfAllocatedHwPackages: getNumber(sourceCluster, 'numberOfAllocatedHwPackages'),
711
+ tasklistV2Enabled: getPathBoolean(sourceCluster, [
712
+ 'externalMetadata',
713
+ 'tasklistV2Enabled',
714
+ ]),
715
+ identityBackendChecksEnabled: getBoolean(sourceCluster, 'identityBackendChecksEnabled'),
716
+ };
717
+ }, [sourceChannelUuid, sourceCluster]);
718
+ /**
719
+ * True when the plan type of the source cluster has no reservation left.
720
+ * Counted without the exclusion that `usageByPlanTypeUuid` applies, thus
721
+ * the answer does not change when the customer takes the offer.
722
+ */
723
+ const sourcePlanTypeHasNoReservationLeft = useMemo(() => {
724
+ const planTypeUuid = getPathString(sourceCluster ?? {}, [
725
+ 'planType',
726
+ 'uuid',
727
+ ]);
728
+ if (!planTypeUuid) {
729
+ return false;
730
+ }
731
+ const reserved = clusterPlanTypesToReserved[planTypeUuid] ?? 0;
732
+ const used = deriveClusterUsageByPlanType(rawClusters)[planTypeUuid]
733
+ ?.allocatedHardwarePackages ?? 0;
734
+ return reserved - used <= 0;
735
+ }, [clusterPlanTypesToReserved, rawClusters, sourceCluster]);
736
+ const duplicate = useMemo(() => {
737
+ if (!sourceCluster) {
738
+ return undefined;
739
+ }
740
+ // The offer to delete the source cluster appears only when the
741
+ // reservation is what blocks the duplicate, and only for a customer who
742
+ // can delete a cluster. console-backend answers 403 for anyone else.
743
+ const canReplace = sourcePlanTypeHasNoReservationLeft &&
744
+ Boolean(authz.visibilities.clusters?.canDelete);
745
+ return {
746
+ sourceName: `${translations.duplicateNoticeTitle} ${getString(sourceCluster, 'name') ?? ''}`,
747
+ notice: `${translations.duplicateNoticeCopied} ${translations.duplicateNoticeNotCopied}`,
748
+ replace: canReplace
749
+ ? {
750
+ label: translations.duplicateReplaceLabel,
751
+ description: translations.duplicateReplaceDescription,
752
+ checked: replaceSource,
753
+ onChange: setReplaceSource,
754
+ confirm: {
755
+ heading: translations.duplicateReplaceConfirmHeading,
756
+ body: translations.duplicateReplaceConfirmBody,
757
+ confirmationLabel: translations.duplicateReplaceConfirmLabel,
758
+ confirmationValue: DELETE_CONFIRMATION_VALUE,
759
+ primaryButtonText: translations.duplicateReplaceConfirmPrimary,
760
+ secondaryButtonText: translations.duplicateReplaceConfirmSecondary,
761
+ },
762
+ }
763
+ : undefined,
764
+ };
765
+ }, [
766
+ authz.visibilities.clusters?.canDelete,
767
+ replaceSource,
768
+ sourceCluster,
769
+ sourcePlanTypeHasNoReservationLeft,
770
+ translations,
771
+ ]);
772
+ /** The name of each carry-over step, for the warning about a failed one. */
773
+ const carryOverStepLabels = useMemo(() => ({
774
+ clusterClients: translations.duplicateCarryOverClusterClients,
775
+ connectorSecrets: translations.duplicateCarryOverConnectorSecrets,
776
+ alerts: translations.duplicateCarryOverAlerts,
777
+ byom: translations.duplicateCarryOverByom,
778
+ byoidp: translations.duplicateCarryOverByoidp,
779
+ backupSchedule: translations.duplicateCarryOverBackupSchedule,
780
+ }), [translations]);
590
781
  const create = useCallback(async (params) => {
591
782
  selectedEncryptionRef.current = params.encryption;
783
+ const body = {
784
+ name: params.name,
785
+ planTypeId: params.clusterPlanType,
786
+ channelId: params.channel,
787
+ generationId: params.generation,
788
+ k8sContextId: params.region,
789
+ autoUpdate: params.autoUpdate,
790
+ stageLabel: params.stageLabel,
791
+ backupRegionId: params.backupRegion,
792
+ encryption: params.encryption,
793
+ numberOfAllocatedHwPackages: params.numberOfAllocatedHwPackages,
794
+ tasklistV2Enabled: params.tasklistV2Enabled,
795
+ identityBackendChecksEnabled: params.identityBackendChecksEnabled,
796
+ description: params.description,
797
+ };
592
798
  try {
799
+ if (sourceClusterId) {
800
+ const response = await ConsoleClusterService.duplicateCluster({
801
+ params: { orgId, clusterId: sourceClusterId },
802
+ body: { ...body, replaceSource },
803
+ config: apiConfig,
804
+ });
805
+ // The new cluster exists, thus the duplicate did not fail. But a
806
+ // step that did not copy leaves the customer with a cluster that
807
+ // is not the cluster they asked for, and only they can fix it.
808
+ const failedSteps = Object.entries(response.carryOver ?? {})
809
+ .filter(([, result]) => typeof result !== 'string')
810
+ .map(([step]) => carryOverStepLabels[step] ?? step);
811
+ if (failedSteps.length > 0) {
812
+ addC4ConsoleNotification({
813
+ kind: 'warning',
814
+ title: translations.duplicateCarryOverFailedTitle,
815
+ subtitle: `${translations.duplicateCarryOverFailedSubtitle} ${failedSteps.join(', ')}.`,
816
+ });
817
+ }
818
+ // The org now holds one reservation more than it pays for, and
819
+ // only the customer can free it.
820
+ if (replaceSource && response.sourceDeleted === false) {
821
+ addC4ConsoleNotification({
822
+ kind: 'warning',
823
+ title: translations.duplicateSourceNotDeletedTitle,
824
+ subtitle: translations.duplicateSourceNotDeletedSubtitle,
825
+ });
826
+ }
827
+ return { success: true, clusterId: response.clusterId };
828
+ }
593
829
  const response = await ConsoleClusterService.createCluster({
594
- params: {
595
- orgId,
596
- },
597
- body: {
598
- name: params.name,
599
- planTypeId: params.clusterPlanType,
600
- channelId: params.channel,
601
- generationId: params.generation,
602
- k8sContextId: params.region,
603
- autoUpdate: params.autoUpdate,
604
- stageLabel: params.stageLabel,
605
- backupRegionId: params.backupRegion,
606
- encryption: params.encryption,
607
- numberOfAllocatedHwPackages: params.numberOfAllocatedHwPackages,
608
- tasklistV2Enabled: params.tasklistV2Enabled,
609
- identityBackendChecksEnabled: params.identityBackendChecksEnabled,
610
- description: params.description,
611
- },
830
+ params: { orgId },
831
+ body,
612
832
  config: apiConfig,
613
833
  });
614
834
  return { success: true, clusterId: response.clusterId };
@@ -617,11 +837,19 @@ export const C4CreateClusterPage = observer(({ orgId, afterCreateModalUrl, talkT
617
837
  runtime.telemetry?.captureException?.(error, {
618
838
  orgId,
619
839
  widget: 'C4CreateClusterPage',
620
- action: 'createCluster',
840
+ action: sourceClusterId ? 'duplicateCluster' : 'createCluster',
621
841
  });
622
842
  return { success: false };
623
843
  }
624
- }, [apiConfig, orgId, runtime.telemetry]);
844
+ }, [
845
+ apiConfig,
846
+ carryOverStepLabels,
847
+ orgId,
848
+ replaceSource,
849
+ runtime.telemetry,
850
+ sourceClusterId,
851
+ translations,
852
+ ]);
625
853
  const postCreate = useCallback((clusterId) => {
626
854
  if (afterCreateModalUrl) {
627
855
  sendNavigate(onNavigate, {
@@ -772,12 +1000,20 @@ export const C4CreateClusterPage = observer(({ orgId, afterCreateModalUrl, talkT
772
1000
  },
773
1001
  },
774
1002
  },
1003
+ initialValues,
1004
+ duplicate,
775
1005
  cta: {
776
- label: translations.ctaCreate,
1006
+ label: duplicate ? translations.duplicateCta : translations.ctaCreate,
777
1007
  states: {
778
- submitting: translations.ctaSubmitting,
779
- success: translations.ctaSuccess,
780
- error: translations.ctaError,
1008
+ submitting: duplicate
1009
+ ? translations.duplicateCtaSubmitting
1010
+ : translations.ctaSubmitting,
1011
+ success: duplicate
1012
+ ? translations.duplicateCtaSuccess
1013
+ : translations.ctaSuccess,
1014
+ error: duplicate
1015
+ ? translations.duplicateCtaError
1016
+ : translations.ctaError,
781
1017
  },
782
1018
  create,
783
1019
  postCreate,
@@ -804,7 +1040,7 @@ export const C4CreateClusterPage = observer(({ orgId, afterCreateModalUrl, talkT
804
1040
  },
805
1041
  authorizationToggle: {
806
1042
  enabled: true,
807
- title: 'Restrict cluster access to only authorized users and clients',
1043
+ title: 'Authorized access',
808
1044
  authorizationDocs: links.identityAuthorizations,
809
1045
  },
810
1046
  features: {
@@ -815,6 +1051,8 @@ export const C4CreateClusterPage = observer(({ orgId, afterCreateModalUrl, talkT
815
1051
  loading,
816
1052
  translations,
817
1053
  planTypes,
1054
+ initialValues,
1055
+ duplicate,
818
1056
  dualRegionBackups,
819
1057
  displayedSalesPlan,
820
1058
  resolvedTalkToAnExpertUrl,
@@ -834,7 +1072,9 @@ export const C4CreateClusterPage = observer(({ orgId, afterCreateModalUrl, talkT
834
1072
  cancel,
835
1073
  ]);
836
1074
  return (_jsx(C4PageTemplate, { loading: loading, header: {
837
- title: translations.title,
1075
+ title: sourceClusterId
1076
+ ? translations.duplicateTitle
1077
+ : translations.title,
838
1078
  }, breadcrumbs: {
839
1079
  elements: [
840
1080
  {
@@ -846,5 +1086,5 @@ export const C4CreateClusterPage = observer(({ orgId, afterCreateModalUrl, talkT
846
1086
  },
847
1087
  },
848
1088
  ],
849
- }, children: !loading && !apiError && _jsx(C4CreateCluster, { ...createClusterProps }) }));
1089
+ }, children: !loading && !apiError && (_jsx(C4CreateCluster, { ...createClusterProps }, sourceCluster ? sourceClusterId : 'create')) }));
850
1090
  });
@@ -27,4 +27,13 @@ export interface C4CreateClusterPageProps {
27
27
  talkToAnExpertUrl?: string;
28
28
  externalLinks?: C4CreateClusterExternalLinks;
29
29
  onNavigate?: (event: C4CreateClusterNavigateEvent) => void;
30
+ /**
31
+ * The cluster to copy. Give it and the page fills the form with the settings
32
+ * of that cluster, and sends the form to the duplicate endpoint. Omit it and
33
+ * the page is the normal create page.
34
+ *
35
+ * The `console.clusterDuplication` flag gates this. While the flag is off,
36
+ * the page drops the id and makes a normal cluster.
37
+ */
38
+ duplicateOfClusterId?: string;
30
39
  }
@@ -16,28 +16,11 @@ import { useC4ConsoleData } from '../../runtime/c4-console-data-context.js';
16
16
  import { useC4ConsoleRuntime, useC4FeatureFlag, } from '../../runtime/c4-console-runtime-context.js';
17
17
  import { CLUSTER_CREATION_BLOCKED_FLAG } from '../../runtime/cluster-creation-blocked.js';
18
18
  import { toApiConfig } from '../../runtime/to-api-config.js';
19
+ import { safeTranslate } from '../../utils/safe-translate.js';
19
20
  import { isClusterReconciliationPaused } from '../is-cluster-reconciliation-paused.js';
20
21
  const DAY = 24 * 60 * 60 * 1000;
21
22
  // Same window the console frontend requests for these charts.
22
23
  const USAGE_DAYS = 360;
23
- function safeTranslate(t, key, fallback, options) {
24
- try {
25
- const translated = t?.(key, options);
26
- if (!translated || translated === key) {
27
- return fallback;
28
- }
29
- if (key.includes(':')) {
30
- const withoutNamespace = key.split(':').slice(1).join(':');
31
- if (translated === withoutNamespace) {
32
- return fallback;
33
- }
34
- }
35
- return translated;
36
- }
37
- catch {
38
- return fallback;
39
- }
40
- }
41
24
  function formatDateTime(date) {
42
25
  const formatter = new Intl.DateTimeFormat('en-GB', {
43
26
  day: '2-digit',
@@ -53,7 +53,7 @@ const C4ClusterConnectorSecretsWidgetImpl = ({ orgId, clusterId, scope = 'cluste
53
53
  canRead: Boolean(orgPermissions?.cluster.connectorSecrets.read),
54
54
  canUpdate: Boolean(orgPermissions?.cluster.connectorSecrets.update),
55
55
  canDelete: Boolean(orgPermissions?.cluster.connectorSecrets.delete),
56
- }, docsUrl: resolvedUrls.docs.connectorSecrets, scope: scope, t: t, onNavigate: onNavigate, onPanelState: setPanelState })] }));
56
+ }, docsUrl: resolvedUrls.docs.connectorSecrets, clusterSecretsDocsUrl: resolvedUrls.docs.clusterSecrets, scope: scope, t: t, onNavigate: onNavigate, onPanelState: setPanelState })] }));
57
57
  };
58
58
  // Reads console data during render, so it must be an observer.
59
59
  export const C4ClusterConnectorSecretsWidget = observer(C4ClusterConnectorSecretsWidgetImpl);
@@ -14,18 +14,10 @@ import { useC4ConsoleAuthz } from '../../runtime/c4-console-authz.js';
14
14
  import { useC4ConsoleData } from '../../runtime/c4-console-data-context.js';
15
15
  import { useC4ConsoleRuntime, useC4DesignSystem, } from '../../runtime/c4-console-runtime-context.js';
16
16
  import { toIdentityApiBaseUrl } from '../../runtime/to-identity-api-base-url.js';
17
+ import { safeTranslate } from '../../utils/safe-translate.js';
17
18
  function isRecord(value) {
18
19
  return Boolean(value) && typeof value === 'object';
19
20
  }
20
- function safeTranslate(t, key, fallback) {
21
- try {
22
- const translated = t?.(key);
23
- return translated && translated !== key ? translated : fallback;
24
- }
25
- catch {
26
- return fallback;
27
- }
28
- }
29
21
  function sendNavigate(onNavigate, event) {
30
22
  onNavigate?.(event);
31
23
  }
@@ -14,6 +14,7 @@ export type Tr = (key: string, fallback: string) => string;
14
14
  */
15
15
  export type ScopedTr = (key: string, clusterFallback: string, environmentFallback: string) => string;
16
16
  export declare function makeScopedTr(tr: Tr, scope: C4WidgetScope): ScopedTr;
17
+ /** Binds `t` to the `jobDashboard:` namespace of this module. */
17
18
  export declare function makeTr(t: TranslateFn | undefined): Tr;
18
19
  export declare function safeT(t: TranslateFn | undefined, key: string, fallback: string): string;
19
20
  export declare function getRegion(cluster: ConsoleClusterDto): string;
@@ -3,48 +3,18 @@
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 { ENVIRONMENT_KEY_SUFFIX } from '../../utils/safe-translate.js';
6
+ import { ENVIRONMENT_KEY_SUFFIX, safeTranslate, } from '../../utils/safe-translate.js';
7
7
  export function makeScopedTr(tr, scope) {
8
8
  return (key, clusterFallback, environmentFallback) => scope === 'environment'
9
9
  ? tr(`${key}${ENVIRONMENT_KEY_SUFFIX}`, environmentFallback)
10
10
  : tr(key, clusterFallback);
11
11
  }
12
+ /** Binds `t` to the `jobDashboard:` namespace of this module. */
12
13
  export function makeTr(t) {
13
- return (key, fallback) => {
14
- if (!t)
15
- return fallback;
16
- try {
17
- const full = `jobDashboard:${key}`;
18
- const result = t(full);
19
- // Guard against the namespace-stripped form (e.g. t('jobDashboard:a.b') → 'a.b')
20
- if (!result || result === full || result === key) {
21
- return fallback;
22
- }
23
- return result;
24
- }
25
- catch {
26
- return fallback;
27
- }
28
- };
14
+ return (key, fallback) => safeTranslate(t, `jobDashboard:${key}`, fallback);
29
15
  }
30
16
  export function safeT(t, key, fallback) {
31
- if (!t)
32
- return fallback;
33
- try {
34
- const result = t(key);
35
- // Some i18n implementations return the key with the namespace prefix stripped
36
- // (e.g. t('ns:a.b') → 'a.b') when a key is missing. Treat that as a miss too.
37
- const keyWithoutNamespace = key.includes(':')
38
- ? key.split(':').slice(1).join(':')
39
- : key;
40
- if (!result || result === key || result === keyWithoutNamespace) {
41
- return fallback;
42
- }
43
- return result;
44
- }
45
- catch {
46
- return fallback;
47
- }
17
+ return safeTranslate(t, key, fallback);
48
18
  }
49
19
  export function getRegion(cluster) {
50
20
  const zeebeRestUrl = cluster.status?.zeebeRestUrl;
@@ -23,6 +23,7 @@ import { useHubApiNaming } from '../../runtime/use-hub-api-naming.js';
23
23
  import { Link, Stack } from '../../ui/index.js';
24
24
  import { clientErrorMessage } from '../../utils/http-error-message.js';
25
25
  import { legacySectionRoles } from '../../utils/role-labels.js';
26
+ import { safeTranslate } from '../../utils/safe-translate.js';
26
27
  import { useExtendTrial } from '../use-extend-trial.js';
27
28
  import { C4ManagementPage } from './c4-management-page.js';
28
29
  import { managementTab } from './management-tabs.js';
@@ -100,26 +101,6 @@ function getNestedValue(record, path) {
100
101
  function getNestedBoolean(record, path) {
101
102
  return getNestedValue(record, path) === true;
102
103
  }
103
- function safeTranslate(t, key, fallback, options) {
104
- try {
105
- const translated = t?.(key, options);
106
- if (!translated || translated === key) {
107
- return fallback;
108
- }
109
- // i18next can return the key *without* the namespace when the namespace is missing.
110
- // Example: `orgmanagement:tabs.api.search` -> `tabs.api.search`
111
- if (key.includes(':')) {
112
- const withoutNamespace = key.split(':').slice(1).join(':');
113
- if (translated === withoutNamespace) {
114
- return fallback;
115
- }
116
- }
117
- return translated;
118
- }
119
- catch {
120
- return fallback;
121
- }
122
- }
123
104
  // Usage charts render one line series (and one legend entry) per cluster. Orgs
124
105
  // with hundreds of clusters overflow the legend and break the layout, so cap the
125
106
  // number of distinct series to the top-N clusters by total value and roll the