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

Add option to clear action logger #3459

Merged
merged 9 commits into from
Apr 23, 2018

Conversation

Keraito
Copy link
Contributor

@Keraito Keraito commented Apr 20, 2018

Issue: Currently, the action loggers stacks up all the events without limit and across all stories. There is already a PR (#3447) open for a limiting option. In the same way, this introduces an optional feature that will clear the action logger when switching away from a story. (Fixes #3443)

What I did

Added a clearActionLogger option to the actions addon that clears the action logger when switching away from a story. It uses the storybook/stories/story-event event for detecting a switch in story.

How to test

I updated the configureAction unit test and the documentation on action options.

@Keraito
Copy link
Contributor Author

Keraito commented Apr 20, 2018

In the corresponding issue @merlinpatt mentioned that he would be willing to do this. I just decided to start working on it and proposed my current progress. If he wants to take over or maybe work together I dont mind.

@Hypnosphi
Copy link
Member

Please use this option in examples/storybook-official

@codecov
Copy link

codecov bot commented Apr 20, 2018

Codecov Report

Merging #3459 into master will decrease coverage by <.01%.
The diff coverage is 12.5%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3459      +/-   ##
==========================================
- Coverage   37.14%   37.13%   -0.01%     
==========================================
  Files         465      465              
  Lines       10320    10328       +8     
  Branches      924      949      +25     
==========================================
+ Hits         3833     3835       +2     
+ Misses       5933     5906      -27     
- Partials      554      587      +33
Impacted Files Coverage Δ
...ddons/actions/src/containers/ActionLogger/index.js 0% <0%> (ø) ⬆️
addons/actions/src/manager.js 0% <0%> (ø) ⬆️
addons/actions/src/preview/action.js 77.41% <100%> (+0.75%) ⬆️
addons/actions/src/preview/configureActions.js 100% <100%> (ø) ⬆️
lib/cli/lib/has_yarn.js 0% <0%> (ø) ⬆️
addons/storysource/src/loader/parse-helpers.js 46.75% <0%> (ø) ⬆️
addons/events/src/components/Event.js 0% <0%> (ø) ⬆️
addons/info/src/components/types/proptypes.js 88.88% <0%> (ø) ⬆️
addons/knobs/src/components/types/Button.js 11.9% <0%> (ø) ⬆️
... and 79 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 34e8e29...36ff731. Read the comment docs.

@Keraito
Copy link
Contributor Author

Keraito commented Apr 21, 2018

Something like this, @Hypnosphi?

})
.add('Clearing the action logger', () => (
<div>
<p>Moving away from this story will clear the action logger</p>
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be more natural if it worked the other way around, and logger would be cleared when opening this story. Can we do this?

Copy link
Member

@ndelangen ndelangen Apr 21, 2018

Choose a reason for hiding this comment

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

I think a natural way for this to work would indeed be:

When the user navigates between stories, it's cleared by default,
unless a user opts to have the log be persisted.

Copy link
Contributor Author

@Keraito Keraito Apr 21, 2018

Choose a reason for hiding this comment

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

I at first tried to do it the way @Hypnosphi described it, but it's slightly more difficult that way because the options are part of the actions and not the stories themselves. The way @ndelangen sounds more natural and should be of less complexity, so I will try my hands on that.

@merlinstardust
Copy link

Sorry I'm late to the conversation but isn't there an overall Storybook configuration that this could go in?

@Hypnosphi
Copy link
Member

@merlinpatt So far, not really. Each addon exposes its own configuration function when needed

@@ -102,3 +102,4 @@ action('my-action', {
|Name|Type|Description|Default|
|---|---|---|---|
|`depth`|Number|Configures the transfered depth of any logged objects.|`10`|
|`clearActionLogger`|Boolean|Flag whether to clear the action logger when switching away from the current story.|`false`|
Copy link
Member

Choose a reason for hiding this comment

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

I would call it "clearOnStoryChange"

@merlinstardust
Copy link

Oh right, I forgot because the action logger is part of the default Storybook setup.

Does the action logger have some sort of top level configuration?

While I see the value in having a user decide to clear it per story, I also find it likely that users would want to clear it on every story change. And that would be frustrating to have to add an option to every single story

@Keraito
Copy link
Contributor Author

Keraito commented Apr 22, 2018

Does the action logger have some sort of top level configuration?

@merlinpatt check out this on configureActions, I think that's what you're looking for.

I also find it likely that users would want to clear it on every story change

Based on the other comments, I will be changing the default behaviour to this

@Keraito
Copy link
Contributor Author

Keraito commented Apr 22, 2018

I processed both feedback of #3459 (comment) and #3459 (comment).

Behaviour wise, actions are still only persisted when switching away from a story. While changing the default to true gets rid of the counter-inituitive behaviour described in #3459 (comment), I didn't see a way yet to make this happen on entry.

@Hypnosphi
Copy link
Member

actions are still only persisted when switching away from a story

That's OK, you're kinda saying "I want logs of this story to be persisted"

Copy link
Contributor

@rhalff rhalff left a comment

Choose a reason for hiding this comment

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

The event id the story change listener depends on (storybook/stories/story-event) seems to be triggered by the storysource addon: https://github.com/storybooks/storybook/blob/master/addons/storysource/src/index.js#L1-L3

Unless the storybook api is changed in the near future anyway, I wouldn't rely on this particular event.

Otherwise at least import the event id as import { EVENT_ID } from '@storybook/addon-storysource so it's clear where the event originates from.

@Hypnosphi
Copy link
Member

Hypnosphi commented Apr 22, 2018

I think this one should be emitted by core (and imported from there)

@rhalff thanks for noticing that

@rhalff
Copy link
Contributor

rhalff commented Apr 22, 2018

Currently there is an onStory() method defined on the api which could be used, it is passed in during register of the addon.

Usage of it is a bit awkward though, e.g.:

export function register() {
  addons.register(ADDON_ID, (api) => {
    const channel = addons.getChannel();
    
    addons.addPanel(PANEL_ID, {
      title: 'Action Logger',
      render: () => <ActionLogger channel={channel} api={api} />,
    });
  });
}

// do something with api.onStory in the ActionLogger
api.onStory((kind, story) => ....)

@Keraito
Copy link
Contributor Author

Keraito commented Apr 22, 2018

Thank you @rhalff, I will look into the onStory method and propose changes accordingly

@Keraito
Copy link
Contributor Author

Keraito commented Apr 23, 2018

Like this @rhalff?

@Keraito
Copy link
Contributor Author

Keraito commented Apr 23, 2018

Added it, thanks for the info @rhalff.

@Hypnosphi Hypnosphi merged commit a735eeb into storybookjs:master Apr 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants