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 Typography from "@mui/material/Typography";
|
||||||
import ConfigBox from "@/Components/v1/ConfigBox/index.jsx";
|
import ConfigBox from "@/Components/v1/ConfigBox/index.jsx";
|
||||||
import Select from "@/Components/v1/Inputs/Select/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
|
// Utils
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { PropTypes } from "prop-types";
|
import { PropTypes } from "prop-types";
|
||||||
import { useTranslation } from "react-i18next";
|
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 { t, i18n } = useTranslation();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const languages = Object.keys(i18n.options.resources || {});
|
const languages = Object.keys(i18n.options.resources || {});
|
||||||
|
const v2Theme = mode === "dark" ? darkTheme : lightTheme;
|
||||||
return (
|
return (
|
||||||
<ConfigBox>
|
<ConfigBox>
|
||||||
<Box>
|
<Box>
|
||||||
@@ -44,6 +48,19 @@ const SettingsUI = ({ HEADING_SX, handleChange, mode, language }) => {
|
|||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
items={languages.map((lang) => ({ _id: lang, name: lang.toUpperCase() }))}
|
items={languages.map((lang) => ({ _id: lang, name: lang.toUpperCase() }))}
|
||||||
></Select>
|
></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>
|
</Stack>
|
||||||
</ConfigBox>
|
</ConfigBox>
|
||||||
);
|
);
|
||||||
@@ -54,6 +71,7 @@ SettingsUI.propTypes = {
|
|||||||
handleChange: PropTypes.func,
|
handleChange: PropTypes.func,
|
||||||
mode: PropTypes.string,
|
mode: PropTypes.string,
|
||||||
language: PropTypes.string,
|
language: PropTypes.string,
|
||||||
|
chartType: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SettingsUI;
|
export default SettingsUI;
|
||||||
@@ -17,7 +17,7 @@ import { useState } from "react";
|
|||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
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 SettingsStats from "./SettingsStats.jsx";
|
||||||
|
|
||||||
import { useFetchSettings, useSaveSettings } from "@/Hooks/settingsHooks.js";
|
import { useFetchSettings, useSaveSettings } from "@/Hooks/settingsHooks.js";
|
||||||
@@ -33,7 +33,7 @@ const BREADCRUMBS = [{ name: `Settings`, path: "/settings" }];
|
|||||||
|
|
||||||
const Settings = () => {
|
const Settings = () => {
|
||||||
// Redux state
|
// 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
|
// Local state
|
||||||
const [settingsData, setSettingsData] = useState({});
|
const [settingsData, setSettingsData] = useState({});
|
||||||
@@ -112,6 +112,11 @@ const Settings = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (name === "chartType") {
|
||||||
|
dispatch(setChartType(value));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (name === "deleteStats") {
|
if (name === "deleteStats") {
|
||||||
await deleteMonitorStats();
|
await deleteMonitorStats();
|
||||||
return;
|
return;
|
||||||
@@ -209,6 +214,7 @@ const Settings = () => {
|
|||||||
handleChange={handleChange}
|
handleChange={handleChange}
|
||||||
mode={mode}
|
mode={mode}
|
||||||
language={language}
|
language={language}
|
||||||
|
chartType={chartType}
|
||||||
/>
|
/>
|
||||||
<SettingsPagespeed
|
<SettingsPagespeed
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
|
|||||||
@@ -123,7 +123,6 @@ export interface Check {
|
|||||||
seo?: number;
|
seo?: number;
|
||||||
performance?: number;
|
performance?: number;
|
||||||
audits?: CheckAudits;
|
audits?: CheckAudits;
|
||||||
__v: number;
|
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -974,6 +974,9 @@
|
|||||||
"description": "Switch between light and dark mode, or change user interface language.",
|
"description": "Switch between light and dark mode, or change user interface language.",
|
||||||
"labelLanguage": "Language",
|
"labelLanguage": "Language",
|
||||||
"labelTheme": "Theme mode",
|
"labelTheme": "Theme mode",
|
||||||
|
"labelChartType": "Chart type",
|
||||||
|
"chartTypeHistogram": "Histogram",
|
||||||
|
"chartTypeHeatmap": "Heatmap",
|
||||||
"title": "Appearance"
|
"title": "Appearance"
|
||||||
},
|
},
|
||||||
"urlSettings": {
|
"urlSettings": {
|
||||||
|
|||||||
Reference in new issue
Block a user