kibana/packages/shared-ux
Kibana Machine 1ebdc33403
[8.17] [Vega] Fix highlight for HJSON (#208858) (#209289)
# Backport

This will backport the following commits from `main` to `8.17`:
- [[Vega] Fix highlight for HJSON
(#208858)](https://github.com/elastic/kibana/pull/208858)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Marco
Vettorello","email":"marco.vettorello@elastic.co"},"sourceCommit":{"committedDate":"2025-02-03T13:18:35Z","message":"[Vega]
Fix highlight for HJSON (#208858)\n\n## Summary\r\n\r\nThis PR fixes the
missing highlight theme for HJSON specs in Vega.\r\nThe issue
https://github.com/elastic/kibana/issues/205711 was caused
by\r\nhttps://github.com/elastic/kibana/pull/182348 that
inadvertently\r\nspecified the code-editor package as sideEffect free.
This cause the\r\ncompiler to exclude every import without exported and
used methods.\r\nThis was the case for the code-editor that registered
some language\r\nhighlighters in that way.\r\n\r\nThe solution adopted
here is to mark the register_language.ts file as a\r\nfile with side
effects, the alternative solution can be to register\r\nthese directly
from within the code_editor component.\r\nA third option is to move
these registration within the monaco package\r\nwhere other languages
are also registered.\r\nI'd like to leave to @elastic/appex-sharedux the
preference to followup\r\nwith a better fix for the future.\r\n\r\nI'd
also like to have the opinion from @elastic/kibana-operations\r\nbecause
the misconfigured package issue can be seen only in production\r\nand
not in development mode. Is it possible that webpack doesn't
apply\r\ntreeshaking when in development mode?\r\n\r\nfix
https://github.com/elastic/kibana/issues/205711\r\nShould also fix the
same issue but for TSVB Markdown\r\n\r\nThe fix was tested on CI by
running at first only the CI FT with the\r\n`sideEffects:false` to
verify the failure
(see\r\n[build](https://buildkite.com/elastic/kibana-pull-request/builds/272375))\r\nand
then with the fix specifying the actual file that contains
side\r\neffects.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"7260564f6a9cd7da71a80e9bd57d836a0bea57c4","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:TSVB","release_note:fix","Feature:Vega","Team:Visualizations","backport:prev-major","v9.1.0"],"title":"[Vega]
Fix highlight for
HJSON","number":208858,"url":"https://github.com/elastic/kibana/pull/208858","mergeCommit":{"message":"[Vega]
Fix highlight for HJSON (#208858)\n\n## Summary\r\n\r\nThis PR fixes the
missing highlight theme for HJSON specs in Vega.\r\nThe issue
https://github.com/elastic/kibana/issues/205711 was caused
by\r\nhttps://github.com/elastic/kibana/pull/182348 that
inadvertently\r\nspecified the code-editor package as sideEffect free.
This cause the\r\ncompiler to exclude every import without exported and
used methods.\r\nThis was the case for the code-editor that registered
some language\r\nhighlighters in that way.\r\n\r\nThe solution adopted
here is to mark the register_language.ts file as a\r\nfile with side
effects, the alternative solution can be to register\r\nthese directly
from within the code_editor component.\r\nA third option is to move
these registration within the monaco package\r\nwhere other languages
are also registered.\r\nI'd like to leave to @elastic/appex-sharedux the
preference to followup\r\nwith a better fix for the future.\r\n\r\nI'd
also like to have the opinion from @elastic/kibana-operations\r\nbecause
the misconfigured package issue can be seen only in production\r\nand
not in development mode. Is it possible that webpack doesn't
apply\r\ntreeshaking when in development mode?\r\n\r\nfix
https://github.com/elastic/kibana/issues/205711\r\nShould also fix the
same issue but for TSVB Markdown\r\n\r\nThe fix was tested on CI by
running at first only the CI FT with the\r\n`sideEffects:false` to
verify the failure
(see\r\n[build](https://buildkite.com/elastic/kibana-pull-request/builds/272375))\r\nand
then with the fix specifying the actual file that contains
side\r\neffects.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"7260564f6a9cd7da71a80e9bd57d836a0bea57c4"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/208858","number":208858,"mergeCommit":{"message":"[Vega]
Fix highlight for HJSON (#208858)\n\n## Summary\r\n\r\nThis PR fixes the
missing highlight theme for HJSON specs in Vega.\r\nThe issue
https://github.com/elastic/kibana/issues/205711 was caused
by\r\nhttps://github.com/elastic/kibana/pull/182348 that
inadvertently\r\nspecified the code-editor package as sideEffect free.
This cause the\r\ncompiler to exclude every import without exported and
used methods.\r\nThis was the case for the code-editor that registered
some language\r\nhighlighters in that way.\r\n\r\nThe solution adopted
here is to mark the register_language.ts file as a\r\nfile with side
effects, the alternative solution can be to register\r\nthese directly
from within the code_editor component.\r\nA third option is to move
these registration within the monaco package\r\nwhere other languages
are also registered.\r\nI'd like to leave to @elastic/appex-sharedux the
preference to followup\r\nwith a better fix for the future.\r\n\r\nI'd
also like to have the opinion from @elastic/kibana-operations\r\nbecause
the misconfigured package issue can be seen only in production\r\nand
not in development mode. Is it possible that webpack doesn't
apply\r\ntreeshaking when in development mode?\r\n\r\nfix
https://github.com/elastic/kibana/issues/205711\r\nShould also fix the
same issue but for TSVB Markdown\r\n\r\nThe fix was tested on CI by
running at first only the CI FT with the\r\n`sideEffects:false` to
verify the failure
(see\r\n[build](https://buildkite.com/elastic/kibana-pull-request/builds/272375))\r\nand
then with the fix specifying the actual file that contains
side\r\neffects.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"7260564f6a9cd7da71a80e9bd57d836a0bea57c4"}}]}]
BACKPORT-->

Co-authored-by: Marco Vettorello <marco.vettorello@elastic.co>
2025-02-03 16:35:53 +01:00
..
avatar/solution Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
button/exit_full_screen [8.x] do not set full screen mode on ExitFullScreenButton re-render (#198012) (#198059) 2024-10-28 14:07:17 -05:00
button_toolbar [react@18] Implicit children type fixes (#192011) 2024-09-09 13:56:02 +02:00
card/no_data Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
chrome [8.x] [Stateful sidenav] Update feedback urls (#198143) (#198480) 2024-10-31 06:06:16 -05:00
code_editor [8.17] [Vega] Fix highlight for HJSON (#208858) (#209289) 2025-02-03 16:35:53 +01:00
error_boundary Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
file Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
link/redirect_app Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
markdown Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
modal/tabbed Upgrade @testing-library/user-event to latest ^14.5.2 (#189949) 2024-09-10 14:31:27 +02:00
page [8.x] Upgrade EUI to v97.3.1 (#199186) (#200052) 2024-11-13 23:41:26 +01:00
prompt [8.x] [ES|QL] Present ES|QL as an equal to data views on the &quot;no data views&quot; screen (#194077) (#195684) 2024-10-10 01:50:53 +02:00
router [react@18] Implicit children type fixes (#192011) 2024-09-09 13:56:02 +02:00
storybook Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
table_persist [8.x] [EuiInMemoryTable] Persist table rows per page and sort (#198297) (#200569) 2024-11-18 09:22:33 -06:00
README.mdx [Shared UX] Adopt multi-package strategy - ExitFullScreenButton (#130355) 2022-04-15 19:12:46 -05:00

# 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.