Skip to content

Commit

Permalink
Event report by alarm type
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Dec 24, 2024
1 parent 8a2ddec commit 582af9c
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/reports/EventReportPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import LocationSearchingIcon from '@mui/icons-material/LocationSearching';
import { useSelector } from 'react-redux';
import { formatSpeed, formatTime } from '../common/util/formatter';
import ReportFilter from './components/ReportFilter';
import { prefixString } from '../common/util/stringUtils';
import { useTranslation } from '../common/components/LocalizationProvider';
import { prefixString, unprefixString } from '../common/util/stringUtils';
import { useTranslation, useTranslationKeys } from '../common/components/LocalizationProvider';
import PageLayout from '../common/components/PageLayout';
import ReportsMenu from './components/ReportsMenu';
import usePersistedState from '../common/util/usePersistedState';
Expand All @@ -24,6 +24,7 @@ import MapPositions from '../map/MapPositions';
import MapCamera from '../map/MapCamera';
import scheduleReport from './common/scheduleReport';
import MapScale from '../map/MapScale';
import SelectField from '../common/components/SelectField';

const columnsArray = [
['eventTime', 'positionFixTime'],
Expand All @@ -46,8 +47,14 @@ const EventReportPage = () => {

const [allEventTypes, setAllEventTypes] = useState([['allEvents', 'eventAll']]);

const alarms = useTranslationKeys((it) => it.startsWith('alarm')).map((it) => ({
key: unprefixString('alarm', it),
name: t(it),
}));

const [columns, setColumns] = usePersistedState('eventColumns', ['eventTime', 'type', 'attributes']);
const [eventTypes, setEventTypes] = useState(['allEvents']);
const [alarmTypes, setAlarmTypes] = useState([]);
const [items, setItems] = useState([]);
const [loading, setLoading] = useState(false);
const [selectedItem, setSelectedItem] = useState(null);
Expand Down Expand Up @@ -82,6 +89,9 @@ const EventReportPage = () => {
const handleSubmit = useCatch(async ({ deviceId, from, to, type }) => {
const query = new URLSearchParams({ deviceId, from, to });
eventTypes.forEach((it) => query.append('type', it));
if (eventTypes[0] !== 'allEvents' && eventTypes.includes('alarm')) {
alarmTypes.forEach((it) => query.append('alarm', it));
}
if (type === 'export') {
window.location.assign(`/api/reports/events/xlsx?${query.toString()}`);
} else if (type === 'mail') {
Expand Down Expand Up @@ -176,8 +186,8 @@ const EventReportPage = () => {
<Select
label={t('reportEventTypes')}
value={eventTypes}
onChange={(event, child) => {
let values = event.target.value;
onChange={(e, child) => {
let values = e.target.value;
const clicked = child.props.value;
if (values.includes('allEvents') && values.length > 1) {
values = [clicked];
Expand All @@ -192,6 +202,19 @@ const EventReportPage = () => {
</Select>
</FormControl>
</div>
{eventTypes[0] !== 'allEvents' && eventTypes.includes('alarm') && (
<div className={classes.filterItem}>
<SelectField
multiple
value={alarmTypes}
onChange={(e) => setAlarmTypes(e.target.value)}
data={alarms}
keyGetter={(it) => it.key}
label={t('sharedAlarms')}
fullWidth
/>
</div>
)}
<ColumnSelect columns={columns} setColumns={setColumns} columnsArray={columnsArray} />
</ReportFilter>
</div>
Expand Down

0 comments on commit 582af9c

Please sign in to comment.