kibana/packages/kbn-ui-framework
Tiago Costa d5b2c8eaf2
Create vendor dll for the client modules (#22618)
* feat(NA): first dll bundler code.

* chore(NA): upgrade to webpack 4.

* chore(NA): updated package.json

* chore(NA): removed old code.

* chore(NA): add parallel option.

* chore(NA): removed console log and old var about  node modules.

* chore(NA): turn off unsafe cache.

* chore(NA): update lock files.

* chore(NA): new config for dll generation.

* chore(NA): update stats emit.

* chore(NA): update dependencies.

* chore(NA): right cache loaders.

* chore(NA): remove ui_bundles alias.

* feat(20749): init implementation on bridge plugin for dll bundler.

* feat(20749): init implementation for dll compiler.

* feat(20749): dll bundler init from other process and webpack wrapper..

* feat(20749): optimizer changes to integrate with  dll bundler.

* chore(20749): split into different processes.

* refact(20749): change to single running process.

* refact(NA): improvements on dll bundler plugin.

* refact(NA): removing including loop on plugins.

* refact(20749): only run dllReference once.

* chore(20749): todo on result.request path building.

* chore(NA): lock files updated.

* chore(NA): avoiding dll paths being removed.

* chore(NA): tests on sync generation.

* chore(NA): changes on entry paths compiler.

* chore(NA): different hooks tests.

* chore(20749): first working version, single process, for dynamic building dll.

* feat(20749): last gross features for the dynamicdllplugin.

* refact(20749): string interpolation when creating the path to delete in every optimizer cycle. feat(20749): creating the DynamicDllPlugin foundations.

* chore(NA): updated base optimizer run function args.

* chore(20749): first working solution with vendor dll both for prod and dev.

* chore(20749): useful todos on client dlls.

* feat(NA): auto built blacklist for server node_modules.

* refact(NA): removed unused code.

* chore(NA): update all webpack and loaders stuff to last versions.

* refact(NA): first refacts on clean taks related with dll. feat(NA): added clean empty folders task.

* refact(NA): removed support for console logs during the build.

* refact(NA): removed extra space.

* refact(NA): removed extra space.

* refact(NA): getDllModules function.

* chore(NA): removed unsafeCache option.

* feat(NA): removed unsafeCache option.

* refact(NA): apply general inheritance principles to the optimizer: hooks, and init. refact(NA): merge dynamic dll plugin into the common config. refact(NA): restore old template structure - vendors.dll style is always emitted.

* fix(NA): fs_optimizer run function by not returning inside async func.

* fix(NA): change template anchor name from vendor to vendors.

* docs(NA): added info about files were keeping when cleaning the bundles.

* fix(NA): filtering elible dll modules to delete.

* refact(NA): removed old dll bundler in favor on new dynamic dll plugin.

* refact(NA): initial split for clean modules on dll task.

* refact(NA): update new dll config model. refact(NA): update config on dynamicdllplugin.

* refact(NA): major work refactor for dynamic dll plugin.

* refact(NA): extract clean node modules on dll task to its own folder.

* refact(NA): organize imports.

* docs(NA): add docs to registerCompilerHooks function for the optimizer.

* refact(NA): finished refactor for dynamic dll plugin with correct error handling for runWebpack function.

* refact(NA): basic structure for clean client modules on dll task.

* fix(NA): resolve path for dll manifest during cclean build tasks.

* refact(NA): split webpack dll related functions to their own file for clean client modules on dll task.

* refact(NA): added error handling for the clean client modules on dll task - webpack dll related functions.

* docs(NA): added license header.

* refact(NA): complete split out the functions from the clean modules on dll task to the code_parser file.

* refact(NA): main task entries compose.

* docs(NA): extend docs for the getDependenciesFromFile function.

* refact(NA): final structure split for clean client node modules dll task.

* fix(NA): added missing param to calculate top level dependencies.

* docs(NA): completed todo description about dll location.

* fix(NA): add production option to webpack config on kbn-pm.

* docs(NA): extended documentation about style extraction.

* refact(NA): removed extra comments.

* feat(NA): env variable to force dll creation.

* feat(NA): include option to define folders to keep on delete empty folders task.

* refact(NA): remove unused method from dll compiler.

* feat(NA): move dlls outside bundles folder and support request for /dlls from a browser perspective.

* chore(NA): gitignore updated to include new dlls folder.

* chore(NA): eslintignore updated.

* chore(NA): removed strange file from repo.

* test(NA): fix failing tests for bundles_route.

* fix(NA): change paths array to path string in a server route config.

* fix(NA): remove infinite loop calls on register hooks functions.

* fix(NA): readFile should only override the file in case it not exists.

* refact(NA): removed dll compiler finish log on success with stats.

* fix(NA): dll compiler alias.

* fix(NA): dynamic dll plugin flow on needs compile.

* fix(NA): raw alias config.

* Revert "fix(NA): raw alias config."

This reverts commit ebb245a786.

* feat(NA): raw alias for moment on dll config model.

* fix(NA): removed uiBundles from base_optimizer call on dynamicdllplugin.

* chore(NA): decrease moment versions.

* chore(NA): temporary changes on dll compiler.

* fix(NA): majority of problems between dll approach, webpackshims and browser tests.

* fix(NA): webpackShims integration with client vendors dll. fix(NA): enable esm modules mutability for development. fix(NA): only clean dll contents from build when they belong to node_modules.

* fix(NA): fix for endless dll compilation loop.

* fix(NA): removed esm plugin and skipped test using wrong stub strategy.

* docs(NA): added some comments for the skipped test.

* feat(NA): considering requires inside webpackShims valid entry paths to add to the dll entry file.

* fix(NA): small fix for the max compilation logic.

* docs(NA): add small explanatory note.

* fix(NA): building requires results with relative requires found onn webpackShims.

* docs(NA): add small note for error handling on dll compiler.

* fix(NA): move precinct to prod dependencies.

* test(NA): testing running functional tests on production.

* fix(NA): restore tests run config for development flag. feat(NA): force dll creation with uiBundles is Dev flag.

* chore(NA): update dependencies.

* feat(NA): test update dll to completely match base optimizer one.

* fix(NA): removed ts.

* refact(NA): removed unused consts.

* fix(NA): set back transpile sacss task in place.

* fix(NA): fix resolve remoing ts and tsx.

* fix(NA): set back transpile sacss task in place.

* fix(NA): removing isDevmode from mustCompileDll.

* fix(NA): add search for import statements into the dependencies visitor.

* fix(NA): add dll suffix to vendors resource on ui bootstrap template.

* fix(NA): some configs for unrelated dll work projects.

* chore(NA): upgrade canvas plugins webpack build to webpack4.

* chore(NA): add shim for moment-duration-format.

* chore(NA): stup moment-duration-format into the moment webpackShim.

* chore(NA): setup moment-duration-format into the moment-timezone webpackShim.

* fix(NA): moment and moment-timezone webpackShims

* chore(NA): added moment and moment-timezone webpackShims to x-pack. fix(NA): revert changes on webpackShims for oss kibana.

* fix(NA): xpack webpackshims for moment.

* fix(NA): remove xpack webpakcshims for moment.

* fix(NA): webpakcshims for moment.

* fix(NA): remove every changes from webpackShims and xpack webpackShims.

* fix(NA): fix visitors to gather server dependencies resulting from export * from and export x, 'x' from.

* chore(NA): update some webpack related dependencies.

* fix(NA): in the dll the plugins need to have their own dependencies. It is the same for the ones into the tests relying on test against distributable.

* feat(NA): including test/plugin_functional plugins into the kbn-pm bootstrap tasks.

* fix(NA): wrong built yarn lock files.

* chore(NA): updated webpack related dependencies.

* feat(NA): add missing color for dynamic_dll_plugin logging tag.

* chore(NA): removed forgotten console.log.

* chore(NA): removed forgotten dead code.

* chore(NA): removed missing old comment.

* docs(NA): added missing notice for 2 tools we have relied on.

* refact(NA): added is to a boolean variable to keep the consistency inside the code parser strategies.

* fix(NA): update notice cli to exclude search inside dlls bundles. chore(NA): update notice file.

* feat(NA): use lodash matches in the code parser visitors logic.

* docs(NA): updated notice file related with the code parser visitors logic..

* docs(NA): added explanation for the process that decides if we should build a new dll or not.

* test(NA): added missing tests for some usefull parts of the code.

* refact(NA): split registerCompileHook function into small ones.

* chore(NA): uncomment scripts from tests.

* feat(NA): isolate code-parser in a kbn package

* fix(NA): missing relative dot into the cwd function.

* chore(NA): update all inter deps to match.

* fix(NA): rebuild the yarn locks and the package jsons based on master ones.

* fix(NA): move babel-code-parser to the prod deps.

* chore(NA): include build path instead of the base root path.

* refact(NA): integrate plugin_functional test plugins with workspaces.

* fix(NA): include missing license for plugin functional test plugins.

* fix(NA): always write posix paths into the dll entry file in order to make the dlls compilation working on windows too. chore(NA): improve error handling into dll compiler.

* fix(NA): revert wrong moved line from canvas.

* fix(NA): match ts-loader version between kibana and x-pack.

* fix(NA): sync dll compiler with base_optimizer.

* fix(NA): exclude kbn-interpreter from the dll.

* refact(NA): remove exclusion of kbn-interpretor from base_optimizer.

* chore(NA): add dlls folder to the yarn kbn clean script.

* fix(NA): missing utf8 input format encoding when reading a file to create the hash into the watch optimizer cahce.

* refact(NA): re-engineering to the dynamic_dll_plugin logs and lifecycle.

* fix(NA): update clean node modules task to search under legacy/core_plugins.

* fix(NA): fix build on windows with globby on cleaning dlls for the watch optimizer cache.

* docs(NA): update documentation for the clean client node modules build task.

* docs(NA): added extra comment to clarify the purpose for the built entrypoints.

* chore(NA): update clean client node_modules code to use posix path.

* feat(NA): add support for discovering server entries over the legacy plugins and the new plugins.
2018-12-05 15:45:19 +00:00
..
components Apache 2.0 license headers (#19383) 2018-05-28 20:06:30 -07:00
dist Introduce query bar update button with dirty checking (#24529) 2018-10-24 18:05:40 -04:00
doc_site Fix misspellings (#19981) 2018-06-26 20:17:41 -07:00
generator-kui Apache 2.0 license headers (#19383) 2018-05-28 20:06:30 -07:00
src Introduce query bar update button with dirty checking (#24529) 2018-10-24 18:05:40 -04:00
Gruntfile.js Apache 2.0 license headers (#19383) 2018-05-28 20:06:30 -07:00
package.json Create vendor dll for the client modules (#22618) 2018-12-05 15:45:19 +00:00
README.md [@kbn/ui-framework] move ui-framework to a package (#17085) 2018-03-13 10:43:39 -07:00

Kibana UI Framework

The Kibana UI Framework is a collection of React UI components for quickly building user interfaces for Kibana. Not using React? No problem! You can still use the CSS behind each component.

Using the Framework

Documentation

Compile the CSS with ./node_modules/grunt/bin/grunt uiFramework:compileCss (OS X) or .\node_modules\grunt\bin\grunt uiFramework:compileCss (Windows).

You can view interactive documentation by running yarn uiFramework:start and then visiting http://localhost:8020/. This will also start watching the SCSS files, and will recompile the CSS automatically for you when you make changes.

You can run node scripts/jest --watch to watch for changes and run the tests as you code.

You can run node scripts/jest --coverage to generate a code coverage report to see how fully-tested the code is.

See the documentation in scripts/jest.js for more options.

Creating components

There are four steps to creating a new component:

  1. Create the SCSS for the component in packages/kbn-ui-framework/src/components.
  2. Create the React portion of the component.
  3. Write tests.
  4. Document it with examples in packages/kbn-ui-framework/doc_site.

You can do this using Yeoman (the easy way), or you can do it manually (the hard way).

Using Yeoman

Create a new component

From the command line, run yarn uiFramework:createComponent.

First, you'll be prompted for what kind of component to create:

Choice Description
Stateless function A stateless functional React component
Component class A class-based React component

Next, you'll enter a series of prompts.

"What's the name of this component?"

Yeoman will ask you what to name the file. It expects you to provide the name in snake case. Yeoman will automatically add file extensions and a "kui" prefix so you should leave those out.

"Where do you want to create this component's files?"

This defaults to the last directory you specified for this prompt, or to the UI Framework's components directory if you haven't specified one. To change this location, type in the path to the directory where the files should live.

If you want Yeoman to automatically generate a directory to organize the files, that directory will be created inside of the location you specify (see next prompt).

"Does it need its own directory?""

This defaults to YES. This will automatically generate a directory with the same name as the file, but without a "kui" prefix.

Done!

Yeoman will generate the files you need in your project's folder system.

For your convenience, it will also output some snippets you can tweak to import and re-export the generated JS and SCSS files.

Manually

Create component SCSS

  1. Create a directory for your component in packages/kbn-ui-framework/src/components.
  2. In this directory, create _{component name}.scss.
  3. Optional: Create any other components that should be logically-grouped in this directory.
  4. Create an _index.scss file in this directory that import all of the new component SCSS files you created.
  5. Import the _index.scss file into packages/kbn-ui-framework/src/components/index.scss.

This makes your styles available to Kibana and the UI Framework documentation.

Create the React component

  1. Create the React component(s) in the same directory as the related SCSS file(s).
  2. Export these components from an index.js file.
  3. Re-export these components from packages/kbn-ui-framework/src/components/index.js.

This makes your React component available for import into Kibana.

Test the component

  1. Start Jest in watch mode by running node scripts/jest --watch.
  2. Create test files with the name pattern of {component name}.test.js.
  3. Write your tests and see them fail or succeed.

To see how well the components have been covered by tests, you can run node scripts/jest --coverage and check the generated report in target/jest-coverage/index.html.

Document the component with examples

  1. Create a directory for your example in packages/kbn-ui-framework/doc_site/src/views. Name it the name of the component.
  2. Create a {component name}_example.js file inside the directory. You'll use this file to define the different examples for your component.
  3. Add the route to this file in packages/kbn-ui-framework/doc_site/src/services/routes/Routes.js.
  4. In the {component name}_example.js file you created, define examples which demonstrate the component and describe its role from a UI perspective.

The complexity of the component should determine how many examples you need to create, and how complex they should be. In general, your examples should demonstrate:

  • The most common use-cases for the component.
  • How the component handles edge cases, e.g. overflowing content, text-based vs. element-based content.
  • The various states of the component, e.g. disabled, selected, empty of content, error state.

Creating documentation

You can use the same Yeoman generator referenced above to create documentation.

From the command line, run yarn uiFramework:documentComponent.

First, you'll be prompted for what kind of documentation to create:

Choice Description
Page A page for documenting a component(s) with multiple demos
Page demo An individual demo of a particular component use case
Sandbox An empty document where you can do pretty much anything

Just follow the prompts and your documentation files will be created. You can use the snippets that are printed to the terminal to integrate these files into the UI Framework documentation site.

Principles

Logically-grouped components

If a component has subcomponents (e.g. ToolBar and ToolBarSearch), tightly-coupled components (e.g. Button and ButtonGroup), or you just want to group some related components together (e.g. TextInput, TextArea, and CheckBox), then they belong in the same logical grouping. In this case, you can create additional SCSS files for these components in the same component directory.

Writing CSS

Check out our CSS style guide and SCSS style guide.

Benefits

Dynamic, interactive documentation

By having a "living style guide", we relieve our designers of the burden of creating and maintaining static style guides. This also makes it easier for our engineers to translate mockups, prototypes, and wireframes into products.

Copy-pasteable UI

Engineers can copy and paste sample code into their projects to quickly get reliable, consistent results.

Remove CSS from the day-to-day

The CSS portion of this framework means engineers don't need to spend mental cycles translating a design into CSS. These cycles can be spent on the things critical to the identity of the specific project they're working on, like architecture and business logic.

If they use the React components, engineers won't even need to see CSS -- it will be encapsulated behind the React components' interfaces.

More UI tests === fewer UI bugs

By covering our UI components with great unit tests and having those tests live within the framework itself, we can rest assured that our UI layer is tested and remove some of that burden from our integration/end-to-end tests.

Why not just use Bootstrap?

In short: we've outgrown it! Third-party CSS frameworks like Bootstrap and Foundation are designed for a general audience, so they offer things we don't need and don't offer things we do need. As a result, we've been forced to override their styles until the original framework is no longer recognizable. When the CSS reaches that point, it's time to take ownership over it and build your own framework.

We also gain the ability to fix some of the common issues with third-party CSS frameworks:

  • They have non-semantic markup.
  • They deeply nest their selectors.

For a more in-depth analysis of the problems with Bootstrap (and similar frameworks), check out this article and the links it has at the bottom: "Bootstrap Bankruptcy".

Examples of other in-house UI frameworks