Fix NPE on remove node.

This commit is contained in:
Paulo Gustavo Veiga 2022-10-07 21:00:54 -07:00
parent c9c2194a57
commit 49de0b4945
4 changed files with 12 additions and 3 deletions

View File

@ -55,7 +55,8 @@ export class DefaultWidgetManager extends WidgetManager {
return topic.getNoteValue(); return topic.getNoteValue();
}, },
setValue(value: string) { setValue(value: string) {
topic.setNoteValue(value); const note = value && value.trim() !== '' ? value : undefined;
topic.setNoteValue(note);
}, },
}; };
this.editorContent = noteContent(model, () => this.setPopoverOpen(false)); this.editorContent = noteContent(model, () => this.setPopoverOpen(false));

View File

@ -16,9 +16,11 @@ const SaveAndDelete = (props: {
<Button color="primary" variant="outlined" onClick={props.submitHandler} sx={{ mr: 1 }}> <Button color="primary" variant="outlined" onClick={props.submitHandler} sx={{ mr: 1 }}>
{$msg('ACCEPT')} {$msg('ACCEPT')}
</Button> </Button>
<Button color="primary" variant="contained" onClick={props.closeModal}> <Button color="primary" variant="contained" onClick={props.closeModal}>
{$msg('CANCEL')} {$msg('CANCEL')}
</Button> </Button>
{props.model.getValue() && props.model.getValue().trim() !== '' && ( {props.model.getValue() && props.model.getValue().trim() !== '' && (
<IconButton <IconButton
onClick={() => { onClick={() => {

View File

@ -164,7 +164,11 @@ export class NodePropertyValueModelBuilder {
this.linkModel = { this.linkModel = {
getValue: (): string => this.selectedTopic()?.getLinkValue(), getValue: (): string => this.selectedTopic()?.getLinkValue(),
setValue: (value: string) => { setValue: (value: string) => {
this.selectedTopic().setLinkValue(value); if (value && value.trim() !== '') {
this.selectedTopic().setLinkValue(value);
} else {
this.selectedTopic().setLinkValue(undefined);
}
}, },
}; };
return this.linkModel; return this.linkModel;
@ -218,7 +222,8 @@ export class NodePropertyValueModelBuilder {
this.noteModel = { this.noteModel = {
getValue: (): string => this.selectedTopic()?.getNoteValue(), getValue: (): string => this.selectedTopic()?.getNoteValue(),
setValue: (value: string) => { setValue: (value: string) => {
this.selectedTopic().setNoteValue(value); const note = value && value.trim() !== '' ? value : undefined;
this.selectedTopic()?.setNoteValue(note);
}, },
}; };
return this.noteModel; return this.noteModel;

View File

@ -777,6 +777,7 @@ abstract class Topic extends NodeGraph {
const model = this.getModel(); const model = this.getModel();
const dispatcher = ActionDispatcher.getInstance(); const dispatcher = ActionDispatcher.getInstance();
const links = model.findFeatureByType(TopicFeatureFactory.Link.id); const links = model.findFeatureByType(TopicFeatureFactory.Link.id);
if (!$defined(value)) { if (!$defined(value)) {
const featureId = links[0].getId(); const featureId = links[0].getId();
dispatcher.removeFeatureFromTopic(topicId, featureId); dispatcher.removeFeatureFromTopic(topicId, featureId);