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

[Canvas][PoC] Add Redux Inspector to Storybook; standardize names and convert a few stories #69357

Closed

Conversation

clintandrewhall
Copy link
Contributor

@clintandrewhall clintandrewhall commented Jun 17, 2020

This branch may need to be split up...?

Summary

This PR is a proof-of-concept that would allow components to be connected to a mock workpad store.

Screen Shot 2020-07-17 at 7 05 45 PM

Screen Shot 2020-07-17 at 7 06 21 PM

There are a lot of parts to this PR:

Moving Storybook from .storybook to storybook

There are a lot of gotchas around typing and using eslint in a directory that begins in a .. It's been a constant pain, so I renamed the directory.

Custom Storybook Addon for Redux Actions

I wrote a custom addon for Storybook that not only provides a store to any redux component, but also patches the dispatch function to output the result of the action.

As a result, we can test our components as if they were in Canvas, and also see the results of any action.

Caveat: some of our reducers use Kibana or other services, and these blow up eventually. This is being mitigated by a project @crob611 is working on.

Applying a new component file structure for Redux components

I'm proposing a new structure for our components that is demonstrated here with asset, asset_manager and workpad_config:

- components
  - foo                       <- directory
    - index.ts                <- thin exporting index, (no redux)
    - foo.ts                  <- redux container
    - foo.component.tsx       <- react component
  - bar
    - index.ts
    - bar.ts
    - bar.component.tsx
    - bar_dep.ts              <- redux sub container
    - bar_dep.component.tsx   <- sub component

The exporting file would be:

export { Foo } from './foo';
export { Foo as FooComponent } from './foo.component';

Gotchas

  • Some of our reducers rely on Kibana services to function. They blow up eventually, but still work.
  • I'm concerned about storyshots choking under the weight of larger components, so I'm excluding stories named 'redux' from that test.
  • This is beyond what kbn-storybook provides, and would require us to stay with our config, rather than migrate.

@clintandrewhall clintandrewhall added review discuss Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas loe:small Small Level of Effort v8.0.0 release_note:skip Skip the PR/issue when compiling release notes impact:medium Addressing this issue will have a medium level of impact on the quality/strength of our product. v7.9.0 labels Jun 17, 2020
@clintandrewhall clintandrewhall requested a review from a team as a code owner June 17, 2020 04:34
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-canvas (Team:Canvas)

@clintandrewhall clintandrewhall changed the title [Canvas] Fix Storybook + Add Redux [Canvas][PoC] Fix Storybook + Add Redux Jun 17, 2020
@poffdeluxe
Copy link
Contributor

This is pretty rad overall!

Are there ways for us to manipulate the redux state from the test file? The ability to modify the state directly from the storybook page is pretty cool

I think I'm a little hesitant to go this direction though if it means we have to continue to maintain two separate storybook test groups (ours and the kbn-storybook stuff). Are any other teams running into these types of redux issues with their storybook tests? Is this something we could get buy-in to pull into kbn-storybook?

@clintandrewhall
Copy link
Contributor Author

@elasticmachine merge upstream

@clintandrewhall
Copy link
Contributor Author

@streamich Could you please help me get these changes/abilities integrated into kbn-storybook so we can migrate Canvas?

@clintandrewhall
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@crob611 crob611 left a comment

Choose a reason for hiding this comment

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

Looks good. Left a few comments that might be for discussion outside this PR

},
};

const reducers = combineReducers({
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this store used by Storybook even need all of the reducers and middleware, etc? Or should it just be used to provide state to components that need it?

* you may not use this file except in compliance with the Elastic License.
*/

import React, { FC } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer FunctionComponent vs FC but I ain't going to fight about it or anything. But, we should reach an agreement on one and stick to that. Maybe add a lint rule to force us to one or the other.

@clintandrewhall
Copy link
Contributor Author

@elasticmachine merge upstream

@clintandrewhall clintandrewhall requested a review from a team as a code owner July 17, 2020 21:58
@clintandrewhall
Copy link
Contributor Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

merge conflict between base and head

@clintandrewhall clintandrewhall changed the title [Canvas][PoC] Fix Storybook + Add Redux [Canvas][PoC] Add Redux Inspector to Storybook; standardize names and convert a few stories Jul 17, 2020
Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

Operations: tweak to precommit config LGTM

@kibanamachine
Copy link
Contributor

💔 Build Failed

Failed CI Steps

Build metrics

async chunks size

id value diff baseline
canvas 1.5MB +403.0B 1.5MB

page load bundle size

id value diff baseline
canvas 1.4MB +153.0B 1.4MB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@clintandrewhall
Copy link
Contributor Author

I'm going to split this PR up into better chunks. There's too much churn and too much to review at once. I'll be referring to this PR and branch moving forward, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss impact:medium Addressing this issue will have a medium level of impact on the quality/strength of our product. loe:small Small Level of Effort release_note:skip Skip the PR/issue when compiling release notes review Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants