-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Add option to clear action logger #3459
Conversation
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. |
Please use this option in |
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Something like this, @Hypnosphi? |
}) | ||
.add('Clearing the action logger', () => ( | ||
<div> | ||
<p>Moving away from this story will clear the action logger</p> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Sorry I'm late to the conversation but isn't there an overall Storybook configuration that this could go in? |
@merlinpatt So far, not really. Each addon exposes its own configuration function when needed |
addons/actions/README.md
Outdated
@@ -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`| |
There was a problem hiding this comment.
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"
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 |
@merlinpatt check out this on
Based on the other comments, I will be changing the default behaviour to this |
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 |
That's OK, you're kinda saying "I want logs of this story to be persisted" |
There was a problem hiding this 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.
I think this one should be emitted by core (and imported from there) @rhalff thanks for noticing that |
Currently there is an 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) => ....) |
Thank you @rhalff, I will look into the |
Like this @rhalff? |
Added it, thanks for the info @rhalff. |
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 thestorybook/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.