Skip to content

Commit

Permalink
feat: add custom label component
Browse files Browse the repository at this point in the history
  • Loading branch information
Kav91 committed Aug 23, 2024
1 parent 4f57079 commit 0ba76b7
Showing 1 changed file with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* eslint
no-console: 0
*/

import React from 'react';
import { Button, Form, Input } from 'semantic-ui-react';
import { DataConsumer } from '../../../context/data';

export default class CustomLabel extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
customLabel: null
};
}

updateDashboard = async (
updateDataContextState,
mapConfig,
nodeId,
action
) => {
if (action === 'save') {
if (!this.state.customLabel) {
delete mapConfig.nodeData[nodeId].customLabel;
} else {
mapConfig.nodeData[nodeId].customLabel = this.state.customLabel;
}
} else if (action === 'delete') {
delete mapConfig.nodeData[nodeId].customLabel;
}
await updateDataContextState({ mapConfig }, ['saveMap']);
};

render() {
return (
<DataConsumer>
{({ mapConfig, selectedNode, updateDataContextState }) => {
const currentCustomLabel =
mapConfig.nodeData[selectedNode].customLabel;

return (
<>
<Form.Group>
<Form.Field
width="16"
control={Input}
value={
this.state.customLabel === null
? currentCustomLabel
: this.state.customLabel
}
label="Custom Label"
onChange={e => this.setState({ customLabel: e.target.value })}
/>
</Form.Group>

{/* <Button
style={{ float: 'right' }}
disabled={!currentCustomLabel}
negative
onClick={() => {
this.updateDashboard(
updateDataContextState,
mapConfig,
selectedNode,
'delete'
);
}}
>
Clear
</Button> */}

<Button
style={{ float: 'right' }}
// disabled={addDisabled}
positive
onClick={() => {
this.updateDashboard(
updateDataContextState,
mapConfig,
selectedNode,
'save'
);
}}
>
Save
</Button>

<br />
</>
);
}}
</DataConsumer>
);
}
}

0 comments on commit 0ba76b7

Please sign in to comment.