Skip to content

Commit c86d059

Browse files
author
mbrill-nt
committed
Changes in General Settings are now applied instantly.
1 parent 2cc94b5 commit c86d059

File tree

7 files changed

+83
-23
lines changed

7 files changed

+83
-23
lines changed

src/options/dummyDataSwitch/DummyDataSwitch.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ export class DummyDataSwitch extends React.PureComponent<Props, State> {
5757
}
5858
dataMapping.showDummyData = newValue;
5959
this.props.onChange.call(this.state.item.path, dataMapping);
60-
/*this.setState({
61-
value:!this.state.value,
62-
dataMapping:this.props.context.options.dataMapping
63-
});*/
6460
};
6561

6662
render() {
63+
if(this.props.context.options.dataMapping === undefined){
64+
this.props.context.options.dataMapping = this.props.item.defaultValue;
65+
}
66+
6767
return (
6868
<div>
6969
<Switch
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import { StandardEditorProps } from '@grafana/data';
3+
import { Switch } from '@grafana/ui';
4+
import { IntSwitch } from 'types';
5+
6+
function onChangeOverride(value: IntSwitch, onChange: any, item: any) {
7+
value.value = !value.value;
8+
onChange.call(item.path, value);
9+
}
10+
11+
export const GenericDataSwitch: React.FC<StandardEditorProps> = ({item, value, onChange, context}) => {
12+
if(context.options[item.path] === undefined){
13+
context.options[item.path] = {value: false}
14+
}
15+
16+
return (
17+
<div>
18+
<Switch
19+
value={context.options[item.path].value}
20+
css={{}}
21+
onChange={() => onChangeOverride(value, onChange, item)}
22+
/>
23+
</div>
24+
);
25+
}

src/options/options.tsx

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { TypeaheadTextField } from './TypeAheadTextfield/TypeaheadTextfield';
44
import { ServiceIconMapping } from './serviceIconMapping/ServiceIconMapping';
55
import { ExternalIconMapping } from './externalIconMapping/ExternalIconMapping';
66
import { DummyDataSwitch } from './dummyDataSwitch/DummyDataSwitch';
7+
import { GenericDataSwitch } from './genericDataSwitch/GenericDataSwitch';
78

89
export const optionsBuilder = (builder: PanelOptionsEditorBuilder<PanelSettings>) => {
910
return (
@@ -108,39 +109,51 @@ export const optionsBuilder = (builder: PanelOptionsEditorBuilder<PanelSettings>
108109
})
109110

110111
//General Settings
111-
.addBooleanSwitch({
112+
.addCustomEditor({
113+
id: 'connectionStats',
112114
path: 'showConnectionStats',
113115
name: 'Show Connection Statistics',
116+
editor: GenericDataSwitch,
114117
category: ['General Settings'],
118+
defaultValue: {value: false}
115119
})
116120

117-
.addBooleanSwitch({
121+
.addCustomEditor({
122+
id: 'sumTimings',
118123
path: 'sumTimings',
119124
name: 'Handle Timings as Sums',
125+
editor: GenericDataSwitch,
120126
description:
121127
'If this setting is active, the timings provided' +
122128
'by the mapped response time columns are considered as a ' +
123129
'continually increasing sum of response times. When ' +
124130
'deactivated, it is considered that the timings provided ' +
125131
'by columns are the actual average response times.',
126132
category: ['General Settings'],
133+
defaultValue: {value: false}
127134
})
128135

129-
.addBooleanSwitch({
136+
.addCustomEditor({
137+
id: 'filterEmptyConnections',
130138
path: 'filterEmptyConnections',
131139
name: 'Filter Empty Data',
140+
editor: GenericDataSwitch,
132141
description:
133142
'If this setting is active, the timings provided by ' +
134143
'the mapped response time columns are considered as a continually ' +
135144
'increasing sum of response times. When deactivated, it is considered ' +
136145
'that the timings provided by columns are the actual average response times.',
137146
category: ['General Settings'],
147+
defaultValue: {value: false}
138148
})
139149

140-
.addBooleanSwitch({
150+
.addCustomEditor({
151+
id: 'showDebugInformation',
141152
path: 'showDebugInformation',
142153
name: 'Show Debug Information',
154+
editor: GenericDataSwitch,
143155
category: ['General Settings'],
156+
defaultValue: {value: false}
144157
})
145158

146159
.addCustomEditor({
@@ -149,12 +162,30 @@ export const optionsBuilder = (builder: PanelOptionsEditorBuilder<PanelSettings>
149162
name: 'Show Dummy Data',
150163
editor: DummyDataSwitch,
151164
category: ['General Settings'],
165+
defaultValue: {
166+
sourceComponentPrefix: 'origin_',
167+
targetComponentPrefix: 'target_',
168+
responseTimeColumn: 'in_timesum',
169+
requestRateColumn: 'in_count',
170+
errorRateColumn: 'error_in',
171+
responseTimeOutgoingColumn: 'out_timesum',
172+
requestRateOutgoingColumn: 'out_count',
173+
errorRateOutgoingColumn: 'error_out',
174+
extOrigin: '',
175+
extTarget: '',
176+
type: '',
177+
showDummyData: true,
178+
baselineRtUpper: 'threshold',
179+
}
152180
})
153181

154-
.addBooleanSwitch({
182+
.addCustomEditor({
183+
id: 'showBaselines',
155184
path: 'showBaselines',
156185
name: 'Show Baselines',
186+
editor: GenericDataSwitch,
157187
category: ['General Settings'],
188+
defaultValue: {value: false}
158189
})
159190

160191
//Appearance

src/panel/canvas/graph_canvas.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export default class CanvasDrawer {
217217
// static element rendering
218218
// cyCanvas.resetTransform(ctx);
219219
cyCanvas.clear(ctx);
220-
if (this.controller.getSettings().showDebugInformation) {
220+
if (this.controller.getSettings().showDebugInformation.value) {
221221
this._drawDebugInformation();
222222
}
223223

@@ -266,7 +266,7 @@ export default class CanvasDrawer {
266266
}
267267

268268
const { showConnectionStats } = this.controller.getSettings();
269-
if (showConnectionStats && cy.zoom() > 1) {
269+
if (showConnectionStats.value && cy.zoom() > 1) {
270270
for (const edge of edges) {
271271
this._drawEdgeLabel(ctx, edge);
272272
}
@@ -494,7 +494,7 @@ export default class CanvasDrawer {
494494
this._drawDonut(ctx, node, 15, 5, 0.5, [errorPct, unknownPct, healthyPct]);
495495

496496
// drawing the baseline status
497-
const showBaselines = this.controller.getSettings().showBaselines;
497+
const showBaselines = this.controller.getSettings().showBaselines.value;
498498
if (showBaselines && responseTime >= 0 && threshold >= 0) {
499499
const thresholdViolation = threshold < responseTime;
500500

@@ -655,7 +655,7 @@ export default class CanvasDrawer {
655655
const xPos = pos.x - labelWidth / 2;
656656
const yPos = pos.y + node.height() * 0.8;
657657

658-
const showBaselines = this.controller.getSettings().showBaselines;
658+
const showBaselines = this.controller.getSettings().showBaselines.value;
659659
const metrics: IntGraphMetrics = node.data('metrics');
660660
const responseTime = _.defaultTo(metrics.response_time, -1);
661661
const threshold = _.defaultTo(metrics.threshold, -1);

src/panel/serviceDependencyGraph/ServiceDependencyGraph.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface PanelState {
2121
animateButtonClass?: string,
2222
showStatistics: boolean;
2323
data: any;
24+
settings:any;
2425
}
2526

2627
cyCanvas(cytoscape);
@@ -214,7 +215,7 @@ export class ServiceDependencyGraph extends PureComponent<PanelState, PanelState
214215
}
215216

216217
getSettings() {
217-
return this.props.controller.state.options;
218+
return this.props.settings;
218219
}
219220

220221
toggleAnimation() {

src/processing/graph_generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class GraphGenerator {
3838
return undefined;
3939
}
4040

41-
const sumMetrics = !this.controller.getSettings().sumTimings;
41+
const sumMetrics = !this.controller.getSettings().sumTimings.value;
4242

4343
var nodeName = dataElements[0].target;
4444
if (nodeName === '' || nodeName === undefined || nodeName === null) {
@@ -201,7 +201,7 @@ class GraphGenerator {
201201
if (!isUndefined(response_time_out)) {
202202
const { sumTimings } = this.controller.getSettings();
203203

204-
if (!sumTimings && metrics.rate) {
204+
if (!sumTimings.value && metrics.rate) {
205205
metrics.response_time = response_time_out / metrics.rate;
206206
} else {
207207
metrics.response_time = response_time_out;
@@ -224,7 +224,7 @@ class GraphGenerator {
224224
_filterData(graph: IntGraph): IntGraph {
225225
const { filterEmptyConnections: filterData } = this.controller.getSettings();
226226

227-
if (filterData) {
227+
if (filterData.value) {
228228
const filteredGraph: IntGraph = {
229229
nodes: [],
230230
edges: [],

src/types.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
export interface PanelSettings {
22
animate: boolean;
3-
sumTimings: boolean;
4-
filterEmptyConnections: boolean;
3+
sumTimings: IntSwitch;
4+
filterEmptyConnections: IntSwitch;
55
style: PanelStyleSettings;
6-
showDebugInformation: boolean;
7-
showConnectionStats: boolean;
6+
showDebugInformation: IntSwitch;
7+
showConnectionStats: IntSwitch;
88
externalIcons: ExternalIconResource[];
99
serviceIcons: IconResource[];
1010
dataMapping: DataMapping;
11-
showDummyData: boolean;
1211
drillDownLink: string;
13-
showBaselines: boolean;
12+
showBaselines: IntSwitch;
1413
columns: string[];
1514
}
1615

@@ -189,3 +188,7 @@ export interface IntTableHeader {
189188
sortFunc?: any
190189
ignoreLiteral?: string
191190
}
191+
192+
export interface IntSwitch {
193+
value: boolean;
194+
}

0 commit comments

Comments
 (0)