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

[kbn-grid-layout] Cleanup memoization and styling #210285

Merged

Conversation

Heenawter
Copy link
Contributor

@Heenawter Heenawter commented Feb 7, 2025

Summary

This PR cleans up the kbn-grid-layout code in two ways:

  1. Rather than memoizing components in their parents, I swapped to using React.memo for all components, which accomplishes the same behaviour in a slightly cleaner way.
  2. I moved all Emotion style definitions outside of the React components so that we no longer have to re-parse the CSS string on every render (see this comment).

Checklist

  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines

@Heenawter Heenawter requested a review from mbondyra February 7, 2025 22:57
@Heenawter Heenawter force-pushed the kbn-grid-layout_cleanup-code-2025-02-07 branch from ea0e84d to e7ec22e Compare February 10, 2025 16:05
@Heenawter Heenawter self-assigned this Feb 10, 2025
@Heenawter Heenawter added Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas technical debt Improvement of the software architecture and operational architecture release_note:skip Skip the PR/issue when compiling release notes impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. backport:version Backport to applied version labels v8.19.0 Project:Collapsable Panels Related to the project for adding collapsable sections to Dashboards. loe:small Small Level of Effort labels Feb 10, 2025
@Heenawter Heenawter marked this pull request as ready for review February 10, 2025 16:32
@Heenawter Heenawter requested a review from a team as a code owner February 10, 2025 16:32
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-presentation (Team:Presentation)

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
dashboard 600.9KB 601.6KB +721.0B

History

cc @Heenawter

Copy link
Member

@nickpeihl nickpeihl left a comment

Choose a reason for hiding this comment

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

lgtm! discussed offline with @Heenawter

code review only

@Heenawter Heenawter merged commit 219f31a into elastic:main Feb 10, 2025
27 checks passed
@Heenawter Heenawter deleted the kbn-grid-layout_cleanup-code-2025-02-07 branch February 10, 2025 20:09
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/13249525893

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.x Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 210285

Questions ?

Please refer to the Backport tool documentation

Heenawter added a commit to Heenawter/kibana that referenced this pull request Feb 10, 2025
## Summary

