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

[Portable Dashboards] Prepare Redux Embeddable System for Dashboard #133681

Closed
ThomThomson opened this issue Jun 6, 2022 · 2 comments · Fixed by #136572
Closed

[Portable Dashboards] Prepare Redux Embeddable System for Dashboard #133681

ThomThomson opened this issue Jun 6, 2022 · 2 comments · Fixed by #136572
Labels
enhancement New value added to drive a business result Feature:Dashboard Dashboard related features Feature:Input Control Input controls visualization impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. loe:x-large Extra Large Level of Effort Project:Portable Dashboard Related to the Portable Dashboards initiative Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas

Comments

@ThomThomson
Copy link
Contributor

ThomThomson commented Jun 6, 2022

Part of #133677

Redux Embeddables System

In the Controls project, a new system was added to allow Embeddables to easily use redux toolkit to better manage their state. This creates an easily understandable communication layer between the Embeddable class and the inner react components via the redux store and a context.

This system is quite robust and is used for all of the control embeddables. That said it has a few drawbacks which can be easily addressed before using it for state management of the Dashboard Container.

What needs to change?

Single Redux Store

The original redux embeddable system uses a single redux store with reducers being dynamically added and removed on embeddable creation / deletion. This works well, but the selector is used to narrow down the embeddable by ID to fetch only appropriate state which means the selector cannot be used for its intended purpose, narrowing down state changes which require a re-render.

This should be fixed by changing the wrapper to create a new store for each embeddable it is used with, and destroy the store when the embeddable is destroyed. This will allow the selector to be used correctly.

Only for input

The original redux embeddable system was only used to track embeddable input, which meant that anything which was placed in the redux store was also persisted into the saved object. This necessitated another system for interaction between the embeddable and the react components because not all state should be persisted.

This should be fixed by making the redux store universal for any type of state that an embeddable could need. These three levels of state are as follows:

  1. Embeddable Input is all state which should be persisted to re-create the embeddable as it is.
  2. Embeddable Output is all state which is created by an embeddable to communicate with outside code.
  3. Embeddable State is ephemeral state which needs to be tracked, but should be lost on page changes.

Only for use with React Components

The original redux embeddable system was created as a react wrapper which was in charge of creating the store, injecting the reducers, and tracking all state for the components underneath. This allowed for communication between the embeddable class and the react components underneath. In the embeddable class, state would be updated via the embeddable's updateInput method, which is the same way external code would update it. Inside the Embeddable's react component, state changes would be dispatched via redux.

The system picked up all changes in both types of state and kept them in sync. This works great from a user point of view.

The problem with this is: From a DX point of view, embeddable state should be managed in the same way regardless of where it is changed from.

To fix this, the redux embeddable system should be changed so that it can be created by an initial method, and synced by a react component / wrapper. This way, the embeddable class can also use the dispatch methods and the reducers to influence its own state.

Other Considerations

Because this Redux Embeddable system underpins the Controls project as well, some light structural changes should be expected there as well. These changes will involve removing some extraneous state sync systems, and aligning all of the controls state with the new version of the Redux Embeddables system.

@ThomThomson ThomThomson added Feature:Dashboard Dashboard related features Feature:Input Control Input controls visualization enhancement New value added to drive a business result Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas loe:x-large Extra Large Level of Effort impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. Project:Portable Dashboard Related to the Portable Dashboards initiative labels Jun 6, 2022
@elasticmachine
Copy link
Contributor

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

@ThomThomson
Copy link
Contributor Author

Proposed Architecture:
Screen Shot 2022-07-08 at 3 04 14 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New value added to drive a business result Feature:Dashboard Dashboard related features Feature:Input Control Input controls visualization impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. loe:x-large Extra Large Level of Effort Project:Portable Dashboard Related to the Portable Dashboards initiative Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants