Skip to content

Commit

Permalink
Option to show all devices
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Jul 24, 2024
1 parent 995ec5b commit 909b12f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/settings/DevicesPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from 'react';
import { useSelector } from 'react-redux';
import { useNavigate } from 'react-router-dom';
import {
Table, TableRow, TableCell, TableHead, TableBody, Button, TableFooter,
Table, TableRow, TableCell, TableHead, TableBody, Button, TableFooter, FormControlLabel, Switch,
} from '@mui/material';
import LinkIcon from '@mui/icons-material/Link';
import { useEffectAsync } from '../reactHelper';
Expand Down Expand Up @@ -31,12 +31,14 @@ const DevicesPage = () => {
const [timestamp, setTimestamp] = useState(Date.now());
const [items, setItems] = useState([]);
const [searchKeyword, setSearchKeyword] = useState('');
const [showAll, setShowAll] = useState(false);
const [loading, setLoading] = useState(false);

useEffectAsync(async () => {
setLoading(true);
try {
const response = await fetch('/api/devices');
const query = new URLSearchParams({ all: showAll });
const response = await fetch(`/api/devices?${query.toString()}`);
if (response.ok) {
setItems(await response.json());
} else {
Expand All @@ -45,7 +47,7 @@ const DevicesPage = () => {
} finally {
setLoading(false);
}
}, [timestamp]);
}, [timestamp, showAll]);

const handleExport = () => {
window.location.assign('/api/reports/devices/xlsx');
Expand Down Expand Up @@ -101,9 +103,23 @@ const DevicesPage = () => {
</TableBody>
<TableFooter>
<TableRow>
<TableCell colSpan={admin ? 9 : 8} align="right">
<TableCell>
<Button onClick={handleExport} variant="text">{t('reportExport')}</Button>
</TableCell>
<TableCell colSpan={admin ? 8 : 7} align="right">
<FormControlLabel
control={(
<Switch
value={showAll}
onChange={(e) => setShowAll(e.target.checked)}
size="small"
/>
)}
label={t('notificationAlways')}
labelPlacement="start"
disabled={!admin}
/>
</TableCell>
</TableRow>
</TableFooter>
</Table>
Expand Down

0 comments on commit 909b12f

Please sign in to comment.