Files
Checkmate/client/src/Pages/Incidents/Components/OptionsHeader/index.jsx
T

139 lines
3.6 KiB
React
Raw Normal View History

2025-01-29 15:06:41 -08:00
// Components
import { Stack, Typography, Button, ButtonGroup } from "@mui/material";
2025-09-27 14:54:55 -07:00
import Select from "@/Components/v1/Inputs/Select/index.jsx";
2025-01-29 15:06:41 -08:00
import PropTypes from "prop-types";
//Utils
import { useTheme } from "@emotion/react";
2025-09-25 10:11:41 -07:00
import SkeletonLayout from "./skeleton.jsx";
2025-03-12 00:56:28 +05:30
import { useTranslation } from "react-i18next";
2025-01-29 15:06:41 -08:00
const OptionsHeader = ({
shouldRender,
selectedMonitor = 0,
setSelectedMonitor,
monitors,
filter = "all",
setFilter,
dateRange = "hour",
setDateRange,
}) => {
const theme = useTheme();
2025-03-12 00:56:28 +05:30
const { t } = useTranslation();
2025-01-29 15:06:41 -08:00
const monitorNames = typeof monitors !== "undefined" ? Object.values(monitors) : [];
2025-07-03 02:15:37 +05:30
const filterOptions = [
{ _id: "all", name: t("incidentsOptionsHeaderFilterAll") },
{ _id: "down", name: t("incidentsOptionsHeaderFilterDown") },
{ _id: "resolve", name: t("incidentsOptionsHeaderFilterCannotResolve") },
{ _id: "resolved", name: t("incidentsOptionsHeaderFilterResolved") },
];
2025-01-29 15:06:41 -08:00
2025-03-02 12:51:36 +05:30
// The stacks below which are three in number have the same style so
const stackStyles = {
direction: "row",
alignItems: "center",
gap: theme.spacing(6),
};
2025-01-29 15:06:41 -08:00
if (!shouldRender) return <SkeletonLayout />;
return (
<Stack
direction="row"
justifyContent="space-between"
>
2025-03-02 12:51:36 +05:30
<Stack {...stackStyles}>
2025-01-29 15:06:41 -08:00
<Typography
display="inline-block"
component="h1"
color={theme.palette.primary.contrastTextSecondary}
>
2025-03-12 00:56:28 +05:30
{t("incidentsOptionsHeader")}
2025-01-29 15:06:41 -08:00
</Typography>
<Select
id="incidents-select-monitor"
2025-03-12 00:56:28 +05:30
placeholder={t("incidentsOptionsPlaceholderAllServers")}
2025-01-29 15:06:41 -08:00
value={selectedMonitor}
onChange={(e) => setSelectedMonitor(e.target.value)}
items={monitorNames}
sx={{
backgroundColor: theme.palette.primary.main,
color: theme.palette.primary.contrastTextSecondary,
}}
maxWidth={250}
2025-01-29 15:06:41 -08:00
/>
</Stack>
2025-03-02 12:51:36 +05:30
<Stack {...stackStyles}>
2025-01-29 15:06:41 -08:00
<Typography
display="inline-block"
component="h1"
color={theme.palette.primary.contrastTextSecondary}
>
2025-03-12 00:56:28 +05:30
{t("incidentsOptionsHeaderFilterBy")}
2025-01-29 15:06:41 -08:00
</Typography>
2025-07-03 02:15:37 +05:30
<Select
id="incidents-select-filter"
value={filter}
onChange={(e) => setFilter(e.target.value)}
items={filterOptions}
sx={{
backgroundColor: theme.palette.primary.main,
color: theme.palette.primary.contrastTextSecondary,
}}
/>
2025-01-29 15:06:41 -08:00
</Stack>
2025-03-02 12:51:36 +05:30
<Stack {...stackStyles}>
2025-01-29 15:06:41 -08:00
<Typography
display="inline-block"
component="h1"
color={theme.palette.primary.contrastTextSecondary}
>
2025-03-12 00:56:28 +05:30
{t("incidentsOptionsHeaderShow")}
2025-01-29 15:06:41 -08:00
</Typography>
<ButtonGroup>
2025-01-29 15:06:41 -08:00
<Button
variant="group"
filled={(dateRange === "hour").toString()}
onClick={() => setDateRange("hour")}
>
2025-03-12 00:56:28 +05:30
{t("incidentsOptionsHeaderLastHour")}
2025-01-29 15:06:41 -08:00
</Button>
<Button
variant="group"
filled={(dateRange === "day").toString()}
onClick={() => setDateRange("day")}
>
2025-03-12 00:56:28 +05:30
{t("incidentsOptionsHeaderLastDay")}
2025-01-29 15:06:41 -08:00
</Button>
<Button
variant="group"
filled={(dateRange === "week").toString()}
onClick={() => setDateRange("week")}
>
2025-03-12 00:56:28 +05:30
{t("incidentsOptionsHeaderLastWeek")}
2025-01-29 15:06:41 -08:00
</Button>
<Button
variant="group"
filled={(dateRange === "all").toString()}
onClick={() => setDateRange("all")}
>
2025-03-12 00:56:28 +05:30
{t("incidentsOptionsHeaderFilterAll")}
2025-01-29 15:06:41 -08:00
</Button>
</ButtonGroup>
</Stack>
</Stack>
);
};
OptionsHeader.propTypes = {
shouldRender: PropTypes.bool,
selectedMonitor: PropTypes.string,
setSelectedMonitor: PropTypes.func,
monitors: PropTypes.object,
filter: PropTypes.string,
setFilter: PropTypes.func,
dateRange: PropTypes.string,
setDateRange: PropTypes.func,
};
export default OptionsHeader;