Skip to content

Commit d8dcad7

Browse files
author
mbrill-nt
committed
Code style improvements
1 parent 082cf98 commit d8dcad7

File tree

20 files changed

+356
-334
lines changed

20 files changed

+356
-334
lines changed

src/options/DefaultSettings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const DefaultSettings: PanelSettings = {
3232
style: {
3333
healthyColor: 'rgb(87, 148, 242)',
3434
dangerColor: 'rgb(196, 22, 42)',
35-
unknownColor: 'rgb(123, 123, 138)',
35+
noDataColor: 'rgb(123, 123, 138)',
3636
},
3737

3838
serviceIcons: [

src/options/TypeAheadTextfield/TypeaheadTextfield.tsx

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
import React from 'react';
22
import Autosuggest from 'react-autosuggest';
3-
import { StandardEditorProps } from '@grafana/data';
3+
import { StandardEditorContext, StandardEditorProps } from '@grafana/data';
44
import './TypeaheadTextfield.css';
55
import { PanelSettings } from '../../types';
66

77
interface Props extends StandardEditorProps<string, PanelSettings> {
88
item: any;
99
value: string;
1010
onChange: (value?: string) => void;
11-
context: any;
11+
context: StandardEditorContext<any>;
1212
}
1313

1414
interface State {
1515
item: any;
1616
value: string;
1717
onChange: (value?: string) => void;
18-
context: any;
18+
context: StandardEditorContext<any>;
1919
suggestions: string[];
2020
}
2121

2222
export class TypeaheadTextField extends React.PureComponent<Props, State> {
2323
constructor(props: Props | Readonly<Props>) {
2424
super(props);
2525

26-
var value = props.value;
26+
var { value } = props;
2727
if (value === undefined) {
2828
value = props.item.defaultValue;
2929
}
@@ -34,47 +34,53 @@ export class TypeaheadTextField extends React.PureComponent<Props, State> {
3434
};
3535
}
3636

37-
renderSuggestion(suggestion: any) {
37+
renderSuggestion(suggestion: string) {
3838
return <div>{suggestion}</div>;
3939
}
4040

41-
getColumns() {
41+
getColumnNames() {
4242
var { data } = this.props.context;
4343
var series;
4444
var columnNames = [];
4545
if (data !== undefined && data.length > 0) {
4646
series = data[0].fields;
4747
for (const index in series) {
4848
const field = series[index];
49-
if (field.config !== undefined && field.config.displayName !== undefined) {
50-
columnNames.push(field.config.displayName);
49+
const { config, name } = field;
50+
if (config !== undefined && config.displayName !== undefined) {
51+
columnNames.push(config.displayName);
5152
} else {
52-
columnNames.push(field.name);
53+
columnNames.push(name);
5354
}
5455
}
5556
}
5657
return columnNames;
5758
}
5859

59-
onChange = (event: any, { newValue, method }: any) => {
60+
onChange = (event: React.FormEvent<HTMLInputElement>, { newValue }: { newValue: string }) => {
61+
//TODO make this type nicer!
62+
const { path } = this.props.item;
63+
const { value } = event.currentTarget;
6064
this.setState({
61-
value: event.currentTarget.value,
65+
value: value,
6266
});
63-
this.props.onChange.call(this.props.item.path, newValue);
67+
this.props.onChange.call(path, newValue);
6468
};
6569

66-
getSuggestions = (value: any) => {
70+
getSuggestions = (value: string) => {
6771
var inputValue = '';
68-
if (value.value !== undefined) {
72+
if (value !== undefined) {
6973
return [];
7074
}
7175
if (value !== undefined && value !== null && value !== '') {
7276
inputValue = value.trim().toLowerCase();
7377
}
78+
7479
const inputLength = inputValue.length;
75-
return inputLength === 0
76-
? []
77-
: this.getColumns().filter(column => column.toLowerCase().slice(0, inputLength) === inputValue);
80+
if (inputLength === 0 || inputValue === undefined) {
81+
return [];
82+
}
83+
return this.getColumnNames().filter(columnName => columnName.toLowerCase().startsWith(inputValue));
7884
};
7985

8086
onSuggestionsFetchRequested = (value: any) => {
@@ -83,7 +89,7 @@ export class TypeaheadTextField extends React.PureComponent<Props, State> {
8389
});
8490
};
8591

86-
getSuggestionValue = (suggestion: any) => {
92+
getSuggestionValue = (suggestion: string) => {
8793
return suggestion;
8894
};
8995

@@ -94,7 +100,7 @@ export class TypeaheadTextField extends React.PureComponent<Props, State> {
94100
};
95101

96102
render() {
97-
var value = this.props.value;
103+
var { value } = this.props;
98104
if (value === undefined) {
99105
value = this.props.item.defaultValue;
100106
}

src/options/dummyDataSwitch/DummyDataSwitch.tsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
import React from 'react';
2-
import { StandardEditorProps } from '@grafana/data';
2+
import { StandardEditorContext, StandardEditorProps } from '@grafana/data';
33
import { PanelSettings, DataMapping } from '../../types';
44
import { Switch } from '@grafana/ui';
55

66
interface Props extends StandardEditorProps<boolean, PanelSettings> {
77
item: any;
88
value: boolean;
99
onChange: (value?: boolean) => void;
10-
context: any;
10+
context: StandardEditorContext<any>;
1111
}
1212

1313
interface State {
1414
item: any;
1515
value: boolean;
1616
dataMapping: DataMapping | undefined;
1717
onChange: (value?: boolean) => void;
18-
context: any;
18+
context: StandardEditorContext<any>;
1919
}
2020

2121
export class DummyDataSwitch extends React.PureComponent<Props, State> {
2222
constructor(props: Props | Readonly<Props>) {
2323
super(props);
2424

25-
var dataMapping = this.props.context.options.dataMapping;
25+
var { dataMapping } = props.context.options;
2626
if (dataMapping === undefined) {
27-
dataMapping = this.props.item.defaultValue;
27+
dataMapping = props.item.defaultValue;
2828
}
2929
this.state = {
3030
dataMapping: dataMapping,
@@ -50,31 +50,30 @@ export class DummyDataSwitch extends React.PureComponent<Props, State> {
5050
};
5151
};
5252

53-
onChange = (event: any) => {
54-
var dataMapping = this.props.context.options.dataMapping;
55-
var newValue = !dataMapping.showDummyData;
56-
dataMapping = this.state.dataMapping;
53+
onChange = () => {
54+
var { dataMapping } = this.props.context.options;
55+
const { item } = this.state;
56+
const { onChange } = this.props;
57+
const newValue = !dataMapping.showDummyData;
5758

5859
if (newValue) {
5960
this.setState({ dataMapping: dataMapping });
6061
dataMapping = this.getDummyDataMapping();
6162
}
6263
dataMapping.showDummyData = newValue;
63-
this.props.onChange.call(this.state.item.path, dataMapping);
64+
onChange.call(item.path, dataMapping);
6465
};
6566

6667
render() {
67-
if (this.props.context.options.dataMapping === undefined) {
68+
var { dataMapping } = this.props.context.options;
69+
if (dataMapping === undefined) {
70+
dataMapping = this.props.item.defaultValue;
6871
this.props.context.options.dataMapping = this.props.item.defaultValue;
6972
}
7073

7174
return (
7275
<div>
73-
<Switch
74-
value={this.props.context.options.dataMapping.showDummyData}
75-
css={{}}
76-
onChange={(event: any) => this.onChange(event)}
77-
/>
76+
<Switch value={dataMapping.showDummyData} css={{}} onChange={() => this.onChange()} />
7877
</div>
7978
);
8079
}

src/options/externalIconMapping/ExternalIconMapping.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import React from 'react';
1+
import React, { ChangeEvent } from 'react';
22
import { remove } from 'lodash';
3-
import { StandardEditorProps } from '@grafana/data';
3+
import { StandardEditorContext, StandardEditorProps } from '@grafana/data';
44
import { PanelSettings } from '../../types';
55

66
interface Props extends StandardEditorProps<string, PanelSettings> {
77
item: any;
88
value: string;
99
onChange: (value?: string) => void;
10-
context: any;
10+
context: StandardEditorContext<any>;
1111
}
1212

1313
export class ExternalIconMapping extends React.PureComponent<Props, Props> {
@@ -29,12 +29,12 @@ export class ExternalIconMapping extends React.PureComponent<Props, Props> {
2929
this.state.onChange.call(this.state.item.path, this.state.context.options.externalIcons);
3030
}
3131

32-
setPatternValue(event: any, index: number) {
32+
setPatternValue(event: React.FormEvent<HTMLInputElement>, index: number) {
3333
this.state.context.options.externalIcons[index].pattern = event.currentTarget.value;
3434
this.state.onChange.call(this.state.item.path, this.state.context.options.externalIcons);
3535
}
3636

37-
setFileNameValue(event: any, index: number) {
37+
setFileNameValue(event: ChangeEvent<HTMLSelectElement>, index: number) {
3838
this.state.context.options.externalIcons[index].filename = event.currentTarget.value;
3939
this.state.onChange.call(this.state.item.path, this.state.context.options.externalIcons);
4040
}

src/options/options.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ export const optionsBuilder = (builder: PanelOptionsEditorBuilder<PanelSettings>
209209
})
210210

211211
.addColorPicker({
212-
path: 'style.unknownColor',
212+
path: 'style.noDataColor',
213213
name: 'No Data Color',
214214
category: ['Appearance'],
215-
defaultValue: DefaultSettings.style.unknownColor,
215+
defaultValue: DefaultSettings.style.noDataColor,
216216
})
217217

218218
//Service Icon Mapping

0 commit comments

Comments
 (0)