diff --git a/web/ui/mantine-ui/src/pages/query/ResolutionInput.tsx b/web/ui/mantine-ui/src/pages/query/ResolutionInput.tsx new file mode 100644 index 0000000000..7ca1ca44d7 --- /dev/null +++ b/web/ui/mantine-ui/src/pages/query/ResolutionInput.tsx @@ -0,0 +1,142 @@ +import { FC, useState } from "react"; +import { Select, TextInput } from "@mantine/core"; +import { + formatPrometheusDuration, + parsePrometheusDuration, +} from "../../lib/formatTime"; +import { + GraphResolution, + getEffectiveResolution, +} from "../../state/queryPageSlice"; + +interface ResolutionInputProps { + resolution: GraphResolution; + range: number; + onChangeResolution: (resolution: GraphResolution) => void; +} + +const ResolutionInput: FC = ({ + resolution, + range, + onChangeResolution, +}) => { + const [customResolutionInput, setCustomResolutionInput] = useState( + formatPrometheusDuration(getEffectiveResolution(resolution, range)) + ); + + const onChangeCustomResolutionInput = (resText: string): void => { + const newResolution = parsePrometheusDuration(resText); + + if (resolution.type === "custom" && newResolution === resolution.value) { + // Nothing changed. + return; + } + + if (newResolution === null) { + setCustomResolutionInput( + formatPrometheusDuration(getEffectiveResolution(resolution, range)) + ); + } else { + onChangeResolution({ type: "custom", value: newResolution }); + } + }; + + return ( + <> +