-
Notifications
You must be signed in to change notification settings - Fork 8.5k
📕 Storybook for everyone (take 2) #43529
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
Merged
Merged
Changes from all commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
28971f3
chore: 🤖 add Infra sample Storybook story
streamich 666871c
chore: 🤖 add @kbn/storybook package
streamich d783b52
chore: 🤖 add sample SIEM stories
streamich a1ed9f4
chore: 🤖 add Canvas new Storybook config
streamich 2a83b27
fix: 🐛 fix TypeScript errors
streamich f49b9a6
chore: 🤖 add @kbn/babel-preset to package.json
streamich 4585e82
chore: 🤖 move dependencies to devDependencies
streamich 1a357ec
chore: 🤖 catch up with master
streamich 5484761
chore: 🤖 make Storybook dependencies non-dev
streamich e800762
chore: 🤖 catch-up with master
streamich b4b587f
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich a4f797f
chore: 🤖 upgrade Storybook dependencies
streamich 6482901
chore: 🤖 add packages to webpack
streamich e932374
fix: 🐛 fix TypeScript type check
streamich 2d03884
chore: 🤖 catch-up with master
streamich f2a89f5
chore: 🤖 disable ESLint warnings
streamich cae01fa
chore: 🤖 remove Storybook info plugin
streamich 28e3c2b
chore: 🤖 upate yarn.lock
streamich cc31878
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich 90da44b
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich 89a8086
chore: 🤖 add Storbook to Embeddables
streamich a29a447
Merge branch 'master' into storybook-2
streamich 35e143d
feat: 🎸 add --clean flag to Storybook CLI
streamich f72dd98
Merge branch 'master' of github.com:elastic/kibana into pr/43529
97d8ff9
coalesce yarn.lock versions
49b07cd
update kbn/pm dist
ec78413
This reverts commit 97d8ff9f53c627589838b2558044de58753b4347 and 49b0…
ba94dde
chore: 🤖 use fs instead of mkdirp
streamich 1d70621
chore: 🤖 use debug for message logging
streamich a2245f5
chore: 🤖 catch up with master
streamich 25bb279
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich 8ce3f9d
chore: 🤖 update yarn.lock
streamich 8d41985
feat: 🎸 add link to kbn-storybook package
streamich 710c9f9
docs: ✏️ add Storybook readme
streamich c6981f0
chore: 🤖 remove packages that failed DLL build
streamich 401572c
style: 💄 add ESLint comma
streamich 80f9be0
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich fd96192
chore: 🤖 apply changes from #52209
streamich 463b579
fix: 🐛 make Canvas Storybook build again
streamich 3f4f7f4
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich b9fab20
chore: 🤖 move Canvas stories to global Storybook
streamich 732020e
chore: 🤖 move more Canvas components to global Storybook
streamich f68166c
chore: 🤖 move more Canvas stories to global Storybook
streamich 16412b2
chore: 🤖 move <ItemGrid> and <KeyboardShortcutsDoc> to NP SB
streamich 2dfc316
chore: 🤖 move shape picker Canvas stories to global Storybook
streamich ad3bc8b
chore: 🤖 move Canvas sidebar stories to global Storybook
streamich e4878a7
fix: 🐛 split imports to not import path.resolve in Storybook
streamich 1955060
chore: 🤖 move tag and PDF panel Canvas stories to global SB
streamich 99cbe6d
chore: 🤖 move Canvas share website flyout stories to global SB
streamich d6a4747
fix: 🐛 clean up <ShareWebsiteFlyout> imports
streamich 6f363a4
chore: 🤖 add back Canvas withInfo decorator
streamich 714e95c
chore: 🤖 look for Canvas stories everywhere in /canvas folder
streamich 8d1e2db
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich 0f0a91d
test: 💍 mock correct files in Storyshots
streamich f5ff62f
test: 💍 update Canvas Storyshot snapshots
streamich b64a662
chore: 🤖 move more Canvas components to global Storybook
streamich d8fc07a
chore: 🤖 move more Canvas components to global Storybook
streamich ed9aec7
test: 💍 update Canvas Storyshots
streamich 5eb4c38
Merge branch 'master' into storybook-2
elasticmachine 87323f9
chore: 🤖 rebuild @kbn/pm
streamich a2ea8bb
chore: 🤖 catch up with master
streamich b609cbb
chore: 🤖 refresh @kbn/pm dist/index.js artifact
streamich 8fb92a1
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich 0f78d5f
chore: 🤖 catch up with master
streamich e41d520
chore: 🤖 update yarn.lock
streamich 5386be1
chore: 🤖 update @kbn/pm artifact
streamich 1b2d995
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich eef1fc0
feat: 🎸 address review comments
streamich 4cc67d7
fix: 🐛 remove circular import
streamich c773ec2
chore: 🤖 catch up with master
streamich 9083e70
chore: 🤖 update yarn.lock
streamich 3b42a13
test: 💍 disable a test suite
streamich 28dd3fb
test: 💍 update Canvas storyshots
streamich 2d8d08d
chore: 🤖 remvoe build step from @kbn/storybook
streamich d4e7847
chore: 🤖 enable disabled functional test suite
streamich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,3 +18,4 @@ | |
| */ | ||
|
|
||
| export { withProcRunner } from './with_proc_runner'; | ||
| export { ProcRunner } from './proc_runner'; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Kibana Storybook | ||
|
|
||
| This package provides ability to add [Storybook](https://storybook.js.org/) to any Kibana plugin. | ||
|
|
||
| - [Setup Instructions](#setup-instructions) | ||
|
|
||
|
|
||
| ## Setup Instructions | ||
|
|
||
| 1. Add `storybook.js` launcher file to your plugin. For example, create a file at | ||
| `src/plugins/<plugin>/scripts/storybook.js`, with the following contents: | ||
|
|
||
| ```js | ||
| import { join } from 'path'; | ||
|
|
||
| // eslint-disable-next-line | ||
| require('@kbn/storybook').runStorybookCli({ | ||
| name: '<plugin>', | ||
| storyGlobs: [join(__dirname, '..', 'public', 'components', '**', '*.examples.tsx')], | ||
| }); | ||
| ``` | ||
| 2. Add your plugin alias to `src/dev/storybook/aliases.ts` config. | ||
| 3. Create sample Storybook stories. For example, in your plugin create create a file at | ||
| `src/plugins/<plugin>/public/components/hello_world/__examples__/hello_world.examples.tsx` with | ||
| the following contents: | ||
|
|
||
| ```jsx | ||
| import * as React from 'react'; | ||
| import { storiesOf } from '@storybook/react'; | ||
|
|
||
| storiesOf('Hello world', module).add('default', () => <div>Hello world!</div>); | ||
| ``` | ||
| 4. Launch Storybook with `yarn storybook <plugin>`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| const fs = require('fs'); | ||
| const { join } = require('path'); | ||
| const Rx = require('rxjs'); | ||
| const { first } = require('rxjs/operators'); | ||
| const storybook = require('@storybook/react/standalone'); | ||
| const { run } = require('@kbn/dev-utils'); | ||
| const { generateStorybookEntry } = require('./lib/storybook_entry'); | ||
| const { REPO_ROOT, CURRENT_CONFIG } = require('./lib/constants'); | ||
| const { buildDll } = require('./lib/dll'); | ||
|
|
||
| exports.runStorybookCli = config => { | ||
| const { name, storyGlobs } = config; | ||
| run( | ||
| async ({ flags, log, procRunner }) => { | ||
| log.debug('Global config:\n', require('./lib/constants')); | ||
|
|
||
| const currentConfig = JSON.stringify(config, null, 2); | ||
| const currentConfigDir = join(CURRENT_CONFIG, '..'); | ||
| await fs.promises.mkdir(currentConfigDir, { recursive: true }); | ||
| log.debug('Writing currentConfig:\n', CURRENT_CONFIG + '\n', currentConfig); | ||
| await fs.promises.writeFile(CURRENT_CONFIG, `exports.currentConfig = ${currentConfig};`); | ||
|
|
||
| await buildDll({ | ||
| rebuildDll: flags.rebuildDll, | ||
| log, | ||
| procRunner, | ||
| }); | ||
|
|
||
| // Build sass and continue when initial build complete | ||
| await procRunner.run('watch sass', { | ||
| cmd: process.execPath, | ||
| args: ['scripts/build_sass', '--watch'], | ||
| cwd: REPO_ROOT, | ||
| wait: /scss bundles created/, | ||
| }); | ||
|
|
||
| const subj = new Rx.ReplaySubject(1); | ||
| generateStorybookEntry({ log, storyGlobs }).subscribe(subj); | ||
|
|
||
| await subj.pipe(first()).toPromise(); | ||
|
|
||
| await Promise.all([ | ||
| // route errors | ||
| subj.toPromise(), | ||
|
|
||
| new Promise(() => { | ||
| // storybook never completes, so neither will this promise | ||
| const configDir = join(__dirname, 'storybook_config'); | ||
| log.debug('Config dir:', configDir); | ||
| storybook({ | ||
| mode: 'dev', | ||
| port: 9001, | ||
| configDir, | ||
| }); | ||
| }), | ||
| ]); | ||
| }, | ||
| { | ||
| flags: { | ||
| boolean: ['rebuildDll'], | ||
| }, | ||
| description: ` | ||
| Run the storybook examples for ${name} | ||
| `, | ||
| } | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| const { resolve, dirname } = require('path'); | ||
|
|
||
| exports.REPO_ROOT = dirname(require.resolve('../../../package.json')); | ||
| exports.ASSET_DIR = resolve(exports.REPO_ROOT, 'built_assets/storybook'); | ||
| exports.CURRENT_CONFIG = resolve(exports.ASSET_DIR, 'current.config.js'); | ||
| exports.STORY_ENTRY_PATH = resolve(exports.ASSET_DIR, 'stories.entry.js'); | ||
| exports.DLL_DIST_DIR = resolve(exports.ASSET_DIR, 'dll'); | ||
| exports.DLL_NAME = 'storybook_dll'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| const { resolve } = require('path'); | ||
| const { existsSync } = require('fs'); | ||
|
|
||
| const { REPO_ROOT, DLL_DIST_DIR } = require('./constants'); | ||
|
|
||
| exports.buildDll = async ({ rebuildDll, log, procRunner }) => { | ||
| if (rebuildDll) { | ||
| log.info('rebuilding dll'); | ||
| } else if (!existsSync(resolve(DLL_DIST_DIR, 'dll.js'))) { | ||
| log.info('dll missing, rebuilding'); | ||
| } else { | ||
| log.info('dll exists'); | ||
| return; | ||
| } | ||
|
|
||
| await procRunner.run('build dll ', { | ||
| cmd: require.resolve('webpack/bin/webpack'), | ||
| args: ['--config', require.resolve('./webpack.dll.config.js')], | ||
| cwd: REPO_ROOT, | ||
| wait: true, | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| const { resolve, relative, dirname } = require('path'); | ||
| const Fs = require('fs'); | ||
| const Rx = require('rxjs'); | ||
| const { mergeMap, map, debounceTime } = require('rxjs/operators'); | ||
| const normalize = require('normalize-path'); | ||
| const { promisify } = require('util'); | ||
|
|
||
| const watch = require('glob-watcher'); | ||
| const mkdirp = require('mkdirp'); // eslint-disable-line | ||
| const glob = require('fast-glob'); | ||
|
|
||
| const mkdirpAsync = promisify(mkdirp); | ||
| const writeFileAsync = promisify(Fs.writeFile); | ||
|
|
||
| const { REPO_ROOT, STORY_ENTRY_PATH } = require('./constants'); | ||
| const STORE_ENTRY_DIR = dirname(STORY_ENTRY_PATH); | ||
|
|
||
| exports.generateStorybookEntry = ({ log, storyGlobs }) => { | ||
| const globs = ['built_assets/css/**/*.light.css', ...storyGlobs]; | ||
| log.info('Storybook globs:\n', globs); | ||
| const norm = p => normalize(relative(STORE_ENTRY_DIR, p)); | ||
|
|
||
| return Rx.defer(() => | ||
| glob(globs, { | ||
| absolute: true, | ||
| cwd: REPO_ROOT, | ||
| onlyFiles: true, | ||
| }) | ||
| ).pipe( | ||
| map(paths => { | ||
| log.info('Discovered Storybook entry points:\n', paths); | ||
| return new Set(paths.map(norm)); | ||
| }), | ||
| mergeMap( | ||
| paths => | ||
| new Rx.Observable(observer => { | ||
| observer.next(paths); | ||
|
|
||
| const chokidar = watch(globs, { cwd: REPO_ROOT }) | ||
| .on('add', path => { | ||
| observer.next(paths.add(norm(resolve(REPO_ROOT, path)))); | ||
| }) | ||
| .on('unlink', path => { | ||
| observer.next(paths.delete(norm(resolve(REPO_ROOT, path)))); | ||
| }); | ||
|
|
||
| return () => { | ||
| chokidar.close(); | ||
| }; | ||
| }) | ||
| ), | ||
| debounceTime(200), | ||
| mergeMap(async (paths, i) => { | ||
| await mkdirpAsync(STORE_ENTRY_DIR); | ||
|
|
||
| let content = ''; | ||
| for (const path of paths) { | ||
| content += `require('${path}');\n`; | ||
| } | ||
|
|
||
| await writeFileAsync(STORY_ENTRY_PATH, content); | ||
|
|
||
| if (i === 0) { | ||
| log.info('%d paths written to entry file', paths.size); | ||
| } else { | ||
| log.info('entry file updated'); | ||
| } | ||
| }) | ||
| ); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.