|
1 | 1 | import React, { useState } from 'react';
|
2 | 2 | import {
|
3 |
| - FormControl, InputLabel, Select, MenuItem, Button, TextField, Typography, |
| 3 | + FormControl, InputLabel, Select, MenuItem, Button, TextField, Typography, Autocomplete |
4 | 4 | } from '@mui/material';
|
5 | 5 | import { useDispatch, useSelector } from 'react-redux';
|
6 | 6 | import dayjs from 'dayjs';
|
@@ -93,34 +93,39 @@ const ReportFilter = ({ children, handleSubmit, handleSchedule, showOnly, ignore
|
93 | 93 | {!ignoreDevice && (
|
94 | 94 | <div className={classes.filterItem}>
|
95 | 95 | <FormControl fullWidth>
|
96 |
| - <InputLabel>{t(multiDevice ? 'deviceTitle' : 'reportDevice')}</InputLabel> |
97 |
| - <Select |
98 |
| - label={t(multiDevice ? 'deviceTitle' : 'reportDevice')} |
99 |
| - value={multiDevice ? deviceIds : deviceId || ''} |
100 |
| - onChange={(e) => dispatch(multiDevice ? devicesActions.selectIds(e.target.value) : devicesActions.selectId(e.target.value))} |
| 96 | + <Autocomplete |
101 | 97 | multiple={multiDevice}
|
102 |
| - > |
103 |
| - {Object.values(devices).sort((a, b) => a.name.localeCompare(b.name)).map((device) => ( |
104 |
| - <MenuItem key={device.id} value={device.id}>{device.name}</MenuItem> |
105 |
| - ))} |
106 |
| - </Select> |
| 98 | + limitTags={1} |
| 99 | + disableClearable |
| 100 | + size="small" |
| 101 | + options={Object.values(devices).sort((a, b) => a.name.localeCompare(b.name))} |
| 102 | + getOptionLabel={(option) => option?.name ?? ''} |
| 103 | + value={multiDevice ? deviceIds.map(did => devices[did]) : devices[deviceId] || ''} |
| 104 | + onChange={(event, newValue) => { |
| 105 | + console.log(newValue); |
| 106 | + dispatch(multiDevice ? devicesActions.selectIds(newValue.map(device => device.id)) : devicesActions.selectId(newValue?.id ?? null)) |
| 107 | + }} |
| 108 | + renderInput={(params) => <TextField {...params} label={t(multiDevice ? 'deviceTitle' : 'reportDevice')} />} |
| 109 | + /> |
107 | 110 | </FormControl>
|
108 | 111 | </div>
|
109 | 112 | )}
|
110 | 113 | {includeGroups && (
|
111 | 114 | <div className={classes.filterItem}>
|
112 | 115 | <FormControl fullWidth>
|
113 |
| - <InputLabel>{t('settingsGroups')}</InputLabel> |
114 |
| - <Select |
115 |
| - label={t('settingsGroups')} |
116 |
| - value={groupIds} |
117 |
| - onChange={(e) => dispatch(reportsActions.updateGroupIds(e.target.value))} |
118 |
| - multiple |
119 |
| - > |
120 |
| - {Object.values(groups).sort((a, b) => a.name.localeCompare(b.name)).map((group) => ( |
121 |
| - <MenuItem key={group.id} value={group.id}>{group.name}</MenuItem> |
122 |
| - ))} |
123 |
| - </Select> |
| 116 | + <Autocomplete |
| 117 | + multiple |
| 118 | + limitTags={1} |
| 119 | + disableClearable |
| 120 | + size="small" |
| 121 | + options={Object.values(groups).sort((a, b) => a.name.localeCompare(b.name))} |
| 122 | + getOptionLabel={(option) => option?.name ?? ''} |
| 123 | + value={groupIds.map(gid => groups[gid])} |
| 124 | + onChange={(event, newValue) => { |
| 125 | + dispatch(reportsActions.updateGroupIds(newValue.map(group => group.id))) |
| 126 | + }} |
| 127 | + renderInput={(params) => <TextField {...params} label={t('settingsGroups')} />} |
| 128 | + /> |
124 | 129 | </FormControl>
|
125 | 130 | </div>
|
126 | 131 | )}
|
|
0 commit comments