Skip to content

Commit 83ceac1

Browse files
authored
chore: update storybook and stories (#2007)
* chore(deps): update storybook/x * chore: migrate addons to .storybook/main.js * chore: migrate storybook config to .storybook/main.js * chore(deps): fix storybook postCSS * chore(deps): migrate static-dir flag to main.js @see https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated---static-dir-cli-flag * chore: ignore storybook-static/ * chore(deps): use storybook-CRA dep This addresses the following warning when running `npm run storybook`: WARN Storybook support for Create React App is now a separate preset. WARN To use the new preset, install `@storybook/preset-create-react-app` and add it to the list of `addons` in your `.storybook/main.js` config file. WARN The built-in preset has been disabled in Storybook 6.0. * chore(deps): use webpack5 with storybook @see https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#webpack-5 * fix: storybook webpack errors Resolves the following error: Error: NormalModuleFactory.beforeResolve (IgnorePlugin) is no longer a waterfall hook, but a bailing hook instead. Do not return the passed object, but modify it instead. Returning false will ignore the request and results in no module created. * fix: npm run storybook succeeds but displays error in built website * fix: Support CSFv3 storybook components @see https://storybook.js.org/docs/react/api/csf * chore: update Cid.stories.js * fix: default storybook argTypes * chore: update JsonEditor.stories.js * chore: update AddFilesInfo.stories.js * fix: Cid.stories.js * chore: update info-boxes/**/*.stories.js * update: breadcrumbs.stories.js * chore: run storiesOf migration script * Ran `git ls-files | grep 'stories.js' | xargs -n1 -- npx --yes sb migrate storiesof-to-csf --glob` * Normalized default stories exports * Added jsdoc comment for default exports * export default as object literal * chore: add jsdoc for story exports * chore: update eslint rules * disable default export rule for stories * enable react/prop-types validation warning * feat: Migrate FilesList.stories * chore: update .storybook/main.js * fix: mark PinningModal file prop as required * feat: Finish migrating PinningModal story * fix: remove countly.init error for storybook * feat: Migrate remaining storybook stories * fix: npm install and build * fix: eslint should pass CI * chore: fix typecheck failures * fix: run @storybook/cli migrate storiesof-to-csf Migrated leftover storiesOf stories with: `npx @storybook/cli migrate storiesof-to-csf -g '**/(Radio|PublishModal).stories.js'` * fix: run eslint --fix * fix: build-storybook warnings & errors * fix: PublishModal.stories.js renders properly * feat: add test-storybook to CI * chore: add test-storybook.yml
1 parent 3d04988 commit 83ceac1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+82741
-65050
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!.storybook

.eslintrc.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,19 @@ module.exports = {
77
}
88
},
99
extends: ['react-app', 'standard', 'plugin:jsx-a11y/recommended'],
10-
plugins: ['jsx-a11y'],
10+
plugins: ['jsx-a11y', 'storybook'],
1111
// ignore .ts files because it fails to parse it.
12-
ignorePatterns: 'src/**/*.ts'
12+
ignorePatterns: 'src/**/*.ts',
13+
rules: {
14+
'react/prop-types': [0, { ignore: ['className'], customValidators: [], skipUndeclared: true }] // TODO: set this rule to error when all issues are resolved.
15+
},
16+
overrides: [
17+
{
18+
files: ['src/**/*.stories.js'],
19+
excludedFiles: '*.test.js',
20+
rules: {
21+
'import/no-anonymous-default-export': 'off'
22+
}
23+
}
24+
]
1325
}

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ jobs:
152152
needs: build
153153
uses: ./.github/workflows/test-e2e.yml
154154

