@flightctl/ui-components 0.9.3 → 0.10.0-rc1
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/dist/src/components/DetailsPage/DetailsPage.d.ts +2 -1
- package/dist/src/components/DetailsPage/DetailsPage.d.ts.map +1 -1
- package/dist/src/components/DetailsPage/DetailsPage.js +2 -1
- package/dist/src/components/DetailsPage/DetailsPage.js.map +1 -1
- package/dist/src/components/DetailsPage/DetailsPageActions.d.ts +10 -0
- package/dist/src/components/DetailsPage/DetailsPageActions.d.ts.map +1 -1
- package/dist/src/components/DetailsPage/DetailsPageActions.js +23 -1
- package/dist/src/components/DetailsPage/DetailsPageActions.js.map +1 -1
- package/dist/src/components/Device/DeviceDetails/DeviceDetailsPage.d.ts.map +1 -1
- package/dist/src/components/Device/DeviceDetails/DeviceDetailsPage.js +29 -3
- package/dist/src/components/Device/DeviceDetails/DeviceDetailsPage.js.map +1 -1
- package/dist/src/components/Device/DeviceDetails/DeviceDetailsTab.d.ts.map +1 -1
- package/dist/src/components/Device/DeviceDetails/DeviceDetailsTab.js +0 -4
- package/dist/src/components/Device/DeviceDetails/DeviceDetailsTab.js.map +1 -1
- package/dist/src/components/Device/DeviceDetails/DeviceDetailsTabContent/StatusContent.d.ts.map +1 -1
- package/dist/src/components/Device/DeviceDetails/DeviceDetailsTabContent/StatusContent.js +8 -2
- package/dist/src/components/Device/DeviceDetails/DeviceDetailsTabContent/StatusContent.js.map +1 -1
- package/dist/src/components/Device/DevicesPage/DecommissionedDeviceTableRow.d.ts.map +1 -1
- package/dist/src/components/Device/DevicesPage/DecommissionedDeviceTableRow.js +1 -3
- package/dist/src/components/Device/DevicesPage/DecommissionedDeviceTableRow.js.map +1 -1
- package/dist/src/components/Device/DevicesPage/DecommissionedDevicesTable.d.ts.map +1 -1
- package/dist/src/components/Device/DevicesPage/DecommissionedDevicesTable.js +0 -3
- package/dist/src/components/Device/DevicesPage/DecommissionedDevicesTable.js.map +1 -1
- package/dist/src/components/Device/DevicesPage/DeviceToolbarFilters.d.ts.map +1 -1
- package/dist/src/components/Device/DevicesPage/DeviceToolbarFilters.js +3 -1
- package/dist/src/components/Device/DevicesPage/DeviceToolbarFilters.js.map +1 -1
- package/dist/src/components/Device/DevicesPage/DevicesPage.d.ts.map +1 -1
- package/dist/src/components/Device/DevicesPage/DevicesPage.js +1 -1
- package/dist/src/components/Device/DevicesPage/DevicesPage.js.map +1 -1
- package/dist/src/components/Device/DevicesPage/EnrolledDeviceTableRow.d.ts +3 -1
- package/dist/src/components/Device/DevicesPage/EnrolledDeviceTableRow.d.ts.map +1 -1
- package/dist/src/components/Device/DevicesPage/EnrolledDeviceTableRow.js +12 -4
- package/dist/src/components/Device/DevicesPage/EnrolledDeviceTableRow.js.map +1 -1
- package/dist/src/components/Device/DevicesPage/EnrolledDevicesTable.d.ts +2 -1
- package/dist/src/components/Device/DevicesPage/EnrolledDevicesTable.d.ts.map +1 -1
- package/dist/src/components/Device/DevicesPage/EnrolledDevicesTable.js +7 -6
- package/dist/src/components/Device/DevicesPage/EnrolledDevicesTable.js.map +1 -1
- package/dist/src/components/Events/useEvents.d.ts.map +1 -1
- package/dist/src/components/Events/useEvents.js +12 -0
- package/dist/src/components/Events/useEvents.js.map +1 -1
- package/dist/src/components/Fleet/CreateFleet/steps/UpdatePolicyStep.js +1 -1
- package/dist/src/components/Fleet/CreateFleet/steps/UpdatePolicyStep.js.map +1 -1
- package/dist/src/components/Fleet/FleetDetails/FleetDetailsPage.d.ts.map +1 -1
- package/dist/src/components/Fleet/FleetDetails/FleetDetailsPage.js +4 -3
- package/dist/src/components/Fleet/FleetDetails/FleetDetailsPage.js.map +1 -1
- package/dist/src/components/Fleet/FleetDetails/FleetDevicesCharts.d.ts.map +1 -1
- package/dist/src/components/Fleet/FleetDetails/FleetDevicesCharts.js +7 -1
- package/dist/src/components/Fleet/FleetDetails/FleetDevicesCharts.js.map +1 -1
- package/dist/src/components/Fleet/FleetDetails/FleetRestoreBanner.d.ts +8 -0
- package/dist/src/components/Fleet/FleetDetails/FleetRestoreBanner.d.ts.map +1 -0
- package/dist/src/components/Fleet/FleetDetails/FleetRestoreBanner.js +36 -0
- package/dist/src/components/Fleet/FleetDetails/FleetRestoreBanner.js.map +1 -0
- package/dist/src/components/Fleet/FleetsPage.d.ts.map +1 -1
- package/dist/src/components/Fleet/FleetsPage.js +2 -0
- package/dist/src/components/Fleet/FleetsPage.js.map +1 -1
- package/dist/src/components/ListPage/ListPageActions.d.ts +3 -2
- package/dist/src/components/ListPage/ListPageActions.d.ts.map +1 -1
- package/dist/src/components/ListPage/ListPageActions.js +27 -1
- package/dist/src/components/ListPage/ListPageActions.js.map +1 -1
- package/dist/src/components/Masthead/CommandLineToolsPage.d.ts.map +1 -1
- package/dist/src/components/Masthead/CommandLineToolsPage.js +18 -14
- package/dist/src/components/Masthead/CommandLineToolsPage.js.map +1 -1
- package/dist/src/components/OverviewPage/Cards/Alerts/AlertsCard.d.ts.map +1 -1
- package/dist/src/components/OverviewPage/Cards/Alerts/AlertsCard.js +15 -5
- package/dist/src/components/OverviewPage/Cards/Alerts/AlertsCard.js.map +1 -1
- package/dist/src/components/OverviewPage/Cards/Status/DeviceStatusChart.d.ts.map +1 -1
- package/dist/src/components/OverviewPage/Cards/Status/DeviceStatusChart.js +7 -1
- package/dist/src/components/OverviewPage/Cards/Status/DeviceStatusChart.js.map +1 -1
- package/dist/src/components/OverviewPage/Overview.d.ts.map +1 -1
- package/dist/src/components/OverviewPage/Overview.js +4 -2
- package/dist/src/components/OverviewPage/Overview.js.map +1 -1
- package/dist/src/components/Status/StatusDisplay.d.ts +3 -1
- package/dist/src/components/Status/StatusDisplay.d.ts.map +1 -1
- package/dist/src/components/Status/StatusDisplay.js +8 -8
- package/dist/src/components/Status/StatusDisplay.js.map +1 -1
- package/dist/src/components/SystemRestore/PendingSyncDevicesAlert.d.ts +7 -0
- package/dist/src/components/SystemRestore/PendingSyncDevicesAlert.d.ts.map +1 -0
- package/dist/src/components/SystemRestore/PendingSyncDevicesAlert.js +22 -0
- package/dist/src/components/SystemRestore/PendingSyncDevicesAlert.js.map +1 -0
- package/dist/src/components/SystemRestore/SuspendedDevicesAlert.d.ts +16 -0
- package/dist/src/components/SystemRestore/SuspendedDevicesAlert.d.ts.map +1 -0
- package/dist/src/components/SystemRestore/SuspendedDevicesAlert.js +75 -0
- package/dist/src/components/SystemRestore/SuspendedDevicesAlert.js.map +1 -0
- package/dist/src/components/SystemRestore/SystemRestoreBanners.css +6 -0
- package/dist/src/components/SystemRestore/SystemRestoreBanners.d.ts +28 -0
- package/dist/src/components/SystemRestore/SystemRestoreBanners.d.ts.map +1 -0
- package/dist/src/components/SystemRestore/SystemRestoreBanners.js +38 -0
- package/dist/src/components/SystemRestore/SystemRestoreBanners.js.map +1 -0
- package/dist/src/components/charts/utils.js +1 -1
- package/dist/src/components/charts/utils.js.map +1 -1
- package/dist/src/components/common/OrganizationGuard.d.ts +13 -0
- package/dist/src/components/common/OrganizationGuard.d.ts.map +1 -0
- package/dist/src/components/common/OrganizationGuard.js +106 -0
- package/dist/src/components/common/OrganizationGuard.js.map +1 -0
- package/dist/src/components/common/OrganizationSelector.d.ts +8 -0
- package/dist/src/components/common/OrganizationSelector.d.ts.map +1 -0
- package/dist/src/components/common/OrganizationSelector.js +92 -0
- package/dist/src/components/common/OrganizationSelector.js.map +1 -0
- package/dist/src/components/common/PageNavigation.d.ts +4 -0
- package/dist/src/components/common/PageNavigation.d.ts.map +1 -0
- package/dist/src/components/common/PageNavigation.js +46 -0
- package/dist/src/components/common/PageNavigation.js.map +1 -0
- package/dist/src/components/form/FilterSelect.css +3 -4
- package/dist/src/components/form/validations.d.ts +9 -0
- package/dist/src/components/form/validations.d.ts.map +1 -1
- package/dist/src/components/form/validations.js +12 -1
- package/dist/src/components/form/validations.js.map +1 -1
- package/dist/src/components/modals/ResumeDevicesModal/ResumeDevicesModal.d.ts +15 -0
- package/dist/src/components/modals/ResumeDevicesModal/ResumeDevicesModal.d.ts.map +1 -0
- package/dist/src/components/modals/ResumeDevicesModal/ResumeDevicesModal.js +56 -0
- package/dist/src/components/modals/ResumeDevicesModal/ResumeDevicesModal.js.map +1 -0
- package/dist/src/components/modals/massModals/ResumeDevicesModal/MassResumeDevicesModal.d.ts +7 -0
- package/dist/src/components/modals/massModals/ResumeDevicesModal/MassResumeDevicesModal.d.ts.map +1 -0
- package/dist/src/components/modals/massModals/ResumeDevicesModal/MassResumeDevicesModal.js +265 -0
- package/dist/src/components/modals/massModals/ResumeDevicesModal/MassResumeDevicesModal.js.map +1 -0
- package/dist/src/components/modals/massModals/ResumeDevicesModal/ResumeAllDevicesConfirmationDialog.d.ts +9 -0
- package/dist/src/components/modals/massModals/ResumeDevicesModal/ResumeAllDevicesConfirmationDialog.d.ts.map +1 -0
- package/dist/src/components/modals/massModals/ResumeDevicesModal/ResumeAllDevicesConfirmationDialog.js +27 -0
- package/dist/src/components/modals/massModals/ResumeDevicesModal/ResumeAllDevicesConfirmationDialog.js.map +1 -0
- package/dist/src/hooks/useAccessReview.d.ts.map +1 -1
- package/dist/src/hooks/useAccessReview.js +17 -4
- package/dist/src/hooks/useAccessReview.js.map +1 -1
- package/dist/src/hooks/useAlertsEnabled.d.ts +2 -0
- package/dist/src/hooks/useAlertsEnabled.d.ts.map +1 -0
- package/dist/src/hooks/useAlertsEnabled.js +50 -0
- package/dist/src/hooks/useAlertsEnabled.js.map +1 -0
- package/dist/src/hooks/useAppContext.d.ts +3 -6
- package/dist/src/hooks/useAppContext.d.ts.map +1 -1
- package/dist/src/hooks/useAppContext.js +1 -0
- package/dist/src/hooks/useAppContext.js.map +1 -1
- package/dist/src/hooks/useFetch.d.ts +6 -7
- package/dist/src/hooks/useFetch.d.ts.map +1 -1
- package/dist/src/hooks/useFetch.js +2 -3
- package/dist/src/hooks/useFetch.js.map +1 -1
- package/dist/src/hooks/useFetchPeriodically.d.ts.map +1 -1
- package/dist/src/hooks/useFetchPeriodically.js +4 -9
- package/dist/src/hooks/useFetchPeriodically.js.map +1 -1
- package/dist/src/hooks/useSystemRestoreContext.d.ts +16 -0
- package/dist/src/hooks/useSystemRestoreContext.d.ts.map +1 -0
- package/dist/src/hooks/useSystemRestoreContext.js +45 -0
- package/dist/src/hooks/useSystemRestoreContext.js.map +1 -0
- package/dist/src/types/extraTypes.d.ts +17 -18
- package/dist/src/types/extraTypes.d.ts.map +1 -1
- package/dist/src/types/extraTypes.js +1 -6
- package/dist/src/types/extraTypes.js.map +1 -1
- package/dist/src/types/rbac.d.ts +1 -0
- package/dist/src/types/rbac.d.ts.map +1 -1
- package/dist/src/types/rbac.js +1 -0
- package/dist/src/types/rbac.js.map +1 -1
- package/dist/src/utils/api.d.ts +2 -15
- package/dist/src/utils/api.d.ts.map +1 -1
- package/dist/src/utils/api.js +1 -40
- package/dist/src/utils/api.js.map +1 -1
- package/dist/src/utils/devices.d.ts +2 -0
- package/dist/src/utils/devices.d.ts.map +1 -1
- package/dist/src/utils/devices.js +11 -1
- package/dist/src/utils/devices.js.map +1 -1
- package/dist/src/utils/organizationStorage.d.ts +4 -0
- package/dist/src/utils/organizationStorage.d.ts.map +1 -0
- package/dist/src/utils/organizationStorage.js +18 -0
- package/dist/src/utils/organizationStorage.js.map +1 -0
- package/dist/src/utils/query.d.ts +2 -0
- package/dist/src/utils/query.d.ts.map +1 -1
- package/dist/src/utils/query.js +16 -0
- package/dist/src/utils/query.js.map +1 -1
- package/dist/src/utils/status/common.d.ts +1 -0
- package/dist/src/utils/status/common.d.ts.map +1 -1
- package/dist/src/utils/status/common.js.map +1 -1
- package/dist/src/utils/status/devices.d.ts +5 -0
- package/dist/src/utils/status/devices.d.ts.map +1 -1
- package/dist/src/utils/status/devices.js +44 -5
- package/dist/src/utils/status/devices.js.map +1 -1
- package/dist/src/utils/status/fleet.js +1 -1
- package/dist/src/utils/status/fleet.js.map +1 -1
- package/dist/src/utils/status/repository.js +1 -1
- package/dist/src/utils/status/repository.js.map +1 -1
- package/package.json +1 -1
- package/src/components/DetailsPage/DetailsPage.tsx +3 -0
- package/src/components/DetailsPage/DetailsPageActions.tsx +45 -0
- package/src/components/Device/DeviceDetails/DeviceDetailsPage.tsx +57 -5
- package/src/components/Device/DeviceDetails/DeviceDetailsTab.tsx +0 -5
- package/src/components/Device/DeviceDetails/DeviceDetailsTabContent/StatusContent.tsx +11 -3
- package/src/components/Device/DevicesPage/DecommissionedDeviceTableRow.tsx +0 -2
- package/src/components/Device/DevicesPage/DecommissionedDevicesTable.tsx +0 -3
- package/src/components/Device/DevicesPage/DeviceToolbarFilters.tsx +5 -1
- package/src/components/Device/DevicesPage/DevicesPage.tsx +1 -0
- package/src/components/Device/DevicesPage/EnrolledDeviceTableRow.tsx +15 -3
- package/src/components/Device/DevicesPage/EnrolledDevicesTable.tsx +11 -5
- package/src/components/Events/useEvents.ts +12 -0
- package/src/components/Fleet/CreateFleet/steps/UpdatePolicyStep.tsx +1 -1
- package/src/components/Fleet/FleetDetails/FleetDetailsPage.tsx +4 -5
- package/src/components/Fleet/FleetDetails/FleetDevicesCharts.tsx +9 -3
- package/src/components/Fleet/FleetDetails/FleetRestoreBanner.tsx +46 -0
- package/src/components/Fleet/FleetsPage.tsx +2 -0
- package/src/components/ListPage/ListPageActions.tsx +46 -3
- package/src/components/Masthead/CommandLineToolsPage.tsx +17 -14
- package/src/components/OverviewPage/Cards/Alerts/AlertsCard.tsx +19 -5
- package/src/components/OverviewPage/Cards/Status/DeviceStatusChart.tsx +8 -2
- package/src/components/OverviewPage/Overview.tsx +5 -2
- package/src/components/Status/StatusDisplay.tsx +32 -23
- package/src/components/SystemRestore/PendingSyncDevicesAlert.tsx +36 -0
- package/src/components/SystemRestore/SuspendedDevicesAlert.tsx +144 -0
- package/src/components/SystemRestore/SystemRestoreBanners.css +6 -0
- package/src/components/SystemRestore/SystemRestoreBanners.tsx +82 -0
- package/src/components/charts/utils.ts +1 -1
- package/src/components/common/OrganizationGuard.tsx +124 -0
- package/src/components/common/OrganizationSelector.tsx +192 -0
- package/src/components/common/PageNavigation.tsx +103 -0
- package/src/components/form/FilterSelect.css +3 -4
- package/src/components/form/validations.ts +14 -0
- package/src/components/modals/ResumeDevicesModal/ResumeDevicesModal.tsx +114 -0
- package/src/components/modals/massModals/ResumeDevicesModal/MassResumeDevicesModal.tsx +465 -0
- package/src/components/modals/massModals/ResumeDevicesModal/ResumeAllDevicesConfirmationDialog.tsx +55 -0
- package/src/hooks/useAccessReview.ts +20 -4
- package/src/hooks/useAlertsEnabled.ts +50 -0
- package/src/hooks/useAppContext.tsx +9 -7
- package/src/hooks/useFetch.ts +1 -3
- package/src/hooks/useFetchPeriodically.ts +4 -11
- package/src/hooks/useSystemRestoreContext.tsx +54 -0
- package/src/types/extraTypes.ts +17 -23
- package/src/types/rbac.ts +1 -0
- package/src/utils/api.ts +2 -51
- package/src/utils/devices.ts +11 -1
- package/src/utils/organizationStorage.ts +13 -0
- package/src/utils/query.ts +22 -0
- package/src/utils/status/common.ts +1 -0
- package/src/utils/status/devices.ts +49 -2
- package/src/utils/status/fleet.ts +1 -1
- package/src/utils/status/repository.ts +1 -1
- package/dist/src/hooks/useAlerts.d.ts +0 -26
- package/dist/src/hooks/useAlerts.d.ts.map +0 -1
- package/dist/src/hooks/useAlerts.js +0 -114
- package/dist/src/hooks/useAlerts.js.map +0 -1
- package/dist/src/utils/metrics.d.ts +0 -9
- package/dist/src/utils/metrics.d.ts.map +0 -1
- package/dist/src/utils/metrics.js +0 -48
- package/dist/src/utils/metrics.js.map +0 -1
- package/src/hooks/useAlerts.ts +0 -147
- package/src/utils/metrics.ts +0 -49
package/src/hooks/useAlerts.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { useAppContext } from './useAppContext';
|
|
3
|
-
import { useAccessReview } from './useAccessReview';
|
|
4
|
-
import { RESOURCE, VERB } from '../types/rbac';
|
|
5
|
-
|
|
6
|
-
// AlertManager alert structure
|
|
7
|
-
type AlertManagerAlert = {
|
|
8
|
-
fingerprint: string;
|
|
9
|
-
labels: {
|
|
10
|
-
alertname: string;
|
|
11
|
-
org_id: string;
|
|
12
|
-
resource: string;
|
|
13
|
-
[key: string]: string;
|
|
14
|
-
};
|
|
15
|
-
annotations: Record<string, string>;
|
|
16
|
-
startsAt: string;
|
|
17
|
-
endsAt: string;
|
|
18
|
-
updatedAt: string;
|
|
19
|
-
status: {
|
|
20
|
-
state: string;
|
|
21
|
-
inhibitedBy: string[];
|
|
22
|
-
mutedBy: string[];
|
|
23
|
-
silencedBy: string[];
|
|
24
|
-
};
|
|
25
|
-
receivers: Array<{ name: string }>;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const DEFAULT_REFRESH_INTERVAL = 30000; // 30 seconds
|
|
29
|
-
|
|
30
|
-
export const useAlerts = (
|
|
31
|
-
refreshInterval: number = DEFAULT_REFRESH_INTERVAL,
|
|
32
|
-
): [AlertManagerAlert[], boolean, unknown, VoidFunction] => {
|
|
33
|
-
const { getAlerts } = useAppContext();
|
|
34
|
-
const [alerts, setAlerts] = React.useState<AlertManagerAlert[]>([]);
|
|
35
|
-
const [isLoading, setIsLoading] = React.useState(true);
|
|
36
|
-
const [error, setError] = React.useState<unknown>();
|
|
37
|
-
const [forceRefresh, setForceRefresh] = React.useState(0);
|
|
38
|
-
|
|
39
|
-
const refetch = React.useCallback(() => {
|
|
40
|
-
setForceRefresh((prev) => prev + 1);
|
|
41
|
-
}, []);
|
|
42
|
-
|
|
43
|
-
React.useEffect(() => {
|
|
44
|
-
let abortController: AbortController;
|
|
45
|
-
let intervalId: NodeJS.Timeout;
|
|
46
|
-
|
|
47
|
-
const fetchAlerts = async () => {
|
|
48
|
-
if (!getAlerts) {
|
|
49
|
-
setIsLoading(false);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
abortController = new AbortController();
|
|
55
|
-
const alertsData = await getAlerts<AlertManagerAlert[]>(abortController.signal);
|
|
56
|
-
setAlerts(alertsData || []);
|
|
57
|
-
setError(undefined);
|
|
58
|
-
} catch (err) {
|
|
59
|
-
if (!abortController.signal.aborted) {
|
|
60
|
-
setError(err);
|
|
61
|
-
setAlerts([]);
|
|
62
|
-
}
|
|
63
|
-
} finally {
|
|
64
|
-
if (!abortController.signal.aborted) {
|
|
65
|
-
setIsLoading(false);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// Initial fetch
|
|
71
|
-
fetchAlerts();
|
|
72
|
-
|
|
73
|
-
// Set up periodic refresh only if getAlerts is available
|
|
74
|
-
if (getAlerts && refreshInterval > 0) {
|
|
75
|
-
intervalId = setInterval(() => {
|
|
76
|
-
fetchAlerts();
|
|
77
|
-
}, refreshInterval);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return () => {
|
|
81
|
-
if (intervalId) {
|
|
82
|
-
clearInterval(intervalId);
|
|
83
|
-
}
|
|
84
|
-
abortController?.abort();
|
|
85
|
-
};
|
|
86
|
-
}, [getAlerts, refreshInterval, forceRefresh]);
|
|
87
|
-
|
|
88
|
-
return [alerts, isLoading, error, refetch];
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// Type guard to check if error is HttpError with status property
|
|
92
|
-
const isHttpError = (error: unknown): error is { status: number } => {
|
|
93
|
-
const errorObj = error as Record<string, unknown>;
|
|
94
|
-
return typeof error === 'object' && error !== null && 'status' in error && typeof errorObj.status === 'number';
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export const useAlertsEnabled = (): boolean => {
|
|
98
|
-
const { getAlerts } = useAppContext();
|
|
99
|
-
const [alertsEnabled, setAlertsEnabled] = React.useState(false);
|
|
100
|
-
|
|
101
|
-
const [canListAlerts, alertsLoading] = useAccessReview(RESOURCE.ALERTS, VERB.LIST);
|
|
102
|
-
const checkServiceEnabled = Boolean(getAlerts) && !alertsLoading && canListAlerts;
|
|
103
|
-
|
|
104
|
-
React.useEffect(() => {
|
|
105
|
-
let abortController: AbortController;
|
|
106
|
-
|
|
107
|
-
const checkAlertServiceEnabled = async () => {
|
|
108
|
-
if (!getAlerts) {
|
|
109
|
-
// If getAlerts is not available, alerts are disabled
|
|
110
|
-
setAlertsEnabled(false);
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
try {
|
|
115
|
-
abortController = new AbortController();
|
|
116
|
-
await getAlerts<AlertManagerAlert[]>(abortController.signal);
|
|
117
|
-
setAlertsEnabled(true);
|
|
118
|
-
} catch (err) {
|
|
119
|
-
if (!abortController.signal.aborted) {
|
|
120
|
-
// Check if AlertManager is disabled (501 Not Implemented) or unavailable (500 Internal Server Error)
|
|
121
|
-
if (isHttpError(err) && (err.status === 501 || err.status === 500)) {
|
|
122
|
-
setAlertsEnabled(false);
|
|
123
|
-
} else {
|
|
124
|
-
// For other errors, assume alerts are enabled but there's a temporary issue
|
|
125
|
-
setAlertsEnabled(true);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
if (checkServiceEnabled) {
|
|
132
|
-
// Check only if we know that the user has permisions to read the alerts
|
|
133
|
-
checkAlertServiceEnabled();
|
|
134
|
-
} else if (!getAlerts) {
|
|
135
|
-
// If getAlerts is not available, immediately set to disabled
|
|
136
|
-
setAlertsEnabled(false);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return () => {
|
|
140
|
-
abortController?.abort();
|
|
141
|
-
};
|
|
142
|
-
}, [getAlerts, checkServiceEnabled]);
|
|
143
|
-
|
|
144
|
-
return alertsEnabled;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export type { AlertManagerAlert };
|
package/src/utils/metrics.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { MetricValue, PrometheusMetric } from '../types/extraTypes';
|
|
2
|
-
|
|
3
|
-
const getMetricSeries = (metrics: PrometheusMetric[], name: string): MetricValue[] => {
|
|
4
|
-
const metricItem = metrics.find((metric) => {
|
|
5
|
-
if (metric.metric.__name__ !== name) {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
return true;
|
|
9
|
-
});
|
|
10
|
-
return metricItem?.values || [];
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// TODO use a standard library for the calculation
|
|
14
|
-
const getPeriodTimestamps = (period: string) => {
|
|
15
|
-
const to = Date.now();
|
|
16
|
-
|
|
17
|
-
let step = 5;
|
|
18
|
-
|
|
19
|
-
let from: number;
|
|
20
|
-
switch (period) {
|
|
21
|
-
case '15m':
|
|
22
|
-
from = to - 15 * 60 * 1000;
|
|
23
|
-
break;
|
|
24
|
-
case '30m':
|
|
25
|
-
from = to - 30 * 60 * 1000;
|
|
26
|
-
break;
|
|
27
|
-
case '1h':
|
|
28
|
-
from = to - 1 * 60 * 60 * 1000;
|
|
29
|
-
step = 20;
|
|
30
|
-
break;
|
|
31
|
-
case '8h':
|
|
32
|
-
from = to - 8 * 60 * 60 * 1000;
|
|
33
|
-
step = 30;
|
|
34
|
-
break;
|
|
35
|
-
case '24h':
|
|
36
|
-
step = 120;
|
|
37
|
-
from = to - 24 * 60 * 60 * 1000;
|
|
38
|
-
break;
|
|
39
|
-
case '72h':
|
|
40
|
-
default:
|
|
41
|
-
step = 600;
|
|
42
|
-
from = to - 72 * 60 * 60 * 1000;
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
// Prometheus query requires seconds, not milliseconds
|
|
46
|
-
return { from: from / 1000, to: to / 1000, step };
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export { getMetricSeries, getPeriodTimestamps };
|