Merge pull request #1512 from bluewave-labs/fix/fe/charts-date-display
fix: fe/charts date display
This commit is contained in:
5 files changed
+77
-26
No files matched your search
@@ -13,9 +13,14 @@ import { useTheme } from "@emotion/react";
|
|||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { formatDateWithTz } from "../../../Utils/timeUtils";
|
import { formatDateWithTz } from "../../../Utils/timeUtils";
|
||||||
import "./index.css";
|
import {
|
||||||
|
tooltipDateFormatLookup,
|
||||||
|
tickDateFormatLookup,
|
||||||
|
} from "../Utils/chartUtilFunctions";
|
||||||
|
|
||||||
const CustomToolTip = ({ active, payload, label }) => {
|
import "./index.css";
|
||||||
|
const CustomToolTip = ({ active, payload, label, dateRange }) => {
|
||||||
|
const format = tooltipDateFormatLookup(dateRange);
|
||||||
const uiTimezone = useSelector((state) => state.ui.timezone);
|
const uiTimezone = useSelector((state) => state.ui.timezone);
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
if (active && payload && payload.length) {
|
if (active && payload && payload.length) {
|
||||||
@@ -41,7 +46,7 @@ const CustomToolTip = ({ active, payload, label }) => {
|
|||||||
fontWeight: 500,
|
fontWeight: 500,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{formatDateWithTz(label, "ddd, MMMM D, YYYY, h:mm A", uiTimezone)}
|
{formatDateWithTz(label, format, uiTimezone)}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Box mt={theme.spacing(1)}>
|
<Box mt={theme.spacing(1)}>
|
||||||
<Box
|
<Box
|
||||||
@@ -102,13 +107,12 @@ CustomToolTip.propTypes = {
|
|||||||
})
|
})
|
||||||
),
|
),
|
||||||
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
|
dateRange: PropTypes.string,
|
||||||
};
|
};
|
||||||
const CustomTick = ({ x, y, payload, index }) => {
|
const CustomTick = ({ x, y, payload, index, dateRange }) => {
|
||||||
|
const format = tickDateFormatLookup(dateRange);
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
const uiTimezone = useSelector((state) => state.ui.timezone);
|
const uiTimezone = useSelector((state) => state.ui.timezone);
|
||||||
// Render nothing for the first tick
|
|
||||||
if (index === 0) return null;
|
|
||||||
return (
|
return (
|
||||||
<Text
|
<Text
|
||||||
x={x}
|
x={x}
|
||||||
@@ -118,7 +122,7 @@ const CustomTick = ({ x, y, payload, index }) => {
|
|||||||
fontSize={11}
|
fontSize={11}
|
||||||
fontWeight={400}
|
fontWeight={400}
|
||||||
>
|
>
|
||||||
{formatDateWithTz(payload?.value, "h:mm a", uiTimezone)}
|
{formatDateWithTz(payload?.value, format, uiTimezone)}
|
||||||
</Text>
|
</Text>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -128,9 +132,10 @@ CustomTick.propTypes = {
|
|||||||
y: PropTypes.number,
|
y: PropTypes.number,
|
||||||
payload: PropTypes.object,
|
payload: PropTypes.object,
|
||||||
index: PropTypes.number,
|
index: PropTypes.number,
|
||||||
|
dateRange: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MonitorDetailsAreaChart = ({ checks }) => {
|
const MonitorDetailsAreaChart = ({ checks, dateRange }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const memoizedChecks = useMemo(() => checks, [checks[0]]);
|
const memoizedChecks = useMemo(() => checks, [checks[0]]);
|
||||||
const [isHovered, setIsHovered] = useState(false);
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
@@ -184,16 +189,14 @@ const MonitorDetailsAreaChart = ({ checks }) => {
|
|||||||
<XAxis
|
<XAxis
|
||||||
stroke={theme.palette.border.dark}
|
stroke={theme.palette.border.dark}
|
||||||
dataKey="_id"
|
dataKey="_id"
|
||||||
tick={<CustomTick />}
|
tick={<CustomTick dateRange={dateRange} />}
|
||||||
minTickGap={0}
|
|
||||||
axisLine={false}
|
axisLine={false}
|
||||||
tickLine={false}
|
tickLine={false}
|
||||||
height={20}
|
height={20}
|
||||||
interval="equidistantPreserveStart"
|
|
||||||
/>
|
/>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
cursor={{ stroke: theme.palette.border.light }}
|
cursor={{ stroke: theme.palette.border.light }}
|
||||||
content={<CustomToolTip />}
|
content={<CustomToolTip dateRange={dateRange} />}
|
||||||
wrapperStyle={{ pointerEvents: "none" }}
|
wrapperStyle={{ pointerEvents: "none" }}
|
||||||
/>
|
/>
|
||||||
<Area
|
<Area
|
||||||
@@ -211,6 +214,7 @@ const MonitorDetailsAreaChart = ({ checks }) => {
|
|||||||
|
|
||||||
MonitorDetailsAreaChart.propTypes = {
|
MonitorDetailsAreaChart.propTypes = {
|
||||||
checks: PropTypes.array,
|
checks: PropTypes.array,
|
||||||
|
dateRange: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default MonitorDetailsAreaChart;
|
export default MonitorDetailsAreaChart;
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
export const tooltipDateFormatLookup = (dateRange) => {
|
||||||
|
const dateFormatLookup = {
|
||||||
|
day: "ddd. MMMM D, YYYY, hh:mm A",
|
||||||
|
week: "ddd. MMMM D, YYYY, hh:mm A",
|
||||||
|
month: "ddd. MMMM D, YYYY",
|
||||||
|
};
|
||||||
|
const format = dateFormatLookup[dateRange];
|
||||||
|
if (format === undefined) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return format;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const tickDateFormatLookup = (dateRange) => {
|
||||||
|
const tickFormatLookup = {
|
||||||
|
day: "h:mm A",
|
||||||
|
week: "MM/D, h:mm A",
|
||||||
|
month: "ddd. M/D",
|
||||||
|
};
|
||||||
|
const format = tickFormatLookup[dateRange];
|
||||||
|
if (format === undefined) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return format;
|
||||||
|
};
|
||||||
@@ -4,7 +4,7 @@ import { useTheme } from "@mui/material";
|
|||||||
import { Text } from "recharts";
|
import { Text } from "recharts";
|
||||||
import { formatDateWithTz } from "../../../Utils/timeUtils";
|
import { formatDateWithTz } from "../../../Utils/timeUtils";
|
||||||
import { Box, Stack, Typography } from "@mui/material";
|
import { Box, Stack, Typography } from "@mui/material";
|
||||||
|
import { tickDateFormatLookup, tooltipDateFormatLookup } from "./chartUtilFunctions";
|
||||||
/**
|
/**
|
||||||
* Custom tick component for rendering time with timezone.
|
* Custom tick component for rendering time with timezone.
|
||||||
*
|
*
|
||||||
@@ -15,9 +15,10 @@ import { Box, Stack, Typography } from "@mui/material";
|
|||||||
* @param {number} props.index - The index of the tick.
|
* @param {number} props.index - The index of the tick.
|
||||||
* @returns {JSX.Element} The rendered tick component.
|
* @returns {JSX.Element} The rendered tick component.
|
||||||
*/
|
*/
|
||||||
export const TzTick = ({ x, y, payload, index }) => {
|
export const TzTick = ({ x, y, payload, index, dateRange }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const uiTimezone = useSelector((state) => state.ui.timezone);
|
const uiTimezone = useSelector((state) => state.ui.timezone);
|
||||||
|
const format = tickDateFormatLookup(dateRange);
|
||||||
return (
|
return (
|
||||||
<Text
|
<Text
|
||||||
x={x}
|
x={x}
|
||||||
@@ -27,7 +28,7 @@ export const TzTick = ({ x, y, payload, index }) => {
|
|||||||
fontSize={11}
|
fontSize={11}
|
||||||
fontWeight={400}
|
fontWeight={400}
|
||||||
>
|
>
|
||||||
{formatDateWithTz(payload?.value, "h:mm a", uiTimezone)}
|
{formatDateWithTz(payload?.value, format, uiTimezone)}
|
||||||
</Text>
|
</Text>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -37,6 +38,7 @@ TzTick.propTypes = {
|
|||||||
y: PropTypes.number,
|
y: PropTypes.number,
|
||||||
payload: PropTypes.object,
|
payload: PropTypes.object,
|
||||||
index: PropTypes.number,
|
index: PropTypes.number,
|
||||||
|
dateRange: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,9 +111,12 @@ export const InfrastructureTooltip = ({
|
|||||||
yIdx = -1,
|
yIdx = -1,
|
||||||
yLabel,
|
yLabel,
|
||||||
dotColor,
|
dotColor,
|
||||||
|
dateRange,
|
||||||
}) => {
|
}) => {
|
||||||
const uiTimezone = useSelector((state) => state.ui.timezone);
|
const uiTimezone = useSelector((state) => state.ui.timezone);
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
|
const format = tooltipDateFormatLookup(dateRange);
|
||||||
if (active && payload && payload.length) {
|
if (active && payload && payload.length) {
|
||||||
const [hardwareType, metric] = yKey.split(".");
|
const [hardwareType, metric] = yKey.split(".");
|
||||||
return (
|
return (
|
||||||
@@ -133,7 +138,7 @@ export const InfrastructureTooltip = ({
|
|||||||
fontWeight: 500,
|
fontWeight: 500,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{formatDateWithTz(label, "ddd, MMMM D, YYYY, h:mm A", uiTimezone)}
|
{formatDateWithTz(label, format, uiTimezone)}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Box mt={theme.spacing(1)}>
|
<Box mt={theme.spacing(1)}>
|
||||||
<Box
|
<Box
|
||||||
@@ -185,11 +190,20 @@ InfrastructureTooltip.propTypes = {
|
|||||||
yIdx: PropTypes.number,
|
yIdx: PropTypes.number,
|
||||||
yLabel: PropTypes.string,
|
yLabel: PropTypes.string,
|
||||||
dotColor: PropTypes.string,
|
dotColor: PropTypes.string,
|
||||||
|
dateRange: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TemperatureTooltip = ({ active, payload, label, keys, dotColor }) => {
|
export const TemperatureTooltip = ({
|
||||||
|
active,
|
||||||
|
payload,
|
||||||
|
label,
|
||||||
|
keys,
|
||||||
|
dotColor,
|
||||||
|
dateRange,
|
||||||
|
}) => {
|
||||||
const uiTimezone = useSelector((state) => state.ui.timezone);
|
const uiTimezone = useSelector((state) => state.ui.timezone);
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const format = tooltipDateFormatLookup(dateRange);
|
||||||
const formatCoreKey = (key) => {
|
const formatCoreKey = (key) => {
|
||||||
return key.replace(/^core(\d+)$/, "Core $1");
|
return key.replace(/^core(\d+)$/, "Core $1");
|
||||||
};
|
};
|
||||||
@@ -213,7 +227,7 @@ export const TemperatureTooltip = ({ active, payload, label, keys, dotColor }) =
|
|||||||
fontWeight: 500,
|
fontWeight: 500,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{formatDateWithTz(label, "ddd, MMMM D, YYYY, h:mm A", uiTimezone)}
|
{formatDateWithTz(label, format, uiTimezone)}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Stack direction="column">
|
<Stack direction="column">
|
||||||
@@ -273,4 +287,6 @@ TemperatureTooltip.propTypes = {
|
|||||||
PropTypes.string,
|
PropTypes.string,
|
||||||
PropTypes.number,
|
PropTypes.number,
|
||||||
]),
|
]),
|
||||||
|
dotColor: PropTypes.string,
|
||||||
|
dateRange: PropTypes.string,
|
||||||
};
|
};
|
||||||
@@ -13,9 +13,8 @@ import { useNavigate } from "react-router-dom";
|
|||||||
import Empty from "./empty";
|
import Empty from "./empty";
|
||||||
import { logger } from "../../../Utils/Logger";
|
import { logger } from "../../../Utils/Logger";
|
||||||
import { formatDurationRounded, formatDurationSplit } from "../../../Utils/timeUtils";
|
import { formatDurationRounded, formatDurationSplit } from "../../../Utils/timeUtils";
|
||||||
|
import { TzTick, PercentTick } from "../../../Components/Charts/Utils/chartUtils";
|
||||||
import {
|
import {
|
||||||
TzTick,
|
|
||||||
PercentTick,
|
|
||||||
InfrastructureTooltip,
|
InfrastructureTooltip,
|
||||||
TemperatureTooltip,
|
TemperatureTooltip,
|
||||||
} from "../../../Components/Charts/Utils/chartUtils";
|
} from "../../../Components/Charts/Utils/chartUtils";
|
||||||
@@ -414,12 +413,13 @@ const InfrastructureDetails = () => {
|
|||||||
yLabel: "Memory usage",
|
yLabel: "Memory usage",
|
||||||
yDomain: [0, 1],
|
yDomain: [0, 1],
|
||||||
yTick: <PercentTick />,
|
yTick: <PercentTick />,
|
||||||
xTick: <TzTick />,
|
xTick: <TzTick dateRange={dateRange} />,
|
||||||
toolTip: (
|
toolTip: (
|
||||||
<InfrastructureTooltip
|
<InfrastructureTooltip
|
||||||
dotColor={theme.palette.primary.main}
|
dotColor={theme.palette.primary.main}
|
||||||
yKey={"avgMemoryUsage"}
|
yKey={"avgMemoryUsage"}
|
||||||
yLabel={"Memory usage"}
|
yLabel={"Memory usage"}
|
||||||
|
dateRange={dateRange}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -433,12 +433,13 @@ const InfrastructureDetails = () => {
|
|||||||
yLabel: "CPU usage",
|
yLabel: "CPU usage",
|
||||||
yDomain: [0, 1],
|
yDomain: [0, 1],
|
||||||
yTick: <PercentTick />,
|
yTick: <PercentTick />,
|
||||||
xTick: <TzTick />,
|
xTick: <TzTick dateRange={dateRange} />,
|
||||||
toolTip: (
|
toolTip: (
|
||||||
<InfrastructureTooltip
|
<InfrastructureTooltip
|
||||||
dotColor={theme.palette.success.main}
|
dotColor={theme.palette.success.main}
|
||||||
yKey={"avgCpuUsage"}
|
yKey={"avgCpuUsage"}
|
||||||
yLabel={"CPU usage"}
|
yLabel={"CPU usage"}
|
||||||
|
dateRange={dateRange}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -450,7 +451,7 @@ const InfrastructureDetails = () => {
|
|||||||
gradientStartColor: theme.palette.error.main,
|
gradientStartColor: theme.palette.error.main,
|
||||||
heading: "CPU Temperature",
|
heading: "CPU Temperature",
|
||||||
yLabel: "Temperature",
|
yLabel: "Temperature",
|
||||||
xTick: <TzTick />,
|
xTick: <TzTick dateRange={dateRange} />,
|
||||||
yDomain: [
|
yDomain: [
|
||||||
0,
|
0,
|
||||||
Math.max(
|
Math.max(
|
||||||
@@ -462,6 +463,7 @@ const InfrastructureDetails = () => {
|
|||||||
<TemperatureTooltip
|
<TemperatureTooltip
|
||||||
keys={tempKeys}
|
keys={tempKeys}
|
||||||
dotColor={theme.palette.error.main}
|
dotColor={theme.palette.error.main}
|
||||||
|
dateRange={dateRange}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -476,13 +478,14 @@ const InfrastructureDetails = () => {
|
|||||||
yLabel: "Disk Usage",
|
yLabel: "Disk Usage",
|
||||||
yDomain: [0, 1],
|
yDomain: [0, 1],
|
||||||
yTick: <PercentTick />,
|
yTick: <PercentTick />,
|
||||||
xTick: <TzTick />,
|
xTick: <TzTick dateRange={dateRange} />,
|
||||||
toolTip: (
|
toolTip: (
|
||||||
<InfrastructureTooltip
|
<InfrastructureTooltip
|
||||||
dotColor={theme.palette.warning.main}
|
dotColor={theme.palette.warning.main}
|
||||||
yKey={`disks.usagePercent`}
|
yKey={`disks.usagePercent`}
|
||||||
yLabel={"Disc usage"}
|
yLabel={"Disc usage"}
|
||||||
yIdx={idx}
|
yIdx={idx}
|
||||||
|
dateRange={dateRange}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
})) || []),
|
})) || []),
|
||||||
|
|||||||
@@ -410,7 +410,10 @@ const DetailsPage = () => {
|
|||||||
</IconBox>
|
</IconBox>
|
||||||
<Typography component="h2">Response Times</Typography>
|
<Typography component="h2">Response Times</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
<MonitorDetailsAreaChart checks={monitor?.stats?.groupChecks ?? []} />
|
<MonitorDetailsAreaChart
|
||||||
|
checks={monitor?.stats?.groupChecks ?? []}
|
||||||
|
dateRange={dateRange}
|
||||||
|
/>
|
||||||
</ChartBox>
|
</ChartBox>
|
||||||
<ChartBox
|
<ChartBox
|
||||||
gap={theme.spacing(8)}
|
gap={theme.spacing(8)}
|
||||||
|
|||||||
Reference in new issue
Block a user