Skip to content

Commit d6e1fb4

Browse files
authored
feat: add custom label functionality (#109)
* feat: add custom label functionality * feat: add custom label component
1 parent b3d1cc4 commit d6e1fb4

File tree

5 files changed

+113
-3
lines changed

5 files changed

+113
-3
lines changed

nerdlets/entity-mode/components/observability-map.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ function ObservabilityMap(props) {
5353
highlightStrokeColor: 'blue',
5454
fontSize: 16,
5555
highlightFontSize: 16,
56-
labelProperty: node => cleanNodeId(node.name || node.id),
56+
labelProperty: node =>
57+
cleanNodeId(node.customLabel || node.name || node.id),
5758
// fontColor: 'white',
5859
viewGenerator: node => <NodeHandler node={node} nodeSize={nodeSize} />
5960
},
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/* eslint
2+
no-console: 0
3+
*/
4+
5+
import React from 'react';
6+
import { Button, Form, Input } from 'semantic-ui-react';
7+
import { DataConsumer } from '../../../context/data';
8+
9+
export default class CustomLabel extends React.PureComponent {
10+
constructor(props) {
11+
super(props);
12+
this.state = {
13+
customLabel: null
14+
};
15+
}
16+
17+
updateDashboard = async (
18+
updateDataContextState,
19+
mapConfig,
20+
nodeId,
21+
action
22+
) => {
23+
if (action === 'save') {
24+
if (!this.state.customLabel) {
25+
delete mapConfig.nodeData[nodeId].customLabel;
26+
} else {
27+
mapConfig.nodeData[nodeId].customLabel = this.state.customLabel;
28+
}
29+
} else if (action === 'delete') {
30+
delete mapConfig.nodeData[nodeId].customLabel;
31+
}
32+
await updateDataContextState({ mapConfig }, ['saveMap']);
33+
};
34+
35+
render() {
36+
return (
37+
<DataConsumer>
38+
{({ mapConfig, selectedNode, updateDataContextState }) => {
39+
const currentCustomLabel =
40+
mapConfig.nodeData[selectedNode].customLabel;
41+
42+
return (
43+
<>
44+
<Form.Group>
45+
<Form.Field
46+
width="16"
47+
control={Input}
48+
value={
49+
this.state.customLabel === null
50+
? currentCustomLabel
51+
: this.state.customLabel
52+
}
53+
label="Custom Label"
54+
onChange={e => this.setState({ customLabel: e.target.value })}
55+
/>
56+
</Form.Group>
57+
58+
{/* <Button
59+
style={{ float: 'right' }}
60+
disabled={!currentCustomLabel}
61+
negative
62+
onClick={() => {
63+
this.updateDashboard(
64+
updateDataContextState,
65+
mapConfig,
66+
selectedNode,
67+
'delete'
68+
);
69+
}}
70+
>
71+
Clear
72+
</Button> */}
73+
74+
<Button
75+
style={{ float: 'right' }}
76+
// disabled={addDisabled}
77+
positive
78+
onClick={() => {
79+
this.updateDashboard(
80+
updateDataContextState,
81+
mapConfig,
82+
selectedNode,
83+
'save'
84+
);
85+
}}
86+
>
87+
Save
88+
</Button>
89+
90+
<br />
91+
</>
92+
);
93+
}}
94+
</DataConsumer>
95+
);
96+
}
97+
}

nerdlets/observability-maps-nerdlet/components/node/edit/edit-node.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import IconSet from './icon-set';
77
import CustomAlertSeverity from './custom-alert-severity';
88
import Options from './options';
99
import DrilldownDashboard from './drilldown-dashboard';
10+
import CustomLabel from './custom-label';
1011

1112
export default class EditNode extends React.PureComponent {
1213
constructor(props) {
@@ -41,6 +42,8 @@ export default class EditNode extends React.PureComponent {
4142
return <Options />;
4243
case 'dash':
4344
return <DrilldownDashboard />;
45+
case 'customLabel':
46+
return <CustomLabel />;
4447
default:
4548
return '';
4649
}
@@ -110,6 +113,15 @@ export default class EditNode extends React.PureComponent {
110113
})
111114
}
112115
/>
116+
<Menu.Item
117+
name="Custom Label"
118+
active={selectedEditOption === 'customLabel'}
119+
onClick={() =>
120+
this.setState({
121+
selectedEditOption: 'customLabel'
122+
})
123+
}
124+
/>
113125
</Menu>
114126

115127
<Form>{componentSelect()}</Form>

nerdlets/observability-maps-nerdlet/components/observability-maps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default class ObservabilityMaps extends React.Component {
4444
highlightStrokeColor: 'blue',
4545
fontSize: 16,
4646
highlightFontSize: 16,
47-
labelProperty: node => cleanNodeId(node.id),
47+
labelProperty: node => cleanNodeId(node.customLabel || node.id),
4848
fontColor: 'white',
4949
viewGenerator: node => <NodeHandler node={node} nodeSize={nodeSize} />
5050
},

nerdlets/observability-maps-nerdlet/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ i {
438438
margin: 0 !important;
439439
}
440440

441-
.icons > .icon {
441+
.icons > .icon {
442442
margin: 0 !important;
443443
}
444444

0 commit comments

Comments
 (0)