@camunda/ccma-saas-frontend 0.1.0 → 0.3.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.
- package/lib/esm/components/c4-billing-page/c4-billing-page.mocks.d.ts +3 -0
- package/lib/esm/components/c4-billing-page/c4-billing-page.mocks.js +154 -0
- package/lib/esm/components/c4-billing-page/elements/value-metric.d.ts +2 -0
- package/lib/esm/components/c4-billing-page/elements/value-metric.js +14 -3
- package/lib/esm/components/c4-billing-page/elements/value-metric.spec.js +18 -0
- package/lib/esm/components/c4-charts-dashboard/elements/alluvial-chart.js +58 -1
- package/lib/esm/components/c4-charts-dashboard/elements/bar-chart.js +40 -6
- package/lib/esm/components/c4-charts-dashboard/elements/line-chart.js +6 -0
- package/lib/esm/components/c4-cluster-details-alerts/c4-cluster-details-alerts.mocks.d.ts +5 -0
- package/lib/esm/components/c4-cluster-details-alerts/c4-cluster-details-alerts.mocks.js +83 -0
- package/lib/esm/components/c4-cluster-details-clients/c4-cluster-details-clients.mocks.d.ts +6 -0
- package/lib/esm/components/c4-cluster-details-clients/c4-cluster-details-clients.mocks.js +79 -0
- package/lib/esm/components/c4-cluster-details-connector-secrets/c4-cluster-details-connector-secrets.mocks.d.ts +3 -0
- package/lib/esm/components/c4-cluster-details-connector-secrets/c4-cluster-details-connector-secrets.mocks.js +65 -0
- package/lib/esm/components/c4-cluster-details-hot-backups/c4-cluster-details-hot-backups.mocks.d.ts +60 -0
- package/lib/esm/components/c4-cluster-details-hot-backups/c4-cluster-details-hot-backups.mocks.js +143 -0
- package/lib/esm/components/c4-cluster-details-ip-whitelist/c4-cluster-details-ip-whitelist.mocks.d.ts +6 -0
- package/lib/esm/components/c4-cluster-details-ip-whitelist/c4-cluster-details-ip-whitelist.mocks.js +51 -0
- package/lib/esm/components/c4-cluster-list/c4-cluster-list.d.ts +1 -1
- package/lib/esm/components/c4-cluster-list/c4-cluster-list.js +63 -2
- package/lib/esm/components/c4-cluster-list/c4-cluster-list.mocks.d.ts +4 -0
- package/lib/esm/components/c4-cluster-list/c4-cluster-list.mocks.js +132 -0
- package/lib/esm/components/c4-cluster-list/c4-cluster-list.types.d.ts +7 -0
- package/lib/esm/components/c4-cluster-overview/applications.d.ts +1 -1
- package/lib/esm/components/c4-cluster-overview/applications.js +17 -3
- package/lib/esm/components/c4-cluster-overview/applications.spec.js +27 -1
- package/lib/esm/components/c4-cluster-overview/c4-cluster-overview.mocks.d.ts +8 -0
- package/lib/esm/components/c4-cluster-overview/c4-cluster-overview.mocks.js +203 -0
- package/lib/esm/components/c4-cluster-overview/cluster-details.d.ts +2 -0
- package/lib/esm/components/c4-cluster-overview/cluster-details.js +59 -9
- package/lib/esm/components/c4-cluster-overview/cluster-load.js +38 -3
- package/lib/esm/components/c4-cluster-settings/c4-cluster-settings.mocks.d.ts +16 -0
- package/lib/esm/components/c4-cluster-settings/c4-cluster-settings.mocks.js +104 -0
- package/lib/esm/components/c4-cluster-settings/elements/app-integrations-toggle.d.ts +14 -0
- package/lib/esm/components/c4-cluster-settings/elements/app-integrations-toggle.js +12 -0
- package/lib/esm/components/c4-cluster-settings/elements/cluster-settings.d.ts +5 -1
- package/lib/esm/components/c4-cluster-settings/elements/cluster-settings.js +10 -3
- package/lib/esm/components/c4-cluster-settings/elements/external-identity-provider-modal.d.ts +20 -0
- package/lib/esm/components/c4-cluster-settings/elements/external-identity-provider-modal.js +85 -0
- package/lib/esm/components/c4-cluster-settings/elements/external-identity-provider-modal.spec.d.ts +1 -0
- package/lib/esm/components/c4-cluster-settings/elements/external-identity-provider-modal.spec.js +93 -0
- package/lib/esm/components/c4-cluster-settings/elements/external-identity-provider.d.ts +20 -0
- package/lib/esm/components/c4-cluster-settings/elements/external-identity-provider.js +15 -0
- package/lib/esm/components/c4-cluster-settings/elements/external-identity-provider.spec.d.ts +1 -0
- package/lib/esm/components/c4-cluster-settings/elements/external-identity-provider.spec.js +50 -0
- package/lib/esm/components/c4-cluster-settings/elements/optimize-filtering-settings.d.ts +10 -4
- package/lib/esm/components/c4-cluster-settings/elements/optimize-filtering-settings.js +116 -24
- package/lib/esm/components/c4-cluster-settings/elements/optimize-filtering-settings.spec.d.ts +1 -0
- package/lib/esm/components/c4-cluster-settings/elements/optimize-filtering-settings.spec.js +120 -0
- package/lib/esm/components/c4-cluster-tag-selector/c4-cluster-tag-selector.js +19 -1
- package/lib/esm/components/c4-console-dashboard/c4-console-dashboard.mocks.d.ts +2 -0
- package/lib/esm/components/c4-console-dashboard/c4-console-dashboard.mocks.js +186 -0
- package/lib/esm/components/c4-create-alert-modal/c4-create-alert-modal.d.ts +2 -0
- package/lib/esm/components/c4-create-alert-modal/c4-create-alert-modal.js +132 -0
- package/lib/esm/components/c4-create-alert-modal/c4-create-alert-modal.mocks.d.ts +2 -0
- package/lib/esm/components/c4-create-alert-modal/c4-create-alert-modal.mocks.js +20 -0
- package/lib/esm/components/c4-create-alert-modal/c4-create-alert-modal.types.d.ts +22 -0
- package/lib/esm/components/c4-create-alert-modal/c4-create-alert-modal.types.js +6 -0
- package/lib/esm/components/c4-create-cluster/c4-create-cluster-tile-grid.d.ts +32 -0
- package/lib/esm/components/c4-create-cluster/c4-create-cluster-tile-grid.js +71 -0
- package/lib/esm/components/c4-create-cluster/c4-create-cluster-tile-grid.spec.d.ts +1 -0
- package/lib/esm/components/c4-create-cluster/c4-create-cluster-tile-grid.spec.js +83 -0
- package/lib/esm/components/c4-create-cluster/c4-create-cluster.js +31 -58
- package/lib/esm/components/c4-create-cluster/c4-create-cluster.mocks.d.ts +64 -0
- package/lib/esm/components/c4-create-cluster/c4-create-cluster.mocks.js +298 -0
- package/lib/esm/components/c4-create-cluster-api-client-modal/c4-create-cluster-api-client-modal.js +48 -30
- package/lib/esm/components/c4-create-cluster-api-client-modal/c4-create-cluster-api-client-modal.mocks.d.ts +2 -0
- package/lib/esm/components/c4-create-cluster-api-client-modal/c4-create-cluster-api-client-modal.mocks.js +23 -0
- package/lib/esm/components/c4-create-cluster-api-client-modal/c4-create-cluster-api-client-modal.types.d.ts +2 -0
- package/lib/esm/components/c4-create-connector-secret-modal/c4-create-connector-secret-modal.mocks.d.ts +2 -0
- package/lib/esm/components/c4-create-connector-secret-modal/c4-create-connector-secret-modal.mocks.js +15 -0
- package/lib/esm/components/c4-create-console-api-client-modal/c4-create-console-api-client-modal.js +5 -5
- package/lib/esm/components/c4-create-console-api-client-modal/c4-create-console-api-client-modal.mocks.d.ts +2 -0
- package/lib/esm/components/c4-create-console-api-client-modal/c4-create-console-api-client-modal.mocks.js +13 -0
- package/lib/esm/components/c4-create-console-api-client-modal/c4-create-console-api-client-modal.types.d.ts +1 -0
- package/lib/esm/components/c4-create-ip-whitelist-modal/c4-create-ip-whitelist-modal.d.ts +2 -0
- package/lib/esm/components/c4-create-ip-whitelist-modal/c4-create-ip-whitelist-modal.js +77 -0
- package/lib/esm/components/c4-create-ip-whitelist-modal/c4-create-ip-whitelist-modal.mocks.d.ts +2 -0
- package/lib/esm/components/c4-create-ip-whitelist-modal/c4-create-ip-whitelist-modal.mocks.js +11 -0
- package/lib/esm/components/c4-create-ip-whitelist-modal/c4-create-ip-whitelist-modal.types.d.ts +14 -0
- package/lib/esm/components/c4-create-ip-whitelist-modal/c4-create-ip-whitelist-modal.types.js +6 -0
- package/lib/esm/components/c4-data-table/c4-data-table.js +117 -34
- package/lib/esm/components/c4-data-table/c4-data-table.stability.spec.d.ts +1 -0
- package/lib/esm/components/c4-data-table/c4-data-table.stability.spec.js +151 -0
- package/lib/esm/components/c4-job-dashboard-details-page/c4-job-dashboard-details-page.mocks.d.ts +2 -0
- package/lib/esm/components/c4-job-dashboard-details-page/c4-job-dashboard-details-page.mocks.js +231 -0
- package/lib/esm/components/c4-job-dashboard-details-page/elements/c4-job-dashboard-piechart.js +56 -2
- package/lib/esm/components/c4-job-dashboard-details-page/elements/c4-job-dashboard-time-chart.js +36 -1
- package/lib/esm/components/c4-job-dashboard-overview-page/c4-job-dashboard-overview.mocks.d.ts +2 -0
- package/lib/esm/components/c4-job-dashboard-overview-page/c4-job-dashboard-overview.mocks.js +102 -0
- package/lib/esm/components/c4-job-dashboard-shared/c4-job-dashboard-ds-colors.d.ts +10 -0
- package/lib/esm/components/c4-job-dashboard-shared/c4-job-dashboard-ds-colors.js +16 -0
- 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 +103 -1
- package/lib/esm/components/c4-management-activity/c4-management-activity.mocks.d.ts +4 -0
- package/lib/esm/components/c4-management-activity/c4-management-activity.mocks.js +63 -0
- package/lib/esm/components/c4-management-activity/c4-management-activity.types.d.ts +11 -0
- package/lib/esm/components/c4-management-api/c4-management-api.mocks.d.ts +43 -0
- package/lib/esm/components/c4-management-api/c4-management-api.mocks.js +118 -0
- package/lib/esm/components/c4-management-overview/c4-management-overview.js +6 -4
- package/lib/esm/components/c4-old-dashboard/c4-old-dashboard.js +1 -1
- package/lib/esm/components/c4-old-dashboard/c4-old-dashboard.types.d.ts +1 -0
- package/lib/esm/components/c4-selectable-tile/c4-selectable-tile.js +4 -1
- package/lib/esm/components/c4-telemetry-page/telemetry-for-component.js +58 -36
- package/lib/esm/components/c4-usage-history/elements/usage-history-charts.js +6 -0
- package/lib/esm/components/c4-user-details/tabs/authorized-resources.js +3 -1
- package/lib/esm/components/shared-charts/ds-charts.smoke.spec.d.ts +1 -0
- package/lib/esm/components/shared-charts/ds-charts.smoke.spec.js +47 -0
- package/lib/esm/components/shared-charts/ds-line-chart.d.ts +33 -0
- package/lib/esm/components/shared-charts/ds-line-chart.js +55 -0
- package/lib/esm/components/shared-charts/ds-meter-chart.d.ts +22 -0
- package/lib/esm/components/shared-charts/ds-meter-chart.js +48 -0
- package/lib/esm/components/shared-charts/recharts-tokens.d.ts +24 -0
- package/lib/esm/components/shared-charts/recharts-tokens.js +51 -0
- package/lib/esm/externalUrls.const.d.ts +2 -0
- package/lib/esm/externalUrls.const.js +7 -0
- package/lib/esm/externalUrls.const.spec.js +2 -0
- package/lib/esm/i18n/en/entities/orgroles.json +0 -16
- package/lib/esm/i18n/en/pages/clusterdetails.json +9 -1
- package/lib/esm/i18n/en/pages/orgmanagement.json +9 -2
- package/lib/esm/index.d.ts +17 -2
- package/lib/esm/index.js +11 -2
- package/lib/esm/runtime/c4-console-authz.d.ts +26 -0
- package/lib/esm/runtime/c4-console-authz.js +58 -28
- package/lib/esm/runtime/c4-console-authz.spec.js +84 -17
- package/lib/esm/runtime/c4-console-data-context.js +40 -0
- package/lib/esm/runtime/c4-console-data-context.types.d.ts +19 -1
- package/lib/esm/runtime/c4-console-data-store.d.ts +25 -1
- package/lib/esm/runtime/c4-console-data-store.js +145 -31
- package/lib/esm/runtime/c4-console-data-store.nav.spec.d.ts +1 -0
- package/lib/esm/runtime/c4-console-data-store.nav.spec.js +121 -0
- package/lib/esm/runtime/c4-console-data-store.spec.js +35 -6
- package/lib/esm/runtime/c4-console-events-context.d.ts +18 -0
- package/lib/esm/runtime/c4-console-events-context.js +62 -0
- package/lib/esm/runtime/c4-console-runtime.types.d.ts +12 -0
- package/lib/esm/runtime/c4-user-notifications-context.d.ts +19 -0
- package/lib/esm/runtime/c4-user-notifications-context.js +201 -0
- package/lib/esm/runtime/c4-user-notifications-context.spec.d.ts +1 -0
- package/lib/esm/runtime/c4-user-notifications-context.spec.js +80 -0
- package/lib/esm/runtime/c4-user-notifications-context.types.d.ts +31 -0
- package/lib/esm/runtime/c4-user-notifications-context.types.js +6 -0
- package/lib/esm/runtime/c4-user-theme.d.ts +27 -0
- package/lib/esm/runtime/c4-user-theme.js +106 -0
- package/lib/esm/runtime/decode-access-token.d.ts +12 -0
- package/lib/esm/runtime/decode-access-token.js +39 -0
- package/lib/esm/runtime/nav/camunda-apps.d.ts +45 -0
- package/lib/esm/runtime/nav/camunda-apps.js +100 -0
- package/lib/esm/runtime/nav/camunda-apps.spec.d.ts +1 -0
- package/lib/esm/runtime/nav/camunda-apps.spec.js +90 -0
- package/lib/esm/runtime/nav/use-webapp-nav-data.d.ts +75 -0
- package/lib/esm/runtime/nav/use-webapp-nav-data.js +211 -0
- package/lib/esm/runtime/nav/use-webapp-nav-data.spec.d.ts +1 -0
- package/lib/esm/runtime/nav/use-webapp-nav-data.spec.js +91 -0
- package/lib/esm/runtime/to-api-config.js +4 -0
- package/lib/esm/ui/index.d.ts +1 -0
- package/lib/esm/ui/index.js +3 -2
- package/lib/esm/widgets/cluster-details/c4-cluster-details-app.d.ts +1 -0
- package/lib/esm/widgets/cluster-details/c4-cluster-details-app.js +32 -13
- package/lib/esm/widgets/cluster-details/c4-cluster-details-app.merge.spec.d.ts +1 -0
- package/lib/esm/widgets/cluster-details/c4-cluster-details-app.merge.spec.js +49 -0
- package/lib/esm/widgets/cluster-details/c4-cluster-details-app.types.d.ts +8 -0
- package/lib/esm/widgets/cluster-details/cluster-details-tabs.d.ts +23 -0
- package/lib/esm/widgets/cluster-details/cluster-details-tabs.js +83 -0
- package/lib/esm/widgets/cluster-details/cluster-details-tabs.spec.d.ts +1 -0
- package/lib/esm/widgets/cluster-details/cluster-details-tabs.spec.js +33 -0
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-alerts-tab.js +17 -84
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-ip-whitelist-tab.js +19 -35
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-overview-tab.js +38 -18
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-overview-tab.spec.js +38 -14
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-settings-tab.d.ts +2 -0
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-settings-tab.js +190 -3
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-settings-tab.spec.js +60 -1
- package/lib/esm/widgets/clusters/c4-clusters-page.js +80 -44
- package/lib/esm/widgets/clusters/c4-clusters-page.spec.js +48 -48
- package/lib/esm/widgets/clusters/c4-clusters-page.types.d.ts +2 -0
- package/lib/esm/widgets/connector-management/c4-connector-management-executables-table-page.js +2 -1
- package/lib/esm/widgets/connector-management/c4-connector-management-outbound-details-page.js +10 -3
- package/lib/esm/widgets/connector-management/c4-connector-management-page.js +1 -1
- package/lib/esm/widgets/connector-management/c4-connector-management-page.spec.js +32 -0
- package/lib/esm/widgets/connector-management/c4-connector-management.shared.js +4 -3
- package/lib/esm/widgets/dashboard/c4-dashboard-app.js +21 -2
- package/lib/esm/widgets/group-details/c4-group-details-page.js +3 -2
- package/lib/esm/widgets/management/c4-management-app.js +80 -24
- package/lib/esm/widgets/management/c4-management-app.spec.js +32 -10
- package/lib/esm/widgets/management/management-tabs.d.ts +22 -0
- package/lib/esm/widgets/management/management-tabs.js +76 -0
- package/lib/esm/widgets/management/management-tabs.spec.d.ts +1 -0
- package/lib/esm/widgets/management/management-tabs.spec.js +28 -0
- package/lib/esm/widgets/management/tabs/c4-management-overview-tab.d.ts +2 -1
- package/lib/esm/widgets/management/tabs/c4-management-overview-tab.js +11 -2
- package/lib/esm/widgets/management/tabs/c4-management-users-tab.js +0 -10
- package/lib/esm/widgets/user-details/c4-user-details-page.js +0 -10
- package/package.json +9 -7
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { jsx as _jsx } 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
|
+
import { ExternalNotificationsService, } from '@camunda/ccma-api';
|
|
8
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from 'react';
|
|
9
|
+
import { useC4ConsoleRuntime } from './c4-console-runtime-context.js';
|
|
10
|
+
import { toApiConfig } from './to-api-config.js';
|
|
11
|
+
const NotificationsContext = createContext(undefined);
|
|
12
|
+
function sortNewestFirst(list) {
|
|
13
|
+
return [...list].sort((a, b) => b.timestamp - a.timestamp);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Merge a single incoming (SSE) notification into the list, mirroring the c3
|
|
17
|
+
* `updateNotifications` semantics: `new`/`read` upsert, anything else
|
|
18
|
+
* (`dismissed`) removes. Result stays newest-first.
|
|
19
|
+
*/
|
|
20
|
+
function mergeIncoming(list, incoming) {
|
|
21
|
+
const withoutIncoming = list.filter((n) => n.uuid !== incoming.uuid);
|
|
22
|
+
if (incoming.state === 'new' || incoming.state === 'read') {
|
|
23
|
+
withoutIncoming.push(incoming);
|
|
24
|
+
}
|
|
25
|
+
return sortNewestFirst(withoutIncoming);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Provides the per-user notification **feed** (the bell-icon inbox): initial
|
|
29
|
+
* fetch, live SSE updates, and optimistic mark-read / dismiss / analytics —
|
|
30
|
+
* the c4 equivalent of c3's `C3NotificationProvider`.
|
|
31
|
+
*
|
|
32
|
+
* This is NOT the in-app toast stack; for transient toasts use
|
|
33
|
+
* `C4ConsoleNotificationsProvider` / `addC4ConsoleNotification`.
|
|
34
|
+
*
|
|
35
|
+
* The provider does not decide when to mark notifications read on open — the
|
|
36
|
+
* panel drives that (call `markAllAsRead` + `trackPanelOpened`). Must be nested
|
|
37
|
+
* inside `C4ConsoleRuntimeProvider`.
|
|
38
|
+
*/
|
|
39
|
+
export const C4UserNotificationsProvider = ({ orgId, children, live = true, }) => {
|
|
40
|
+
const runtime = useC4ConsoleRuntime();
|
|
41
|
+
const [notifications, setNotifications] = useState([]);
|
|
42
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
43
|
+
const [error, setError] = useState(undefined);
|
|
44
|
+
// Keep the latest orgId available to async callbacks without re-creating them.
|
|
45
|
+
const orgIdRef = useRef(orgId);
|
|
46
|
+
orgIdRef.current = orgId;
|
|
47
|
+
const refetch = useCallback(async () => {
|
|
48
|
+
setIsLoading(true);
|
|
49
|
+
setError(undefined);
|
|
50
|
+
try {
|
|
51
|
+
const result = await ExternalNotificationsService.getUserNotifications({
|
|
52
|
+
config: toApiConfig(runtime),
|
|
53
|
+
params: { orgId },
|
|
54
|
+
});
|
|
55
|
+
setNotifications(sortNewestFirst(result));
|
|
56
|
+
}
|
|
57
|
+
catch (caught) {
|
|
58
|
+
setError(caught);
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
setIsLoading(false);
|
|
62
|
+
}
|
|
63
|
+
}, [runtime, orgId]);
|
|
64
|
+
// Initial fetch + refetch on org change. Clear stale data immediately so a
|
|
65
|
+
// previous org's feed never bleeds into the new one.
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
setNotifications([]);
|
|
68
|
+
void refetch();
|
|
69
|
+
}, [refetch]);
|
|
70
|
+
// Live SSE subscription, scoped to the current org. Closed on unmount and on
|
|
71
|
+
// org change (the c3 provider leaked this).
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (!live) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
let connection;
|
|
77
|
+
try {
|
|
78
|
+
connection = ExternalNotificationsService.streamUserNotifications({
|
|
79
|
+
config: toApiConfig(runtime),
|
|
80
|
+
onEvent: (incoming) => {
|
|
81
|
+
if (incoming.orgId && incoming.orgId !== orgIdRef.current) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
setNotifications((prev) => mergeIncoming(prev, incoming));
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch (caught) {
|
|
89
|
+
runtime.telemetry?.captureException?.(caught, {
|
|
90
|
+
context: 'C4UserNotificationsProvider.stream',
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return () => connection?.close();
|
|
94
|
+
}, [live, runtime, orgId]);
|
|
95
|
+
const persistState = useCallback((uuid, state) => {
|
|
96
|
+
void ExternalNotificationsService.setNotificationState({
|
|
97
|
+
config: toApiConfig(runtime),
|
|
98
|
+
params: { uuid, state },
|
|
99
|
+
}).catch((caught) => {
|
|
100
|
+
runtime.telemetry?.captureException?.(caught, {
|
|
101
|
+
context: 'C4UserNotificationsProvider.setNotificationState',
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}, [runtime]);
|
|
105
|
+
const markAsRead = useCallback((uuid) => {
|
|
106
|
+
const target = notifications.find((n) => n.uuid === uuid);
|
|
107
|
+
if (!target || target.state !== 'new') {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
setNotifications((prev) => prev.map((n) => n.uuid === uuid && n.state === 'new' ? { ...n, state: 'read' } : n));
|
|
111
|
+
persistState(uuid, 'read');
|
|
112
|
+
}, [notifications, persistState]);
|
|
113
|
+
const markAllAsRead = useCallback(() => {
|
|
114
|
+
const unreadUuids = notifications
|
|
115
|
+
.filter((n) => n.state === 'new')
|
|
116
|
+
.map((n) => n.uuid);
|
|
117
|
+
if (unreadUuids.length === 0) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
setNotifications((prev) => prev.map((n) => (n.state === 'new' ? { ...n, state: 'read' } : n)));
|
|
121
|
+
void ExternalNotificationsService.markManyAsRead({
|
|
122
|
+
config: toApiConfig(runtime),
|
|
123
|
+
params: { uuids: unreadUuids },
|
|
124
|
+
}).catch((caught) => {
|
|
125
|
+
runtime.telemetry?.captureException?.(caught, {
|
|
126
|
+
context: 'C4UserNotificationsProvider.markManyAsRead',
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}, [notifications, runtime]);
|
|
130
|
+
const dismiss = useCallback((uuid) => {
|
|
131
|
+
if (!notifications.some((n) => n.uuid === uuid)) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
setNotifications((prev) => prev.filter((n) => n.uuid !== uuid));
|
|
135
|
+
persistState(uuid, 'dismiss');
|
|
136
|
+
}, [notifications, persistState]);
|
|
137
|
+
const dismissAll = useCallback(() => {
|
|
138
|
+
if (notifications.length === 0) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
setNotifications([]);
|
|
142
|
+
void ExternalNotificationsService.dismissAll({
|
|
143
|
+
config: toApiConfig(runtime),
|
|
144
|
+
params: { orgId },
|
|
145
|
+
}).catch((caught) => {
|
|
146
|
+
runtime.telemetry?.captureException?.(caught, {
|
|
147
|
+
context: 'C4UserNotificationsProvider.dismissAll',
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}, [notifications.length, runtime, orgId]);
|
|
151
|
+
const trackPanelOpened = useCallback(() => {
|
|
152
|
+
runtime.telemetry?.track?.('notification-panel-opened');
|
|
153
|
+
void ExternalNotificationsService.trackEvent({
|
|
154
|
+
config: toApiConfig(runtime),
|
|
155
|
+
params: { orgId, event: 'notification-panel-opened' },
|
|
156
|
+
});
|
|
157
|
+
}, [runtime, orgId]);
|
|
158
|
+
const trackCtaClicked = useCallback((identifier) => {
|
|
159
|
+
runtime.telemetry?.track?.('notification-clicked-cta', { identifier });
|
|
160
|
+
void ExternalNotificationsService.trackEvent({
|
|
161
|
+
config: toApiConfig(runtime),
|
|
162
|
+
params: { orgId, event: 'notification-clicked-cta', id: identifier },
|
|
163
|
+
});
|
|
164
|
+
}, [runtime, orgId]);
|
|
165
|
+
const value = useMemo(() => ({
|
|
166
|
+
notifications,
|
|
167
|
+
isLoading,
|
|
168
|
+
error,
|
|
169
|
+
hasUnread: notifications.some((n) => n.state === 'new'),
|
|
170
|
+
markAsRead,
|
|
171
|
+
markAllAsRead,
|
|
172
|
+
dismiss,
|
|
173
|
+
dismissAll,
|
|
174
|
+
trackPanelOpened,
|
|
175
|
+
trackCtaClicked,
|
|
176
|
+
refetch,
|
|
177
|
+
}), [
|
|
178
|
+
notifications,
|
|
179
|
+
isLoading,
|
|
180
|
+
error,
|
|
181
|
+
markAsRead,
|
|
182
|
+
markAllAsRead,
|
|
183
|
+
dismiss,
|
|
184
|
+
dismissAll,
|
|
185
|
+
trackPanelOpened,
|
|
186
|
+
trackCtaClicked,
|
|
187
|
+
refetch,
|
|
188
|
+
]);
|
|
189
|
+
return (_jsx(NotificationsContext.Provider, { value: value, children: children }));
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Access the user notification feed. Throws if no `C4UserNotificationsProvider`
|
|
193
|
+
* is mounted.
|
|
194
|
+
*/
|
|
195
|
+
export const useC4UserNotifications = () => {
|
|
196
|
+
const context = useContext(NotificationsContext);
|
|
197
|
+
if (!context) {
|
|
198
|
+
throw new Error('useC4UserNotifications must be used within C4UserNotificationsProvider');
|
|
199
|
+
}
|
|
200
|
+
return context;
|
|
201
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { act, renderHook, waitFor } from '@testing-library/react';
|
|
3
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
+
vi.mock('@camunda/ccma-api', () => ({
|
|
5
|
+
ExternalNotificationsService: {
|
|
6
|
+
getUserNotifications: vi.fn(),
|
|
7
|
+
setNotificationState: vi.fn().mockResolvedValue(undefined),
|
|
8
|
+
markManyAsRead: vi.fn().mockResolvedValue(undefined),
|
|
9
|
+
dismissAll: vi.fn().mockResolvedValue(undefined),
|
|
10
|
+
trackEvent: vi.fn().mockResolvedValue(undefined),
|
|
11
|
+
streamUserNotifications: vi.fn(() => ({ close: vi.fn(), state: 'closed' })),
|
|
12
|
+
},
|
|
13
|
+
}));
|
|
14
|
+
import { ExternalNotificationsService } from '@camunda/ccma-api';
|
|
15
|
+
import { C4ConsoleRuntimeProvider } from './c4-console-runtime-context.js';
|
|
16
|
+
import { C4UserNotificationsProvider, useC4UserNotifications, } from './c4-user-notifications-context.js';
|
|
17
|
+
const runtime = {
|
|
18
|
+
stage: 'dev',
|
|
19
|
+
auth: { getAccessToken: async () => 'token' },
|
|
20
|
+
backendUrls: {},
|
|
21
|
+
};
|
|
22
|
+
const notif = (over) => ({
|
|
23
|
+
uuid: 'n1',
|
|
24
|
+
timestamp: 1,
|
|
25
|
+
state: 'new',
|
|
26
|
+
source: 'console',
|
|
27
|
+
type: 'org',
|
|
28
|
+
title: 't',
|
|
29
|
+
description: 'd',
|
|
30
|
+
...over,
|
|
31
|
+
});
|
|
32
|
+
const wrapper = ({ children }) => (_jsx(C4ConsoleRuntimeProvider, { config: runtime, children: _jsx(C4UserNotificationsProvider, { orgId: 'org-1', live: false, children: children }) }));
|
|
33
|
+
const mockService = vi.mocked(ExternalNotificationsService);
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
vi.clearAllMocks();
|
|
36
|
+
mockService.getUserNotifications.mockResolvedValue([
|
|
37
|
+
notif({ uuid: 'old', timestamp: 1, state: 'read' }),
|
|
38
|
+
notif({ uuid: 'new', timestamp: 2, state: 'new' }),
|
|
39
|
+
]);
|
|
40
|
+
});
|
|
41
|
+
describe('C4UserNotificationsProvider', () => {
|
|
42
|
+
it('fetches, sorts newest-first, and derives hasUnread', async () => {
|
|
43
|
+
const { result } = renderHook(() => useC4UserNotifications(), { wrapper });
|
|
44
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
45
|
+
expect(result.current.notifications.map((n) => n.uuid)).toEqual([
|
|
46
|
+
'new',
|
|
47
|
+
'old',
|
|
48
|
+
]);
|
|
49
|
+
expect(result.current.hasUnread).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
it('markAsRead optimistically flips state and persists', async () => {
|
|
52
|
+
const { result } = renderHook(() => useC4UserNotifications(), { wrapper });
|
|
53
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
54
|
+
act(() => result.current.markAsRead('new'));
|
|
55
|
+
expect(result.current.notifications.find((n) => n.uuid === 'new')?.state).toBe('read');
|
|
56
|
+
expect(result.current.hasUnread).toBe(false);
|
|
57
|
+
expect(mockService.setNotificationState).toHaveBeenCalledWith(expect.objectContaining({ params: { uuid: 'new', state: 'read' } }));
|
|
58
|
+
});
|
|
59
|
+
it('dismiss removes the notification and persists', async () => {
|
|
60
|
+
const { result } = renderHook(() => useC4UserNotifications(), { wrapper });
|
|
61
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
62
|
+
act(() => result.current.dismiss('old'));
|
|
63
|
+
expect(result.current.notifications.map((n) => n.uuid)).toEqual(['new']);
|
|
64
|
+
expect(mockService.setNotificationState).toHaveBeenCalledWith(expect.objectContaining({ params: { uuid: 'old', state: 'dismiss' } }));
|
|
65
|
+
});
|
|
66
|
+
it('markAllAsRead batches only the unread uuids', async () => {
|
|
67
|
+
const { result } = renderHook(() => useC4UserNotifications(), { wrapper });
|
|
68
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
69
|
+
act(() => result.current.markAllAsRead());
|
|
70
|
+
expect(mockService.markManyAsRead).toHaveBeenCalledWith(expect.objectContaining({ params: { uuids: ['new'] } }));
|
|
71
|
+
expect(result.current.hasUnread).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
it('dismissAll clears the list and calls the bulk endpoint', async () => {
|
|
74
|
+
const { result } = renderHook(() => useC4UserNotifications(), { wrapper });
|
|
75
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
76
|
+
act(() => result.current.dismissAll());
|
|
77
|
+
expect(result.current.notifications).toHaveLength(0);
|
|
78
|
+
expect(mockService.dismissAll).toHaveBeenCalledWith(expect.objectContaining({ params: { orgId: 'org-1' } }));
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { NotificationDto } from '@camunda/ccma-shared-types';
|
|
2
|
+
import type React from 'react';
|
|
3
|
+
export interface C4UserNotificationsProviderProps {
|
|
4
|
+
/** Organization whose feed is shown. Changing it re-fetches and re-subscribes. */
|
|
5
|
+
orgId: string;
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
/** Disable the live SSE subscription (e.g. Storybook / tests). Default `true`. */
|
|
8
|
+
live?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface C4UserNotificationsState {
|
|
11
|
+
/** The user's notifications for the current org, newest-first. */
|
|
12
|
+
notifications: NotificationDto[];
|
|
13
|
+
isLoading: boolean;
|
|
14
|
+
error: Error | undefined;
|
|
15
|
+
/** True while any notification is in the `new` (unread) state. */
|
|
16
|
+
hasUnread: boolean;
|
|
17
|
+
/** Optimistically mark one notification read (`PATCH …/:uuid/read`). */
|
|
18
|
+
markAsRead: (uuid: string) => void;
|
|
19
|
+
/** Optimistically mark every currently-unread notification read (batched). */
|
|
20
|
+
markAllAsRead: () => void;
|
|
21
|
+
/** Optimistically remove one notification (`PATCH …/:uuid/dismiss`). */
|
|
22
|
+
dismiss: (uuid: string) => void;
|
|
23
|
+
/** Optimistically remove all notifications for the org (bulk endpoint). */
|
|
24
|
+
dismissAll: () => void;
|
|
25
|
+
/** Fire the `notification-panel-opened` analytics event. */
|
|
26
|
+
trackPanelOpened: () => void;
|
|
27
|
+
/** Fire the `notification-clicked-cta` analytics event for a notification. */
|
|
28
|
+
trackCtaClicked: (identifier?: string) => void;
|
|
29
|
+
/** Force a re-fetch of the feed. */
|
|
30
|
+
refetch: () => Promise<void>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type C4ThemePreference = 'light' | 'dark' | 'system';
|
|
2
|
+
export type C4ResolvedTheme = 'light' | 'dark';
|
|
3
|
+
export interface C4UserThemeState {
|
|
4
|
+
/** The user's stored preference. Initialized from the access-token claim. */
|
|
5
|
+
theme: C4ThemePreference;
|
|
6
|
+
/** `theme` with `system` resolved to the OS setting (live-updates on change). */
|
|
7
|
+
resolvedTheme: C4ResolvedTheme;
|
|
8
|
+
/** Optimistically set + persist the preference (`PATCH external/user/theme`). */
|
|
9
|
+
setTheme: (theme: C4ThemePreference) => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Reads and persists the user's theme **preference**. This hook does NOT apply
|
|
13
|
+
* the theme to the DOM — how `resolvedTheme` maps onto `<html>`
|
|
14
|
+
* (`data-carbon-theme`, the DS `.dark` class) is the host's responsibility. In
|
|
15
|
+
* `designSystem: 'ds'` mode `C4ConsoleRuntimeProvider` already mirrors the
|
|
16
|
+
* Carbon theme onto the DS `.dark` class, so a host typically only needs to set
|
|
17
|
+
* `data-carbon-theme` from `resolvedTheme`.
|
|
18
|
+
*
|
|
19
|
+
* The initial preference is decoded from the access token's
|
|
20
|
+
* `https://camunda.com/settings.theme` claim; `system` is resolved locally via
|
|
21
|
+
* `matchMedia` and kept live. `setTheme` updates state immediately and persists
|
|
22
|
+
* in the background (failures are reported via `runtime.telemetry`, the local
|
|
23
|
+
* value is kept — matching the c3 behaviour).
|
|
24
|
+
*
|
|
25
|
+
* Must be used within `C4ConsoleRuntimeProvider`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function useC4UserTheme(): C4UserThemeState;
|
|
@@ -0,0 +1,106 @@
|
|
|
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 { ExternalAccountsService } from '@camunda/ccma-api';
|
|
7
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
8
|
+
import { useC4ConsoleRuntime } from './c4-console-runtime-context.js';
|
|
9
|
+
import { decodeAccessTokenPayload } from './decode-access-token.js';
|
|
10
|
+
import { toApiConfig } from './to-api-config.js';
|
|
11
|
+
const SETTINGS_CLAIM = 'https://camunda.com/settings';
|
|
12
|
+
function isThemePreference(value) {
|
|
13
|
+
return value === 'light' || value === 'dark' || value === 'system';
|
|
14
|
+
}
|
|
15
|
+
function prefersDark() {
|
|
16
|
+
if (typeof window === 'undefined' || !window.matchMedia) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
20
|
+
}
|
|
21
|
+
function resolve(theme) {
|
|
22
|
+
if (theme === 'system') {
|
|
23
|
+
return prefersDark() ? 'dark' : 'light';
|
|
24
|
+
}
|
|
25
|
+
return theme;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Reads and persists the user's theme **preference**. This hook does NOT apply
|
|
29
|
+
* the theme to the DOM — how `resolvedTheme` maps onto `<html>`
|
|
30
|
+
* (`data-carbon-theme`, the DS `.dark` class) is the host's responsibility. In
|
|
31
|
+
* `designSystem: 'ds'` mode `C4ConsoleRuntimeProvider` already mirrors the
|
|
32
|
+
* Carbon theme onto the DS `.dark` class, so a host typically only needs to set
|
|
33
|
+
* `data-carbon-theme` from `resolvedTheme`.
|
|
34
|
+
*
|
|
35
|
+
* The initial preference is decoded from the access token's
|
|
36
|
+
* `https://camunda.com/settings.theme` claim; `system` is resolved locally via
|
|
37
|
+
* `matchMedia` and kept live. `setTheme` updates state immediately and persists
|
|
38
|
+
* in the background (failures are reported via `runtime.telemetry`, the local
|
|
39
|
+
* value is kept — matching the c3 behaviour).
|
|
40
|
+
*
|
|
41
|
+
* Must be used within `C4ConsoleRuntimeProvider`.
|
|
42
|
+
*/
|
|
43
|
+
export function useC4UserTheme() {
|
|
44
|
+
const runtime = useC4ConsoleRuntime();
|
|
45
|
+
const [theme, setThemeState] = useState('light');
|
|
46
|
+
const [resolvedTheme, setResolvedTheme] = useState('light');
|
|
47
|
+
const initializedRef = useRef(false);
|
|
48
|
+
// Initialize the preference from the access-token claim once.
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (initializedRef.current) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
let cancelled = false;
|
|
54
|
+
void (async () => {
|
|
55
|
+
try {
|
|
56
|
+
const token = await runtime.auth.getAccessToken();
|
|
57
|
+
if (cancelled) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const payload = decodeAccessTokenPayload(token);
|
|
61
|
+
const settings = payload?.[SETTINGS_CLAIM];
|
|
62
|
+
const claimTheme = settings && typeof settings === 'object'
|
|
63
|
+
? settings.theme
|
|
64
|
+
: undefined;
|
|
65
|
+
const initial = isThemePreference(claimTheme) ? claimTheme : 'light';
|
|
66
|
+
initializedRef.current = true;
|
|
67
|
+
setThemeState(initial);
|
|
68
|
+
setResolvedTheme(resolve(initial));
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// Keep the light default if the token can't be read.
|
|
72
|
+
}
|
|
73
|
+
})();
|
|
74
|
+
return () => {
|
|
75
|
+
cancelled = true;
|
|
76
|
+
};
|
|
77
|
+
}, [runtime.auth]);
|
|
78
|
+
// Track OS color-scheme changes while the preference is `system`.
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (typeof window === 'undefined' || !window.matchMedia) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const media = window.matchMedia('(prefers-color-scheme: dark)');
|
|
84
|
+
const onChange = () => {
|
|
85
|
+
if (theme === 'system') {
|
|
86
|
+
setResolvedTheme(media.matches ? 'dark' : 'light');
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
media.addEventListener('change', onChange);
|
|
90
|
+
return () => media.removeEventListener('change', onChange);
|
|
91
|
+
}, [theme]);
|
|
92
|
+
const setTheme = useCallback((next) => {
|
|
93
|
+
setThemeState(next);
|
|
94
|
+
setResolvedTheme(resolve(next));
|
|
95
|
+
runtime.telemetry?.track?.('theme:update', { value: next });
|
|
96
|
+
void ExternalAccountsService.updateUserTheme({
|
|
97
|
+
config: toApiConfig(runtime),
|
|
98
|
+
theme: next,
|
|
99
|
+
}).catch((error) => {
|
|
100
|
+
runtime.telemetry?.captureException?.(error, {
|
|
101
|
+
context: 'useC4UserTheme.setTheme',
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}, [runtime]);
|
|
105
|
+
return { theme, resolvedTheme, setTheme };
|
|
106
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal helpers for reading claims out of a Camunda access token
|
|
3
|
+
* (client-side, no verification — the backend remains the source of truth).
|
|
4
|
+
* Shared by the authz and theme hooks so the base64url decode lives in one
|
|
5
|
+
* place.
|
|
6
|
+
*/
|
|
7
|
+
export declare function base64UrlDecodeToString(input: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Decode the payload segment of a JWT. Returns `undefined` for anything that
|
|
10
|
+
* isn't a well-formed token with a JSON object payload.
|
|
11
|
+
*/
|
|
12
|
+
export declare function decodeAccessTokenPayload(accessToken: string): Record<string, unknown> | undefined;
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
/**
|
|
7
|
+
* Internal helpers for reading claims out of a Camunda access token
|
|
8
|
+
* (client-side, no verification — the backend remains the source of truth).
|
|
9
|
+
* Shared by the authz and theme hooks so the base64url decode lives in one
|
|
10
|
+
* place.
|
|
11
|
+
*/
|
|
12
|
+
export function base64UrlDecodeToString(input) {
|
|
13
|
+
const padded = input
|
|
14
|
+
.replace(/-/g, '+')
|
|
15
|
+
.replace(/_/g, '/')
|
|
16
|
+
.padEnd(Math.ceil(input.length / 4) * 4, '=');
|
|
17
|
+
return atob(padded);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Decode the payload segment of a JWT. Returns `undefined` for anything that
|
|
21
|
+
* isn't a well-formed token with a JSON object payload.
|
|
22
|
+
*/
|
|
23
|
+
export function decodeAccessTokenPayload(accessToken) {
|
|
24
|
+
const parts = accessToken.split('.');
|
|
25
|
+
if (parts.length < 2) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const json = base64UrlDecodeToString(parts[1] ?? '');
|
|
30
|
+
const parsed = JSON.parse(json);
|
|
31
|
+
if (!parsed || typeof parsed !== 'object') {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
return parsed;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type CamundaWebApp, type ExternalClusterDto, type ExternalOrganizationDto } from '@camunda/ccma-shared-types';
|
|
2
|
+
/**
|
|
3
|
+
* Pure, icon-free navigation domain rules ported from c3's `utils/camunda.ts`.
|
|
4
|
+
* These encode the Camunda-specific quirks (admin↔identity aliasing, zeebe as
|
|
5
|
+
* the admin health proxy) so the presentational navigation library never has to
|
|
6
|
+
* reimplement them. Nothing here renders — outputs are plain data.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Apps shown in cluster navigation by default, in display order. `identity` is
|
|
10
|
+
* excluded because it is the legacy alias of `admin`; `resolveAdminAppName`
|
|
11
|
+
* picks the right display alias per cluster.
|
|
12
|
+
*/
|
|
13
|
+
export declare const DEFAULT_NAV_APPS: CamundaWebApp[];
|
|
14
|
+
/** Whether `app` is the admin/identity pair (they share URL + permission). */
|
|
15
|
+
export declare function isAdminApp(app: CamundaWebApp | undefined): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Picks the display alias (`admin` vs `identity`) for a cluster by its zeebe
|
|
18
|
+
* version. Renamed in 8.9.0-alpha5; URL and permission still live on
|
|
19
|
+
* `identity` for older clusters.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveAdminAppName(cluster: ExternalClusterDto): 'admin' | 'identity';
|
|
22
|
+
/** Endpoint URL for an app, handling identity/admin aliasing. */
|
|
23
|
+
export declare function getEndpointForApp(app: CamundaWebApp, endpoints: ExternalClusterDto['endpoints']): string | undefined;
|
|
24
|
+
/** Title-cased app label (e.g. `operate` → `Operate`). */
|
|
25
|
+
export declare function getReadableAppName(app: CamundaWebApp): string;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the org grants read access to an app, handling identity/admin
|
|
28
|
+
* aliasing. Consumers typically feed this into an `isAppVisible` callback.
|
|
29
|
+
*/
|
|
30
|
+
export declare function hasReadPermissionForApp(app: CamundaWebApp, permissions: ExternalOrganizationDto['permissions'] | undefined): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Whether an app is healthy on a cluster. Admin/identity have no dedicated
|
|
33
|
+
* health status — they ride zeebe's ingress — so zeebe is used as their health
|
|
34
|
+
* proxy (matching the c3 "zeebe as admin health proxy" contract).
|
|
35
|
+
*/
|
|
36
|
+
export declare function isAppHealthyOnCluster(cluster: ExternalClusterDto, app: CamundaWebApp): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Replaces the path of `modelerEndpoint` with `/org/{orgId}`, used to derive
|
|
39
|
+
* the Web Modeler URL for a sibling org from a known modeler endpoint. Assumes
|
|
40
|
+
* all modeler URLs share a host across orgs (SaaS pattern). Returns `undefined`
|
|
41
|
+
* for an unparseable URL.
|
|
42
|
+
*/
|
|
43
|
+
export declare function buildModelerOrgUrl(modelerEndpoint: string, orgId: string): string | undefined;
|
|
44
|
+
/** The stage tag carried on `labels.camunda[0]`, if present. */
|
|
45
|
+
export declare function getClusterStage(cluster: ExternalClusterDto): string | undefined;
|
|
@@ -0,0 +1,100 @@
|
|
|
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 { checkVersion, VersionCheckOperator, } from '@camunda/ccma-shared-types';
|
|
7
|
+
/**
|
|
8
|
+
* Pure, icon-free navigation domain rules ported from c3's `utils/camunda.ts`.
|
|
9
|
+
* These encode the Camunda-specific quirks (admin↔identity aliasing, zeebe as
|
|
10
|
+
* the admin health proxy) so the presentational navigation library never has to
|
|
11
|
+
* reimplement them. Nothing here renders — outputs are plain data.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Apps shown in cluster navigation by default, in display order. `identity` is
|
|
15
|
+
* excluded because it is the legacy alias of `admin`; `resolveAdminAppName`
|
|
16
|
+
* picks the right display alias per cluster.
|
|
17
|
+
*/
|
|
18
|
+
export const DEFAULT_NAV_APPS = [
|
|
19
|
+
'operate',
|
|
20
|
+
'tasklist',
|
|
21
|
+
'optimize',
|
|
22
|
+
'admin',
|
|
23
|
+
];
|
|
24
|
+
/** Whether `app` is the admin/identity pair (they share URL + permission). */
|
|
25
|
+
export function isAdminApp(app) {
|
|
26
|
+
return app === 'identity' || app === 'admin';
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Picks the display alias (`admin` vs `identity`) for a cluster by its zeebe
|
|
30
|
+
* version. Renamed in 8.9.0-alpha5; URL and permission still live on
|
|
31
|
+
* `identity` for older clusters.
|
|
32
|
+
*/
|
|
33
|
+
export function resolveAdminAppName(cluster) {
|
|
34
|
+
return checkVersion({
|
|
35
|
+
possiblyVersionOrDockerPath: cluster.generation?.versions?.zeebe,
|
|
36
|
+
trueForSnapshot: true,
|
|
37
|
+
versionToCompareTo: '8.9.0-alpha5',
|
|
38
|
+
operator: VersionCheckOperator.GreaterThanOrEqual,
|
|
39
|
+
})
|
|
40
|
+
? 'admin'
|
|
41
|
+
: 'identity';
|
|
42
|
+
}
|
|
43
|
+
/** Endpoint URL for an app, handling identity/admin aliasing. */
|
|
44
|
+
export function getEndpointForApp(app, endpoints) {
|
|
45
|
+
if (!endpoints) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
if (isAdminApp(app)) {
|
|
49
|
+
return endpoints.admin ?? endpoints.identity;
|
|
50
|
+
}
|
|
51
|
+
return endpoints[app];
|
|
52
|
+
}
|
|
53
|
+
/** Title-cased app label (e.g. `operate` → `Operate`). */
|
|
54
|
+
export function getReadableAppName(app) {
|
|
55
|
+
return app.charAt(0).toUpperCase() + app.slice(1);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Whether the org grants read access to an app, handling identity/admin
|
|
59
|
+
* aliasing. Consumers typically feed this into an `isAppVisible` callback.
|
|
60
|
+
*/
|
|
61
|
+
export function hasReadPermissionForApp(app, permissions) {
|
|
62
|
+
const cluster = permissions?.cluster;
|
|
63
|
+
if (!cluster) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (isAdminApp(app)) {
|
|
67
|
+
return Boolean(cluster.admin?.read || cluster.identity?.read);
|
|
68
|
+
}
|
|
69
|
+
return Boolean(cluster[app]?.read);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Whether an app is healthy on a cluster. Admin/identity have no dedicated
|
|
73
|
+
* health status — they ride zeebe's ingress — so zeebe is used as their health
|
|
74
|
+
* proxy (matching the c3 "zeebe as admin health proxy" contract).
|
|
75
|
+
*/
|
|
76
|
+
export function isAppHealthyOnCluster(cluster, app) {
|
|
77
|
+
const healthKey = isAdminApp(app) ? 'zeebe' : app;
|
|
78
|
+
return cluster.status?.[healthKey] === 'Healthy';
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Replaces the path of `modelerEndpoint` with `/org/{orgId}`, used to derive
|
|
82
|
+
* the Web Modeler URL for a sibling org from a known modeler endpoint. Assumes
|
|
83
|
+
* all modeler URLs share a host across orgs (SaaS pattern). Returns `undefined`
|
|
84
|
+
* for an unparseable URL.
|
|
85
|
+
*/
|
|
86
|
+
export function buildModelerOrgUrl(modelerEndpoint, orgId) {
|
|
87
|
+
try {
|
|
88
|
+
const url = new URL(modelerEndpoint);
|
|
89
|
+
url.pathname = `/org/${orgId}`;
|
|
90
|
+
url.search = '';
|
|
91
|
+
return url.toString();
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** The stage tag carried on `labels.camunda[0]`, if present. */
|
|
98
|
+
export function getClusterStage(cluster) {
|
|
99
|
+
return cluster.labels?.camunda?.[0];
|
|
100
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|