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

area/ui: Add a preference to render function names from the right #5382

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

yomete
Copy link
Contributor

@yomete yomete commented Dec 11, 2024

This adds a new preference to determine if long function names should be displayed from the left or right hand side. By default it is set to true/checked.

image

This new preference aims to solve the issue where long function names in the icicle graph are shortened due to the stack's width, and you only see the LHS of the function name.

When the preference is unchecked/set to false, and the rect that displays the function name is not wide enough to show the entire name, then we just show the right hand side of the function name.

Checked
image

Unchecked
image

@yomete yomete requested a review from a team as a code owner December 11, 2024 13:38
Copy link

alwaysmeticulous bot commented Dec 11, 2024

🤖 Meticulous spotted visual differences in 158 of 223 screens tested: view and approve differences detected.

Meticulous simulated ~5 hours of user flows against your PR.

Last updated for commit 70275cb. This comment will update as new commits are pushed.

Copy link
Contributor

@manojVivek manojVivek left a comment

Choose a reason for hiding this comment

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

Just a minor feedback, looks great otherwise!

USER_PREFERENCES.SHOW_FUNCTION_NAME_FROM_LEFT.key
);

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This useState + useEffect combo can be replaced with a single useMemo that returns the text that can be used below to render.

Technically, useState + useEffect method has to render the component twice before it renders the expected output while the useMemo approach would do it in a single render. Not a biggie, but it improves the readability as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, i'll make that change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm so I made changes based on the feedback above to now use useMemo.

  const displayText = useMemo(() => {
    const textElement = textRef.current;
    if (textElement === null) return text;

    return showFunctionNameFromLeft ? text : calculateTruncatedText(text, textElement, width);
  }, [text, width, showFunctionNameFromLeft, textRef]);

but with this new change we don't get to see the truncated text when it should be shown.

I'm assuming this is related to the usage of the textRef ref and the fact that useMemo is running before the ref is attached to the DOM, therefore the initial render will always have textRef.current as null, and the memoization is preventing subsequent updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants