From edb45d7fc13d925cad6d147e84e543630e20d66d Mon Sep 17 00:00:00 2001 From: Yury Molodov Date: Mon, 3 Apr 2023 06:20:10 +0200 Subject: [PATCH] feat: add accept/cancel buttons for settings (#4013) (#4052) --- .../GlobalSettings/GlobalSettings.tsx | 51 ++++++++++++++++--- .../LimitsConfigurator/LimitsConfigurator.tsx | 4 +- .../ServerConfigurator/ServerConfigurator.tsx | 19 ++++--- .../GlobalSettings/Timezones/style.scss | 2 +- .../Configurators/GlobalSettings/style.scss | 13 +++++ .../ThemeControl/ThemeControl.tsx | 13 +++-- .../packages/vmui/src/hooks/useFetchQuery.ts | 2 +- 7 files changed, 83 insertions(+), 21 deletions(-) diff --git a/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/GlobalSettings.tsx b/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/GlobalSettings.tsx index fb7c0ec2b..4751a112e 100644 --- a/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/GlobalSettings.tsx +++ b/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/GlobalSettings.tsx @@ -7,7 +7,7 @@ import Modal from "../../Main/Modal/Modal"; import "./style.scss"; import Tooltip from "../../Main/Tooltip/Tooltip"; import LimitsConfigurator from "./LimitsConfigurator/LimitsConfigurator"; -import { SeriesLimits } from "../../../types"; +import { Theme } from "../../../types"; import { useCustomPanelDispatch, useCustomPanelState } from "../../../state/customPanel/CustomPanelStateContext"; import { getAppModeEnable } from "../../../utils/app-mode"; import classNames from "classnames"; @@ -22,7 +22,7 @@ const GlobalSettings: FC = () => { const { isMobile } = useDeviceDetect(); const appModeEnable = getAppModeEnable(); - const { serverUrl: stateServerUrl } = useAppState(); + const { serverUrl: stateServerUrl, theme } = useAppState(); const { timezone: stateTimezone } = useTimeState(); const { seriesLimits } = useCustomPanelState(); @@ -31,20 +31,40 @@ const GlobalSettings: FC = () => { const customPanelDispatch = useCustomPanelDispatch(); const [serverUrl, setServerUrl] = useState(stateServerUrl); - const [limits, setLimits] = useState(seriesLimits); + const [limits, setLimits] = useState(seriesLimits); const [timezone, setTimezone] = useState(stateTimezone); + const setDefaultsValues = () => { + setServerUrl(stateServerUrl); + setLimits(seriesLimits); + setTimezone(stateTimezone); + }; + const [open, setOpen] = useState(false); const handleOpen = () => setOpen(true); - const handleClose = () => setOpen(false); + const handleClose = () => { + setOpen(false); + setDefaultsValues(); + }; + + const handleCloseForce = () => { + setOpen(false); + setDefaultsValues(); + }; + + const handleChangeTheme = (value: Theme) => { + dispatch({ type: "SET_THEME", payload: value }); + }; const handlerApply = () => { dispatch({ type: "SET_SERVER", payload: serverUrl }); timeDispatch({ type: "SET_TIMEZONE", payload: timezone }); customPanelDispatch({ type: "SET_SERIES_LIMITS", payload: limits }); + setOpen(false); }; useEffect(() => { + // the tenant selector can change the serverUrl if (stateServerUrl === serverUrl) return; setServerUrl(stateServerUrl); }, [stateServerUrl]); @@ -88,10 +108,10 @@ const GlobalSettings: FC = () => { {!appModeEnable && (
)} @@ -110,9 +130,28 @@ const GlobalSettings: FC = () => { {!appModeEnable && (
- +
)} +
+ + +
)} diff --git a/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/LimitsConfigurator/LimitsConfigurator.tsx b/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/LimitsConfigurator/LimitsConfigurator.tsx index d4ce7e0f7..0e898e42c 100644 --- a/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/LimitsConfigurator/LimitsConfigurator.tsx +++ b/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/LimitsConfigurator/LimitsConfigurator.tsx @@ -51,7 +51,7 @@ const LimitsConfigurator: FC = ({ limits, onChange , on
Series limits by tabs - +
diff --git a/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/ServerConfigurator/ServerConfigurator.tsx b/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/ServerConfigurator/ServerConfigurator.tsx index 7705911b2..6f0600aad 100644 --- a/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/ServerConfigurator/ServerConfigurator.tsx +++ b/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/ServerConfigurator/ServerConfigurator.tsx @@ -1,16 +1,21 @@ -import React, { FC, useState } from "preact/compat"; +import React, { FC, useEffect, useState } from "preact/compat"; import { ErrorTypes } from "../../../../types"; import TextField from "../../../Main/TextField/TextField"; import { isValidHttpUrl } from "../../../../utils/url"; export interface ServerConfiguratorProps { serverUrl: string + stateServerUrl: string onChange: (url: string) => void onEnter: () => void - onBlur: () => void } -const ServerConfigurator: FC = ({ serverUrl, onChange , onEnter, onBlur }) => { +const ServerConfigurator: FC = ({ + serverUrl, + stateServerUrl, + onChange , + onEnter +}) => { const [error, setError] = useState(""); @@ -18,10 +23,13 @@ const ServerConfigurator: FC = ({ serverUrl, onChange , const value = val || ""; onChange(value); setError(""); - if (!value) setError(ErrorTypes.emptyServer); - if (!isValidHttpUrl(value)) setError(ErrorTypes.validServer); }; + useEffect(() => { + if (!stateServerUrl) setError(ErrorTypes.emptyServer); + if (!isValidHttpUrl(stateServerUrl)) setError(ErrorTypes.validServer); + }, [stateServerUrl]); + return ( = ({ serverUrl, onChange , error={error} onChange={onChangeServer} onEnter={onEnter} - onBlur={onBlur} inputmode="url" /> ); diff --git a/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/Timezones/style.scss b/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/Timezones/style.scss index 266172f89..512f24db3 100644 --- a/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/Timezones/style.scss +++ b/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/Timezones/style.scss @@ -46,7 +46,7 @@ } &-list { - max-height: 200px; + max-height: 300px; background-color: $color-background-block; border-radius: $border-radius-medium; overflow: auto; diff --git a/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/style.scss b/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/style.scss index ff26ee339..9a1706615 100644 --- a/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/style.scss +++ b/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/style.scss @@ -32,4 +32,17 @@ font-weight: bold; margin-bottom: $padding-global; } + + &-footer { + display: flex; + align-items: center; + justify-content: flex-end; + gap: $padding-small; + width: 100%; + } + + &_mobile &-footer { + display: grid; + grid-template-columns: 1fr 1fr; + } } diff --git a/app/vmui/packages/vmui/src/components/Configurators/ThemeControl/ThemeControl.tsx b/app/vmui/packages/vmui/src/components/Configurators/ThemeControl/ThemeControl.tsx index c770f506a..1d2885004 100644 --- a/app/vmui/packages/vmui/src/components/Configurators/ThemeControl/ThemeControl.tsx +++ b/app/vmui/packages/vmui/src/components/Configurators/ThemeControl/ThemeControl.tsx @@ -1,19 +1,22 @@ import React from "react"; import "./style.scss"; -import { useAppDispatch, useAppState } from "../../../state/common/StateContext"; import { Theme } from "../../../types"; import Toggle from "../../Main/Toggle/Toggle"; import useDeviceDetect from "../../../hooks/useDeviceDetect"; import classNames from "classnames"; +import { FC } from "preact/compat"; + +interface ThemeControlProps { + theme: Theme; + onChange: (val: Theme) => void +} const options = Object.values(Theme).map(value => ({ title: value, value })); -const ThemeControl = () => { +const ThemeControl: FC = ({ theme, onChange }) => { const { isMobile } = useDeviceDetect(); - const { theme } = useAppState(); - const dispatch = useAppDispatch(); const handleClickItem = (value: string) => { - dispatch({ type: "SET_THEME", payload: value as Theme }); + onChange(value as Theme); }; return ( diff --git a/app/vmui/packages/vmui/src/hooks/useFetchQuery.ts b/app/vmui/packages/vmui/src/hooks/useFetchQuery.ts index e105bc92b..5c9dcf2c5 100644 --- a/app/vmui/packages/vmui/src/hooks/useFetchQuery.ts +++ b/app/vmui/packages/vmui/src/hooks/useFetchQuery.ts @@ -79,7 +79,7 @@ export const useFetchQuery = ({ setFetchQueue([...fetchQueue, controller]); try { const isDisplayChart = displayType === "chart"; - const seriesLimit = showAllSeries ? Infinity : stateSeriesLimits[displayType]; + const seriesLimit = showAllSeries ? Infinity : (+stateSeriesLimits[displayType] || Infinity); const tempData: MetricBase[] = []; const tempTraces: Trace[] = []; let counter = 1;