Skip to content

Commit 5d9ec46

Browse files
author
mbrill-nt
committed
Icon Mapping is now divided into external and internal icons
1 parent b239cf9 commit 5d9ec46

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

src/options/DefaultSettings.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export const DefaultSettings: PanelSettings = {
4545
pattern: 'spok|star trek',
4646
filename: 'star_trek',
4747
},
48+
],
49+
50+
externalIcons: [
4851
{
4952
pattern: 'web',
5053
filename: 'web',

src/options/iconMapping/IconMapping.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,39 +42,40 @@ export class IconMapping extends React.PureComponent<Props, State> {
4242
}
4343

4444
addMapping() {
45-
const { icons } = this.state.context.options;
4645
const { path } = this.state.item;
46+
const icons = this.state.context.options[path];
4747
icons.push({ pattern: 'my-type', filename: 'default' });
4848
this.state.onChange.call(path, icons);
4949
}
5050

5151
removeMapping(index: number) {
52-
const { icons } = this.state.context.options;
5352
const { path } = this.state.item;
53+
const icons = this.state.context.options[path];
5454
icons.splice(index, 1);
5555
this.state.onChange.call(path, icons);
5656
}
5757

5858
setPatternValue(event: React.ChangeEvent<HTMLInputElement>, index: number) {
59-
const { icons } = this.state.context.options;
6059
const { path } = this.state.item;
60+
const icons = this.state.context.options[path];
6161
icons[index].pattern = event.currentTarget.value;
6262
this.state.onChange.call(path, icons);
6363
}
6464

6565
setFileNameValue(event: ChangeEvent<HTMLSelectElement>, index: number) {
66-
const { icons } = this.state.context.options;
6766
const { path } = this.state.item;
67+
const icons = this.state.context.options[path];
6868
icons[index].filename = event.currentTarget.value.toString();
6969
this.props.onChange.call(path, icons);
7070
}
7171

7272
render() {
73-
var { icons } = this.state.context.options;
73+
const { path } = this.state.item;
7474
const { icons: iconNames } = this.state;
75+
var icons = this.state.context.options[path];
7576
if (icons === undefined) {
7677
icons = this.state.item.defaultValue;
77-
this.state.context.options.icons = this.state.item.defaultValue;
78+
this.state.context.options[path] = this.state.item.defaultValue;
7879
}
7980

8081
return (

src/options/options.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,26 @@ export const optionsBuilder = (builder: PanelOptionsEditorBuilder<PanelSettings>
229229
id: 'iconMapping',
230230
editor: IconMapping,
231231
name: '',
232+
description:
233+
'This setting controls which images should be mapped to your directly monitored nodes. ' +
234+
'The node names are matched by the regex pattern provided in the "Target Name(Regex) column.',
232235
category: ['Icon Mapping'],
233236
defaultValue: DefaultSettings.icons,
234237
})
235238

239+
//External Icon Mapping
240+
.addCustomEditor({
241+
path: 'externalIcons',
242+
id: 'externalIconMapping',
243+
editor: IconMapping,
244+
name: '',
245+
description:
246+
'This setting controls which images should be mapped to the external nodes. ' +
247+
'The given type column is matched by the regex pattern provided in the "Target Name(Regex) column.',
248+
category: ['External Icon Mapping'],
249+
defaultValue: DefaultSettings.externalIcons,
250+
})
251+
236252
//Tracing Drilldown
237253
.addTextInput({
238254
path: 'drillDownLink',

src/panel/asset_utils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { find } from 'lodash';
2-
import { ExternalIconResource } from 'types';
2+
import { IconResource } from 'types';
33

44
export default {
55
getAssetUrl(assetName: string) {
66
var baseUrl = 'public/plugins/novatec-sdg-panel';
77
return baseUrl + '/assets/' + assetName;
88
},
99

10-
getTypeSymbol(type: string, externalIcons: ExternalIconResource[], resolveName = true) {
10+
getTypeSymbol(type: string, externalIcons: IconResource[], resolveName = true) {
1111
if (!type) {
1212
return this.getAssetUrl('default.png');
1313
}

src/panel/canvas/graph_canvas.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ export default class CanvasDrawer {
124124

125125
_getImageAsset(assetName: string, resolveName = true) {
126126
if (!_.has(this.imageAssets, assetName)) {
127-
const assetUrl = assetUtils.getTypeSymbol(assetName, this.controller.getSettings(true).icons, resolveName);
127+
const { externalIcons } = this.controller.getSettings(true);
128+
const assetUrl = assetUtils.getTypeSymbol(assetName, externalIcons, resolveName);
128129
this._loadImage(assetUrl, assetName);
129130
}
130131

@@ -538,7 +539,7 @@ export default class CanvasDrawer {
538539
});
539540

540541
if (mapping) {
541-
const image = this._getAsset(mapping.filename, 'service_icons/' + mapping.filename + '.png');
542+
const image = this._getAsset(mapping.filename, 'icons/' + mapping.filename + '.png');
542543
if (image != null) {
543544
const cX = node.position().x;
544545
const cY = node.position().y;

src/types.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface PanelSettings {
88
showDebugInformation: boolean;
99
showConnectionStats: boolean;
1010
icons: IconResource[];
11+
externalIcons: IconResource[];
1112
dataMapping: DataMapping;
1213
drillDownLink: string;
1314
showBaselines: boolean;
@@ -45,11 +46,6 @@ export interface IconResource {
4546
filename: string;
4647
}
4748

48-
export interface ExternalIconResource {
49-
pattern: string;
50-
filename: string;
51-
}
52-
5349
export interface QueryResponseColumn {
5450
type?: string;
5551
text: string;

0 commit comments

Comments
 (0)