Skip to content

Commit

Permalink
Alarm formatting, fixing alarm_level
Browse files Browse the repository at this point in the history
  • Loading branch information
balbatross committed Feb 19, 2024
1 parent 8dfcde6 commit cec0031
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useAlarms = (deviceId: string) => {
})

const refetch = () => {
client.refetchQueries({include: ['DeviceConnectivity']})
client.refetchQueries({include: ['GetDeviceAlarms']})
}

useEffect(() => {
Expand Down
53 changes: 48 additions & 5 deletions packages/core-ui/command-surface/src/views/alarms.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,62 @@
import { Box, List, ListItem, Typography } from '@mui/material'
import React, { useContext } from 'react'
import { Box, Collapse, Divider, IconButton, List, ListItem, Typography } from '@mui/material'
import React, { useContext, useState } from 'react'
import { DeviceControlContext } from '../context';
import { ChevronRight, KeyboardArrowDown } from '@mui/icons-material';
import moment from 'moment';

export const AlarmList = () => {

const { alarms } = useContext(DeviceControlContext);

const sortedAlarms = alarms?.slice()?.sort((a,b) => a.createdAt?.getTime() - b.createdAt?.getTime())

const [ expanded, setExpanded ] = useState<string[]>([])

const toggleExpansion = (id: string) => {
if(expanded.includes(id)){
let ex = expanded.slice()
ex.splice(ex.indexOf(id), 1)

setExpanded(ex)
}else{
setExpanded([...expanded, id])
}
}

return (
<Box sx={{flex: 1}}>
<Box sx={{display: 'flex', alignItems: 'center', marginBottom: '12px', marginTop: '12px', justifyContent: 'center'}}>
<Typography>Alarms</Typography>
</Box>
<List>
{alarms?.map((alarm) => (
<ListItem>{alarm.message} {alarm.severity} {alarm.createdAt} {alarm.cause?.title}</ListItem>
<List sx={{overflowY: 'auto'}}>
{sortedAlarms?.map((alarm) => (
<>
<ListItem>
<Box sx={{display: 'flex', alignItems: 'flex-start'}}>
{/* <IconButton onClick={() => toggleExpansion(alarm.id)}>
{expanded.includes(alarm.id) ? <KeyboardArrowDown /> : <ChevronRight />}
</IconButton> */}
</Box>
<Box sx={{display: 'flex', flex: 1, flexDirection: 'column'}}>
<Box sx={{display: 'flex', justifyContent: 'space-between'}}>
<Typography>{alarm.message}</Typography>
<Box sx={{display: 'flex'}}>
{/* <Divider orientation='vertical'/> */}
<Typography>{alarm.cause?.title}</Typography>
</Box>
</Box>
<Box>
<Typography>Raised at: {moment(alarm.createdAt).format("hh:mma - DD/MM/YYYY")}</Typography>
<Typography>Severity : {alarm.severity}</Typography>
</Box>
<Collapse in={expanded.includes(alarm.id)}>
</Collapse>
</Box>

{/* {alarm.message} {alarm.severity} {alarm.createdAt} {alarm.cause?.title} */}
</ListItem>
<Divider />
</>
))}
</List>
</Box>
Expand Down
6 changes: 3 additions & 3 deletions packages/core/command-alarms/src/hook/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export const makeHook = (
const jsCode = transpile(`
enum ALARM_LEVEL {
CRITICAL,
FAULT,
WARNING
CRITICAL = 'Critical',
FAULT = 'Fault',
WARNING = 'Warning'
}
enum PATHWAYS {
Expand Down
2 changes: 0 additions & 2 deletions packages/core/command-alarms/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export class AlarmCenter {
async hook (alarms: Alarm[], alarmPathways: AlarmPathway[], values: any, typedValues: any) {
//Look up device and routing key in alarms list

console.log({values, typedValues})

const hookInst = new Hook(this.register, alarms, alarmPathways);


Expand Down

0 comments on commit cec0031

Please sign in to comment.