Update x-axis labels for uptime monitor details chart
This commit is contained in:
1 parent
67749585e0
commit
ef13af3884
2 files changed
+27
-14
No files matched your search
@@ -14,8 +14,14 @@ 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 "./index.css";
|
||||||
|
// ddd, MMMM D, YYYY, h:mm A
|
||||||
const CustomToolTip = ({ active, payload, label }) => {
|
const CustomToolTip = ({ active, payload, label, dateRange }) => {
|
||||||
|
const formatLookup = {
|
||||||
|
day: "ddd. MMMM D, YYYY, hh:mm A",
|
||||||
|
week: "ddd. MMMM D, YYYY, hh:mm A",
|
||||||
|
month: "ddd. MMMM D, YYYY",
|
||||||
|
};
|
||||||
|
const format = formatLookup[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 +47,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 +108,17 @@ 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 formatLookup = {
|
||||||
|
day: "h:mm A",
|
||||||
|
week: "MM/D, h:mm A",
|
||||||
|
month: "ddd. M/D",
|
||||||
|
};
|
||||||
|
const format = formatLookup[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 +128,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 +138,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 +195,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 +220,7 @@ const MonitorDetailsAreaChart = ({ checks }) => {
|
|||||||
|
|
||||||
MonitorDetailsAreaChart.propTypes = {
|
MonitorDetailsAreaChart.propTypes = {
|
||||||
checks: PropTypes.array,
|
checks: PropTypes.array,
|
||||||
|
dateRange: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default MonitorDetailsAreaChart;
|
export default MonitorDetailsAreaChart;
|
||||||
@@ -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