-
Notifications
You must be signed in to change notification settings - Fork 45
Fixing validation, highlighting and authoring state #181
Conversation
…en elements are deleting.
…g link was deleted or restored.
LGTM |
src/ontodia/editor/authoringState.ts
Outdated
if (!isNew) { return true; } | ||
|
||
const linkModel = (event as LinkChange).after; | ||
const isConnectedToTheElements = elementIris.find(elementIri => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use Set<ElementIri>
instead of an array, you'll be able to perform this test in two calls:
elementIris.has(linkModel.link.sourceId) || elementIris.has(link.targetId);
src/ontodia/editor/authoringState.ts
Outdated
): AuthoringState { | ||
const events = state.events.filter(event => { | ||
const isNew = event.type === AuthoringKind.ChangeLink && !event.before; | ||
if (!isNew) { return true; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend testing this directly (without isNew
variable):
if (!(event.type === AuthoringKind.ChangeLink && !event.before)) { return true; }
This way you won't need a cast later: (event as LinkChange)
for (const item of items) { | ||
if (item instanceof Element) { | ||
if (AuthoringState.isNewElement(state, item.iri)) { | ||
if (AuthoringState.isNewElement(this.authoringState, item.iri)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be easier to replace this whole if
-statement with something like this:
this.discardChange(event);
this.model.removeElement(item.id);
This way you don't even need to have deleteNewLinksReleatedToElements()
method at all.
// delete newly created entity | ||
for (const element of elements) { | ||
this.model.removeElement(element.id); | ||
const isOriginalEntity = !event || event.type === AuthoringKind.ChangeElement && event.before; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this block could be simplified by reusing discardChange()
logic a little bit more:
// remove new connected links
const linksToRemove = new Set<string>();
for (const element of elements) {
for (const link of element.links) {
if (link.data && AuthoringState.isNewLink(state, link.data)) {
linksToRemove.add(link.id);
}
}
}
// delete separately to prevent modification while iterating
linksToRemove.forEach(linkId => this.model.removeLink(linkId));
if (event) {
this.discardChange(event);
}
const batch = this.model.history.startBatch(); | ||
const dangerousIris: ElementIri[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's so dangerous about these?
No description provided.