Skip to content

[dashboard as code] embeddable transforms registry#227141

Merged
nreese merged 27 commits intoelastic:mainfrom
nreese:embeddable_transforms
Jul 16, 2025
Merged

[dashboard as code] embeddable transforms registry#227141
nreese merged 27 commits intoelastic:mainfrom
nreese:embeddable_transforms

Conversation

@nreese
Copy link
Contributor

@nreese nreese commented Jul 8, 2025

Closes #222472
Closes #222466

Problem

Dashboard CRUD request and response shapes are overly complex because

  1. panel state contains extracted references
  2. by-value panel state often mirrors embeddable saved object state, which usually contains stringified JSON. For example, a by-value maps panel state contains layerListJSON instead of exposing just layerList.

To simplify dashboard CRUD request and response shapes, embeddables need a mechanism to

  1. inject references in dashboard CRUD read APIs
  2. transform by-value embeddable state to a more consumable shape in dashboard CRUD read APIs
  3. extract references in dashbaord CRUD write APIs

The embeddable transforms registry is the solution to these problems and allows embeddables to transform embeddable state that is part of dashboard CRUD APIs.

Changes to Embeddable plugin

Adds transforms registry to embeddable server and public plugins, allowing embeddable implementations to register transforms.

Changes to Dashboard plugin

Updates dashboard CRUD write APIs to use transformIn function to extract references.

The below image shows the create request body. The dashboard contains a single by-reference book embeddable. Notice how the savedObjectId has not been extracted to a reference.
Screenshot 2025-07-10 at 11 28 47 AM

The below image shows the saved object for the dashboard above. Notice how the persisted state has saved object reference extracted. Panel embeddableConfig no longer contains savedObjectId key and references contains savedObjectRef.
Screenshot 2025-07-10 at 11 30 41 AM

Updates dashboard CRUD read APIs to use transformOut function to inject references and transform stored embeddable state to a more consumable shape. Dashboards loaded from stored URL state also use transformOut for the same purpose.

Changes to embeddable_examples

Implements book saved object
Screenshot 2025-07-10 at 11 09 33 AM

Implements book content management CRUD API
Screenshot 2025-07-10 at 11 08 51 AM

Updates book embeddable to use book CRUD API

@nreese
Copy link
Contributor Author

nreese commented Jul 9, 2025

@elasticmachine merge upstream

@nreese
Copy link
Contributor Author

nreese commented Jul 10, 2025

/ci

@nreese
Copy link
Contributor Author

nreese commented Jul 10, 2025

/ci

@nreese nreese changed the title Embeddable transforms [dashboard as code] embeddable transforms registry Jul 10, 2025
@nreese
Copy link
Contributor Author

nreese commented Jul 10, 2025

/ci

@nreese nreese marked this pull request as ready for review July 10, 2025 20:34
@nreese nreese requested a review from a team as a code owner July 10, 2025 20:34
@nreese nreese added Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas t// release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting v9.2.0 labels Jul 10, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-presentation (Team:Presentation)

@nreese
Copy link
Contributor Author

nreese commented Jul 11, 2025

@elasticmachine merge upstream

@botelastic botelastic bot added the Feature:Embedding Embedding content via iFrame label Jul 11, 2025
@nickpeihl nickpeihl self-requested a review July 11, 2025 17:12
Copy link
Contributor

@nickpeihl nickpeihl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! Code review and tested book embeddable example.

I did add a few questions, but nothing blocking. I can't wait to start adding transforms in our other embeddables!

developerExamples: DeveloperExamplesSetup;
embeddable: EmbeddableSetup;
uiActions: UiActionsStart;
uiActions: UiActionsSetup;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like we even use the UIActionsSetup dependency. I wonder if we can get rid of it?

@nreese
Copy link
Contributor Author

nreese commented Jul 14, 2025

@elasticmachine merge upstream

Copy link
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a cursory review of this as well, ran locally and messed around with the book example, also looked through the code. Left a couple tiny nits and a few other comments, but nothing blocking at all. Nice work! Will be great to get this merged!

export type BookEmbeddableState = SerializedTitles & (BookState | BookByReferenceState);

// Shape of stored state <=9.1
export type BookEmbeddableState910 = SerializedTitles &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this type used? Can we have all BWC related code and types isolated in a BWC file or folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BookEmbeddableState910 is used to type transformOut storedState parameter as storedState: BookEmbeddableState | BookEmbeddableState910.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have all BWC related code and types isolated in a BWC file or folder?

I am not sure that is possible since transformOut receives current state and legacy state. Handling of both types occurs in the same method.

@nreese nreese force-pushed the embeddable_transforms branch from ad5b8f0 to c20199f Compare July 16, 2025 14:39
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
dashboard 682 684 +2
embeddable 105 106 +1
total +3

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
embeddable 124 135 +11

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
dashboard 619.6KB 620.2KB +634.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
embeddable 16.8KB 17.1KB +308.0B
Unknown metric groups

API count

id before after diff
embeddable 148 159 +11

ESLint disabled line counts

id before after diff
dashboard 18 19 +1

Total ESLint disabled count

id before after diff
dashboard 18 19 +1

History

@nreese nreese merged commit bfab28a into elastic:main Jul 16, 2025
12 checks passed
Bluefinger pushed a commit to Bluefinger/kibana that referenced this pull request Jul 22, 2025
Closes elastic#222472
Closes elastic#222466

