Skip to content

Commit 93fa074

Browse files
committed
Adjust codebase to Typescript 4 and stronger eslint checks
1 parent fc09917 commit 93fa074

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

src/core.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import $ from 'jquery';
22
import * as _ from 'lodash';
33
import WorldmapCtrl from './worldmap_ctrl';
4-
import DataFormatter, { DataFormat } from './data_formatter';
4+
import DataFormatter, { DataFormat, DataContainer } from './data_formatter';
55
import { ErrorManager } from './errors';
66

77
export class WorldmapCore {
@@ -126,7 +126,7 @@ export class WorldmapCore {
126126
* an out-of-band location source.
127127
*/
128128

129-
const data = [];
129+
const data = new DataContainer();
130130
let series;
131131

132132
if (this.settings.locationData === 'geohash') {

src/data_formatter.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import DataFormatter from './data_formatter';
1+
import DataFormatter, { DataContainer } from './data_formatter';
22
import { ErrorManager } from './errors';
33
import * as jQuery from 'jquery';
44

@@ -424,7 +424,7 @@ describe('DataFormatter', () => {
424424
});
425425

426426
describe('when data is coming from "json result" (regular)', () => {
427-
const data: any[] = [];
427+
const data = new DataContainer();
428428
beforeEach(() => {
429429
const ctrl = {
430430
panel: {
@@ -462,7 +462,7 @@ describe('DataFormatter', () => {
462462
});
463463

464464
describe('when data is coming from "json result" (dataframe)', () => {
465-
const data: any[] = [];
465+
const data = new DataContainer();
466466
beforeEach(() => {
467467
const ctrl = {
468468
panel: {

src/data_formatter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ interface DataInfo {
1414
count: number;
1515
}
1616

17+
// https://stackoverflow.com/a/44441178
18+
export class DataContainer extends Array<Record<string, any>> {
19+
highestValue: number | undefined;
20+
lowestValue: number | undefined;
21+
valueRange: number | undefined;
22+
thresholds: [] | undefined;
23+
}
24+
1725
export enum DataFormat {
1826
Table = 'table',
1927
Timeseries = 'timeseries',

src/worldmap.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createBasicMap } from '../test/map_builder';
33
import $ from 'jquery';
44
import PluginSettings from './settings';
55
import { TemplateSrv } from 'grafana/app/features/templating/template_srv';
6-
import DataFormatter from './data_formatter';
6+
import DataFormatter, { DataContainer } from './data_formatter';
77
import { ColorModes } from './model';
88

99
describe('Worldmap', () => {
@@ -603,6 +603,7 @@ function setupInteractionMocks() {
603603
* Mock window.location methods.
604604
* https://remarkablemark.org/blog/2018/11/17/mock-window-location/
605605
*/
606+
// @ts-ignore
606607
delete window.location;
607608
// @ts-ignore
608609
window.location = {};
@@ -762,7 +763,7 @@ describe('ClickthroughLinks', () => {
762763

763764
// Apply data as table format.
764765
const dataFormatter = new DataFormatter(ctrl);
765-
const data: any[] = [];
766+
const data = new DataContainer();
766767
dataFormatter.setTableValues(tableData, data);
767768
data.thresholds = [];
768769

test/map_builder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export function createBasicMap() {
55
document.body.insertAdjacentHTML('afterbegin', fixture);
66

77
let ctrl = {
8+
settings: {},
89
panel: {
910
center: {
1011
mapCenterLatitude: 0,

tsconfig.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
{
22
"extends": "./node_modules/@grafana/toolkit/src/config/tsconfig.plugin.json",
3-
"include": ["src", "types"],
3+
"include": [
4+
"src",
5+
"types"
6+
],
7+
"exclude": [
8+
"node_modules",
9+
"dist"
10+
],
411
"compilerOptions": {
5-
"rootDir": "./src",
6-
"baseUrl": "./src",
12+
"outDir": "dist",
713
"typeRoots": ["./node_modules/@types"],
814
"noImplicitAny": false
915
}

0 commit comments

Comments
 (0)