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

[Dashboard] [Collapsable Panels] Switch to using props #200793

Merged

Conversation

Heenawter
Copy link
Contributor

@Heenawter Heenawter commented Nov 19, 2024

Closes #200090

Summary

This PR migrates the GridLayout component a more traditional React design using props rather than providing an API. This change serves two purposes:

  1. It makes the eventual Dashboard migration easier, since it is more similar to react-grid-layout's implementation
  2. It makes the GridLayout component less opinionated by moving the logic for panel management (i.e. panel placement, etc) to the parent component.

I tried to keep efficiency in mind for this comparison, and ensured that we are still keeping the number of rerenders o a minimum. This PR should not introduce any extra renders in comparison to the API version.

Checklist

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

Identify risks

There are no risks to this PR, since all work is contained in the examples plugin.

@Heenawter Heenawter added Feature:Dashboard Dashboard related features Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas loe:medium Medium Level of Effort release_note:skip Skip the PR/issue when compiling release notes impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Project:Collapsable Panels Related to the project for adding collapsable sections to Dashboards. labels Nov 19, 2024
@Heenawter Heenawter self-assigned this Nov 19, 2024
@Heenawter Heenawter force-pushed the kbn-grid-layout_switch-to-props_2024-11-19 branch from 8ac8d36 to 53684fc Compare November 20, 2024 18:18
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I modified this example to more similarly match how the Dashboard integration will work by adding a mock dashboard API. We use the panels$ + rows$ behaviour subjects as our "source of truth" for the layout engine, so that we always stay in sync.

