Skip to content

Commit 32b474b

Browse files
author
Marius Brill
committed
fix linting errors
1 parent 14b022b commit 32b474b

File tree

14 files changed

+72
-84
lines changed

14 files changed

+72
-84
lines changed

src/options/TypeAheadTextfield/TypeaheadTextfield.tsx

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
import React from 'react';
2-
import Autosuggest from 'react-autosuggest';
2+
import Autosuggest, { InputProps } from 'react-autosuggest';
33
import { StandardEditorContext, StandardEditorProps } from '@grafana/data';
44
import './TypeaheadTextfield.css';
55
import { PanelSettings } from '../../types';
6-
76
interface Props extends StandardEditorProps<string, PanelSettings> {
87
item: any;
98
value: string;
109
onChange: (value?: string) => void;
1110
context: StandardEditorContext<any>;
1211
}
13-
1412
interface State {
1513
item: any;
1614
value: string;
1715
onChange: (value?: string) => void;
1816
context: StandardEditorContext<any>;
1917
suggestions: string[];
2018
}
21-
2219
export class TypeaheadTextField extends React.PureComponent<Props, State> {
2320
constructor(props: Props | Readonly<Props>) {
2421
super(props);
25-
2622
var { value } = props;
2723
if (value === undefined) {
2824
value = props.item.defaultValue;
@@ -33,11 +29,9 @@ export class TypeaheadTextField extends React.PureComponent<Props, State> {
3329
suggestions: [],
3430
};
3531
}
36-
3732
renderSuggestion(suggestion: string) {
3833
return <div>{suggestion}</div>;
3934
}
40-
4135
getColumnNames() {
4236
var { data } = this.props.context;
4337
var series;
@@ -56,17 +50,15 @@ export class TypeaheadTextField extends React.PureComponent<Props, State> {
5650
}
5751
return columnNames;
5852
}
59-
60-
onChange = (event: React.FormEvent<HTMLInputElement>, { newValue }: { newValue: string }) => {
53+
onChange = (event: React.FormEvent<HTMLElement>, { newValue }: { newValue: string }) => {
6154
//TODO make this type nicer!
6255
const { path } = this.props.item;
63-
const { value } = event.currentTarget;
56+
const { value } = event.currentTarget as HTMLInputElement;
6457
this.setState({
6558
value: value,
6659
});
6760
this.props.onChange.call(path, newValue);
6861
};
69-
7062
getSuggestions = (value: string) => {
7163
var inputValue = '';
7264
if (value !== undefined) {
@@ -75,44 +67,36 @@ export class TypeaheadTextField extends React.PureComponent<Props, State> {
7567
if (value !== undefined && value !== null && value !== '') {
7668
inputValue = value.trim().toLowerCase();
7769
}
78-
7970
const inputLength = inputValue.length;
8071
if (inputLength === 0 || inputValue === undefined) {
8172
return [];
8273
}
83-
return this.getColumnNames().filter(columnName => columnName.toLowerCase().startsWith(inputValue));
74+
return this.getColumnNames().filter((columnName) => columnName.toLowerCase().startsWith(inputValue));
8475
};
85-
8676
onSuggestionsFetchRequested = (value: any) => {
8777
this.setState({
8878
suggestions: this.getSuggestions(value),
8979
});
9080
};
91-
9281
getSuggestionValue = (suggestion: string) => {
9382
return suggestion;
9483
};
95-
9684
onSuggestionsClearRequested = () => {
9785
this.setState({
9886
suggestions: [],
9987
});
10088
};
101-
10289
render() {
10390
var { value } = this.props;
10491
if (value === undefined) {
10592
value = this.props.item.defaultValue;
10693
}
107-
10894
const suggestions = this.getSuggestions(value);
109-
110-
const inputProps = {
95+
const inputProps: InputProps<string> = {
11196
placeholder: 'Enter column name...',
11297
value,
11398
onChange: this.onChange,
11499
};
115-
116100
return (
117101
<Autosuggest
118102
suggestions={suggestions}

src/options/iconMapping/IconMapping.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export class IconMapping extends React.PureComponent<Props, State> {
2727
icons: [],
2828
};
2929
fetch(assetUtils.getAssetUrl('icon_index.json'))
30-
.then(response => response.json())
31-
.then(data => {
30+
.then((response) => response.json())
31+
.then((data) => {
3232
data.sort();
3333
this.setState({
3434
icons: data,
@@ -75,7 +75,11 @@ export class IconMapping extends React.PureComponent<Props, State> {
7575
var icons = this.state.context.options[path];
7676
if (icons === undefined) {
7777
icons = this.state.item.defaultValue;
78-
this.state.context.options[path] = this.state.item.defaultValue;
78+
const context = this.state.context;
79+
context.options[path] = this.state.item.defaultValue;
80+
this.setState({
81+
context: context,
82+
});
7983
}
8084

8185
return (
@@ -94,16 +98,18 @@ export class IconMapping extends React.PureComponent<Props, State> {
9498
type="text"
9599
className="input-small gf-form-input"
96100
value={icon.pattern}
97-
onChange={e => this.setPatternValue(e, index)}
101+
onChange={(e) => this.setPatternValue(e, index)}
98102
/>
99103

100104
<select
101105
className="input-small gf-form-input"
102106
value={icon.filename}
103-
onChange={e => this.setFileNameValue(e, index)}
107+
onChange={(e) => this.setFileNameValue(e, index)}
104108
>
105-
{iconNames.map((iconNames: string) => (
106-
<option value={iconNames}>{iconNames}</option>
109+
{iconNames.map((iconName: string, index: number) => (
110+
<option key={iconName + '-' + index} value={iconName}>
111+
{iconName}
112+
</option>
107113
))}
108114
</select>
109115

src/panel/PanelController.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import React, { LegacyRef } from 'react';
2-
import { PureComponent } from 'react';
1+
import React, { LegacyRef, PureComponent } from 'react';
32
import {
43
AbsoluteTimeRange,
54
DataFrame,
@@ -111,7 +110,7 @@ export class PanelController extends PureComponent<Props, PanelState> {
111110
hasOnlyTableQueries(inputData: DataFrame[]) {
112111
var result = true;
113112

114-
_.each(inputData, dataElement => {
113+
_.each(inputData, (dataElement) => {
115114
if (!_.has(dataElement, 'columns')) {
116115
result = false;
117116
}
@@ -131,7 +130,7 @@ export class PanelController extends PureComponent<Props, PanelState> {
131130
}
132131

133132
_transformEdges(edges: IntGraphEdge[]): CyData[] {
134-
const cyEdges = _.map(edges, edge => {
133+
const cyEdges = _.map(edges, (edge) => {
135134
const cyEdge = {
136135
group: 'edges',
137136
data: {
@@ -150,7 +149,7 @@ export class PanelController extends PureComponent<Props, PanelState> {
150149
}
151150

152151
_transformNodes(nodes: IntGraphNode[]): CyData[] {
153-
const cyNodes = _.map(nodes, node => {
152+
const cyNodes = _.map(nodes, (node) => {
154153
const result: CyData = {
155154
group: 'nodes',
156155
data: {
@@ -177,7 +176,7 @@ export class PanelController extends PureComponent<Props, PanelState> {
177176

178177
if (cyNode) {
179178
element.data(cyNode.data);
180-
_.remove(inputArray, n => n.data.id === cyNode.data.id);
179+
_.remove(inputArray, (n) => n.data.id === cyNode.data.id);
181180
elements.push(element);
182181
} else {
183182
element.remove();

src/panel/asset_utils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default {
1616
return this.getAssetUrl(type);
1717
}
1818

19-
const icon = find(externalIcons, icon => icon.pattern.toLowerCase() === type.toLowerCase());
19+
const icon = find(externalIcons, (icon) => icon.pattern.toLowerCase() === type.toLowerCase());
2020

2121
if (icon !== undefined) {
2222
return this.getAssetUrl(icon.filename + '.png');

src/panel/canvas/graph_canvas.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ export default class CanvasDrawer {
256256
const edges = this.cytoscape.edges().toArray();
257257
const hasSelection = this.selectionNeighborhood.size() > 0;
258258

259-
const transparentEdges = edges.filter(edge => hasSelection && !this.selectionNeighborhood.has(edge));
260-
const opaqueEdges = edges.filter(edge => !hasSelection || this.selectionNeighborhood.has(edge));
259+
const transparentEdges = edges.filter((edge) => hasSelection && !this.selectionNeighborhood.has(edge));
260+
const opaqueEdges = edges.filter((edge) => !hasSelection || this.selectionNeighborhood.has(edge));
261261

262262
ctx.globalAlpha = 0.25;
263263
this._drawEdges(ctx, transparentEdges, now);

src/panel/canvas/particle_engine.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export default class ParticleEngine {
5959
const cy = this.drawer.cytoscape;
6060

6161
const now = Date.now();
62-
cy.edges().forEach(edge => {
62+
cy.edges().forEach((edge) => {
6363
let particles: Particles = edge.data('particles');
6464
const metrics: IntGraphMetrics = edge.data('metrics');
6565

@@ -109,9 +109,9 @@ export default class ParticleEngine {
109109
const cy = this.drawer.cytoscape;
110110

111111
const count = _(cy.edges())
112-
.map(edge => edge.data('particles'))
112+
.map((edge) => edge.data('particles'))
113113
.filter()
114-
.map(particleArray => particleArray.normal.length + particleArray.danger.length)
114+
.map((particleArray) => particleArray.normal.length + particleArray.danger.length)
115115
.sum();
116116

117117
return count;

src/panel/layout_options.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ const options = {
1010
nodeDimensionsIncludeLabels: false, // whether labels should be included in determining the space used by a node
1111

1212
// layout event callbacks
13-
ready: function() {}, // on layoutready
14-
stop: function() {}, // on layoutstop
13+
ready: function () {}, // on layoutready
14+
stop: function () {}, // on layoutstop
1515

1616
// positioning options
1717
randomize: false, // use random node positions at beginning of layout
1818
avoidOverlap: true, // if true, prevents overlap of node bounding boxes
1919
handleDisconnected: true, // if true, avoids disconnected components from overlapping
2020
convergenceThreshold: 0.01, // when the alpha value (system energy) falls below this value, the layout stops
21-
nodeSpacing: function(node: any) {
21+
nodeSpacing: function (node: any) {
2222
return 50;
2323
}, // extra spacing around nodes
2424
flow: undefined as undefined, // use DAG/tree flow layout if specified, e.g. { axis: 'y', minSeparation: 30 }

src/panel/serviceDependencyGraph/ServiceDependencyGraph.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import CanvasDrawer from 'panel/canvas/graph_canvas';
22
import cytoscape, { EdgeCollection, EdgeSingular, ElementDefinition, NodeSingular } from 'cytoscape';
3-
import React from 'react';
4-
import { PureComponent } from 'react';
3+
import React, { PureComponent } from 'react';
54
import { PanelController } from '../PanelController';
65
import cyCanvas from 'cytoscape-canvas';
76
import cola from 'cytoscape-cola';
@@ -142,7 +141,7 @@ export class ServiceDependencyGraph extends PureComponent<PanelState, PanelState
142141
this.runLayout();
143142
} else {
144143
if (cyNodes.length > 0) {
145-
_.each(updatedNodes, node => {
144+
_.each(updatedNodes, (node) => {
146145
node.lock();
147146
});
148147
this.runLayout(true);
@@ -152,7 +151,7 @@ export class ServiceDependencyGraph extends PureComponent<PanelState, PanelState
152151
}
153152

154153
_transformNodes(nodes: IntGraphNode[]): ElementDefinition[] {
155-
const cyNodes: ElementDefinition[] = _.map(nodes, node => {
154+
const cyNodes: ElementDefinition[] = _.map(nodes, (node) => {
156155
const result: ElementDefinition = {
157156
group: 'nodes',
158157
data: {
@@ -171,7 +170,7 @@ export class ServiceDependencyGraph extends PureComponent<PanelState, PanelState
171170
}
172171

173172
_transformEdges(edges: IntGraphEdge[]): ElementDefinition[] {
174-
const cyEdges: ElementDefinition[] = _.map(edges, edge => {
173+
const cyEdges: ElementDefinition[] = _.map(edges, (edge) => {
175174
const cyEdge: ElementDefinition = {
176175
group: 'edges',
177176
data: {
@@ -199,7 +198,7 @@ export class ServiceDependencyGraph extends PureComponent<PanelState, PanelState
199198

200199
if (cyNode) {
201200
element.data(cyNode.data);
202-
_.remove(inputArray, n => n.data.id === cyNode.data.id);
201+
_.remove(inputArray, (n) => n.data.id === cyNode.data.id);
203202
elements.push(element);
204203
} else {
205204
element.remove();
@@ -247,7 +246,7 @@ export class ServiceDependencyGraph extends PureComponent<PanelState, PanelState
247246
const options = {
248247
...layoutOptions,
249248

250-
stop: function() {
249+
stop: function () {
251250
if (unlockNodes) {
252251
that.unlockNodes();
253252
}
@@ -385,7 +384,7 @@ export class ServiceDependencyGraph extends PureComponent<PanelState, PanelState
385384
return (
386385
<div className="graph-container">
387386
<div className="service-dependency-graph">
388-
<div className="canvas-container" ref={ref => (this.ref = ref)}></div>
387+
<div className="canvas-container" ref={(ref) => (this.ref = ref)}></div>
389388
<div className="zoom-button-container">
390389
<button className="btn navbar-button width-100" onClick={() => this.toggleAnimation()}>
391390
<i className={this.state.animateButtonClass}></i>

src/panel/statistics/IncomingStatistics.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TableContent } from 'types';
33

44
export const NodeStatistics = (receiving: TableContent[]) => {
55
return (
6-
<div>
6+
<>
77
<div className="secondHeader--selection">Incoming Statistics</div>
88
{() => {
99
if (receiving.length > 0) {
@@ -15,8 +15,8 @@ export const NodeStatistics = (receiving: TableContent[]) => {
1515
<th className="table--th--selectionSmall">Requests</th>
1616
<th className="table--th--selectionSmall">Error Rate</th>
1717
</tr>
18-
{receiving.map((node: TableContent) => (
19-
<tr>
18+
{receiving.map((node: TableContent, index: number) => (
19+
<tr key={'row-' + index}>
2020
<td className="table--td--selection" title="{{node.name}}">
2121
{node.name}
2222
</td>
@@ -30,6 +30,6 @@ export const NodeStatistics = (receiving: TableContent[]) => {
3030
}
3131
return <div className="no-data--selection">No incoming statistics available.</div>;
3232
}}
33-
</div>
33+
</>
3434
);
3535
};

src/panel/statistics/SortableTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function sort(a: string, b: string, order: string, ignoreLiteral: string) {
2323
}
2424

2525
export const SortableTable: React.FC<SortableTableProps> = ({ tableHeaders, data }) => {
26-
tableHeaders.forEach(function(value, i) {
26+
tableHeaders.forEach(function (value, i) {
2727
value.classes = 'table--td--selection';
2828
if (i !== 0) {
2929
value.sortFunc = (a: string, b: string, order: string, _dataField: any, _rowA: any) => {

0 commit comments

Comments
 (0)