155+
test-storybook:
156+
name: 'test:e2e'
157+
uses: ./.github/workflows/test-storybook.yml
158+
155159
# separate check for TS
156160
typecheck:
157161
name: typecheck
@@ -171,7 +175,7 @@ jobs:
171175
release:
172176
name: 'Run semantic release'
173177
runs-on: ubuntu-latest
174-
needs: [build, publishPreview, eslint, typecheck, test-e2e, test-unit]
178+
needs: [build, publishPreview, eslint, typecheck, test-e2e, test-unit, test-storybook]
175179
steps:
176180
- name: Checkout 🛎️
177181
uses: actions/checkout@v2
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
on:
2+
workflow_call:
3+
4+
jobs:
5+
6+
test-storybook:
7+
name: 'test:storybook'
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- name: Setup node
13+
uses: actions/setup-node@v3
14+
with:
15+
node-version: 16.12.0
16+
- name: Setup npm@8.1.0
17+
run: |
18+
npm install -g npm@8.1.0
19+
20+
- name: Cache bigger downloads
21+
uses: actions/cache@v2
22+
id: cache
23+
with:
24+
path: ${{ github.workspace }}/.cache
25+
key: ${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
26+
restore-keys: |
27+
${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
28+
${{ runner.os }}-
29+
30+
- name: Install dependencies
31+
run: npm ci --prefer-offline --no-audit --progress=false --cache ${{ github.workspace }}/.cache/npm
32+
33+
- name: Run test-storybook:ci
34+
run: npm run test-storybook:ci

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/playwright-report
99
test/e2e/setup/ipfs-backend.json
1010
test/e2e/state.json
11+
storybook-static
1112

1213
# production
1314
/build

.storybook/addons.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

.storybook/config.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

.storybook/main.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @file StoryBook configuration file
3+
* @see https://github.com/storybookjs/storybook/blob/master/MIGRATION.md#from-version-52x-to-53x
4+
*/
5+
6+
const webpack = require('webpack')
7+
8+
const webpackOverride = require('../config-overrides')
9+
10+
/** @type {import('@storybook/core-common').StorybookConfig} */
11+
const storybookConfig = {
12+
core: {
13+
builder: 'webpack5'
14+
},
15+
reactOptions: {
16+
legacyRootApi: true
17+
},
18+
stories: [
19+
'../src/**/*.stories.@(ts|js|tsx|jsx)'
20+
],
21+
framework: '@storybook/react',
22+
addons: [
23+
'@storybook/addon-essentials',
24+
'@storybook/addon-actions',
25+
'@storybook/addon-links',
26+
'@storybook/addon-a11y',
27+
// '@storybook/addon-knobs',
28+
'@storybook/addon-controls',
29+
// '@storybook/addon-postcss',
30+
'@storybook/preset-create-react-app',
31+
'@storybook/addon-coverage'
32+
],
33+
staticDirs: [
34+
'../public'
35+
],
36+
features: {
37+
postcss: false,
38+
storyStoreV7: true
39+
},
40+
webpackFinal: async (config) => {
41+
return webpackOverride({
42+
...config,
43+
// @see https://github.com/storybookjs/storybook/issues/18276#issuecomment-1137101774
44+
plugins: config.plugins.map(plugin => {
45+
if (plugin.constructor.name === 'IgnorePlugin') {
46+
return new webpack.IgnorePlugin({
47+
resourceRegExp: plugin.options.resourceRegExp,
48+
contextRegExp: plugin.options.contextRegExp
49+
})
50+
}
51+
52+
return plugin
53+
})
54+
})
55+
}
56+
}
57+
58+
module.exports = storybookConfig

.storybook/preview.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Provider } from 'redux-bundler-react'
2+
import { I18nextProvider } from 'react-i18next'
3+
import { DndProvider } from 'react-dnd'
4+
import 'react-virtualized/styles.css'
5+
import '../src/index.css'
6+
7+
import getStore from '../src/bundles'
8+
import i18n from '../src/i18n'
9+
import DndBackend from '../src/lib/dnd-backend'
10+
11+
/**
12+
* @type {import('@storybook/addons').BaseAnnotations}
13+
*/
14+
const baseAnnotations = {
15+
decorators: [
16+
(Story) => (
17+
<Provider store={getStore(undefined)}>
18+
<I18nextProvider i18n={i18n} >
19+
<DndProvider backend={DndBackend}>
20+
<Story />
21+
</DndProvider>
22+
</I18nextProvider>
23+
</Provider>
24+
)
25+
],
26+
/**
27+
* @see https://storybook.js.org/docs/react/essentials/actions#automatically-matching-args
28+
*/
29+
argTypes: {
30+
onChange: {
31+
action: 'changed'
32+
},
33+
onClick: {
34+
action: 'clicked'
35+
}
36+
}
37+
}
38+
39+
export const decorators = baseAnnotations.decorators
40+
export const argTypes = baseAnnotations.argTypes

0 commit comments

Comments
 (0)