Add cancel buttons

This commit is contained in:
Ladd Hoffman 2023-07-09 16:33:11 -05:00
parent f978c20104
commit 56132b2fec
2 changed files with 33 additions and 22 deletions

View File

@ -99,25 +99,32 @@ export class Edge {
if (initializing) return; if (initializing) return;
addEdgeForm(new Edge(graph, null, graph.getVertex(from), graph.getVertex(to))); addEdgeForm(new Edge(graph, null, graph.getVertex(from), graph.getVertex(to)));
}, },
}); })
.button({
form.button({ id: 'save',
id: 'save', name: 'Save',
name: 'Save', cb: ({ form: { value } }, { initializing }) => {
cb: ({ form: { value } }, { initializing }) => { if (initializing) return;
if (initializing) return; // Handle additions and updates
// Handle additions and updates for (const { type, weight } of value.edges) {
for (const { type, weight } of value.edges) { graph.setEdgeWeight(type, from, to, weight);
graph.setEdgeWeight(type, from, to, weight);
}
// Handle removals
for (const edge of graph.getEdges(null, from, to)) {
if (!value.edges.find(({ type }) => type === edge.type)) {
graph.deleteEdge(edge.type, from, to);
} }
} // Handle removals
graph.redraw(); for (const edge of graph.getEdges(null, from, to)) {
}, if (!value.edges.find(({ type }) => type === edge.type)) {
}); graph.deleteEdge(edge.type, from, to);
}
}
graph.redraw();
},
})
.button({
id: 'cancel',
name: 'Cancel',
cb: (_, { initializing }) => {
if (initializing) return;
doc.clear();
},
});
} }
} }

View File

@ -48,11 +48,10 @@ export class Vertex {
const form = doc.form().lastElement; const form = doc.form().lastElement;
form form
.textField({ .textField({
id: 'id', name: 'id', defaultValue: vertex.id, disabled: true, id: 'id', name: 'id', defaultValue: vertex.id,
}) })
.textField({ id: 'type', name: 'type', defaultValue: vertex.type }) .textField({ id: 'type', name: 'type', defaultValue: vertex.type })
.textField({ id: 'label', name: 'label', defaultValue: vertex.label }) .textField({ id: 'label', name: 'label', defaultValue: vertex.label })
.button({ .button({
id: 'save', id: 'save',
name: 'Save', name: 'Save',
@ -69,9 +68,14 @@ export class Vertex {
} }
}, },
}) })
.button({
id: 'cancel',
name: 'Cancel',
cb: (_, { initializing }) => {
if (initializing) return;
doc.clear();
}, },
}); });
return doc; return doc;
} }
} }