Skip to content

Commit

Permalink
Disable emergency shutdown button when the dome is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Sep 30, 2024
1 parent 5f29506 commit cacceae
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/components/LVMWebRoot/AlertsModal/AlertsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@
*/

import React from 'react';
import { Box, Button, Group, List, Modal, Stack, Text } from '@mantine/core';
import { IconInfoCircle } from '@tabler/icons-react';
import {
Alert,
Box,
Button,
Group,
List,
Modal,
Stack,
Text,
Tooltip,
} from '@mantine/core';
import useAlertsContext from '@/src/hooks/use-alerts-context';
import useAPICall from '@/src/hooks/use-api-call';
import useTask from '@/src/hooks/use-task';
import { EnclosureResponse } from '../../APITables/EnclosureTable/types';
import classes from './AlertModal.module.css';

export type AlertsModalProps = {
Expand All @@ -17,13 +30,27 @@ export type AlertsModalProps = {
};

export default function AlertsModal(props: AlertsModalProps) {
// Get status of the enclosure so that we can disable the emergency shutdown button.
const [enclosure, , noData, refresh] = useAPICall<EnclosureResponse>('/enclosure', {
interval: 30000,
});

const { opened, close } = props;

const alerts = useAlertsContext();
const [activeAlerts, setActiveAlerts] = React.useState<string[]>([]);

const domeClosed =
(enclosure?.dome_status.labels.includes('CLOSED') && !noData) || false;

const [runner] = useTask();

React.useEffect(() => {
if (opened) {
refresh();
}
}, [opened]);

React.useEffect(() => {
if (!alerts) {
return;
Expand Down Expand Up @@ -85,6 +112,11 @@ export default function AlertsModal(props: AlertsModalProps) {
overlayProps={{ backgroundOpacity: 0.55, blur: 3 }}
>
<Stack gap="lg">
{domeClosed && (
<Alert variant="filled" color="blue" radius={5} icon={<IconInfoCircle />}>
The dome is closed. This alert for informational purposes only.
</Alert>
)}
<Box>
<Text pb={10}>The following alerts are active:</Text>
<List withPadding>
Expand All @@ -94,7 +126,13 @@ export default function AlertsModal(props: AlertsModalProps) {
</List>
</Box>
<Group justify="flex-end">
<Button onClick={shutDown}>Emergency shutdown</Button>
<Tooltip
label={domeClosed ? 'The dome is already closed' : 'Closes the dome'}
>
<Button onClick={shutDown} disabled={domeClosed}>
Emergency shutdown
</Button>
</Tooltip>
<Button variant="default" onClick={close}>
Dismiss
</Button>
Expand Down

0 comments on commit cacceae

Please sign in to comment.