Add context menu option for opening source view (Fixes #4405)#4423
Conversation
Codecov ReportBase: 88.52% // Head: 88.58% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #4423 +/- ##
==========================================
+ Coverage 88.52% 88.58% +0.05%
==========================================
Files 283 282 -1
Lines 25508 25518 +10
Branches 6869 6875 +6
==========================================
+ Hits 22582 22606 +24
+ Misses 2717 2707 -10
+ Partials 209 205 -4
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
|
This looks great! Adding Julien and Nazim so that they can comment on whether they agree with this UI and implementation. I wonder if it's worth adding a tooltip to this context menu item. The transform items have tooltips, but that's because they really need tooltips, heh. It's probably fine to have no tooltip for this new item. I did notice one problem in the deploy preview, but this is totally my fault and a problem with the initial implementation, and we can fix it in a follow-up. I made the assumption that the call node which opens the source view is always the selected call node. But when using the context menu to open the source view, the right clicked call node can be different from the selected call node. This is a problem because the selected call node influences the behavior of the source view in that it determines which line is scrolled into view. You can see this in this profile in the deploy preview as follows:
Now the source view will show GC.cpp, but it will be scrolled to display the contents of the "js::gc::GCRuntime::gcSlice" function. Ideally, it would be scrolled to display the contents of the "markUntilBudgetExhausted" function. Fixing this is probably a bit complicated, so let's leave it for a follow-up. |
I wouldn't mind adding a tooltip, it's just that I don't know what the tooltip should be saying 😛 Also, should I be adding tests for this since coverage is dropping? I tried to add a test to CallNodeContextMenu.test.js that looks like this: it('can show source file', function () {
const {
profile,
funcNamesPerThread: [funcNames],
} = getProfileFromTextSamples(`
A[file:git:github.com/rust-lang/rust:library/std/src/sys/unix/thread.rs:53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b]
`);
const funcIndex = funcNames.indexOf('A');
const store = storeWithProfile(profile);
store.dispatch(changeRightClickedCallNode(0, [funcIndex]));
const { getByText } = setup(store);
expect(document.querySelector(".sourceView")).not.toBeInTheDocument();
fireFullClick(getByText(/Show/));
expect(document.querySelector(".sourceView")).toBeInTheDocument();
});But it didn't really work out since
Similarly, there is an inconsistency with keyboard shortcuts in the context menu. Right-clicking a different call node from the selected node and using any of the call node transform shortcuts, results on the transform being applied to the right-clicked node. However, when pressing enter in this situation, it shows the source view for the selected call node instead. Furthermore, the call node transform shortcuts seem to dismiss the context menu, while other shortcuts such as "Expand all" and "Show file" don't. Should this also be tackled in the follow up? Regarding the problem itself, I saw that BottomBox.js is using
However, I don't know how to get the line timings for the right clicked call node without potentially copy-pasting and slightly modifying a whole bunch of code from per-thread/index.js (also not sure if it'll work after doing this). So maybe I can watch and learn from whoever does the follow up 😄 |
Yeah it would be good to fix this, but I even think we should try to fix this before merging this patch actually. The alternative is that we don't specify the "Enter" shortcut for now.
I don't see this on my side. |
The plan sounds good to me at least :-) |
I think it would be good enough to check the content of |
julienw
left a comment
There was a problem hiding this comment.
This looks reasonable, thanks for the patch!
As you mentioned, it would be good to have some tests for the new behaviors (menu + stack chart). That's why I'm marking 'Request Changes'.
Thanks again!
|
Fixing the Enter key shouldn't be too hard:
const nodeIndex =
rightClickedCallNodeIndex !== null
? rightClickedCallNodeIndex
: selectedCallNodeIndex; |
|
Sorry for the delayed response, still at work right now, but hopefully I'll have addressed some of these later tonight.
Here's what I observe on production:
If we fix the Enter key should we be fixing "*" (Expand all) too?
To me, the stack chart like behavior makes most sense. The context menu has focus, so keys should only be controlling that and not things behind it. However, if this behavior is made consistent, the Enter key when pressed in a context menu on options other than "Show file" would be selecting that option rather than showing the file. In contrast, using the other shortcuts regardless of which context menu option is selected, would trigger the action for the shortcut. Would that be acceptable or should we not show the enter shortcut in the context menu? Also apologies, I can't tell if I'm over-complicating/thinking things 😄
Awesome, I think I can write a test asserting against the sourceViewFile. |
julienw
left a comment
There was a problem hiding this comment.
This looks pretty solid to me! Indeed your solution to fix Enter and * looks just as good as mine.
It would be good to have a test for the flame graph changes. You can shamelessly plug into the existing test can be navigated with the keyboard. The function J already has a file name attached to it (look at setupFlameGraph), maybe you can attach one to B as well so that you don't have to target J specifically in that test.
It would also be good to have a test for "*" and "Enter" in a right click setup but I don't think there is a prior existing test you could reuse, so I won't ask you to provide one.
I think it would be better to file them separately. We prefer smaller targeted PRs as they're easier to review :-) |
Added to |
julienw
left a comment
There was a problem hiding this comment.
Looks good to me, thanks a lot!
We're still waiting for the l10n approval before merging.

Hey, it seems to look fine visually and functionally as far as I tested, so hopefully it's not horribly wrong:

Instead of restricting the context menu option to flame graph and call tree tabs only, I also allowed stack chart to open the source view via right-click and enter. Didn't do double click in stack chart though, since it's used for something else. Is this fine?
Also, is there anything more I need to be doing for i18n/l10n during or if/after this PR lands?
Fixes #4405
Production
Deploy preview