Commit 9f1b56b
[User Storage Service] browser client, React hooks, injection rendering (elastic#268312)
Epic: elastic/kibana-team#2769
## Summary
Adds the browser foundation for the Core User Storage service (Step 2 of
the project; the server-side foundation landed in elastic#256912).
Three pieces:
**A. Server-rendered injection.**
- RenderingService` pre-fetches the current user's stored values per
request via `userStorage.asScoped(request).getAll()` and inlines them
under a new `userStorage.values` field on `<kbn-injected-metadata>`.
- Bounded by a 50ms timeout (mirroring the existing `clusterInfo`
pattern at `rendering_service.tsx:234`)
- skipped for anonymous pages and when `asScoped` returns `null` (no
`profile_uid`).
**B. Browser client.**
- Three new packages in `src/core/packages/user-storage/`:
1. `@kbn/core-user-storage-browser` (public API: `IUserStorageClient`,
`UserStorageProvider`, `useUserStorage`, `useUserStorageClient`)
2. `@kbn/core-user-storage-browser-internal` (`UserStorageService`,
`UserStorageClient`, `UserStorageApi`)
3. `@kbn/core-user-storage-browser-mocks`.
- The client seeds an in-memory cache from injected metadata at boot, so
`get(key)` is synchronous at first paint. `set`/`remove` write through
HTTP and refresh the cache on success.
- Architectural diagram
<img width="1295" height="631" alt="image"
src="https://github.com/user-attachments/assets/0b3e9113-9ef1-47d7-8f7d-37bf8730e432"
/>
**C. React hook + provider.**
- `useUserStorage(key, default)` returns `[value, setter]` with an
Observable-backed subscription, and throws a helpful error when used
outside `<UserStorageProvider>`.
- `useUserStorageClient()` is the escape hatch for consumers that depend
on `remove`, `getUpdate$`, and `getUpdateErrors$`.
## Checklist
Check the PR satisfies following conditions.
Reviewers should verify this PR satisfies this list as well.
- ~[ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)~
- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- ~[ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~
- ~[ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.~
- ~[ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed~
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.
---------
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Anton Dosov <anton.dosov@elastic.co>1 parent 84ae422 commit 9f1b56b
91 files changed
Lines changed: 2419 additions & 109 deletions
File tree
- .github
- packages/kbn-optimizer
- src
- core
- packages
- injected-metadata
- browser-internal/src
- browser-mocks/src
- common-internal/src
- lifecycle
- browser-mocks
- src
- browser
- src
- plugins/browser-internal/src
- rendering/server-internal
- src
- __snapshots__
- test_helpers
- root
- browser-internal
- src
- server-internal/src
- user-storage
- browser-internal
- src
- browser-mocks
- src
- browser
- src
- common/src
- server-internal/src
- routes
- test/scout_user_storage
- api/tests
- ui
- tests
- server/integration_tests/user_storage
- platform
- test/user_storage/plugins/user_storage_test
- public
- components
- server
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
352 | 355 | | |
353 | 356 | | |
354 | 357 | | |
355 | 358 | | |
356 | | - | |
357 | 359 | | |
358 | 360 | | |
359 | 361 | | |
| |||
927 | 929 | | |
928 | 930 | | |
929 | 931 | | |
| 932 | + | |
930 | 933 | | |
931 | 934 | | |
932 | 935 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
| 536 | + | |
| 537 | + | |
536 | 538 | | |
537 | 539 | | |
538 | 540 | | |
| |||
1245 | 1247 | | |
1246 | 1248 | | |
1247 | 1249 | | |
1248 | | - | |
| 1250 | + | |
1249 | 1251 | | |
1250 | 1252 | | |
1251 | 1253 | | |
| |||
1710 | 1712 | | |
1711 | 1713 | | |
1712 | 1714 | | |
| 1715 | + | |
1713 | 1716 | | |
1714 | 1717 | | |
1715 | 1718 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
102 | 106 | | |
103 | 107 | | |
104 | 108 | | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
67 | 70 | | |
68 | 71 | | |
69 | 72 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
96 | 99 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| |||
0 commit comments