improving telemetria 1 month discretization select

This commit is contained in:
joseCorte-exe 2023-04-17 16:27:59 -03:00
parent bd306e856d
commit fea6bbb6ce

View File

@ -44,7 +44,8 @@ export default function Telemetria({ userName, clients }: any) {
const [unity, setUnity] = useState(clients[0]?.codigo_scde);
const [startDate, setStartDate] = useState(new Date());
const [endDate, setEndDate] = useState(new Date());
const [month, setMonth] = useState(new Date().getMonth() + 1);
const [month, setMonth] = useState(new Date().getMonth());
const [endMonth, setEndMonth] = useState(new Date().getMonth() + 1);
const [discretization, setDiscretization] = useState('1_hora');
const [openSnackSuccess, setOpenSnackSuccess] = useState<boolean>(false)
@ -279,6 +280,7 @@ export default function Telemetria({ userName, clients }: any) {
</div>
{
discretization === '1_mes' ?
<>
<FormControl sx={{ minWidth: 120, width: 200, ml: 1, mr: 1 }} size="small">
<InputLabel>Discretização</InputLabel>
<Select
@ -289,9 +291,7 @@ export default function Telemetria({ userName, clients }: any) {
onChange={value => {
setMonth(value.target.value as number)
const firstOfTheMonth: Date = new Date(startDate.getFullYear(), (value.target.value as number) - 1, 1)
const lastOfTheMonth: Date = new Date(startDate.getFullYear(), firstOfTheMonth.getMonth() + 1, 0)
setStartDate(firstOfTheMonth)
setEndDate(lastOfTheMonth)
}}
sx={{ height: 63, mb: 2 }}
fullWidth
@ -306,6 +306,33 @@ export default function Telemetria({ userName, clients }: any) {
}
</Select>
</FormControl>
{discretization === '1_mes' && <FormControl sx={{ minWidth: 120, width: 200, ml: 1, mr: 1 }} size="small">
<InputLabel>Discretização</InputLabel>
<Select
labelId="demo-select-small"
id="demo-select-small"
value={endMonth}
label="Mês"
onChange={value => {
setEndMonth(value.target.value as number)
const firstOfTheMonth: Date = new Date(startDate.getFullYear(), (value.target.value as number) - 1, 1)
const lastOfTheMonth: Date = new Date(startDate.getFullYear(), firstOfTheMonth.getMonth() + 1, 0)
setEndDate(lastOfTheMonth)
}}
sx={{ height: 63, mb: 2 }}
fullWidth
>
<MenuItem value="">
<em>Nenhum</em>
</MenuItem>
{
months.slice(0, new Date().getUTCMonth() + 1).map(value => {
return <MenuItem key={value} value={months.indexOf(value) + 1 as number}>{value}</MenuItem>
})
}
</Select>
</FormControl>}
</>
:
<LocalizationProvider dateAdapter={AdapterDateFns}>
<div className='datePicker'>