This PR cleans up the `kbn-grid-layout` code in two ways:
1. Rather than memoizing components in their parents, I swapped to using
`React.memo` for all components, which accomplishes the same behaviour
in a slightly cleaner way.
2. I moved all Emotion style definitions **outside** of the React
components so that we no longer have to re-parse the CSS string on every
render (see [this
comment](elastic/eui#6828 (comment))).

### Checklist

- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

(cherry picked from commit 219f31a)

# Conflicts:
#	src/platform/packages/private/kbn-grid-layout/grid/grid_panel/resize_handle.tsx
Heenawter added a commit that referenced this pull request Feb 11, 2025
…10466)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[kbn-grid-layout] Cleanup memoization and styling
(#210285)](#210285)

<!--- Backport version: 9.6.4 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Hannah
Mudge","email":"Heenawter@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-02-05T22:18:04Z","message":"[Dashboard]
Presentation panel refactor (#207275)\n\nCloses
https://github.com/elastic/kibana/issues/206686\r\nCloses
https://github.com/elastic/kibana/issues/197897\r\nPart of
https://github.com/elastic/kibana/issues/207852\r\n\r\n##
Summary\r\n\r\nThis PR is a major refactor of the `PresentationPanel`
component,\r\nincluding an overhaul of the hover action and panel title
components.\r\nSome notable highlights include:\r\n- All styles in the
`PresentationPanel` component were moved from SASS\r\nto Emotion\r\n-
The over-complicated logic to combine hover actions when the
panel\r\nshrinks was removed in favour of CSS, driven by a
[container\r\nquery](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_containment/Container_queries)\r\nRemoving
the `updateCombineHoverActions` function (which was defined in\r\na
React component and not memoized) also made a difference
in\r\nperformance when dragging:\r\n \r\n | Before | After |\r\n
|--------|--------|\r\n|\r\n![image](https://github.com/user-attachments/assets/e66898d6-a6fc-42c7-9e24-f116d3bd85a6)\r\n|\r\n![image](https://github.com/user-attachments/assets/1f1d75ba-2ebc-4def-9d2e-14dfd5e1a585)\r\n|\r\n
\r\n\r\n- The over-complicated logic defined
in\r\n`usePresentationPanelTitleClickHandle`, which was meant to ignore
the\r\n`onClick` that would trigger after a panel was dragged, was
converted to\r\n2 lines of CSS\r\n\r\n### Small usability
improvements\r\n\r\nThis PR also includes a few small usability
improvements, such as:\r\n\r\n- Ensuring that only the **first** row of
hover actions overlaps with\r\nthe Dashboard's sticky top navigation
bar, and this only happens when\r\nthe dashboard has no controls. This
results in much better behaviour in\r\nmost scenarios:\r\n \r\n | Before
| After |\r\n |--------|--------|\r\n|
![Jan-27-2025\r\n16-14-26](https://github.com/user-attachments/assets/2bf5eaa0-06ab-4d87-897f-d217f189daf7)\r\n|
![Jan-27-2025\r\n16-13-41](https://github.com/user-attachments/assets/61b0f06a-1363-4bfc-8a2b-c57a3e736552)\r\n|\r\n\r\n-
Adding a small delay for hiding the hover actions on mouse
leave,\r\nwhich makes it a lot easier to grab the drag handle:\r\n\r\n |
Before | After |\r\n |--------|--------|\r\n|
![Jan-27-2025\r\n16-21-11](https://github.com/user-attachments/assets/65138e53-1856-44f0-913f-01383b8aa6c2)\r\n|
![Jan-27-2025\r\n16-20-17](https://github.com/user-attachments/assets/7c8ba4d8-8b77-4bc5-85af-a082cace1f96)\r\n|\r\n\r\n-
Preventing the resize handle from overlapping Dashboard's stick
top\r\nnavigation:\r\n\r\n | Before | After |\r\n
|--------|--------|\r\n|
![Jan-27-2025\r\n16-24-31](https://github.com/user-attachments/assets/5363a302-5f6a-4483-9782-516023567d87)\r\n|
![Jan-27-2025\r\n16-25-04](https://github.com/user-attachments/assets/8614d025-b45b-4af2-81d6-c62a086ca427)\r\n|\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"c35698bcf81314f833467fde2d3c14785b83c1ad","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["performance","Team:Presentation","loe:medium","technical
debt","release_note:skip","impact:high","backport:version","v9.1.0","v8.19.0"],"title":"[Dashboard]
Presentation panel
refactor","number":207275,"url":"https://github.com/elastic/kibana/pull/207275","mergeCommit":{"message":"[Dashboard]
Presentation panel refactor (#207275)\n\nCloses
https://github.com/elastic/kibana/issues/206686\r\nCloses
https://github.com/elastic/kibana/issues/197897\r\nPart of
https://github.com/elastic/kibana/issues/207852\r\n\r\n##
Summary\r\n\r\nThis PR is a major refactor of the `PresentationPanel`
component,\r\nincluding an overhaul of the hover action and panel title
components.\r\nSome notable highlights include:\r\n- All styles in the
`PresentationPanel` component were moved from SASS\r\nto Emotion\r\n-
The over-complicated logic to combine hover actions when the
panel\r\nshrinks was removed in favour of CSS, driven by a
[container\r\nquery](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_containment/Container_queries)\r\nRemoving
the `updateCombineHoverActions` function (which was defined in\r\na
React component and not memoized) also made a difference
in\r\nperformance when dragging:\r\n \r\n | Before | After |\r\n
|--------|--------|\r\n|\r\n![image](https://github.com/user-attachments/assets/e66898d6-a6fc-42c7-9e24-f116d3bd85a6)\r\n|\r\n![image](https://github.com/user-attachments/assets/1f1d75ba-2ebc-4def-9d2e-14dfd5e1a585)\r\n|\r\n
\r\n\r\n- The over-complicated logic defined
in\r\n`usePresentationPanelTitleClickHandle`, which was meant to ignore
the\r\n`onClick` that would trigger after a panel was dragged, was
converted to\r\n2 lines of CSS\r\n\r\n### Small usability
improvements\r\n\r\nThis PR also includes a few small usability
improvements, such as:\r\n\r\n- Ensuring that only the **first** row of
hover actions overlaps with\r\nthe Dashboard's sticky top navigation
bar, and this only happens when\r\nthe dashboard has no controls. This
results in much better behaviour in\r\nmost scenarios:\r\n \r\n | Before
| After |\r\n |--------|--------|\r\n|
![Jan-27-2025\r\n16-14-26](https://github.com/user-attachments/assets/2bf5eaa0-06ab-4d87-897f-d217f189daf7)\r\n|
![Jan-27-2025\r\n16-13-41](https://github.com/user-attachments/assets/61b0f06a-1363-4bfc-8a2b-c57a3e736552)\r\n|\r\n\r\n-
Adding a small delay for hiding the hover actions on mouse
leave,\r\nwhich makes it a lot easier to grab the drag handle:\r\n\r\n |
Before | After |\r\n |--------|--------|\r\n|
![Jan-27-2025\r\n16-21-11](https://github.com/user-attachments/assets/65138e53-1856-44f0-913f-01383b8aa6c2)\r\n|
![Jan-27-2025\r\n16-20-17](https://github.com/user-attachments/assets/7c8ba4d8-8b77-4bc5-85af-a082cace1f96)\r\n|\r\n\r\n-
Preventing the resize handle from overlapping Dashboard's stick
top\r\nnavigation:\r\n\r\n | Before | After |\r\n
|--------|--------|\r\n|
![Jan-27-2025\r\n16-24-31](https://github.com/user-attachments/assets/5363a302-5f6a-4483-9782-516023567d87)\r\n|
![Jan-27-2025\r\n16-25-04](https://github.com/user-attachments/assets/8614d025-b45b-4af2-81d6-c62a086ca427)\r\n|\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"c35698bcf81314f833467fde2d3c14785b83c1ad"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/207275","number":207275,"mergeCommit":{"message":"[Dashboard]
Presentation panel refactor (#207275)\n\nCloses
https://github.com/elastic/kibana/issues/206686\r\nCloses
https://github.com/elastic/kibana/issues/197897\r\nPart of
https://github.com/elastic/kibana/issues/207852\r\n\r\n##
Summary\r\n\r\nThis PR is a major refactor of the `PresentationPanel`
component,\r\nincluding an overhaul of the hover action and panel title
components.\r\nSome notable highlights include:\r\n- All styles in the
`PresentationPanel` component were moved from SASS\r\nto Emotion\r\n-
The over-complicated logic to combine hover actions when the
panel\r\nshrinks was removed in favour of CSS, driven by a
[container\r\nquery](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_containment/Container_queries)\r\nRemoving
the `updateCombineHoverActions` function (which was defined in\r\na
React component and not memoized) also made a difference
in\r\nperformance when dragging:\r\n \r\n | Before | After |\r\n
|--------|--------|\r\n|\r\n![image](https://github.com/user-attachments/assets/e66898d6-a6fc-42c7-9e24-f116d3bd85a6)\r\n|\r\n![image](https://github.com/user-attachments/assets/1f1d75ba-2ebc-4def-9d2e-14dfd5e1a585)\r\n|\r\n
\r\n\r\n- The over-complicated logic defined
in\r\n`usePresentationPanelTitleClickHandle`, which was meant to ignore
the\r\n`onClick` that would trigger after a panel was dragged, was
converted to\r\n2 lines of CSS\r\n\r\n### Small usability
improvements\r\n\r\nThis PR also includes a few small usability
improvements, such as:\r\n\r\n- Ensuring that only the **first** row of
hover actions overlaps with\r\nthe Dashboard's sticky top navigation
bar, and this only happens when\r\nthe dashboard has no controls. This
results in much better behaviour in\r\nmost scenarios:\r\n \r\n | Before
| After |\r\n |--------|--------|\r\n|
![Jan-27-2025\r\n16-14-26](https://github.com/user-attachments/assets/2bf5eaa0-06ab-4d87-897f-d217f189daf7)\r\n|
![Jan-27-2025\r\n16-13-41](https://github.com/user-attachments/assets/61b0f06a-1363-4bfc-8a2b-c57a3e736552)\r\n|\r\n\r\n-
Adding a small delay for hiding the hover actions on mouse
leave,\r\nwhich makes it a lot easier to grab the drag handle:\r\n\r\n |
Before | After |\r\n |--------|--------|\r\n|
![Jan-27-2025\r\n16-21-11](https://github.com/user-attachments/assets/65138e53-1856-44f0-913f-01383b8aa6c2)\r\n|
![Jan-27-2025\r\n16-20-17](https://github.com/user-attachments/assets/7c8ba4d8-8b77-4bc5-85af-a082cace1f96)\r\n|\r\n\r\n-
Preventing the resize handle from overlapping Dashboard's stick
top\r\nnavigation:\r\n\r\n | Before | After |\r\n
|--------|--------|\r\n|
![Jan-27-2025\r\n16-24-31](https://github.com/user-attachments/assets/5363a302-5f6a-4483-9782-516023567d87)\r\n|
![Jan-27-2025\r\n16-25-04](https://github.com/user-attachments/assets/8614d025-b45b-4af2-81d6-c62a086ca427)\r\n|\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"c35698bcf81314f833467fde2d3c14785b83c1ad"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:version Backport to applied version labels impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:small Small Level of Effort Project:Collapsable Panels Related to the project for adding collapsable sections to Dashboards. release_note:skip Skip the PR/issue when compiling release notes Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas technical debt Improvement of the software architecture and operational architecture v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants