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.step) { // Nothing changed. return; } if (newResolution === null) { setCustomResolutionInput( formatPrometheusDuration(getEffectiveResolution(resolution, range)) ); } else { onChangeResolution({ type: "custom", step: newResolution }); } }; return ( <>