Minor refactoring around theme access

This commit is contained in:
Torkel Ödegaard 2019-02-08 15:38:45 +01:00
parent 7e03913d0d
commit 5436c28448
9 changed files with 13 additions and 60 deletions

View File

@ -6,13 +6,11 @@ module.exports = {
},
"moduleDirectories": ["node_modules", "public"],
"roots": [
"<rootDir>/scripts",
"<rootDir>/public/app",
"<rootDir>/public/test",
"<rootDir>/packages"
],
"testRegex": "(\\.|/)(test)\\.(jsx?|tsx?)$",
"testPathIgnorePatterns": ["webpack.test.js"],
"moduleFileExtensions": [
"ts",
"tsx",

View File

@ -1,5 +1,6 @@
import _ from 'lodash';
import { PanelPlugin } from 'app/types/plugins';
import { GrafanaTheme, getTheme, GrafanaThemeType } from '@grafana/ui';
export interface BuildInfo {
version: string;
@ -36,8 +37,11 @@ export class Settings {
loginError: any;
viewersCanEdit: boolean;
disableSanitizeHtml: boolean;
theme: GrafanaTheme;
constructor(options: Settings) {
this.theme = options.bootData.user.lightTheme ? getTheme(GrafanaThemeType.Light) : getTheme(GrafanaThemeType.Dark);
const defaults = {
datasources: {},
windowTitlePrefix: 'Grafana - ',

View File

@ -2,7 +2,6 @@ import React, { PureComponent } from 'react';
import classNames from 'classnames';
import { TimeSeries } from 'app/core/core';
import { SeriesColorPicker } from '@grafana/ui';
// import { ThemeProvider } from 'app/core/utils/ConfigProvider';
export const LEGEND_STATS = ['min', 'max', 'avg', 'current', 'total'];

View File

@ -1,5 +1,5 @@
import _ from 'lodash';
import { colors, GrafanaThemeType, getColorFromHexRgbOrName } from '@grafana/ui';
import { colors, getColorFromHexRgbOrName } from '@grafana/ui';
import TimeSeries from 'app/core/time_series2';
import config from 'app/core/config';
@ -113,7 +113,7 @@ export class DataProcessor {
const series = new TimeSeries({
datapoints: datapoints,
alias: alias,
color: getColorFromHexRgbOrName(color, config.bootData.user.lightTheme ? GrafanaThemeType.Light : GrafanaThemeType.Dark),
color: getColorFromHexRgbOrName(color, config.theme.type),
unit: seriesData.unit,
});

View File

@ -25,7 +25,7 @@ import ReactDOM from 'react-dom';
import { Legend, GraphLegendProps } from './Legend/Legend';
import { GraphCtrl } from './module';
import { GrafanaThemeType, getValueFormat } from '@grafana/ui';
import { getValueFormat } from '@grafana/ui';
import { provideTheme } from 'app/core/utils/ConfigProvider';
const LegendWithThemeProvider = provideTheme(Legend);
@ -55,10 +55,7 @@ class GraphElement {
this.panelWidth = 0;
this.eventManager = new EventManager(this.ctrl);
this.thresholdManager = new ThresholdManager(this.ctrl);
this.timeRegionManager = new TimeRegionManager(
this.ctrl,
config.bootData.user.lightTheme ? GrafanaThemeType.Light : GrafanaThemeType.Dark
);
this.timeRegionManager = new TimeRegionManager(this.ctrl, config.theme.type);
this.tooltip = new GraphTooltip(this.elem, this.ctrl.dashboard, this.scope, () => {
return this.sortedSeries;
});

View File

@ -10,7 +10,7 @@ import { MetricsPanelCtrl } from 'app/plugins/sdk';
import { DataProcessor } from './data_processor';
import { axesEditorComponent } from './axes_editor';
import config from 'app/core/config';
import { GrafanaThemeType, getColorFromHexRgbOrName } from '@grafana/ui';
import { getColorFromHexRgbOrName } from '@grafana/ui';
class GraphCtrl extends MetricsPanelCtrl {
static template = template;
@ -244,7 +244,7 @@ class GraphCtrl extends MetricsPanelCtrl {
}
onColorChange = (series, color) => {
series.setColor(getColorFromHexRgbOrName(color, config.bootData.user.lightTheme ? GrafanaThemeType.Light : GrafanaThemeType.Dark));
series.setColor(getColorFromHexRgbOrName(color, config.theme.type));
this.panel.aliasColors[series.alias] = color;
this.render();
};

View File

@ -588,10 +588,7 @@ class SingleStatCtrl extends MetricsPanelCtrl {
fill: 1,
zero: false,
lineWidth: 1,
fillColor: getColorFromHexRgbOrName(
panel.sparkline.fillColor,
config.bootData.user.lightTheme ? GrafanaThemeType.Light : GrafanaThemeType.Dark
),
fillColor: getColorFromHexRgbOrName(panel.sparkline.fillColor, config.theme.type),
},
},
yaxes: { show: false },
@ -608,10 +605,7 @@ class SingleStatCtrl extends MetricsPanelCtrl {
const plotSeries = {
data: data.flotpairs,
color: getColorFromHexRgbOrName(
panel.sparkline.lineColor,
config.bootData.user.lightTheme ? GrafanaThemeType.Light : GrafanaThemeType.Dark
),
color: getColorFromHexRgbOrName(panel.sparkline.lineColor, config.theme.type),
};
$.plot(plotCanvas, [plotSeries], options);

View File

@ -6,7 +6,6 @@ import { transformDataToTable } from './transformers';
import { tablePanelEditor } from './editor';
import { columnOptionsTab } from './column_options';
import { TableRenderer } from './renderer';
import { GrafanaThemeType } from '@grafana/ui';
class TablePanelCtrl extends MetricsPanelCtrl {
static templateUrl = 'module.html';
@ -131,7 +130,7 @@ class TablePanelCtrl extends MetricsPanelCtrl {
this.dashboard.isTimezoneUtc(),
this.$sanitize,
this.templateSrv,
config.bootData.user.lightTheme ? GrafanaThemeType.Light : GrafanaThemeType.Dark,
config.theme.type
);
return super.render(this.table);

View File

@ -1,38 +0,0 @@
const webpack = require('webpack');
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
config = merge(common, {
mode: 'development',
devtool: 'cheap-module-source-map',
externals: {
'react/addons': true,
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': true,
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
},
],
},
plugins: [
new webpack.SourceMapDevToolPlugin({
filename: null, // if no value is provided the sourcemap is inlined
test: /\.(ts|js)($|\?)/i, // process .js and .ts files only
}),
],
});
module.exports = config;