Skip to content

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

Merged
yomete merged 4 commits into
mainfrom
function-name-right-side
Dec 16, 2024
Merged

area/ui: Add a preference to render function names from the right#5382
yomete merged 4 commits into
mainfrom
function-name-right-side

Conversation

@yomete
Copy link
Copy Markdown
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
@alwaysmeticulous
Copy link
Copy Markdown

alwaysmeticulous Bot commented Dec 11, 2024

🤖 Meticulous spotted visual differences in 103 of 209 screens tested: view and approve differences detected.

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

Last updated for commit 450644d. This comment will update as new commits are pushed.

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah yes, I missed the ref. Then lets go with the current implementation only.

@yomete yomete enabled auto-merge December 16, 2024 11:39
@yomete yomete disabled auto-merge December 16, 2024 14:20
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