@camunda/ccma-saas-frontend 0.20.5 → 0.21.1

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.
@@ -215,6 +215,7 @@ export { C4ClusterDetailsApp } from './widgets/cluster-details/c4-cluster-detail
215
215
  export type { C4ClusterDetailsAppProps, C4ClusterDetailsNavigateEvent, C4ClusterDetailsTabId, } from './widgets/cluster-details/c4-cluster-details-app.types.js';
216
216
  export { C4ClusterDetailsPage } from './widgets/cluster-details/c4-cluster-details-page.js';
217
217
  export type { C4ClusterDetailsPageBanner, C4ClusterDetailsPageProps, C4ClusterDetailsTab, } from './widgets/cluster-details/c4-cluster-details-page.types.js';
218
+ export { parseClusterDetailsTabId } from './widgets/cluster-details/cluster-details-tab-url.js';
218
219
  export { CLUSTER_DETAILS_TABS, type ClusterDetailsTabDescriptor, clusterDetailsTab, } from './widgets/cluster-details/cluster-details-tabs.js';
219
220
  export { C4ClustersPage } from './widgets/clusters/c4-clusters-page.js';
220
221
  export type { C4ClustersNavigateEvent, C4ClustersPageProps, C4ClustersPageTranslations, } from './widgets/clusters/c4-clusters-page.types.js';
package/lib/esm/index.js CHANGED
@@ -123,6 +123,7 @@ export { ENVIRONMENT_KEY_SUFFIX, safeTranslate, scopedTranslate, } from './utils
123
123
  export { C4ClusterClientDetailsApp } from './widgets/cluster-client-details/c4-cluster-client-details-app.js';
124
124
  export { C4ClusterDetailsApp } from './widgets/cluster-details/c4-cluster-details-app.js';
125
125
  export { C4ClusterDetailsPage } from './widgets/cluster-details/c4-cluster-details-page.js';
126
+ export { parseClusterDetailsTabId } from './widgets/cluster-details/cluster-details-tab-url.js';
126
127
  export { CLUSTER_DETAILS_TABS, clusterDetailsTab, } from './widgets/cluster-details/cluster-details-tabs.js';
127
128
  export { C4ClustersPage } from './widgets/clusters/c4-clusters-page.js';
128
129
  export { C4ConnectorManagementExecutableDetailsPage } from './widgets/connector-management/c4-connector-management-executable-details-page.js';
@@ -21,6 +21,7 @@ import { clusterHealthOverride } from '../cluster-health-override.js';
21
21
  import { useClusterApiClients } from '../environment/use-cluster-api-clients.js';
22
22
  import { useClusterVersionFlags } from '../environment/use-cluster-version-flags.js';
23
23
  import { C4ClusterDetailsPage } from './c4-cluster-details-page.js';
24
+ import { readClusterDetailsTabFromUrl, writeClusterDetailsTabToUrl, } from './cluster-details-tab-url.js';
24
25
  import { clusterDetailsTab } from './cluster-details-tabs.js';
25
26
  import { getClusterRegionCode } from './cluster-region-code.js';
26
27
  import { C4ClusterDetailsActivityTab } from './tabs/c4-cluster-details-activity-tab.js';
