BALKANGraph / FamilyTreeJS

Build family tree app with BALKAN FamilyTreeJS library. Family Tree also called a genealogy or a pedigree chart, is a chart representing family relationships in a conventional tree structure.
57 stars 17 forks source link

Dialog on delete? #150

Open unclebay143 opened 6 days ago

unclebay143 commented 6 days ago

Similar to https://code.balkan.app/org-chart-js/dialog-on-save#JS

ZornitsaPesheva commented 5 days ago

For FamilyTree JS we use only onUpdateNode to update the database: https://balkan.app/FamilyTreeJS/Docs/GettingStarted#database

unclebay143 commented 3 days ago

For FamilyTree JS we use only onUpdateNode to update the database: https://balkan.app/FamilyTreeJS/Docs/GettingStarted#database

Does that mean we cannot display a confirmation modal for delete? And can't prevent accidental delete through confirmation?

Deleted members are also deleted from the tree before the onUpdateNode is triggered

ZornitsaPesheva commented 3 days ago

No, you can have the same dialog, but you need to use on the onUpdateNode. You have the deleted nodes in args.

unclebay143 commented 3 days ago

No, you can have the same dialog, but you need to use on the onUpdateNode. You have the deleted nodes in args.

that's the point, we can't intercept it, even if we show a confirmation modal, it gets deleted before the modal shows for instance my code looks like this. image

ZornitsaPesheva commented 3 days ago

Oh, I see... you need to return false if you don't have to delete the node.

family.onUpdateNode((args) => {
  //post the data from args to your server
  if (condition is met) {
    return false
  }
});
unclebay143 commented 3 days ago

Ah, so close! Thanks @ZornitsaPesheva, able to achieve my thought now, the overall code now is as below:

familyTree.current.onUpdateNode(
  (updatedTreeData: { removeNodeId: string }) => {
    const isDeleteAction = !!updatedTreeData.removeNodeId;
    if (isDeleteAction && !confirm("Do you want to delete?")) {
      return false;
    }
    saveTree(updatedTreeData);
  }
);