Minor refactoring around theme access

pull/15235/head
Torkel Ödegaard 6 years ago
parent 7e03913d0d
commit 5436c28448
  1. 2
      jest.config.js
  2. 4
      public/app/core/config.ts
  3. 1
      public/app/plugins/panel/graph/Legend/LegendSeriesItem.tsx
  4. 4
      public/app/plugins/panel/graph/data_processor.ts
  5. 7
      public/app/plugins/panel/graph/graph.ts
  6. 4
      public/app/plugins/panel/graph/module.ts
  7. 10
      public/app/plugins/panel/singlestat/module.ts
  8. 3
      public/app/plugins/panel/table/module.ts
  9. 38
      scripts/webpack/webpack.test.js

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

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

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

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

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

@ -10,7 +10,7 @@ import { MetricsPanelCtrl } from 'app/plugins/sdk';
import { DataProcessor } from './data_processor'; import { DataProcessor } from './data_processor';
import { axesEditorComponent } from './axes_editor'; import { axesEditorComponent } from './axes_editor';
import config from 'app/core/config'; import config from 'app/core/config';
import { GrafanaThemeType, getColorFromHexRgbOrName } from '@grafana/ui'; import { getColorFromHexRgbOrName } from '@grafana/ui';
class GraphCtrl extends MetricsPanelCtrl { class GraphCtrl extends MetricsPanelCtrl {
static template = template; static template = template;
@ -244,7 +244,7 @@ class GraphCtrl extends MetricsPanelCtrl {
} }
onColorChange = (series, color) => { 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.panel.aliasColors[series.alias] = color;
this.render(); this.render();
}; };

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

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

@ -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;
Loading…
Cancel
Save