Skip to content
Snippets Groups Projects
Commit d488c0bc authored by Maximilian Giller's avatar Maximilian Giller :squid:
Browse files

Makes connect on drag optional and implementes proper labels for checkboxes

parent 51a86d0c
No related branches found
No related tags found
1 merge request!2Implemented editor in the react framework
Pipeline #56799 passed
...@@ -15,6 +15,7 @@ type propTypes = any; ...@@ -15,6 +15,7 @@ type propTypes = any;
type stateTypes = { type stateTypes = {
graph: Graph; graph: Graph;
visibleLabels: boolean; visibleLabels: boolean;
connectOnDrag: boolean;
selectedNode: Node; selectedNode: Node;
keys: { [name: string]: boolean }; keys: { [name: string]: boolean };
}; };
...@@ -60,6 +61,7 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> { ...@@ -60,6 +61,7 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> {
this.state = { this.state = {
graph: undefined, graph: undefined,
visibleLabels: true, visibleLabels: true,
connectOnDrag: true,
selectedNode: undefined, selectedNode: undefined,
keys: {}, keys: {},
}; };
...@@ -338,6 +340,11 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> { ...@@ -338,6 +340,11 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> {
private handleNodeDrag(node: Node, translate: positionTranslate) { private handleNodeDrag(node: Node, translate: positionTranslate) {
this.selectNode(node); this.selectNode(node);
// Should run connect logic?
if (!this.state.connectOnDrag) {
return;
}
const closest = this.state.graph.getClosestOtherNode(node); const closest = this.state.graph.getClosestOtherNode(node);
// Is close enough for new link? // Is close enough for new link?
...@@ -396,7 +403,13 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> { ...@@ -396,7 +403,13 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> {
<li>CTRL+Click node to delete</li> <li>CTRL+Click node to delete</li>
<li>Click link to delete</li> <li>Click link to delete</li>
<li>SHIFT+Click a second node to connect</li> <li>SHIFT+Click a second node to connect</li>
<li>Drag node close to other node to connect</li> {this.state.connectOnDrag ? (
<li>
Drag node close to other node to connect
</li>
) : (
""
)}
</ul> </ul>
<hr /> <hr />
<NodeDetails <NodeDetails
...@@ -409,6 +422,7 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> { ...@@ -409,6 +422,7 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> {
<hr /> <hr />
<div> <div>
<input <input
id="node-labe-visibility"
type={"checkbox"} type={"checkbox"}
checked={this.state.visibleLabels} checked={this.state.visibleLabels}
onChange={(event) => { onChange={(event) => {
...@@ -422,7 +436,28 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> { ...@@ -422,7 +436,28 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> {
}); });
}} }}
/> />
Node labels // TODO: Proper label for checkbox <label htmlFor="node-labe-visibility">
Node labels
</label>
<br />
<input
id="connect-on-drag"
type={"checkbox"}
checked={this.state.connectOnDrag}
onChange={(event) => {
const newValue = event.target.checked;
if (newValue == this.state.connectOnDrag) {
return;
}
this.setState({
connectOnDrag: newValue,
});
}}
/>
<label htmlFor="connect-on-drag">
Connect nodes when dragged
</label>
</div> </div>
</div> </div>
{this.state.graph ? ( {this.state.graph ? (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment