Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcuts for navigating to next/prev node #4784

Merged
merged 17 commits into from
Sep 2, 2020
Merged

Conversation

grittaweisheit
Copy link
Contributor

@grittaweisheit grittaweisheit commented Aug 28, 2020

This PR makes it possible to navigate between nodes in a skeleton tracing via "," and "ctr + ." .

URL of deployed dev instance (used for testing):

Steps to test:

  • open a skeleton tracing
  • have some nodes
  • navigate with "," to the preceding, or with "ctr + ." to the subsequent node
  • when on a branch point the node with the highest (subsequent) / lowest (preceding) id is selected
  • if navigating back over a branch that was already navigated over, the path that was already taken is chosen again

Issues:


Copy link
Member

@daniel-wer daniel-wer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, I like this feature a lot and you did a good job implementing it, it's already a pleasure to use 🎉
There are a couple of edge-cases which I annotated and I suggested a more edge-case-resistant approach to detect invalid navigation lists :)

CHANGELOG.unreleased.md Outdated Show resolved Hide resolved
@@ -229,6 +303,7 @@ function onClick(
);
} else {
Store.dispatch(setActiveNodeAction(nodeId));
Store.dispatch(updateNavigationListAction([nodeId], 0));
Copy link
Member

@daniel-wer daniel-wer Aug 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's very hard to catch all the cases where the navigation list becomes "invalid" and would need to emptied. For example, this is the straight-forward case where a user selects another node, but there are also many other cases, like: Deleting one (or all) nodes of a tree, deleting a group with all its trees, creating a new tree, jumping to a branchpoint (using the J shortcut), ...

Therefore, what do you think about not trying to catch all these cases preemptively, but on-demand. What I mean by that is for every "hit" in the navigation list in the toSubsequentNode and toPrecedingNode functions, so whenever a node that was already in the list would be set active, before doing that you check whether the node from the list is a neighbor of the currently active node:

  • If it is not a neighbor, empty the list (as you did here) because something happened in between that made the navigation list invalid, otherwise the nodes would be neighbors. Then you search a neighbor as you would do if the list was empty or exhausted.
  • If it is a neighbor, proceed as usual

What do you think about this approach? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I adjusted it a little bit and just check it in advance by comparing the active node with the list's node at the active index.

Copy link
Member

@daniel-wer daniel-wer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works like a charm in my tests, very cool!

I made some suggestions to simplify the code. I'm not too happy about the code duplication, but as the two cases differ in quite a few lines I don't see an easy way to unify the two functions. So I'd say we should aim to simplify the methods as much as possible but keep them separate :)

Please also add the two new shortcuts to the list of keyboard shortcuts (keyboard_shortcuts.md)

Comment on lines 175 to 180
if (
activeNodeId !== navigationList.list[navigationList.activeIndex] ||
!navigationList.list.length
) {
isValidList = false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could get rid of the let isValidList by directly assigning the result of the comparison here, like:

const isValidList = navigationList.list.length && activeNodeId === navigationList.list[navigationList.activeIndex];

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same in the other function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty neat! Thanks :)

Comment on lines 192 to 197
const { tree, node } = getNodeAndTree(tracing, activeNodeId, activeTreeId)
.map(([maybeTree, maybeNode]) => ({ tree: maybeTree, node: maybeNode }))
.getOrElse({
tree: null,
node: null,
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe simplify this to

const [ tree, node ] = getNodeAndTree(tracing, activeNodeId, activeTreeId)
  .getOrElse([null, null]);

Same in the other method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flow is not happy with that :( . Maybe I could extract it in an extra method so it at least doesn't appear twice?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:/ Yes you could put it into a getNodeAndTreeOrNull method in the skeleton tracing accessor file or you could annotate my proposed solution with a // $FlowFixMe to silence flow (as we know that the code is correct).

Copy link
Member

@daniel-wer daniel-wer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done, lgtm 👍

@grittaweisheit grittaweisheit merged commit a5a0902 into master Sep 2, 2020
@philippotto philippotto deleted the navigate-nodes branch June 14, 2022 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add shortcuts for navigating to next/prev node
2 participants