Skip to content

[EuiInputPopover] Refactor & clean ups#7241

Merged
cee-chen merged 6 commits intoelastic:mainfrom
cee-chen:input-popover-setup
Oct 2, 2023
Merged

[EuiInputPopover] Refactor & clean ups#7241
cee-chen merged 6 commits intoelastic:mainfrom
cee-chen:input-popover-setup

Conversation

@cee-chen
Copy link
Copy Markdown
Contributor

@cee-chen cee-chen commented Oct 1, 2023

Summary

I'm working on pulling out some logic that EuiComboBox needs directly into EuiInputPopover for #7192, and was struggling to understand and work around some of the existing logic. Since I saw several things that bothered me/that could stand to be cleaned up, I decided to do my favorite thing - refactor and write missing tests 😅

I've opted to make this refactor separate/standalone from my EuiComboBox work in order to make code review less of a headache. As always, I strongly recommend following along by commit and hiding whitespace changes (the scary LOC diffs on this PR are literally just from indentation changes on snapshots).

What this PR does:

  • Removes an extra unnecessary <div> in the popover
  • Updates inline width style to use logical inline-size property instead of width
  • Memoizes and greatly cleans up onKeydown callback
  • Generally tries to make the code more understandable and adds more comments as to why specific things are done a specific way
  • Adds more EuiInputPopover tests to automatically catch if code changes/breaks something that was meant to do a specific thing a specific way

QA

Functionally, nothing should have changed in this PR except for 2 removed <div> wrappers and a logical property.

General checklist

  • Browser QA
    • Checked in mobile
    • Checked in Chrome, Safari, Edge, and Firefox
    • Checked for accessibility including keyboard-only and screenreader modes
      - [ ] Checked in both light and dark modes
  • Docs site QA - N/A
  • Code quality checklist
  • Release checklist - ❓ skipping changelog as nothing affecting end-users or consumers should have occurred, but I'd be curious to hear if y'all feel there should be one
  • Designer checklist - N/A

@cee-chen cee-chen force-pushed the input-popover-setup branch from 0c63c75 to e8ca2d6 Compare October 1, 2023 05:08
@cee-chen cee-chen added skip-changelog Use on PRs to skip changelog requirement (Don't delete - used for automation) tech debt labels Oct 1, 2023
- allows us to remove an extra unnecessary div wrapper, and it general lends itself to cleaner and more React-like code

+ add more detailed/clearer tests to reflect the comments added to the useEffects
- [microperf] don't bother finding/iterating through tabbable items when `disableFocusTrap` is true

- [microperf] Clean up unnecessary extra Array map by using `.hasAttribute()` instead

- make if conditions more readable/understandable by using early returns, var names, and writing tests

- pull out `closePopover` from props to add it to dependency array

- remove unnecessary type
- Remove unnecessary div by passing onKeyDown to the parent EuiPanel popover

- now that the current target of the keydown event can be guaranteed to be the panel, we can remove the `panelEl` dependency from the array
- Move classes/styling up to top of file
- add jsdoc block
- add clearer comments on why state is being used over refs for the input/panel refs
@cee-chen cee-chen force-pushed the input-popover-setup branch from e8ca2d6 to 98805e0 Compare October 1, 2023 05:17
@kibanamachine
Copy link
Copy Markdown

Preview staging links for this PR:

@elasticmachine
Copy link
Copy Markdown
Collaborator

💚 Build Succeeded

@cee-chen cee-chen marked this pull request as ready for review October 2, 2023 15:44
@cee-chen cee-chen requested a review from a team as a code owner October 2, 2023 15:44
@cee-chen
Copy link
Copy Markdown
Contributor Author

cee-chen commented Oct 2, 2023

@breehall Any chance I can shoot this PR your way today/tomorrow for review? 🙏 It's somewhat high priority as it's blocking another EuiComboBox PR. If you don't have bandwidth, no worries, please let me know!

@cee-chen cee-chen requested a review from breehall October 2, 2023 17:23
@breehall
Copy link
Copy Markdown
Contributor

breehall commented Oct 2, 2023

Absolutely! Taking a look now

Copy link
Copy Markdown
Contributor

@breehall breehall left a comment

Choose a reason for hiding this comment

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

This is good to go! This was a good refactor with great code quality improvements around comments, readability, and code structure. Great work simplifying the portion of code used to set width on the popover and removing an unnecessary .map(). I tested the production and staging versions of the PR and don't see any changes visually or in functionality.

Comment on lines +79 to +83
const inputWidth = useResizeObserver(inputEl, 'width').width;

const panelWidth = useMemo(() => {
return inputWidth < panelMinWidth ? panelMinWidth : inputWidth;
}, [panelMinWidth, inputWidth]);
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.

[Attaching to the closest block of code] This is a lot easier to understand (especially with the new comments)

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.

Music to my ears. Thank you so much Bree!

Also, for some context as to what I was cursing about & struggling with that I mentioned earlier today - it took me way too long to figure out what the tabbable logic was trying to accomplish and how to QA it (it really seems, functionally, to only affect the EuiAutoRefresh component). Which is why writing tests and leaving good code comments is so important :)

@cee-chen cee-chen merged commit 10a50bb into elastic:main Oct 2, 2023
@cee-chen cee-chen deleted the input-popover-setup branch October 2, 2023 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Use on PRs to skip changelog requirement (Don't delete - used for automation) tech debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants