mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
## Summary This PR aims at relocating some of the Kibana modules (plugins and packages) into a new folder structure, according to the _Sustainable Kibana Architecture_ initiative. > [!IMPORTANT] > * We kindly ask you to: > * Manually fix the errors in the error section below (if there are any). > * Search for the `packages[\/\\]` and `plugins[\/\\]` patterns in the source code (Babel and Eslint config files), and update them appropriately. > * Manually review `.buildkite/scripts/pipelines/pull_request/pipeline.ts` to ensure that any CI pipeline customizations continue to be correctly applied after the changed path names > * Review all of the updated files, specially the `.ts` and `.js` files listed in the sections below, as some of them contain relative paths that have been updated. > * Think of potential impact of the move, including tooling and configuration files that can be pointing to the relocated modules. E.g.: > * customised eslint rules > * docs pointing to source code > [!NOTE] > * This PR has been auto-generated. > * Any manual contributions will be lost if the 'relocate' script is re-run. > * Try to obtain the missing reviews / approvals before applying manual fixes, and/or keep your changes in a .patch / git stash. > * Please use [#sustainable_kibana_architecture](https://elastic.slack.com/archives/C07TCKTA22E) Slack channel for feedback. Are you trying to rebase this PR to solve merge conflicts? Please follow the steps describe [here](https://elastic.slack.com/archives/C07TCKTA22E/p1734019532879269?thread_ts=1734019339.935419&cid=C07TCKTA22E). #### 3 packages(s) are going to be relocated: | Id | Target folder | | -- | ------------- | | `@kbn/code-editor` | `src/platform/packages/shared/shared-ux/code_editor/impl` | | `@kbn/code-editor-mock` | `src/platform/packages/shared/shared-ux/code_editor/mocks` | | `@kbn/monaco` | `src/platform/packages/shared/kbn-monaco` | <details > <summary>Updated relative paths</summary> ``` src/platform/packages/shared/kbn-monaco/jest.config.js:12 src/platform/packages/shared/kbn-monaco/tsconfig.json:2 src/platform/packages/shared/kbn-monaco/tsconfig.type_check.json:2 src/platform/packages/shared/shared-ux/code_editor/impl/jest.config.js:12 src/platform/packages/shared/shared-ux/code_editor/impl/tsconfig.json:16 src/platform/packages/shared/shared-ux/code_editor/impl/tsconfig.json:2 src/platform/packages/shared/shared-ux/code_editor/impl/tsconfig.type_check.json:18 src/platform/packages/shared/shared-ux/code_editor/impl/tsconfig.type_check.json:2 src/platform/packages/shared/shared-ux/code_editor/impl/tsconfig.type_check.json:25 src/platform/packages/shared/shared-ux/code_editor/impl/tsconfig.type_check.json:28 src/platform/packages/shared/shared-ux/code_editor/impl/tsconfig.type_check.json:31 src/platform/packages/shared/shared-ux/code_editor/impl/tsconfig.type_check.json:34 src/platform/packages/shared/shared-ux/code_editor/impl/tsconfig.type_check.json:37 src/platform/packages/shared/shared-ux/code_editor/impl/tsconfig.type_check.json:40 src/platform/packages/shared/shared-ux/code_editor/mocks/tsconfig.json:16 src/platform/packages/shared/shared-ux/code_editor/mocks/tsconfig.json:2 src/platform/packages/shared/shared-ux/code_editor/mocks/tsconfig.type_check.json:18 src/platform/packages/shared/shared-ux/code_editor/mocks/tsconfig.type_check.json:2 src/platform/packages/shared/shared-ux/code_editor/mocks/tsconfig.type_check.json:25 ``` </details> |
||
---|---|---|
.. | ||
chrome | ||
README.mdx |
# Shared UX Packages This directory contains directories of packages of shared components and other code for use in Kibana solutions. ## How to use these components Each package exports one or more components that can be consumed. ### Lazy by default All components are exported to be lazily-loaded with a default `React.Suspense` default most appropriate to its nature. If a solution needs to alter the `React.Suspense` behavior, (e.g. a different "loading" component), one can import the `Lazy[ComponentName]` version and surround it with a custom `React.Suspense` component. ### "Pure" and "Connected" components If a package contains a component with functionality that relies on a Kibana core or plugin dependency, there are two components exported: a `pure` component and a `connected` component. __Pure__ components: - are focused on how a component looks and behaves; - have their props and handlers exposed as simple types; - have no logic specific to Kibana. __Connected__ components, by contrast: - *compose* their pure counterparts; - rely on Kibana core and plugin dependencies to provide Kibana-specific logic; - require a `ContextProvider` packaged with the component to provide stateful services from a start contract. For example, the `ExitFullScreenButton` "pure" component is a button that is styled with the appropriate translated text. It is simple and without dependency. The "connected" component *composes* that pure component and: - applies EUI theme state; - uses the `coreStart.chrome.setIsVisible` API to change the full screen state `onClick`; - applies `emotion` styles to position the button in the window. ### Connected component providers Connected components are accompanied by a `Provider` which is intended to provide their external services. We typically provide two: one that abstracts away the dependency into a simplified set of functions, and one that maps to the intended dependency directly. For example, the `ExitFullScreenButton` relies on the `coreStart.chrome.setIsVisible` API to interact with the full screen state. The package contains two providers. The `ExitFullScreenButtonProvider` simply expects a single function, `setIsFullScreen`. This pattern is useful for more complicated components that may rely on a number of dependencies: ``` <ExitFullScreenButtonProvider setIsFullScreen={...}> <ExitFullScreenButton /> </ExitFullScreenButtonProvider> ``` The `ExitFullScreenButtonKibanaProvider` creates a facsimile of the `coreStart` contract type, containing only the portions it expects to use. This is a kind of "syntactic-sugar-workaround" to the fact plugin start contracts are not typically available to packages: ``` <ExitFullScreenButtonKibanaProvider coreStart={...}> <ExitFullScreenButton /> </ExitFullScreenButtonProvider> ``` Plugins can use either of these providers in their plugin at either the root of their plugin application or at any level of their React tree, wherever it makes sense. Component compositions can do the same. Either Provider can be used, depending on the situation. ## How can I contribute a component? *__Yes, please!__ :elasticheart:* The easiest way to contribute a shared component to Kibana is to follow our pattern and create a single package containing that contribution. You can use the `generate` script to create a new boilerplate package. > More detail on this is coming soon. Contact the Shared UX team for more information. ## How this collection is organized Typically, the `/packages` directory contains a flat list of packages, where each directory matches the name of the package. Given that we expect to create a large number of packages, we're going to organize them into a loose tree structure: ``` - packages - shared-ux - button - exit_full_screen - [component type] - baz - qux - [subject matter] - foo - bar ``` This structure should then map to the name of the package: ``` - @kbn/shared-ux-button-exit-full-screen - @kbn/shared-ux-[subject matter]-[foo] - @kbn/shared-ux-[subject matter]-[bar] - @kbn/shared-ux-[component-type]-[baz] - @kbn/shared-ux-[component-type]-[qux] ``` ## Why? When we started exploring how to effectively share code between Kibana solutions, we realized-- admittedly through some trial and error-- that the usual ways in which we share code between plugins wasn't going to work. ### Why not a plugin? First, with each component that we create, those components inevitably begin to depend on other plugins. Once our plugin depends on another, that plugin then becomes unable to use Shared UX components without creating a circular dependency. Second, the components, while useful to a plugin, are not actually dependent on the *plugin lifecycle*. They are stateless. Containing-- restricting-- them to a plugin lifecycle adds unnecessary complexity. So we opted to organize our code in packages. ### Why not a single package of components? We started that way, and quickly ran into the "`lodash` bundle problem": containing all of our components in one package (and all of our services in another) meant that any plugin using even one component would inherit *all* of them... even if they weren't used. Bundle sizes would increase dramatically, as well as build times: any minor change would cascade through the entire monorepo. Therefore we've opted to create a package for each component. ### How do your components share code? At present, *they don't*. Some utility code is shared, but this is code that should change very rarely, at most. But that doesn't mean they cannot be *composed* together. `ComponentA` can certainly compose `ComponentB` and `ComponentC`. What's great is the dependencies become very clear, top-down, and reflect the granular nature of each component.