@walter Thank you very much for your help, I have left the code to delete or modify as follows,
diagram.addModelChangedListener((evt: go.ChangedEvent) => {
if (!evt.isTransactionFinished) return;
const txn = evt.object; // a Transaction
if (txn === null) return;
txn.changes.each((e: go.ChangedEvent) => {
// record node insertions and removals
if (e.change === go.ChangeType.Property) {
if (e.modelChange === "linkFromKey") {
console.log(`${e.propertyName} changed From key of link: ${JSON.stringify(e.object)} from: ${e.oldValue} to: ${e.newValue}`);
} else if (e.modelChange === "linkToKey") {
console.log(`${e.propertyName} changed To key of link: ${JSON.stringify(e.object)} from: ${e.oldValue} to: ${e.newValue}`);
}
} else if (e.change === go.ChangeType.Insert && e.modelChange === "linkDataArray") {
console.log(`${e.propertyName} added link: ${JSON.stringify(e.newValue)}`);
} else if (e.change === go.ChangeType.Remove && e.modelChange === "linkDataArray") {
console.log(`${e.propertyName} removed link: ${JSON.stringify(e.oldValue)}`);
const removedLinkData = e.oldValue;
const existingLinkIndex = mappingLinks.findIndex(link => link.from === removedLinkData.from && link.to === removedLinkData.to);
if (existingLinkIndex > -1) {
mappingLinks[existingLinkIndex].deleted = true;
} else {
const removedMappingLink: MappingData = {
from: removedLinkData.from,
to: removedLinkData.to,
config: configId,
deleted: true
};
mappingLinks.push(removedMappingLink);
}
}
});
});
const handleSave = async () => {
if (mappingLinks.length > 0) {
try {
const linksToSave = mappingLinks.filter(link => !link.deleted);
console.log('links a GUARDAR', linksToSave)
const linksToDelete = mappingLinks.filter(link => link.deleted);
console.log('links a ELIMINAR', linksToDelete)
if (linksToSave.length > 0) {
await $treeMapperApi.saveMappingLinks(linksToSave);
alert('Mapping saved successfully');
}
if (linksToDelete.length > 0) {
await $treeMapperApi.deleteMappingLinks(linksToDelete);
alert('Mappings deleted successfully');
}
mappingLinks.splice(0, mappingLinks.length);
} catch (error) {
console.error('Error saving mapping links:', error);
alert('There was an error saving the mapping');
}
} else {
alert('There are no links to save');
}
};
I would like you to help me with the context menu part for this tree mapper, the idea is that when I right click it opens the option to change the order, is this possible? I await your comments.