Skip to content

Commit

Permalink
Support unknown devices logs
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Dec 30, 2023
1 parent 363d473 commit 6b74ea7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
40 changes: 39 additions & 1 deletion modern/src/reports/LogsPage.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
import React, { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import {
Table, TableRow, TableCell, TableHead, TableBody,
Table, TableRow, TableCell, TableHead, TableBody, IconButton, Tooltip,
} from '@mui/material';
import makeStyles from '@mui/styles/makeStyles';
import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline';
import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
import { useTranslation } from '../common/components/LocalizationProvider';
import PageLayout from '../common/components/PageLayout';
import ReportsMenu from './components/ReportsMenu';
import { sessionActions } from '../store';

const useStyles = makeStyles((theme) => ({
columnAction: {
width: '1%',
paddingLeft: theme.spacing(1),
},
success: {
color: theme.palette.success.main,
},
error: {
color: theme.palette.error.main,
},
}));

const LogsPage = () => {
const classes = useStyles();
const navigate = useNavigate();
const dispatch = useDispatch();
const t = useTranslation();

Expand All @@ -19,11 +38,17 @@ const LogsPage = () => {

const items = useSelector((state) => state.session.logs);

const registerDevice = (uniqueId) => {
const query = new URLSearchParams({ uniqueId });
navigate(`/settings/device?${query.toString()}`);
}

return (
<PageLayout menu={<ReportsMenu />} breadcrumbs={['reportTitle', 'statisticsTitle']}>
<Table>
<TableHead>
<TableRow>
<TableCell className={classes.columnAction} />
<TableCell>{t('deviceIdentifier')}</TableCell>
<TableCell>{t('positionProtocol')}</TableCell>
<TableCell>{t('commandData')}</TableCell>
Expand All @@ -32,6 +57,19 @@ const LogsPage = () => {
<TableBody>
{items.map((item, index) => (
<TableRow key={index}>
<TableCell className={classes.columnAction} padding="none">
{item.deviceId ? (
<IconButton size="small" disabled>
<CheckCircleOutlineIcon fontSize="small" className={classes.success} />
</IconButton>
) : (
<Tooltip title={t('loginRegister')}>
<IconButton size="small" onClick={() => registerDevice(item.uniqueId)}>
<HelpOutlineIcon fontSize="small" className={classes.error} />
</IconButton>
</Tooltip>
)}
</TableCell>
<TableCell>{item.uniqueId}</TableCell>
<TableCell>{item.protocol}</TableCell>
<TableCell>{item.data}</TableCell>
Expand Down
2 changes: 2 additions & 0 deletions modern/src/reports/components/ReportsMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ const ReportsMenu = () => {
title={t('sharedLogs')}
link="/reports/logs"
icon={<NotesIcon />}
selected={location.pathname === '/reports/logs'}
/>
{!readonly && (
<MenuItem
title={t('reportScheduled')}
link="/reports/scheduled"
icon={<EventRepeatIcon />}
selected={location.pathname === '/reports/scheduled'}
/>
)}
{admin && (
Expand Down
7 changes: 6 additions & 1 deletion modern/src/settings/DevicePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useAdministrator } from '../common/util/permissions';
import SettingsMenu from './components/SettingsMenu';
import useCommonDeviceAttributes from '../common/attributes/useCommonDeviceAttributes';
import { useCatch } from '../reactHelper';
import useQuery from '../common/util/useQuery';

const useStyles = makeStyles((theme) => ({
details: {
Expand All @@ -41,7 +42,10 @@ const DevicePage = () => {
const commonDeviceAttributes = useCommonDeviceAttributes(t);
const deviceAttributes = useDeviceAttributes(t);

const [item, setItem] = useState();
const query = useQuery();
const uniqueId = query.get('uniqueId');

const [item, setItem] = useState(uniqueId ? { uniqueId } : null);

const handleFiles = useCatch(async (files) => {
if (files.length > 0) {
Expand Down Expand Up @@ -87,6 +91,7 @@ const DevicePage = () => {
onChange={(event) => setItem({ ...item, uniqueId: event.target.value })}
label={t('deviceIdentifier')}
helperText={t('deviceIdentifierHelp')}
disabled={Boolean(uniqueId)}
/>
</AccordionDetails>
</Accordion>
Expand Down

0 comments on commit 6b74ea7

Please sign in to comment.