Skip to content

Commit 7a7a867

Browse files
authored
Add theme to getDisplayProcessor (#66)
* Add theme to getDisplayProcessor * Fix tests
1 parent a9dfd21 commit 7a7a867

File tree

9 files changed

+28
-9
lines changed

9 files changed

+28
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Bug fixes
66

77
- "Available Requirements" panel should be set to $redis datasource #63
8+
- Cannot read property 'v1' of undefined (theme.v1) in the Grafana8 #65
89

910
## 1.2.0 (2021-05-11)
1011

src/redis-gears-panel/components/redis-gears-panel/redis-gears-panel.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ const dataSourceMock = {
3333
const dataSourceSrvGetMock = jest.fn().mockImplementation(() => Promise.resolve(dataSourceMock));
3434

3535
/**
36-
* Mock getDataSourceSrv function
36+
* Mock @grafana/runtime
3737
*/
3838
jest.mock('@grafana/runtime', () => ({
3939
getDataSourceSrv: () => ({
4040
get: dataSourceSrvGetMock,
4141
}),
4242
toDataQueryError: jest.fn().mockImplementation(({ message }: any) => ({ message })),
43+
config: { theme: {} },
4344
}));
4445

4546
/**

src/redis-gears-panel/components/redis-gears-panel/redis-gears-panel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
PanelProps,
1414
toDataFrame,
1515
} from '@grafana/data';
16-
import { getDataSourceSrv, toDataQueryError } from '@grafana/runtime';
16+
import { config, getDataSourceSrv, toDataQueryError } from '@grafana/runtime';
1717
import { Alert, Button, InlineField, InlineFormLabel, Input, RadioButtonGroup, Table } from '@grafana/ui';
1818
import { DefaultScript, ExecutionMode, ExecutionOptions } from '../../constants';
1919
import { PanelOptions } from '../../types';
@@ -182,7 +182,7 @@ export class RedisGearsPanel extends PureComponent<Props, State> {
182182
* Fields
183183
*/
184184
resultDataFrame.fields.forEach((field: Field) => {
185-
field.display = getDisplayProcessor({ field });
185+
field.display = getDisplayProcessor({ field, theme: config.theme });
186186
});
187187

188188
this.setState({

src/redis-keys-panel/components/redis-keys-panel/redis-keys-panel.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React from 'react';
21
import { shallow } from 'enzyme';
2+
import React from 'react';
33
import { Observable } from 'rxjs';
44
import { FieldType, toDataFrame } from '@grafana/data';
55
import { Button, Table } from '@grafana/ui';
@@ -65,12 +65,13 @@ const dataSourceMock = {
6565
const dataSourceSrvGetMock = jest.fn().mockImplementation(() => Promise.resolve(dataSourceMock));
6666

6767
/**
68-
* Mock getDataSourceSrv function
68+
* Mock @grafana/runtime
6969
*/
7070
jest.mock('@grafana/runtime', () => ({
7171
getDataSourceSrv: () => ({
7272
get: dataSourceSrvGetMock,
7373
}),
74+
config: { theme: {} },
7475
}));
7576

7677
/**

src/redis-keys-panel/components/redis-keys-panel/redis-keys-panel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
PanelProps,
1010
toDataFrame,
1111
} from '@grafana/data';
12-
import { getDataSourceSrv } from '@grafana/runtime';
12+
import { config, getDataSourceSrv } from '@grafana/runtime';
1313
import { Button, InlineFormLabel, Input, Table, TableSortByFieldState } from '@grafana/ui';
1414
import {
1515
DefaultCount,
@@ -213,7 +213,7 @@ export class RedisKeysPanel extends PureComponent<Props, State> {
213213
*/
214214
tableDataFrame.fields = tableDataFrame.fields.map((field) => ({
215215
...field,
216-
display: getDisplayProcessor({ field }),
216+
display: getDisplayProcessor({ field, theme: config.theme }),
217217
}));
218218

219219
return tableDataFrame;

src/redis-latency-panel/components/redis-latency-panel-graph/redis-latency-panel-graph.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import { dateTime, dateTimeParse, GraphSeriesXY } from '@grafana/data';
44
import { DefaultColorModeId } from '../../constants';
55
import { RedisLatencyPanelGraph } from './redis-latency-panel-graph';
66

7+
/**
8+
* Mock @grafana/runtime
9+
*/
10+
jest.mock('@grafana/runtime', () => ({
11+
config: { theme: {} },
12+
}));
13+
714
/**
815
* Latency Panel Table
916
*/

src/redis-latency-panel/components/redis-latency-panel-graph/redis-latency-panel-graph.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
TimeZone,
1414
toDataFrame,
1515
} from '@grafana/data';
16+
import { config } from '@grafana/runtime';
1617
import { Chart, colors, GraphWithLegend, LegendDisplayMode } from '@grafana/ui';
1718
import { DefaultColorModeId } from '../../constants';
1819
import { PanelOptions, SeriesMap, SeriesValue } from '../../types';
@@ -116,7 +117,7 @@ export class RedisLatencyPanelGraph extends PureComponent<Props, State> {
116117
*/
117118
seriesDataFrame.fields = seriesDataFrame.fields.map((field) => ({
118119
...field,
119-
display: getDisplayProcessor({ field }),
120+
display: getDisplayProcessor({ field, theme: config.theme }),
120121
}));
121122

122123
/**

src/redis-latency-panel/components/redis-latency-panel-table/redis-latency-panel-table.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import { Table } from '@grafana/ui';
55
import { DisplayNameByFieldName, FieldName } from '../../constants';
66
import { RedisLatencyPanelTable } from './redis-latency-panel-table';
77

8+
/**
9+
* Mock @grafana/runtime
10+
*/
11+
jest.mock('@grafana/runtime', () => ({
12+
config: { theme: {} },
13+
}));
14+
815
/**
916
* Latency Panel Table
1017
*/

src/redis-latency-panel/components/redis-latency-panel-table/redis-latency-panel-table.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { PureComponent } from 'react';
22
import { DataFrame, FieldType, getDisplayProcessor, PanelProps, toDataFrame } from '@grafana/data';
3+
import { config } from '@grafana/runtime';
34
import { Table, TableSortByFieldState } from '@grafana/ui';
45
import { DisplayNameByFieldName, FieldName } from '../../constants';
56
import { PanelOptions, SeriesMap } from '../../types';
@@ -89,7 +90,7 @@ export class RedisLatencyPanelTable extends PureComponent<Props, State> {
8990
*/
9091
tableDataFrame.fields = tableDataFrame.fields.map((field) => ({
9192
...field,
92-
display: getDisplayProcessor({ field }),
93+
display: getDisplayProcessor({ field, theme: config.theme }),
9394
}));
9495

9596
/**

0 commit comments

Comments
 (0)