2023-06-26 10:07:12 +00:00
|
|
|
|
"use client";
|
|
|
|
|
|
|
2023-02-13 13:46:56 +00:00
|
|
|
|
import { FC, useState, useEffect } from "react";
|
|
|
|
|
|
import { Box, Grid, TextField, Select, MenuItem } from "@mui/material";
|
|
|
|
|
|
import { DatePicker } from "@mui/x-date-pickers-pro";
|
|
|
|
|
|
import { useTranslate } from "react-polyglot";
|
2024-03-20 17:51:21 +01:00
|
|
|
|
import { useLeafcutterContext } from "./LeafcutterProvider";
|
2023-02-13 13:46:56 +00:00
|
|
|
|
|
|
|
|
|
|
interface QueryDateRangeSelectorProps {}
|
|
|
|
|
|
|
|
|
|
|
|
export const QueryDateRangeSelector: FC<QueryDateRangeSelectorProps> = () => {
|
|
|
|
|
|
const t = useTranslate();
|
|
|
|
|
|
const [relativeDate, setRelativeDate] = useState("");
|
|
|
|
|
|
const [startDate, setStartDate] = useState(null);
|
|
|
|
|
|
const [endDate, setEndDate] = useState(null);
|
2024-03-20 17:51:21 +01:00
|
|
|
|
const { updateQuery, query } = useLeafcutterContext();
|
2023-02-13 13:46:56 +00:00
|
|
|
|
useEffect(() => {
|
2023-08-25 07:11:33 +00:00
|
|
|
|
if (!query) return;
|
2023-02-13 13:46:56 +00:00
|
|
|
|
setStartDate(query.startDate.values[0] ?? null);
|
|
|
|
|
|
setEndDate(query.endDate.values[0] ?? null);
|
|
|
|
|
|
setRelativeDate(query.relativeDate.values[0] ?? "");
|
|
|
|
|
|
}, [query, setStartDate, setEndDate, setRelativeDate]);
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Box sx={{ height: 305, width: "100%", pt: 2 }}>
|
|
|
|
|
|
<Grid container direction="column">
|
|
|
|
|
|
<Grid item xs={12} sx={{ mb: 2 }}>
|
|
|
|
|
|
<Select
|
|
|
|
|
|
fullWidth
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
placeholder={t("relativeDate")}
|
|
|
|
|
|
value={relativeDate}
|
|
|
|
|
|
onChange={(event: any) => {
|
|
|
|
|
|
setStartDate(null);
|
|
|
|
|
|
setEndDate(null);
|
|
|
|
|
|
setRelativeDate(event.target.value);
|
|
|
|
|
|
updateQuery({
|
|
|
|
|
|
startDate: { values: [] },
|
|
|
|
|
|
});
|
|
|
|
|
|
updateQuery({
|
|
|
|
|
|
endDate: { values: [] },
|
|
|
|
|
|
});
|
|
|
|
|
|
updateQuery({
|
|
|
|
|
|
relativeDate: { values: [event.target.value] },
|
|
|
|
|
|
});
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<MenuItem value={7}>{t("last7Days")}</MenuItem>
|
|
|
|
|
|
<MenuItem value={30}>{t("last30Days")}</MenuItem>
|
|
|
|
|
|
<MenuItem value={90}>{t("last3Months")}</MenuItem>
|
|
|
|
|
|
<MenuItem value={180}>{t("last6Months")}</MenuItem>
|
|
|
|
|
|
<MenuItem value={365}>{t("lastYear")}</MenuItem>
|
|
|
|
|
|
<MenuItem value={730}>{t("last2Years")}</MenuItem>
|
|
|
|
|
|
</Select>
|
|
|
|
|
|
</Grid>
|
|
|
|
|
|
<Grid item sx={{ textAlign: "center", mb: 2 }}>
|
|
|
|
|
|
– or –
|
|
|
|
|
|
</Grid>
|
|
|
|
|
|
<Grid item xs={12}>
|
|
|
|
|
|
<DatePicker
|
|
|
|
|
|
label={t("startDate")}
|
|
|
|
|
|
value={startDate}
|
2024-04-21 20:47:55 +02:00
|
|
|
|
onChange={(date: any) => {
|
2023-02-13 13:46:56 +00:00
|
|
|
|
setStartDate(date);
|
|
|
|
|
|
updateQuery({
|
|
|
|
|
|
startDate: { values: [date] },
|
|
|
|
|
|
});
|
|
|
|
|
|
}}
|
2023-05-24 20:27:57 +00:00
|
|
|
|
// @ts-ignore
|
2023-02-13 13:46:56 +00:00
|
|
|
|
renderInput={(params) => (
|
|
|
|
|
|
<TextField
|
|
|
|
|
|
{...params}
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
width: "100%",
|
|
|
|
|
|
color: "black",
|
|
|
|
|
|
"& .MuiOutlinedInput-root": {
|
|
|
|
|
|
borderBottomLeftRadius: 0,
|
|
|
|
|
|
borderBottomRightRadius: 0,
|
|
|
|
|
|
},
|
|
|
|
|
|
}}
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Grid>
|
|
|
|
|
|
<Grid item xs={12}>
|
|
|
|
|
|
<DatePicker
|
|
|
|
|
|
label={t("endDate")}
|
|
|
|
|
|
value={endDate}
|
2024-04-21 20:47:55 +02:00
|
|
|
|
onChange={(date: any) => {
|
2023-02-13 13:46:56 +00:00
|
|
|
|
setEndDate(date);
|
|
|
|
|
|
updateQuery({
|
|
|
|
|
|
endDate: { values: [date] },
|
|
|
|
|
|
});
|
|
|
|
|
|
}}
|
2023-06-26 10:07:12 +00:00
|
|
|
|
// @ts-ignore
|
2023-02-13 13:46:56 +00:00
|
|
|
|
renderInput={(params) => (
|
|
|
|
|
|
<TextField
|
|
|
|
|
|
{...params}
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
backgroundColor: "white",
|
|
|
|
|
|
mt: "-1px",
|
|
|
|
|
|
width: "100%",
|
|
|
|
|
|
color: "black",
|
|
|
|
|
|
"& .MuiOutlinedInput-root": {
|
|
|
|
|
|
borderTop: 0,
|
|
|
|
|
|
borderTopLeftRadius: 0,
|
|
|
|
|
|
borderTopRightRadius: 0,
|
|
|
|
|
|
},
|
|
|
|
|
|
}}
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Grid>
|
|
|
|
|
|
</Grid>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|