@@ -350,7 +351,16 @@ export const C4ClusterDetailsApp = observer((props) => {
350
351
  const [clusterLoad24h, setClusterLoad24h] = useState([]);
351
352
  const [clusterLoadLoading, setClusterLoadLoading] = useState(false);
352
353
  const [statisticsConfig, setStatisticsConfig] = useState(undefined);
353
- const [activeTabId, setActiveTabId] = useState(props.desiredTabId ?? 'overview');
354
+ // Order: `desiredTabId` from the host, then `?tab=` in the URL, then the
355
+ // default. The URL is read once. A host that gives no `desiredTabId` (for
356
+ // example Hub) gets its tab back after a reload. A host that has its own
357
+ // tab routes opts out with `syncTabToUrl={false}`.
358
+ const syncTabToUrl = props.syncTabToUrl !== false && !props.desiredTabId;
359
+ const [initialUrlTabId] = useState(() => syncTabToUrl ? readClusterDetailsTabFromUrl() : undefined);
360
+ // Set when the URL tab is not a tab of this cluster (for example a hidden
361
+ // tab). Then the normal default applies, including the failover rule.
362
+ const [urlTabDropped, setUrlTabDropped] = useState(false);
363
+ const [activeTabId, setActiveTabId] = useState(props.desiredTabId ?? initialUrlTabId ?? 'overview');
354
364
  useEffect(() => {
355
365
  if (props.desiredTabId) {
356
366
  setActiveTabId(props.desiredTabId);
@@ -1343,13 +1353,38 @@ export const C4ClusterDetailsApp = observer((props) => {
1343
1353
  useEffect(() => {
1344
1354
  if (props.desiredTabId)
1345
1355
  return;
1356
+ // A URL tab beats the failover default, except `overview`: it is the
1357
+ // default too, and a stale `?tab=overview` from an earlier click must not
1358
+ // switch the Encryption default off on every reload.
1359
+ if (initialUrlTabId && initialUrlTabId !== 'overview' && !urlTabDropped) {
1360
+ return;
1361
+ }
1346
1362
  if (appliedFailoverEncryptionDefaultRef.current)
1347
1363
  return;
1348
1364
  if (!needsFailoverEncryptionAction)
1349
1365
  return;
1350
1366
  appliedFailoverEncryptionDefaultRef.current = true;
1351
1367
  setActiveTabId('encryption');
1352
- }, [props.desiredTabId, needsFailoverEncryptionAction]);
1368
+ }, [
1369
+ props.desiredTabId,
1370
+ initialUrlTabId,
1371
+ urlTabDropped,
1372
+ needsFailoverEncryptionAction,
1373
+ ]);
1374
+ // A host with `syncTabToUrl={false}` (Console) can go from a route with a
1375
+ // tab to a route with no valid tab. `desiredTabId` is then `undefined`, and
1376
+ // the tab must go back to the normal default, as on a first visit.
1377
+ const previousDesiredTabIdRef = useRef(props.desiredTabId);
1378
+ useEffect(() => {
1379
+ const previous = previousDesiredTabIdRef.current;
1380
+ previousDesiredTabIdRef.current = props.desiredTabId;
1381
+ if (props.desiredTabId || !previous || props.syncTabToUrl !== false) {
1382
+ return;
1383
+ }
1384
+ setActiveTabId(needsFailoverEncryptionAction ? 'encryption' : 'overview');
1385
+ // Only a change of `desiredTabId` runs this. The other values are read
1386
+ // at that time.
1387
+ }, [props.desiredTabId]);
1353
1388
  const encryptionComponent = (_jsx(C4ClusterDetailsEncryptionTab, { cluster: cluster, orgId: props.orgId, clusterId: props.clusterId, apiConfig: apiConfig, translate: t ?? ((key) => key), activeTabId: activeTabId, onReloadCluster: reloadCluster, restoreInProgress: cluster?.restoreInProgress, isFailoverTarget: isFailoverTarget, secondaryReplicationNotReady: secondaryReplicationNotReady, docsUrls: {
1354
1389
  encryption: urls.docs.encryption,
1355
1390
  encryptionCli: urls.docs.encryptionCli,
@@ -1503,6 +1538,35 @@ export const C4ClusterDetailsApp = observer((props) => {
1503
1538
  cluster?.generation?.versions?.zeebe,
1504
1539
  t,
1505
1540
  ]);
1541
+ // The org request is done, with a result or with an error. After an error
1542
+ // `orgInfo` stays `undefined`, so `orgInfo` alone cannot tell "not yet" from
1543
+ // "failed".
1544
+ const orgInfoRequest = data.orgInfo?.[props.orgId];
1545
+ const isOrgInfoSettled = Boolean(orgInfoRequest && !orgInfoRequest.isLoading);
1546
+ // Check the URL tab against the tabs of this cluster once the data that
1547
+ // decides tab visibility has loaded.
1548
+ useEffect(() => {
1549
+ if (!initialUrlTabId || urlTabDropped)
1550
+ return;
1551
+ if (authz.isLoading ||
1552
+ isClusterLoading ||
1553
+ isCreationParametersLoading ||
1554
+ !isOrgInfoSettled) {
1555
+ return;
1556
+ }
1557
+ if (tabs.some((tab) => tab.id === initialUrlTabId))
1558
+ return;
1559
+ setUrlTabDropped(true);
1560
+ setActiveTabId((current) => current === initialUrlTabId ? 'overview' : current);
1561
+ }, [
1562
+ initialUrlTabId,
1563
+ urlTabDropped,
1564
+ authz.isLoading,
1565
+ isClusterLoading,
1566
+ isCreationParametersLoading,
1567
+ isOrgInfoSettled,
1568
+ tabs,
1569
+ ]);
1506
1570
  useEffect(() => {
1507
1571
  // Only fall back once we have confirmed that the cluster doesn't
1508
1572
  // support PrivateLink. Both the cluster fetch and the
@@ -1554,6 +1618,8 @@ export const C4ClusterDetailsApp = observer((props) => {
1554
1618
  clusterId: props.clusterId,
1555
1619
  tabId: next,
1556
1620
  });
1621
+ if (syncTabToUrl)
1622
+ writeClusterDetailsTabToUrl(next);
1557
1623
  };
1558
1624
  return (_jsxs(_Fragment, { children: [_jsx(C4ClusterDetailsPage, { loading: isClusterLoading || authz.isLoading, padding: props.padding, clusterName: cluster?.name, phaseTag: headerPhaseTag, healthStatus: headerHealthStatus, versionLabel: headerVersionLabel, regionCode: headerRegionCode, isDevelopmentPlan: cluster?.planType?.development, urls: { clusters: urls.clusters }, onNavigateToClusters: () => props.onNavigate?.({ kind: 'clusters', orgId: props.orgId }), menu: {
1559
1625
  canRename,
@@ -43,6 +43,14 @@ export interface C4ClusterDetailsAppProps {
43
43
  clusterId: string;
44
44
  desiredTabId?: C4ClusterDetailsTabId;
45
45
  onNavigate?: (event: C4ClusterDetailsNavigateEvent) => void;
46
+ /**
47
+ * Keep the active tab in the `?tab=` search param of the browser URL
48
+ * (`history.replaceState`) and read it back on load. Defaults to `true`, so a
49
+ * host with no tab routes gets the tab back after a reload. Set `false` if
50
+ * the host owns the URL or uses `?tab=` itself. It has no effect when
51
+ * `desiredTabId` is set: then the host controls the tab.
52
+ */
53
+ syncTabToUrl?: boolean;
46
54
  urls: C4ClusterDetailsUrls;
47
55
  /**
48
56
  * Side/top/bottom padding around the page. Defaults to `'default'`.
@@ -0,0 +1,22 @@
1
+ import type { C4ClusterDetailsTabId } from './c4-cluster-details-app.types.js';
2
+ /**
3
+ * Search param that holds the active tab. The name is the same one that the
4
+ * Console route uses (`?tab=`).
5
+ */
6
+ export declare const CLUSTER_DETAILS_TAB_PARAM = "tab";
7
+ /**
8
+ * Turn a raw `tab` value into a tab id. Return `undefined` if the value is
9
+ * not a known tab.
10
+ */
11
+ export declare function parseClusterDetailsTabId(value: string | null | undefined): C4ClusterDetailsTabId | undefined;
12
+ /**
13
+ * Read the tab from `window.location.search`. Return `undefined` if there is
14
+ * no window, no `tab` param, or an unknown value.
15
+ */
16
+ export declare function readClusterDetailsTabFromUrl(): C4ClusterDetailsTabId | undefined;
17
+ /**
18
+ * Write the tab to the current URL with `history.replaceState`. This keeps
19
+ * the other search params, the hash and `history.state`, so a host router does
20
+ * not see a new entry. It never adds a history entry.
21
+ */
22
+ export declare function writeClusterDetailsTabToUrl(tabId: C4ClusterDetailsTabId): void;
@@ -0,0 +1,59 @@
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 { CLUSTER_DETAILS_TABS } from './cluster-details-tabs.js';
7
+ /**
8
+ * Search param that holds the active tab. The name is the same one that the
9
+ * Console route uses (`?tab=`).
10
+ */
11
+ export const CLUSTER_DETAILS_TAB_PARAM = 'tab';
12
+ // Console used the old name `secureConnectivity` for this tab in its URLs.
13
+ const TAB_ALIASES = {
14
+ secureConnectivity: 'privateNetworking',
15
+ };
16
+ /**
17
+ * Turn a raw `tab` value into a tab id. Return `undefined` if the value is
18
+ * not a known tab.
19
+ */
20
+ export function parseClusterDetailsTabId(value) {
21
+ if (!value)
22
+ return undefined;
23
+ const aliased = TAB_ALIASES[value] ?? value;
24
+ return CLUSTER_DETAILS_TABS.find((tab) => tab.id === aliased)?.id;
25
+ }
26
+ /**
27
+ * Read the tab from `window.location.search`. Return `undefined` if there is
28
+ * no window, no `tab` param, or an unknown value.
29
+ */
30
+ export function readClusterDetailsTabFromUrl() {
31
+ try {
32
+ if (typeof window === 'undefined')
33
+ return undefined;
34
+ const value = new URLSearchParams(window.location.search).get(CLUSTER_DETAILS_TAB_PARAM);
35
+ return parseClusterDetailsTabId(value);
36
+ }
37
+ catch {
38
+ return undefined;
39
+ }
40
+ }
41
+ /**
42
+ * Write the tab to the current URL with `history.replaceState`. This keeps
43
+ * the other search params, the hash and `history.state`, so a host router does
44
+ * not see a new entry. It never adds a history entry.
45
+ */
46
+ export function writeClusterDetailsTabToUrl(tabId) {
47
+ try {
48
+ if (typeof window === 'undefined')
49
+ return;
50
+ const url = new URL(window.location.href);
51
+ if (url.searchParams.get(CLUSTER_DETAILS_TAB_PARAM) === tabId)
52
+ return;
53
+ url.searchParams.set(CLUSTER_DETAILS_TAB_PARAM, tabId);
54
+ window.history.replaceState(window.history.state, '', `${url.pathname}${url.search}${url.hash}`);
55
+ }
56
+ catch {
57
+ // The URL is only a hint for a reload. If it fails, the tab still works.
58
+ }
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camunda/ccma-saas-frontend",
3
- "version": "0.20.5",
3
+ "version": "0.21.1",
4
4
  "description": "Camunda Composite Components",
5
5
  "bugs": {
6
6
  "url": "https://github.com/camunda/camunda-cloud-management-apps/issues"
@@ -46,7 +46,7 @@
46
46
  "@camunda/c4-connectors": "1.10.3",
47
47
  "@playwright/test": "1.63.0",
48
48
  "@camunda/c4-identity": "0.0.45",
49
- "@camunda/camunda-composite-components": "0.25.4",
49
+ "@camunda/camunda-composite-components": "0.25.5",
50
50
  "@camunda/design-system": "0.68.1",
51
51
  "@carbon/react": "1.117.0",
52
52
  "recharts": "3.10.1",
@@ -85,8 +85,8 @@
85
85
  "react-markdown": "^8.0.7 || ^10.0.0"
86
86
  },
87
87
  "dependencies": {
88
- "@camunda/ccma-api": "5.13.0",
89
- "@camunda/ccma-shared-types": "9.3.0",
88
+ "@camunda/ccma-api": "5.13.1",
89
+ "@camunda/ccma-shared-types": "10.0.0",
90
90
  "@pactsafe/pactsafe-react-sdk": "2.15.0",
91
91
  "cron-parser": "5.10.1",
92
92
  "mobx": "6.16.1",