Comment on lines +132 to +134
const panelContents = useMemo(() => {
return renderPanelContents(panelId);
}, [panelId, renderPanelContents]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

By adding the layout prop, this was causing a chain reaction where renderPanelContents was being called whenever the layout changed - by memoizing this component, this removes that unnecessary re-render.

@Heenawter Heenawter marked this pull request as ready for review November 20, 2024 20:40
@Heenawter Heenawter requested a review from a team as a code owner November 20, 2024 20:40
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/grid-layout 25 16 -9

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
@kbn/grid-layout 2 1 -1
Unknown metric groups

API count

id before after diff
@kbn/grid-layout 27 16 -11

ESLint disabled line counts

id before after diff
@kbn/grid-layout 11 10 -1

Total ESLint disabled count

id before after diff
@kbn/grid-layout 11 10 -1

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! I agree that this will make dashboard integration easier.

code review and tested the examples.

@Heenawter Heenawter merged commit 5495322 into elastic:main Nov 21, 2024
23 checks passed
@Heenawter Heenawter deleted the kbn-grid-layout_switch-to-props_2024-11-19 branch November 21, 2024 17:27
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

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

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Nov 21, 2024
Closes elastic#200090

## Summary

This PR migrates the `GridLayout` component a more traditional React
design using **props** rather than providing an API. This change serves
two purposes:
1. It makes the eventual Dashboard migration easier, since it is more
similar to `react-grid-layout`'s implementation
3. It makes the `GridLayout` component less opinionated by moving the
logic for panel management (i.e. panel placement, etc) to the parent
component.

I tried to keep efficiency in mind for this comparison, and ensured that
we are still keeping the number of rerenders **o a minimum**. This PR
should not introduce **any** extra renders in comparison to the API
version.

### 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)

### Identify risks

There are no risks to this PR, since all work is contained in the
`examples` plugin.

---------

Co-authored-by: kibanamachine <[email protected]>
(cherry picked from commit 5495322)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Nov 21, 2024
#201253)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Dashboard] [Collapsable Panels] Switch to using props
(#200793)](#200793)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Hannah
Mudge","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-21T17:27:56Z","message":"[Dashboard]
[Collapsable Panels] Switch to using props (#200793)\n\nCloses
https://github.com/elastic/kibana/issues/200090\r\n\r\n##
Summary\r\n\r\nThis PR migrates the `GridLayout` component a more
traditional React\r\ndesign using **props** rather than providing an
API. This change serves\r\ntwo purposes:\r\n1. It makes the eventual
Dashboard migration easier, since it is more\r\nsimilar to
`react-grid-layout`'s implementation\r\n3. It makes the `GridLayout`
component less opinionated by moving the\r\nlogic for panel management
(i.e. panel placement, etc) to the parent\r\ncomponent.\r\n\r\nI tried
to keep efficiency in mind for this comparison, and ensured that\r\nwe
are still keeping the number of rerenders **o a minimum**. This
PR\r\nshould not introduce **any** extra renders in comparison to the
API\r\nversion.\r\n\r\n### Checklist\r\n\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###
Identify risks\r\n\r\nThere are no risks to this PR, since all work is
contained in the\r\n`examples`
plugin.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"549532240cd8bc271a78b74846021c9023e2da64","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Dashboard","Team:Presentation","loe:medium","release_note:skip","impact:high","v9.0.0","backport:prev-minor","Project:Collapsable
Panels"],"title":"[Dashboard] [Collapsable Panels] Switch to using
props","number":200793,"url":"https://github.com/elastic/kibana/pull/200793","mergeCommit":{"message":"[Dashboard]
[Collapsable Panels] Switch to using props (#200793)\n\nCloses
https://github.com/elastic/kibana/issues/200090\r\n\r\n##
Summary\r\n\r\nThis PR migrates the `GridLayout` component a more
traditional React\r\ndesign using **props** rather than providing an
API. This change serves\r\ntwo purposes:\r\n1. It makes the eventual
Dashboard migration easier, since it is more\r\nsimilar to
`react-grid-layout`'s implementation\r\n3. It makes the `GridLayout`
component less opinionated by moving the\r\nlogic for panel management
(i.e. panel placement, etc) to the parent\r\ncomponent.\r\n\r\nI tried
to keep efficiency in mind for this comparison, and ensured that\r\nwe
are still keeping the number of rerenders **o a minimum**. This
PR\r\nshould not introduce **any** extra renders in comparison to the
API\r\nversion.\r\n\r\n### Checklist\r\n\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###
Identify risks\r\n\r\nThere are no risks to this PR, since all work is
contained in the\r\n`examples`
plugin.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"549532240cd8bc271a78b74846021c9023e2da64"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200793","number":200793,"mergeCommit":{"message":"[Dashboard]
[Collapsable Panels] Switch to using props (#200793)\n\nCloses
https://github.com/elastic/kibana/issues/200090\r\n\r\n##
Summary\r\n\r\nThis PR migrates the `GridLayout` component a more
traditional React\r\ndesign using **props** rather than providing an
API. This change serves\r\ntwo purposes:\r\n1. It makes the eventual
Dashboard migration easier, since it is more\r\nsimilar to
`react-grid-layout`'s implementation\r\n3. It makes the `GridLayout`
component less opinionated by moving the\r\nlogic for panel management
(i.e. panel placement, etc) to the parent\r\ncomponent.\r\n\r\nI tried
to keep efficiency in mind for this comparison, and ensured that\r\nwe
are still keeping the number of rerenders **o a minimum**. This
PR\r\nshould not introduce **any** extra renders in comparison to the
API\r\nversion.\r\n\r\n### Checklist\r\n\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###
Identify risks\r\n\r\nThere are no risks to this PR, since all work is
contained in the\r\n`examples`
plugin.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"549532240cd8bc271a78b74846021c9023e2da64"}}]}]
BACKPORT-->

Co-authored-by: Hannah Mudge <[email protected]>
paulinashakirova pushed a commit to paulinashakirova/kibana that referenced this pull request Nov 26, 2024
Closes elastic#200090

## Summary

This PR migrates the `GridLayout` component a more traditional React
design using **props** rather than providing an API. This change serves
two purposes:
1. It makes the eventual Dashboard migration easier, since it is more
similar to `react-grid-layout`'s implementation
3. It makes the `GridLayout` component less opinionated by moving the
logic for panel management (i.e. panel placement, etc) to the parent
component.

I tried to keep efficiency in mind for this comparison, and ensured that
we are still keeping the number of rerenders **o a minimum**. This PR
should not introduce **any** extra renders in comparison to the API
version.

### 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)

### Identify risks

There are no risks to this PR, since all work is contained in the
`examples` plugin.

---------

Co-authored-by: kibanamachine <[email protected]>
Heenawter added a commit that referenced this pull request Nov 27, 2024
## Summary

