mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Clear the query page when navigating away from it
Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
parent
c73c3e24d7
commit
53affc64db
|
@ -5,7 +5,11 @@ import {
|
|||
IconPlus,
|
||||
} from "@tabler/icons-react";
|
||||
import { useAppDispatch, useAppSelector } from "../../state/hooks";
|
||||
import { addPanel, setPanels } from "../../state/queryPageSlice";
|
||||
import {
|
||||
addPanel,
|
||||
newDefaultPanel,
|
||||
setPanels,
|
||||
} from "../../state/queryPageSlice";
|
||||
import Panel from "./QueryPanel";
|
||||
import { LabelValuesResult } from "../../api/responseTypes/labelValues";
|
||||
import { useAPIQuery } from "../../api/api";
|
||||
|
@ -19,6 +23,7 @@ export default function QueryPage() {
|
|||
const dispatch = useAppDispatch();
|
||||
const [timeDelta, setTimeDelta] = useState(0);
|
||||
|
||||
// Update the panels whenever the URL params change.
|
||||
useEffect(() => {
|
||||
const handleURLChange = () => {
|
||||
const panels = decodePanelOptionsFromURLParams(window.location.search);
|
||||
|
@ -36,6 +41,13 @@ export default function QueryPage() {
|
|||
};
|
||||
}, [dispatch]);
|
||||
|
||||
// Clear the query page when navigating away from it.
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
dispatch(setPanels([newDefaultPanel()]));
|
||||
};
|
||||
}, [dispatch]);
|
||||
|
||||
const { data: metricNamesResult, error: metricNamesError } =
|
||||
useAPIQuery<LabelValuesResult>({
|
||||
path: "/label/__name__/values",
|
||||
|
@ -50,7 +62,10 @@ export default function QueryPage() {
|
|||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (timeResult) {
|
||||
if (!timeResult) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (timeResult.data.resultType !== "scalar") {
|
||||
throw new Error("Unexpected result type from time query");
|
||||
}
|
||||
|
@ -58,7 +73,6 @@ export default function QueryPage() {
|
|||
const browserTime = new Date().getTime() / 1000;
|
||||
const serverTime = timeResult.data.result[0];
|
||||
setTimeDelta(Math.abs(browserTime - serverTime));
|
||||
}
|
||||
}, [timeResult]);
|
||||
|
||||
return (
|
||||
|
|
Loading…
Reference in a new issue