Explore: Refactor ExploreGraph (#58660)

* WIP

* revert collapse changes

* use HorizontalGroup instead of custom styles

* fix tests

* use import aliases
This commit is contained in:
Giordano Ricci
2022-11-16 11:16:27 +01:00
committed by GitHub
parent 174a039ee1
commit 2a9381e998
13 changed files with 136 additions and 109 deletions

View File

@@ -30,7 +30,7 @@ import { RefreshPicker } from '@grafana/ui';
import store from 'app/core/store';
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
import { PanelModel } from 'app/features/dashboard/state';
import { EXPLORE_GRAPH_STYLES, ExploreGraphStyle, ExploreId, QueryOptions, QueryTransaction } from 'app/types/explore';
import { ExploreId, QueryOptions, QueryTransaction } from 'app/types/explore';
import { config } from '../config';
@@ -205,21 +205,6 @@ export const safeStringifyValue = (value: any, space?: number) => {
return '';
};
const DEFAULT_GRAPH_STYLE: ExploreGraphStyle = 'lines';
// we use this function to take any kind of data we loaded
// from an external source (URL, localStorage, whatever),
// and extract the graph-style from it, or return the default
// graph-style if we are not able to do that.
// it is important that this function is able to take any form of data,
// (be it objects, or arrays, or booleans or whatever),
// and produce a best-effort graphStyle.
// note that typescript makes sure we make no mistake in this function.
// we do not rely on ` as ` or ` any `.
export const toGraphStyle = (data: unknown): ExploreGraphStyle => {
const found = EXPLORE_GRAPH_STYLES.find((v) => v === data);
return found ?? DEFAULT_GRAPH_STYLE;
};
export function parseUrlState(initial: string | undefined): ExploreUrlState {
const parsed = safeParseJson(initial);
const errorResult: any = {