chart type option
This commit is contained in:
1 parent
61f3aa1d1c
commit
9904626526
5 files changed
+97
-4
No files matched your search
@@ -0,0 +1,67 @@
|
||||
import Box from "@mui/material/Box";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { HeatmapResponseTime, HistogramResponseTime } from "@/Components/v2/common";
|
||||
import type { Check } from "@/Types/Check";
|
||||
|
||||
interface DummyChartProps {
|
||||
chartType: string;
|
||||
}
|
||||
|
||||
const generateDummyChecks = (): Check[] => {
|
||||
const checks: Check[] = [];
|
||||
for (let i = 0; i < 25; i++) {
|
||||
const isUp = Math.random() > 0.1;
|
||||
checks.push({
|
||||
id: `dummy-${i}`,
|
||||
metadata: {
|
||||
monitorId: "dummy-monitor",
|
||||
teamId: "dummy-team",
|
||||
type: "http",
|
||||
},
|
||||
status: isUp,
|
||||
statusCode: isUp ? 200 : 500,
|
||||
responseTime: Math.floor(Math.random() * 80) + 20,
|
||||
message: "",
|
||||
ack: false,
|
||||
expiry: new Date(Date.now() + 86400000).toISOString(),
|
||||
createdAt: new Date(Date.now() - i * 60000).toISOString(),
|
||||
updatedAt: new Date(Date.now() - i * 60000).toISOString(),
|
||||
});
|
||||
}
|
||||
return checks;
|
||||
};
|
||||
|
||||
const dummyChecks = generateDummyChecks();
|
||||
|
||||
const DummyChart = ({ chartType }: DummyChartProps) => {
|
||||
const theme = useTheme();
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
mt: theme.spacing(4),
|
||||
p: theme.spacing(4),
|
||||
border: 1,
|
||||
borderColor: theme.palette.divider,
|
||||
borderRadius: theme.shape.borderRadius,
|
||||
backgroundColor: theme.palette.background.paper,
|
||||
}}
|
||||
>
|
||||
<Typography
|
||||
variant="body2"
|
||||
color="text.secondary"
|
||||
sx={{ mb: theme.spacing(2) }}
|
||||
>
|
||||
Preview
|
||||
</Typography>
|
||||
{chartType === "histogram" ? (
|
||||
<HistogramResponseTime checks={dummyChecks} />
|
||||
) : (
|
||||
<HeatmapResponseTime checks={dummyChecks} />
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default DummyChart;
|
||||
@@ -3,16 +3,20 @@ import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import ConfigBox from "@/Components/v1/ConfigBox/index.jsx";
|
||||
import Select from "@/Components/v1/Inputs/Select/index.jsx";
|
||||
import DummyChart from "./DummyChart";
|
||||
import { ThemeProvider } from "@mui/material/styles";
|
||||
import { lightTheme, darkTheme } from "@/Utils/Theme/v2Theme";
|
||||
|
||||
// Utils
|
||||
import { useTheme } from "@emotion/react";
|
||||
import { PropTypes } from "prop-types";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
const SettingsUI = ({ HEADING_SX, handleChange, mode, language }) => {
|
||||
const SettingsUI = ({ HEADING_SX, handleChange, mode, language, chartType }) => {
|
||||
const { t, i18n } = useTranslation();
|
||||
const theme = useTheme();
|
||||
const languages = Object.keys(i18n.options.resources || {});
|
||||
const v2Theme = mode === "dark" ? darkTheme : lightTheme;
|
||||
return (
|
||||
<ConfigBox>
|
||||
<Box>
|
||||
@@ -44,6 +48,19 @@ const SettingsUI = ({ HEADING_SX, handleChange, mode, language }) => {
|
||||
onChange={handleChange}
|
||||
items={languages.map((lang) => ({ _id: lang, name: lang.toUpperCase() }))}
|
||||
></Select>
|
||||
<Select
|
||||
name="chartType"
|
||||
label={t("settingsPage.uiSettings.labelChartType")}
|
||||
value={chartType}
|
||||
onChange={handleChange}
|
||||
items={[
|
||||
{ _id: "histogram", name: t("settingsPage.uiSettings.chartTypeHistogram") },
|
||||
{ _id: "heatmap", name: t("settingsPage.uiSettings.chartTypeHeatmap") },
|
||||
]}
|
||||
></Select>
|
||||
<ThemeProvider theme={v2Theme}>
|
||||
<DummyChart chartType={chartType} />
|
||||
</ThemeProvider>
|
||||
</Stack>
|
||||
</ConfigBox>
|
||||
);
|
||||
@@ -54,6 +71,7 @@ SettingsUI.propTypes = {
|
||||
handleChange: PropTypes.func,
|
||||
mode: PropTypes.string,
|
||||
language: PropTypes.string,
|
||||
chartType: PropTypes.string,
|
||||
};
|
||||
|
||||
export default SettingsUI;
|
||||
@@ -17,7 +17,7 @@ import { useState } from "react";
|
||||
import { useTheme } from "@emotion/react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { setTimezone, setMode, setLanguage, setShowURL } from "@/Features/UI/uiSlice.js";
|
||||
import { setTimezone, setMode, setLanguage, setShowURL, setChartType } from "@/Features/UI/uiSlice.js";
|
||||
import SettingsStats from "./SettingsStats.jsx";
|
||||
|
||||
import { useFetchSettings, useSaveSettings } from "@/Hooks/settingsHooks.js";
|
||||
@@ -33,7 +33,7 @@ const BREADCRUMBS = [{ name: `Settings`, path: "/settings" }];
|
||||
|
||||
const Settings = () => {
|
||||
// Redux state
|
||||
const { mode, language = "en", timezone, showURL } = useSelector((state) => state.ui);
|
||||
const { mode, language = "en", timezone, showURL, chartType = "histogram" } = useSelector((state) => state.ui);
|
||||
|
||||
// Local state
|
||||
const [settingsData, setSettingsData] = useState({});
|
||||
@@ -112,6 +112,11 @@ const Settings = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (name === "chartType") {
|
||||
dispatch(setChartType(value));
|
||||
return;
|
||||
}
|
||||
|
||||
if (name === "deleteStats") {
|
||||
await deleteMonitorStats();
|
||||
return;
|
||||
@@ -209,6 +214,7 @@ const Settings = () => {
|
||||
handleChange={handleChange}
|
||||
mode={mode}
|
||||
language={language}
|
||||
chartType={chartType}
|
||||
/>
|
||||
<SettingsPagespeed
|
||||
isAdmin={isAdmin}
|
||||
|
||||
@@ -123,7 +123,6 @@ export interface Check {
|
||||
seo?: number;
|
||||
performance?: number;
|
||||
audits?: CheckAudits;
|
||||
__v: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
@@ -974,6 +974,9 @@
|
||||
"description": "Switch between light and dark mode, or change user interface language.",
|
||||
"labelLanguage": "Language",
|
||||
"labelTheme": "Theme mode",
|
||||
"labelChartType": "Chart type",
|
||||
"chartTypeHistogram": "Histogram",
|
||||
"chartTypeHeatmap": "Heatmap",
|
||||
"title": "Appearance"
|
||||
},
|
||||
"urlSettings": {
|
||||
|
||||
Reference in new issue
Block a user