PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9006 Co-authored-by: Nicolas Inchauspe <710410+nicoinch@users.noreply.github.com> Co-authored-by: Brandon Simmons <210815+jberryman@users.noreply.github.com> Co-authored-by: Daniele Cammareri <5709409+dancamma@users.noreply.github.com> Co-authored-by: Daniel Harvey <4729125+danieljharvey@users.noreply.github.com> Co-authored-by: Rishichandra Wawhal <27274869+wawhal@users.noreply.github.com> Co-authored-by: Samir Talwar <47582+SamirTalwar@users.noreply.github.com> Co-authored-by: Anon Ray <616387+ecthiender@users.noreply.github.com> Co-authored-by: Tom Harding <6302310+i-am-tom@users.noreply.github.com> Co-authored-by: Gil Mizrahi <8547573+soupi@users.noreply.github.com> Co-authored-by: John Kiragu <11444316+kigsmtua@users.noreply.github.com> Co-authored-by: Matthew Goodwin <49927862+m4ttheweric@users.noreply.github.com> Co-authored-by: Divi <32202683+imperfect-fourth@users.noreply.github.com> Co-authored-by: paritosh-08 <85472423+paritosh-08@users.noreply.github.com> Co-authored-by: Aaysha <109507451+aayshasura@users.noreply.github.com> Co-authored-by: Vijay Prasanna <11921040+vijayprasanna13@users.noreply.github.com> Co-authored-by: Erik Magnusson <32518962+ejkkan@users.noreply.github.com> GitOrigin-RevId: fe4953db62326fb3a8de118f8bba2add9bb9c2c2
1.9 KiB
nx-storybook-addon-console-env
This library contains a Storybook addon allowing
to modify some Hasura console env variables (window.__env
), the addon uses
Storybook global variables
under the hood to modify and inject console variables.
What is it for?
Addon
This addon adds a Console env tab in Storybook addons tabs.
It displays and allows to modify some console env vars (for now isAdminSet
and consoleType
) and reloads stories to emulate each type of console or login status.
Stories parameter
It is possible to add parameters to stories (for now isAdminSet
and consoleType
) to force those
variables, otherwise, default variables values are used.
How it works
Some console env vars (for now isAdminSet
and consoleType
) are stored as Storybook globals variables
and are displayed/modified thanks to this addon.
When a console env global variables is updated (through a user interaction in the UI or a story parameter):
- the URL search parameters are updates with the global variables values,
- a reload of the iFrame containing the story is triggered.
A script in preview-body.html
will extract the variables from the URL and build the proper
window.__env
object, then console globals are correctly initialized.
Setup
To manipulate console env variables from Storybook UI, you need to:
- install the addon,
Install addon
Add reference to addon in your .storybook/main.ts
file.
const config: StorybookConfig = {
...
addons: [
...
'storybook-addon-console-env',
...
],
...
};
export default config;
Testing
This addon is tested thanks to Chromatic snapshots. No interaction test has been implemented yet, as the play function cannot interact with addons control.