When the `layout` prop updates, we cannot assume that it is "safe" (i.e.
we cannot assume it has no floating panels and/or colliding panels).
Because of this, we need to resolve each grid row when this prop
changes. When I added this in
#200793, I accidentally only
**compacted** the rows, which did not account for possible collisions
that the Dashboard's panel placement strategies do not account for. This
PR fixes that by calling `resolveGridRow` (which compacts **and**
detects collisions) instead of just `compactGridRow` (which, as the name
suggests, only compacts the rows)

**Before:**




https://github.com/user-attachments/assets/bcea4efd-35fa-425d-ac04-41434ffaa810


**After:**


https://github.com/user-attachments/assets/6cd205c6-d1d5-4a97-8d14-425c2a4bbeda



### 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)

### Identify risks

There are no risks to this PR, since all work is contained in the
`examples` plugin.
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Nov 27, 2024
…02049)

## Summary

When the `layout` prop updates, we cannot assume that it is "safe" (i.e.
we cannot assume it has no floating panels and/or colliding panels).
Because of this, we need to resolve each grid row when this prop
changes. When I added this in
elastic#200793, I accidentally only
**compacted** the rows, which did not account for possible collisions
that the Dashboard's panel placement strategies do not account for. This
PR fixes that by calling `resolveGridRow` (which compacts **and**
detects collisions) instead of just `compactGridRow` (which, as the name
suggests, only compacts the rows)

**Before:**

https://github.com/user-attachments/assets/bcea4efd-35fa-425d-ac04-41434ffaa810

**After:**

https://github.com/user-attachments/assets/6cd205c6-d1d5-4a97-8d14-425c2a4bbeda

### 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)

### Identify risks

There are no risks to this PR, since all work is contained in the
`examples` plugin.

