diff --git a/packages/dashboard/src/components/alert-store.tsx b/packages/dashboard/src/components/alert-store.tsx
index 0b3e6b5ff..acd5de152 100644
--- a/packages/dashboard/src/components/alert-store.tsx
+++ b/packages/dashboard/src/components/alert-store.tsx
@@ -138,31 +138,47 @@ const AlertDialog = React.memo((props: AlertDialogProps) => {
}, [rmf, alertRequest.id, alertRequest.task_id, alertRequest.tier]);
return (
- <>
-
);
});
@@ -268,14 +266,11 @@ export const AlertStore = React.memo(() => {
}
const pushAlertsToBeDisplayed = async (alertRequest: AlertRequest) => {
- console.log('push alert called');
if (!rmf) {
console.error('Alerts API not available');
return;
}
- console.log('api exists');
if (!alertRequest.display) {
- console.log('not displayed');
setOpenAlerts((prev) => {
const filteredAlerts = Object.fromEntries(
Object.entries(prev).filter(([key]) => key !== alertRequest.id),
@@ -294,7 +289,7 @@ export const AlertStore = React.memo(() => {
);
} catch (e) {
console.log(
- `Alert response could not be found for ${alertRequest.id}, ${(e as Error).message}`,
+ `Error retrieving alert response of ID ${alertRequest.id}, ${(e as Error).message}`,
);
setOpenAlerts((prev) => {
return {
@@ -352,9 +347,7 @@ export const AlertStore = React.memo(() => {
return (
<>
{Object.values(openAlerts).map((alert) => {
- const removeThisAlert = () => {
- removeOpenAlert(alert.id);
- };
+ const removeThisAlert = () => removeOpenAlert(alert.id);
return ;
})}
>
diff --git a/packages/dashboard/src/components/appbar.tsx b/packages/dashboard/src/components/appbar.tsx
index 125e00861..a257749e5 100644
--- a/packages/dashboard/src/components/appbar.tsx
+++ b/packages/dashboard/src/components/appbar.tsx
@@ -169,7 +169,6 @@ export const AppBar = React.memo(({ extraToolbarItems }: AppBarProps): React.Rea
const [openCreateTaskForm, setOpenCreateTaskForm] = React.useState(false);
const [favoritesTasks, setFavoritesTasks] = React.useState([]);
const [alertListAnchor, setAlertListAnchor] = React.useState(null);
- const [unacknowledgedAlertsNum, setUnacknowledgedAlertsNum] = React.useState(0);
const [unacknowledgedAlertList, setUnacknowledgedAlertList] = React.useState([]);
const [openAdminActionsDialog, setOpenAdminActionsDialog] = React.useState(false);
const [openFireAlarmTriggerResetDialog, setOpenFireAlarmTriggerResetDialog] =
@@ -203,27 +202,20 @@ export const AppBar = React.memo(({ extraToolbarItems }: AppBarProps): React.Rea
return;
}
+ const updateUnrespondedAlerts = async () => {
+ const { data: alerts } =
+ await rmf.alertsApi.getUnrespondedAlertsAlertsUnrespondedRequestsGet();
+ // alert.display is checked to verify that the dashboard should display it
+ // in the first place
+ const alertsToBeDisplayed = alerts.filter((alert) => alert.display);
+ setUnacknowledgedAlertList(alertsToBeDisplayed.reverse());
+ };
+
const subs: Subscription[] = [];
- subs.push(
- AppEvents.refreshAlert.subscribe({
- next: () => {
- (async () => {
- const resp = await rmf.alertsApi.getUnrespondedAlertsAlertsUnrespondedRequestsGet();
- const alerts = resp.data as AlertRequest[];
- const alertsToBeDisplayed = alerts.filter((alert) => alert.display);
- setUnacknowledgedAlertsNum(alertsToBeDisplayed.length);
- })();
- },
- }),
- );
+ subs.push(AppEvents.refreshAlert.subscribe(updateUnrespondedAlerts));
// Get the initial number of unacknowledged alerts
- (async () => {
- const resp = await rmf.alertsApi.getUnrespondedAlertsAlertsUnrespondedRequestsGet();
- const alerts = resp.data as AlertRequest[];
- const alertsToBeDisplayed = alerts.filter((alert) => alert.display);
- setUnacknowledgedAlertsNum(alertsToBeDisplayed.length);
- })();
+ updateUnrespondedAlerts();
return () => subs.forEach((s) => s.unsubscribe());
}, [rmf]);
@@ -338,12 +330,6 @@ export const AppBar = React.memo(({ extraToolbarItems }: AppBarProps): React.Rea
if (!rmf) {
return;
}
- (async () => {
- const { data: alerts } =
- await rmf.alertsApi.getUnrespondedAlertsAlertsUnrespondedRequestsGet();
- const alertsToBeDisplayed = alerts.filter((alert) => alert.display);
- setUnacknowledgedAlertList(alertsToBeDisplayed.reverse());
- })();
setAlertListAnchor(event.currentTarget);
};
@@ -434,7 +420,7 @@ export const AppBar = React.memo(({ extraToolbarItems }: AppBarProps): React.Rea
color="inherit"
onClick={handleOpenAlertList}
>
-
+