fix: change get display type (#2553)

This commit is contained in:
Yury Molodov 2022-05-16 10:44:13 +03:00 committed by GitHub
parent ff74472621
commit 4e6b483ef1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -9,10 +9,10 @@ import {SyntheticEvent} from "react";
export type DisplayType = "table" | "chart" | "code";
const tabs = [
{value: "chart", icon: <ShowChartIcon/>, label: "Graph"},
export const displayTypeTabs = [
{value: "chart", icon: <ShowChartIcon/>, label: "Graph", prometheusCode: 0},
{value: "code", icon: <CodeIcon/>, label: "JSON"},
{value: "table", icon: <TableChartIcon/>, label: "Table"}
{value: "table", icon: <TableChartIcon/>, label: "Table", prometheusCode: 1}
];
export const DisplayTypeSwitch: FC = () => {
@ -29,7 +29,7 @@ export const DisplayTypeSwitch: FC = () => {
onChange={handleChange}
sx={{minHeight: "0", marginBottom: "-1px"}}
>
{tabs.map(t =>
{displayTypeTabs.map(t =>
<Tab key={t.value}
icon={t.icon}
iconPosition="start"
@ -37,4 +37,4 @@ export const DisplayTypeSwitch: FC = () => {
sx={{minHeight: "41px"}}
/>)}
</Tabs>;
};
};

View File

@ -1,5 +1,5 @@
/* eslint max-lines: 0 */
import {DisplayType} from "../../components/CustomPanel/Configurator/DisplayTypeSwitch";
import {DisplayType, displayTypeTabs} from "../../components/CustomPanel/Configurator/DisplayTypeSwitch";
import {TimeParams, TimePeriod} from "../../types";
import {
dateFromSeconds,
@ -62,10 +62,12 @@ const {duration, endInput, relativeTimeId} = getRelativeTime({
defaultEndInput: new Date(formatDateToLocal(getQueryStringValue("g0.end_input", getDateNowUTC()) as Date)),
});
const query = getQueryArray();
const queryTab = getQueryStringValue("g0.tab", 0);
const displayType = displayTypeTabs.find(t => t.prometheusCode === queryTab || t.value === queryTab);
export const initialState: AppState = {
serverUrl: getDefaultServer(),
displayType: getQueryStringValue("g0.tab", "chart") as DisplayType || "chart",
displayType: (displayType?.value || "chart") as DisplayType,
query: query, // demo_memory_usage_bytes
queryHistory: query.map(q => ({index: 0, values: [q]})),
time: {