add tags to filters
This commit is contained in:
1 parent
3bcdd3c445
commit
c6d82223f9
1 file changed
+46
-2
@@ -1,9 +1,11 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import { Select, Button } from "@/Components/inputs";
|
import { Select, Autocomplete, Button, TextField } from "@/Components/inputs";
|
||||||
|
import { ColoredLabel } from "@/Components/design-elements";
|
||||||
import MenuItem from "@mui/material/MenuItem";
|
import MenuItem from "@mui/material/MenuItem";
|
||||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||||
|
|
||||||
import type { MonitorType } from "@/Types/Monitor";
|
import type { MonitorType } from "@/Types/Monitor";
|
||||||
|
import type { Tag } from "@/Types/Tag";
|
||||||
import { Typography, useTheme } from "@mui/material";
|
import { Typography, useTheme } from "@mui/material";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
@@ -28,6 +30,9 @@ export const ControlsFilter = ({
|
|||||||
setSelectedStatus,
|
setSelectedStatus,
|
||||||
selectedState,
|
selectedState,
|
||||||
setSelectedState,
|
setSelectedState,
|
||||||
|
tagOptions,
|
||||||
|
selectedTags,
|
||||||
|
setSelectedTags,
|
||||||
onClearFilters,
|
onClearFilters,
|
||||||
}: {
|
}: {
|
||||||
showTypes?: boolean;
|
showTypes?: boolean;
|
||||||
@@ -37,13 +42,22 @@ export const ControlsFilter = ({
|
|||||||
setSelectedStatus: React.Dispatch<React.SetStateAction<string>>;
|
setSelectedStatus: React.Dispatch<React.SetStateAction<string>>;
|
||||||
selectedState: string;
|
selectedState: string;
|
||||||
setSelectedState: React.Dispatch<React.SetStateAction<string>>;
|
setSelectedState: React.Dispatch<React.SetStateAction<string>>;
|
||||||
|
tagOptions?: Tag[];
|
||||||
|
selectedTags?: string[];
|
||||||
|
setSelectedTags?: React.Dispatch<React.SetStateAction<string[]>>;
|
||||||
onClearFilters: () => void;
|
onClearFilters: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||||
const isFilterActive =
|
const isFilterActive =
|
||||||
(selectedTypes?.length ?? 0) > 0 || selectedStatus !== "" || selectedState !== "";
|
(selectedTypes?.length ?? 0) > 0 ||
|
||||||
|
selectedStatus !== "" ||
|
||||||
|
selectedState !== "" ||
|
||||||
|
(selectedTags?.length ?? 0) > 0;
|
||||||
|
const selectedTagObjects = (tagOptions ?? []).filter((tag) =>
|
||||||
|
(selectedTags ?? []).includes(tag.id)
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
direction={isSmall ? "column" : "row"}
|
direction={isSmall ? "column" : "row"}
|
||||||
@@ -94,6 +108,36 @@ export const ControlsFilter = ({
|
|||||||
</MenuItem>
|
</MenuItem>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
|
{tagOptions && setSelectedTags && (
|
||||||
|
<Autocomplete
|
||||||
|
multiple
|
||||||
|
options={tagOptions}
|
||||||
|
value={selectedTagObjects}
|
||||||
|
getOptionLabel={(option) => option.name}
|
||||||
|
onChange={(_: unknown, newValue: Tag[]) => {
|
||||||
|
setSelectedTags(newValue.map((tag) => tag.id));
|
||||||
|
}}
|
||||||
|
isOptionEqualToValue={(option, value) => option.id === value.id}
|
||||||
|
renderOptionContent={(option) => (
|
||||||
|
<ColoredLabel
|
||||||
|
text={option.name}
|
||||||
|
color={option.color}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
renderInput={(params) => (
|
||||||
|
<TextField
|
||||||
|
{...params}
|
||||||
|
placeholder={t("common.table.headers.tags")}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
slotProps={{
|
||||||
|
popper: {
|
||||||
|
sx: { width: "fit-content !important", minWidth: 280 },
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
sx={{ minWidth: 180 }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{isFilterActive && (
|
{isFilterActive && (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
|
|||||||
Reference in new issue
Block a user