(cherry picked from commit 57b8bda)
kibanamachine added a commit that referenced this pull request Nov 27, 2024
…pdate (#202049) (#202072)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Dashboard][Collapsable Panels] Fix bug on &#x60;layout&#x60; update
(#202049)](#202049)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Hannah
Mudge","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-27T21:12:15Z","message":"[Dashboard][Collapsable
Panels] Fix bug on `layout` update (#202049)\n\n## Summary\r\n\r\nWhen
the `layout` prop updates, we cannot assume that it is \"safe\"
(i.e.\r\nwe cannot assume it has no floating panels and/or colliding
panels).\r\nBecause of this, we need to resolve each grid row when this
prop\r\nchanges. When I added this
in\r\nhttps://github.com//pull/200793, I accidentally
only\r\n**compacted** the rows, which did not account for possible
collisions\r\nthat the Dashboard's panel placement strategies do not
account for. This\r\nPR fixes that by calling `resolveGridRow` (which
compacts **and**\r\ndetects collisions) instead of just `compactGridRow`
(which, as the name\r\nsuggests, only compacts the
rows)\r\n\r\n**Before:**\r\n\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/bcea4efd-35fa-425d-ac04-41434ffaa810\r\n\r\n\r\n**After:**\r\n\r\n\r\nhttps://github.com/user-attachments/assets/6cd205c6-d1d5-4a97-8d14-425c2a4bbeda\r\n\r\n\r\n\r\n###
Checklist\r\n\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###
Identify risks\r\n\r\nThere are no risks to this PR, since all work is
contained in the\r\n`examples`
plugin.","sha":"57b8bdad3fb64d26b8fe3b0bf12c071857fff9e2","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Dashboard","Team:Presentation","loe:small","release_note:skip","impact:high","v9.0.0","backport:prev-minor","Project:Collapsable
Panels"],"title":"[Dashboard][Collapsable Panels] Fix bug on `layout`
update","number":202049,"url":"https://github.com/elastic/kibana/pull/202049","mergeCommit":{"message":"[Dashboard][Collapsable
Panels] Fix bug on `layout` update (#202049)\n\n## Summary\r\n\r\nWhen
the `layout` prop updates, we cannot assume that it is \"safe\"
(i.e.\r\nwe cannot assume it has no floating panels and/or colliding
panels).\r\nBecause of this, we need to resolve each grid row when this
prop\r\nchanges. When I added this
in\r\nhttps://github.com//pull/200793, I accidentally
only\r\n**compacted** the rows, which did not account for possible
collisions\r\nthat the Dashboard's panel placement strategies do not
account for. This\r\nPR fixes that by calling `resolveGridRow` (which
compacts **and**\r\ndetects collisions) instead of just `compactGridRow`
(which, as the name\r\nsuggests, only compacts the
rows)\r\n\r\n**Before:**\r\n\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/bcea4efd-35fa-425d-ac04-41434ffaa810\r\n\r\n\r\n**After:**\r\n\r\n\r\nhttps://github.com/user-attachments/assets/6cd205c6-d1d5-4a97-8d14-425c2a4bbeda\r\n\r\n\r\n\r\n###
Checklist\r\n\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###
Identify risks\r\n\r\nThere are no risks to this PR, since all work is
contained in the\r\n`examples`
plugin.","sha":"57b8bdad3fb64d26b8fe3b0bf12c071857fff9e2"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/202049","number":202049,"mergeCommit":{"message":"[Dashboard][Collapsable
Panels] Fix bug on `layout` update (#202049)\n\n## Summary\r\n\r\nWhen
the `layout` prop updates, we cannot assume that it is \"safe\"
(i.e.\r\nwe cannot assume it has no floating panels and/or colliding
panels).\r\nBecause of this, we need to resolve each grid row when this
prop\r\nchanges. When I added this
in\r\nhttps://github.com//pull/200793, I accidentally
only\r\n**compacted** the rows, which did not account for possible
collisions\r\nthat the Dashboard's panel placement strategies do not
account for. This\r\nPR fixes that by calling `resolveGridRow` (which
compacts **and**\r\ndetects collisions) instead of just `compactGridRow`
(which, as the name\r\nsuggests, only compacts the
rows)\r\n\r\n**Before:**\r\n\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/bcea4efd-35fa-425d-ac04-41434ffaa810\r\n\r\n\r\n**After:**\r\n\r\n\r\nhttps://github.com/user-attachments/assets/6cd205c6-d1d5-4a97-8d14-425c2a4bbeda\r\n\r\n\r\n\r\n###
Checklist\r\n\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###
Identify risks\r\n\r\nThere are no risks to this PR, since all work is
contained in the\r\n`examples`
plugin.","sha":"57b8bdad3fb64d26b8fe3b0bf12c071857fff9e2"}}]}]
BACKPORT-->

Co-authored-by: Hannah Mudge <[email protected]>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
Closes elastic#200090

## Summary

This PR migrates the `GridLayout` component a more traditional React
design using **props** rather than providing an API. This change serves
two purposes:
1. It makes the eventual Dashboard migration easier, since it is more
similar to `react-grid-layout`'s implementation
3. It makes the `GridLayout` component less opinionated by moving the
logic for panel management (i.e. panel placement, etc) to the parent
component.

I tried to keep efficiency in mind for this comparison, and ensured that
we are still keeping the number of rerenders **o a minimum**. This PR
should not introduce **any** extra renders in comparison to the API
version.

### 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)

### Identify risks

There are no risks to this PR, since all work is contained in the
`examples` plugin.

---------

Co-authored-by: kibanamachine <[email protected]>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
…02049)

## Summary

When the `layout` prop updates, we cannot assume that it is "safe" (i.e.
we cannot assume it has no floating panels and/or colliding panels).
Because of this, we need to resolve each grid row when this prop
changes. When I added this in
elastic#200793, I accidentally only
**compacted** the rows, which did not account for possible collisions
that the Dashboard's panel placement strategies do not account for. This
PR fixes that by calling `resolveGridRow` (which compacts **and**
detects collisions) instead of just `compactGridRow` (which, as the name
suggests, only compacts the rows)

**Before:**




https://github.com/user-attachments/assets/bcea4efd-35fa-425d-ac04-41434ffaa810


**After:**


https://github.com/user-attachments/assets/6cd205c6-d1d5-4a97-8d14-425c2a4bbeda



### 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)

### Identify risks

There are no risks to this PR, since all work is contained in the
`examples` plugin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Feature:Dashboard Dashboard related features impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. loe:medium Medium 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 v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Dashboard][Collapsable Panels] Remove API in favour of props
5 participants