From 13a91f791dc0704768f2d49003cbace2b37274a6 Mon Sep 17 00:00:00 2001 From: Olof Bourghardt Date: Fri, 13 Aug 2021 08:02:49 +0200 Subject: [PATCH] Explore: use GrafanaTheme2 (Explore component) (#37445) * Explore: use GrafanaTheme2 * Explore: change width and paneel padding * Explore: remove the use of stylyesFactory * Explore: fix failing tests * Simpify calculation of width for ExploreGraphNGPanel * Update public/app/features/explore/Explore.tsx Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> * Update public/app/features/explore/Explore.tsx Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> * Prettified code Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> --- public/app/features/explore/Explore.test.tsx | 13 +++++++-- public/app/features/explore/Explore.tsx | 30 ++++++++------------ 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/public/app/features/explore/Explore.test.tsx b/public/app/features/explore/Explore.test.tsx index c0bfa7e7039..393ca9b8a58 100644 --- a/public/app/features/explore/Explore.test.tsx +++ b/public/app/features/explore/Explore.test.tsx @@ -1,11 +1,18 @@ import React from 'react'; -import { DataSourceApi, LoadingState, toUtc, DataQueryError, DataQueryRequest, CoreApp } from '@grafana/data'; +import { + DataSourceApi, + LoadingState, + toUtc, + DataQueryError, + DataQueryRequest, + CoreApp, + createTheme, +} from '@grafana/data'; import { ExploreId } from 'app/types/explore'; import { shallow } from 'enzyme'; import { Explore, Props } from './Explore'; import { scanStopAction } from './state/query'; import { SecondaryActions } from './SecondaryActions'; -import { getTheme } from '@grafana/ui'; const dummyProps: Props = { logsResult: undefined, @@ -69,7 +76,7 @@ const dummyProps: Props = { }, }, addQueryRow: jest.fn(), - theme: getTheme(), + theme: createTheme(), showMetrics: true, showLogs: true, showTable: true, diff --git a/public/app/features/explore/Explore.tsx b/public/app/features/explore/Explore.tsx index a196ba0a832..c9a818cbca3 100644 --- a/public/app/features/explore/Explore.tsx +++ b/public/app/features/explore/Explore.tsx @@ -6,15 +6,8 @@ import { connect, ConnectedProps } from 'react-redux'; import AutoSizer from 'react-virtualized-auto-sizer'; import memoizeOne from 'memoize-one'; import { selectors } from '@grafana/e2e-selectors'; -import { - ErrorBoundaryAlert, - stylesFactory, - withTheme, - CustomScrollbar, - Collapse, - TooltipDisplayMode, -} from '@grafana/ui'; -import { AbsoluteTimeRange, DataQuery, GrafanaTheme, LoadingState, RawTimeRange, DataFrame } from '@grafana/data'; +import { ErrorBoundaryAlert, CustomScrollbar, Collapse, TooltipDisplayMode, withTheme2, Themeable2 } from '@grafana/ui'; +import { AbsoluteTimeRange, DataQuery, LoadingState, RawTimeRange, DataFrame, GrafanaTheme2 } from '@grafana/data'; import LogsContainer from './LogsContainer'; import QueryRows from './QueryRows'; @@ -37,7 +30,7 @@ import { NodeGraphContainer } from './NodeGraphContainer'; import { ResponseErrorContainer } from './ResponseErrorContainer'; import { TraceViewContainer } from './TraceView/TraceViewContainer'; -const getStyles = stylesFactory((theme: GrafanaTheme) => { +const getStyles = (theme: GrafanaTheme2) => { return { exploreMain: css` label: exploreMain; @@ -55,14 +48,14 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => { height: auto !important; flex: unset !important; display: unset !important; - padding: ${theme.panelPadding}px; + padding: ${theme.spacing(1)}; `, }; -}); +}; -export interface ExploreProps { +export interface ExploreProps extends Themeable2 { exploreId: ExploreId; - theme: GrafanaTheme; + theme: GrafanaTheme2; } enum ExploreDrawer { @@ -195,12 +188,13 @@ export class Explore extends React.PureComponent { renderGraphPanel(width: number) { const { graphResult, absoluteRange, timeZone, splitOpen, queryResponse, loading, theme } = this.props; + const spacing = parseInt(theme.spacing(2).slice(0, -2), 10); return ( { renderLogsPanel(width: number) { const { exploreId, syncedTimes, theme } = this.props; - + const spacing = parseInt(theme.spacing(2).slice(0, -2), 10); return ( ; +export default compose(hot(module), connector, withTheme2)(Explore) as React.ComponentType<{ exploreId: ExploreId }>;