mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-09 15:27:11 +00:00
parent
f638496298
commit
edb45d7fc1
7 changed files with 83 additions and 21 deletions
|
@ -7,7 +7,7 @@ import Modal from "../../Main/Modal/Modal";
|
||||||
import "./style.scss";
|
import "./style.scss";
|
||||||
import Tooltip from "../../Main/Tooltip/Tooltip";
|
import Tooltip from "../../Main/Tooltip/Tooltip";
|
||||||
import LimitsConfigurator from "./LimitsConfigurator/LimitsConfigurator";
|
import LimitsConfigurator from "./LimitsConfigurator/LimitsConfigurator";
|
||||||
import { SeriesLimits } from "../../../types";
|
import { Theme } from "../../../types";
|
||||||
import { useCustomPanelDispatch, useCustomPanelState } from "../../../state/customPanel/CustomPanelStateContext";
|
import { useCustomPanelDispatch, useCustomPanelState } from "../../../state/customPanel/CustomPanelStateContext";
|
||||||
import { getAppModeEnable } from "../../../utils/app-mode";
|
import { getAppModeEnable } from "../../../utils/app-mode";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
|
@ -22,7 +22,7 @@ const GlobalSettings: FC = () => {
|
||||||
const { isMobile } = useDeviceDetect();
|
const { isMobile } = useDeviceDetect();
|
||||||
|
|
||||||
const appModeEnable = getAppModeEnable();
|
const appModeEnable = getAppModeEnable();
|
||||||
const { serverUrl: stateServerUrl } = useAppState();
|
const { serverUrl: stateServerUrl, theme } = useAppState();
|
||||||
const { timezone: stateTimezone } = useTimeState();
|
const { timezone: stateTimezone } = useTimeState();
|
||||||
const { seriesLimits } = useCustomPanelState();
|
const { seriesLimits } = useCustomPanelState();
|
||||||
|
|
||||||
|
@ -31,20 +31,40 @@ const GlobalSettings: FC = () => {
|
||||||
const customPanelDispatch = useCustomPanelDispatch();
|
const customPanelDispatch = useCustomPanelDispatch();
|
||||||
|
|
||||||
const [serverUrl, setServerUrl] = useState(stateServerUrl);
|
const [serverUrl, setServerUrl] = useState(stateServerUrl);
|
||||||
const [limits, setLimits] = useState<SeriesLimits>(seriesLimits);
|
const [limits, setLimits] = useState(seriesLimits);
|
||||||
const [timezone, setTimezone] = useState(stateTimezone);
|
const [timezone, setTimezone] = useState(stateTimezone);
|
||||||
|
|
||||||
|
const setDefaultsValues = () => {
|
||||||
|
setServerUrl(stateServerUrl);
|
||||||
|
setLimits(seriesLimits);
|
||||||
|
setTimezone(stateTimezone);
|
||||||
|
};
|
||||||
|
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const handleOpen = () => setOpen(true);
|
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 = () => {
|
const handlerApply = () => {
|
||||||
dispatch({ type: "SET_SERVER", payload: serverUrl });
|
dispatch({ type: "SET_SERVER", payload: serverUrl });
|
||||||
timeDispatch({ type: "SET_TIMEZONE", payload: timezone });
|
timeDispatch({ type: "SET_TIMEZONE", payload: timezone });
|
||||||
customPanelDispatch({ type: "SET_SERIES_LIMITS", payload: limits });
|
customPanelDispatch({ type: "SET_SERIES_LIMITS", payload: limits });
|
||||||
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// the tenant selector can change the serverUrl
|
||||||
if (stateServerUrl === serverUrl) return;
|
if (stateServerUrl === serverUrl) return;
|
||||||
setServerUrl(stateServerUrl);
|
setServerUrl(stateServerUrl);
|
||||||
}, [stateServerUrl]);
|
}, [stateServerUrl]);
|
||||||
|
@ -88,10 +108,10 @@ const GlobalSettings: FC = () => {
|
||||||
{!appModeEnable && (
|
{!appModeEnable && (
|
||||||
<div className="vm-server-configurator__input">
|
<div className="vm-server-configurator__input">
|
||||||
<ServerConfigurator
|
<ServerConfigurator
|
||||||
|
stateServerUrl={stateServerUrl}
|
||||||
serverUrl={serverUrl}
|
serverUrl={serverUrl}
|
||||||
onChange={setServerUrl}
|
onChange={setServerUrl}
|
||||||
onEnter={handlerApply}
|
onEnter={handlerApply}
|
||||||
onBlur={handlerApply}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
@ -110,9 +130,28 @@ const GlobalSettings: FC = () => {
|
||||||
</div>
|
</div>
|
||||||
{!appModeEnable && (
|
{!appModeEnable && (
|
||||||
<div className="vm-server-configurator__input">
|
<div className="vm-server-configurator__input">
|
||||||
<ThemeControl/>
|
<ThemeControl
|
||||||
|
theme={theme}
|
||||||
|
onChange={handleChangeTheme}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
<div className="vm-server-configurator-footer">
|
||||||
|
<Button
|
||||||
|
color="error"
|
||||||
|
variant="outlined"
|
||||||
|
onClick={handleCloseForce}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="primary"
|
||||||
|
variant="contained"
|
||||||
|
onClick={handlerApply}
|
||||||
|
>
|
||||||
|
Apply
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -51,7 +51,7 @@ const LimitsConfigurator: FC<ServerConfiguratorProps> = ({ limits, onChange , on
|
||||||
<div className="vm-limits-configurator">
|
<div className="vm-limits-configurator">
|
||||||
<div className="vm-server-configurator__title">
|
<div className="vm-server-configurator__title">
|
||||||
Series limits by tabs
|
Series limits by tabs
|
||||||
<Tooltip title="To disable limits set to 0">
|
<Tooltip title="Set to 0 to disable the limit">
|
||||||
<Button
|
<Button
|
||||||
variant="text"
|
variant="text"
|
||||||
color="primary"
|
color="primary"
|
||||||
|
@ -67,7 +67,7 @@ const LimitsConfigurator: FC<ServerConfiguratorProps> = ({ limits, onChange , on
|
||||||
startIcon={<RestartIcon/>}
|
startIcon={<RestartIcon/>}
|
||||||
onClick={handleReset}
|
onClick={handleReset}
|
||||||
>
|
>
|
||||||
Reset
|
Reset limits
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,16 +1,21 @@
|
||||||
import React, { FC, useState } from "preact/compat";
|
import React, { FC, useEffect, useState } from "preact/compat";
|
||||||
import { ErrorTypes } from "../../../../types";
|
import { ErrorTypes } from "../../../../types";
|
||||||
import TextField from "../../../Main/TextField/TextField";
|
import TextField from "../../../Main/TextField/TextField";
|
||||||
import { isValidHttpUrl } from "../../../../utils/url";
|
import { isValidHttpUrl } from "../../../../utils/url";
|
||||||
|
|
||||||
export interface ServerConfiguratorProps {
|
export interface ServerConfiguratorProps {
|
||||||
serverUrl: string
|
serverUrl: string
|
||||||
|
stateServerUrl: string
|
||||||
onChange: (url: string) => void
|
onChange: (url: string) => void
|
||||||
onEnter: () => void
|
onEnter: () => void
|
||||||
onBlur: () => void
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ServerConfigurator: FC<ServerConfiguratorProps> = ({ serverUrl, onChange , onEnter, onBlur }) => {
|
const ServerConfigurator: FC<ServerConfiguratorProps> = ({
|
||||||
|
serverUrl,
|
||||||
|
stateServerUrl,
|
||||||
|
onChange ,
|
||||||
|
onEnter
|
||||||
|
}) => {
|
||||||
|
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
|
@ -18,10 +23,13 @@ const ServerConfigurator: FC<ServerConfiguratorProps> = ({ serverUrl, onChange ,
|
||||||
const value = val || "";
|
const value = val || "";
|
||||||
onChange(value);
|
onChange(value);
|
||||||
setError("");
|
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 (
|
return (
|
||||||
<TextField
|
<TextField
|
||||||
autofocus
|
autofocus
|
||||||
|
@ -30,7 +38,6 @@ const ServerConfigurator: FC<ServerConfiguratorProps> = ({ serverUrl, onChange ,
|
||||||
error={error}
|
error={error}
|
||||||
onChange={onChangeServer}
|
onChange={onChangeServer}
|
||||||
onEnter={onEnter}
|
onEnter={onEnter}
|
||||||
onBlur={onBlur}
|
|
||||||
inputmode="url"
|
inputmode="url"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
&-list {
|
&-list {
|
||||||
max-height: 200px;
|
max-height: 300px;
|
||||||
background-color: $color-background-block;
|
background-color: $color-background-block;
|
||||||
border-radius: $border-radius-medium;
|
border-radius: $border-radius-medium;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
|
|
|
@ -32,4 +32,17 @@
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
margin-bottom: $padding-global;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import "./style.scss";
|
import "./style.scss";
|
||||||
import { useAppDispatch, useAppState } from "../../../state/common/StateContext";
|
|
||||||
import { Theme } from "../../../types";
|
import { Theme } from "../../../types";
|
||||||
import Toggle from "../../Main/Toggle/Toggle";
|
import Toggle from "../../Main/Toggle/Toggle";
|
||||||
import useDeviceDetect from "../../../hooks/useDeviceDetect";
|
import useDeviceDetect from "../../../hooks/useDeviceDetect";
|
||||||
import classNames from "classnames";
|
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 options = Object.values(Theme).map(value => ({ title: value, value }));
|
||||||
const ThemeControl = () => {
|
const ThemeControl: FC<ThemeControlProps> = ({ theme, onChange }) => {
|
||||||
const { isMobile } = useDeviceDetect();
|
const { isMobile } = useDeviceDetect();
|
||||||
const { theme } = useAppState();
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
|
|
||||||
const handleClickItem = (value: string) => {
|
const handleClickItem = (value: string) => {
|
||||||
dispatch({ type: "SET_THEME", payload: value as Theme });
|
onChange(value as Theme);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -79,7 +79,7 @@ export const useFetchQuery = ({
|
||||||
setFetchQueue([...fetchQueue, controller]);
|
setFetchQueue([...fetchQueue, controller]);
|
||||||
try {
|
try {
|
||||||
const isDisplayChart = displayType === "chart";
|
const isDisplayChart = displayType === "chart";
|
||||||
const seriesLimit = showAllSeries ? Infinity : stateSeriesLimits[displayType];
|
const seriesLimit = showAllSeries ? Infinity : (+stateSeriesLimits[displayType] || Infinity);
|
||||||
const tempData: MetricBase[] = [];
|
const tempData: MetricBase[] = [];
|
||||||
const tempTraces: Trace[] = [];
|
const tempTraces: Trace[] = [];
|
||||||
let counter = 1;
|
let counter = 1;
|
||||||
|
|
Loading…
Reference in a new issue