From 99402541fbe9b3b09e8184eb03c932d4ff5ae9f3 Mon Sep 17 00:00:00 2001 From: Dmytro Kozlov Date: Thu, 14 Jul 2022 00:05:47 +0300 Subject: [PATCH] vmui: update time picker behavior (#2847) * vmui: update time picker behavior * docs/CHANGELOG.md: document the change Co-authored-by: Aliaksandr Valialkin --- .../Configurator/Time/TimeSelector.tsx | 42 +++++++++++++++---- docs/CHANGELOG.md | 1 + 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/app/vmui/packages/vmui/src/components/CustomPanel/Configurator/Time/TimeSelector.tsx b/app/vmui/packages/vmui/src/components/CustomPanel/Configurator/Time/TimeSelector.tsx index e612dc96c4..8f4f2eb8cb 100644 --- a/app/vmui/packages/vmui/src/components/CustomPanel/Configurator/Time/TimeSelector.tsx +++ b/app/vmui/packages/vmui/src/components/CustomPanel/Configurator/Time/TimeSelector.tsx @@ -1,4 +1,5 @@ import React, {FC, useEffect, useState, useMemo} from "preact/compat"; +import {KeyboardEvent} from "react"; import {useAppDispatch, useAppState} from "../../../../state/common/StateContext"; import {dateFromSeconds, formatDateForNativeInput} from "../../../../utils/time"; import TimeDurationSelector from "./TimeDurationSelector"; @@ -13,6 +14,7 @@ import Paper from "@mui/material/Paper"; import Divider from "@mui/material/Divider"; import ClickAwayListener from "@mui/material/ClickAwayListener"; import Tooltip from "@mui/material/Tooltip"; +import AlarmAdd from "@mui/icons-material/AlarmAdd"; const formatDate = "YYYY-MM-DD HH:mm:ss"; @@ -35,6 +37,7 @@ const classes = { export const TimeSelector: FC = () => { + const [anchorEl, setAnchorEl] = useState(null); const [until, setUntil] = useState(); const [from, setFrom] = useState(); @@ -63,8 +66,30 @@ export const TimeSelector: FC = () => { }; }, [start, end]); - const [anchorEl, setAnchorEl] = useState(null); const open = Boolean(anchorEl); + const setTimeAndClosePicker = () => { + if (from) { + dispatch({type: "SET_FROM", payload: new Date(from)}); + } + if (until) { + dispatch({type: "SET_UNTIL", payload: new Date(until)}); + } + setAnchorEl(null); + }; + const onFromChange = (from: dayjs.Dayjs | null) => setFrom(from?.format(formatDate)); + const onUntilChange = (until: dayjs.Dayjs | null) => setUntil(until?.format(formatDate)); + const onApplyClick = () => setTimeAndClosePicker(); + const onSwitchToNow = () => dispatch({type: "RUN_QUERY_TO_NOW"}); + const onCancelClick = () => { + setUntil(formatDateForNativeInput(dateFromSeconds(end))); + setFrom(formatDateForNativeInput(dateFromSeconds(start))); + setAnchorEl(null); + }; + const onKeyDown = (e: KeyboardEvent) => { + if (e.key === "Enter" || e.keyCode === 13) { + setTimeAndClosePicker(); + } + }; return <> @@ -95,11 +120,11 @@ export const TimeSelector: FC = () => { label="From" ampm={false} value={from} - onChange={date => date && dispatch({type: "SET_FROM", payload: date as unknown as Date})} + onChange={onFromChange} onError={console.log} inputFormat={formatDate} mask="____-__-__ __:__:__" - renderInput={(params) => } + renderInput={(params) => } maxDate={dayjs(until)} PopperProps={{disablePortal: true}}/> @@ -108,18 +133,21 @@ export const TimeSelector: FC = () => { label="To" ampm={false} value={until} - onChange={date => date && dispatch({type: "SET_UNTIL", payload: date as unknown as Date})} + onChange={onUntilChange} onError={console.log} inputFormat={formatDate} mask="____-__-__ __:__:__" - renderInput={(params) => } + renderInput={(params) => } PopperProps={{disablePortal: true}}/> - - + diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 7e8d4aefa7..725ba8ebe9 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -76,6 +76,7 @@ scrape_configs: * BUGFIX: accept tags without values when reading data in [DataDog format](https://docs.victoriametrics.com/Single-server-VictoriaMetrics.html#how-to-send-data-from-datadog-agent). Thanks to @PerGon for the [pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/2839). * BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): properly pass the end of the selected time range to `time` query arg to [/api/v1/query](https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries) when displaying the requested data in JSON and table views. Previously the `time` query arg wasn't set, so `/api/v1/query` was always returning query results for the current time regardless of the selected time range. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2781). * BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): allow clicking on the suggestion from autocomplete list. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2804). +* BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): apply the selected time range in date picker only after clicking the `Apply` button. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2811). ## [v1.78.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.78.1)