[COMPASS-4935] Make plugin stores have initial states when rendering with StoreConnector Created: 08/Jul/21  Updated: 10/Jan/24  Resolved: 07/Mar/22

Status: Closed
Project: Compass
Component/s: Tech debt
Affects Version/s: None
Fix Version/s: No version

Type: Task Priority: Major - P3
Reporter: Rhys Howell Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes: Not Needed

 Description   

A few plugins (`compass-connect`, `compass-collection-stats`, etc) have their stores set up as reflux store with react state mixins. These stores are connected to the plugins using a `StoreConnector` component in `hadron-react-components`.
When these components/plugins are initially mounted, currently react prop validation isn't receiving the proper initial state, so all of their props are invalid. As a result, all of these plugins have their top level props not marked as `required`. This is something that would be good to fix, so that we can know if a prop is actually not present and possibly indicating a bug.
There's a few things we could do to fix this:

  • Update the `reflux-state-mixin` package we use for helping reflux/react work nicely together to initialize or call `getInitialState` and setting the state before mounting the component.
  • Update the `StoreConnector` in `hadron-react-components` to avoid mounting components until the store has its initial state.
  • Remove reflux and reflux-state-mixin and use redux everywhere (lots of work but ideal end result).

This ticket involves making it so that we can make top level props in plugins required and receive errors/warnings when things aren't as expected.

Reference:
Store connector in `hadron-react-components`: https://github.com/mongodb-js/compass/blob/main/packages/hadron-react-components/src/store-connector.jsx
Example `compass-collection-stats` store which exhibits this behavior: https://github.com/mongodb-js/compass/blob/main/packages/compass-collection-stats/src/stores/store.js#L92



 Comments   
Comment by Rhys Howell [ 07/Mar/22 ]

This will go away with other work - compass-connect for instance has been replaced - closing this since we won't do it directly.

Generated at Wed Feb 07 22:37:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.