climech / grit

Multitree-based personal task manager
MIT License
1.67k stars 47 forks source link

Moving nodes #9

Open ironhouzi opened 3 years ago

ironhouzi commented 3 years ago

I'm not sure I clearly see how to move a node/subgraph. I was expecting a grit move <node-id> [-p ]<parent-node-id> or if the node is to be a root node: grit move -r <node-id>.

climech commented 3 years ago

The idea is to unlink the child from its parent, then link another parent to it.

E.g., given the tree:

[ ] Task (26)
 ├──[ ] Subtask (27)
 │   ├──[ ] Subsubtask (29)
 │   └──[ ] Subsubtask (30)
 └──[ ] Subtask (28)
     └──[ ] Subsubtask (31)

To move 31 under 27, first remove the link between 28 and 31 (the direction is always from parent to child):

$ grit unlink 28 31

If 31 has no other parent, this will make it a root. This can be confirmed with grit stat 31, or grit ls which prints out a list of all roots by default.

Now we can link 27 to it:

$ grit link 27 31
$ grit
[ ] Task (26)
 ├──[ ] Subtask (27)
 │   ├──[ ] Subsubtask (29)
 │   ├──[ ] Subsubtask (30)
 │   └──[ ] Subsubtask (31)
 └──[ ] Subtask (28)

I suppose a move command could be useful as a shorthand for switching parents. However, the child may have more than one parent, so it would have to work with that.

ironhouzi commented 3 years ago

Thank you! The UX is somewhat cumbersome, so being able to just make 27 in your example into a root node would be really great. I think the default behavior when sub-subtasks have multiple parents is to keep all parent refs, except the one you're currently modifying.

EDIT: After trying your instructions, I managed to loose nodes -- probably messing up ORIGIN and TARGETS for the link command. I am left with a sense of poor UX in that it was easily possible for me to loose nodes and modify the data structure to a useless state without any way of undoing my actions.

Isammoc commented 3 years ago

@ironhouzi I cannot understand how you manage to lose nodes. If a node does not have any parent (with unlink), it becomes a root node. Only rm/remove seems to be able to delete data.