### Problem
Dashboard CRUD request and response shapes are overly complex because
1) panel state contains extracted references
2) by-value panel state often mirrors embeddable saved object state,
which usually contains stringified JSON. For example, a by-value maps
panel state contains `layerListJSON` instead of exposing just
`layerList`.

To simplify dashboard CRUD request and response shapes, embeddables need
a mechanism to
1) inject references in dashboard CRUD read APIs
2) transform by-value embeddable state to a more consumable shape in
dashboard CRUD read APIs
2) extract references in dashbaord CRUD write APIs

The embeddable transforms registry is the solution to these problems and
allows embeddables to transform embeddable state that is part of
dashboard CRUD APIs.

### Changes to Embeddable plugin
Adds transforms registry to embeddable server and start plugin, allowing
embeddable implementations to register transforms.

### Changes to Dashboard plugin
Updates dashboard CRUD write APIs to use `transformIn` function to
extract references.

The below image shows the create request body. The dashboard contains a
single by-reference book embeddable. Notice how the savedObjectId has
not been extracted to a reference.
<img height="300" alt="Screenshot 2025-07-10 at 11 28 47 AM"
src="https://github.com/user-attachments/assets/f950006e-50bf-44ea-8b9c-77a2123a6713"
/>

The below image shows the saved object for the dashboard above. Notice
how the persisted state has saved object reference extracted. Panel
`embeddableConfig` no longer contains `savedObjectId` key and references
contains `savedObjectRef`.
<img height="400" alt="Screenshot 2025-07-10 at 11 30 41 AM"
src="https://github.com/user-attachments/assets/eb7e9921-b02b-4029-b43d-e6c77f7d65b3"
/>

Updates dashboard CRUD read APIs to use `transformOut` function to
inject references and transform stored embeddable state to a more
consumable shape. Dashboards loaded from stored URL state also use
`transformOut` for the same purpose.

### Changes to embeddable_examples
Implements book saved object
<img height="300" alt="Screenshot 2025-07-10 at 11 09 33 AM"
src="https://github.com/user-attachments/assets/b1785512-4dd3-40bf-b848-6d88b85e3eb2"
/>

Implements book content management CRUD API
<img height="195" alt="Screenshot 2025-07-10 at 11 08 51 AM"
src="https://github.com/user-attachments/assets/378aab47-b2bd-4541-85df-b108a44c8da7"
/>

Updates book embeddable to use book CRUD API

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
kertal pushed a commit to kertal/kibana that referenced this pull request Jul 25, 2025
Closes elastic#222472
Closes elastic#222466

### Problem
Dashboard CRUD request and response shapes are overly complex because
1) panel state contains extracted references
2) by-value panel state often mirrors embeddable saved object state,
which usually contains stringified JSON. For example, a by-value maps
panel state contains `layerListJSON` instead of exposing just
`layerList`.

To simplify dashboard CRUD request and response shapes, embeddables need
a mechanism to
1) inject references in dashboard CRUD read APIs
2) transform by-value embeddable state to a more consumable shape in
dashboard CRUD read APIs
2) extract references in dashbaord CRUD write APIs

The embeddable transforms registry is the solution to these problems and
allows embeddables to transform embeddable state that is part of
dashboard CRUD APIs.

### Changes to Embeddable plugin
Adds transforms registry to embeddable server and start plugin, allowing
embeddable implementations to register transforms.

### Changes to Dashboard plugin
Updates dashboard CRUD write APIs to use `transformIn` function to
extract references.

The below image shows the create request body. The dashboard contains a
single by-reference book embeddable. Notice how the savedObjectId has
not been extracted to a reference.
<img height="300" alt="Screenshot 2025-07-10 at 11 28 47 AM"
src="https://github.com/user-attachments/assets/f950006e-50bf-44ea-8b9c-77a2123a6713"
/>

The below image shows the saved object for the dashboard above. Notice
how the persisted state has saved object reference extracted. Panel
`embeddableConfig` no longer contains `savedObjectId` key and references
contains `savedObjectRef`.
<img height="400" alt="Screenshot 2025-07-10 at 11 30 41 AM"
src="https://github.com/user-attachments/assets/eb7e9921-b02b-4029-b43d-e6c77f7d65b3"
/>

Updates dashboard CRUD read APIs to use `transformOut` function to
inject references and transform stored embeddable state to a more
consumable shape. Dashboards loaded from stored URL state also use
`transformOut` for the same purpose.

### Changes to embeddable_examples
Implements book saved object
<img height="300" alt="Screenshot 2025-07-10 at 11 09 33 AM"
src="https://github.com/user-attachments/assets/b1785512-4dd3-40bf-b848-6d88b85e3eb2"
/>

Implements book content management CRUD API
<img height="195" alt="Screenshot 2025-07-10 at 11 08 51 AM"
src="https://github.com/user-attachments/assets/378aab47-b2bd-4541-85df-b108a44c8da7"
/>

Updates book embeddable to use book CRUD API

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:Embedding Embedding content via iFrame Project:Dashboards API release_note:skip Skip the PR/issue when compiling release notes Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas t// v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Dashboards as code] Embeddables registry example [Dashboards as code] Embeddables registry transforms

5 participants