-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[dashboard as code] embeddable transforms registry #227141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
67e7452
5b26155
5d74e0f
7a6a3aa
592fada
1d6d8a0
ded197a
c485d2a
5f4cb53
e8e7749
92300cc
6bdf84e
8f7618e
31f1c29
9abc658
bda58a3
ba2df22
a1d820f
7d1cd68
2b51d40
cdd8567
9106892
d26f4ac
455429a
d054015
c20199f
86bff4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| export const BOOK_EMBEDDABLE_TYPE = 'book'; | ||
| export const BOOK_SAVED_OBJECT_TYPE = 'book'; | ||
| export const BOOK_CONTENT_ID = 'book'; | ||
| export const BOOK_LATEST_VERSION = 1; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| export type { BookEmbeddableState, BookByReferenceState } from './types'; | ||
|
|
||
| export { | ||
| BOOK_CONTENT_ID, | ||
| BOOK_EMBEDDABLE_TYPE, | ||
| BOOK_LATEST_VERSION, | ||
| BOOK_SAVED_OBJECT_TYPE, | ||
| } from './constants'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import { transformIn } from './transform_in'; | ||
| import { transformOut } from './transform_out'; | ||
|
|
||
| export const bookTransforms = { | ||
| transformOut, | ||
| transformIn, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import { BOOK_SAVED_OBJECT_TYPE } from '../constants'; | ||
| import { BookByReferenceState, BookEmbeddableState } from '../types'; | ||
|
|
||
| export function transformIn(state: BookEmbeddableState) { | ||
| // extract saved object reference for by-reference state | ||
| if ((state as BookByReferenceState).savedObjectId) { | ||
| const { savedObjectId, ...rest } = state as BookByReferenceState; | ||
| return { | ||
| state: rest, | ||
| references: [ | ||
| { | ||
| name: 'savedObjectRef', | ||
| type: BOOK_SAVED_OBJECT_TYPE, | ||
| id: savedObjectId, | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
|
|
||
| // no reference extraction needed for by-value state | ||
| return { state }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import type { Reference } from '@kbn/content-management-utils'; | ||
| import type { BookState } from '../../../server'; | ||
| import { BookEmbeddableState, BookEmbeddableState910 } from '../types'; | ||
| import { BOOK_SAVED_OBJECT_TYPE } from '../constants'; | ||
|
|
||
| export function transformOut( | ||
nreese marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| storedState: BookEmbeddableState | BookEmbeddableState910, | ||
| references?: Reference[] | ||
| ): BookEmbeddableState { | ||
| // storedState may contain legacy state stored from dashboards or URL | ||
|
|
||
| // 9.1.0 by-value state stored book state under attributes | ||
| if ('attributes' in storedState) { | ||
| const { attributes, ...rest } = storedState as { attributes: BookState }; | ||
| return { | ||
| ...attributes, | ||
| ...rest, | ||
| }; | ||
| } | ||
|
|
||
| // 9.1.0 by-reference state stored by-reference id as savedBookId | ||
| if ('savedBookId' in storedState) { | ||
| const { savedBookId, ...rest } = storedState as { savedBookId: string }; | ||
| return { | ||
| ...rest, | ||
| savedObjectId: savedBookId, | ||
| }; | ||
| } | ||
|
|
||
| // inject saved object reference when by-reference | ||
| const savedObjectRef = (references ?? []).find( | ||
| ({ name, type }) => name === 'savedObjectRef' && type === BOOK_SAVED_OBJECT_TYPE | ||
| ); | ||
| if (savedObjectRef) { | ||
| return { | ||
| ...(storedState as BookEmbeddableState), | ||
| savedObjectId: savedObjectRef.id, | ||
| }; | ||
| } | ||
|
|
||
| // storedState is current by-value state | ||
| return storedState as BookEmbeddableState; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import type { SerializedTitles } from '@kbn/presentation-publishing'; | ||
| import type { BookState } from '../../server'; | ||
|
|
||
| export interface BookByReferenceState { | ||
| savedObjectId: string; | ||
| } | ||
|
|
||
| export type BookEmbeddableState = SerializedTitles & (BookState | BookByReferenceState); | ||
|
|
||
| // Shape of stored state <=9.1 | ||
| export type BookEmbeddableState910 = SerializedTitles & | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I am not sure that is possible since |
||
| ({ attributes: BookState } | { savedBookId: string }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| export type { BookEmbeddableState, BookByReferenceState } from './book'; | ||
|
|
||
| export { | ||
| BOOK_CONTENT_ID, | ||
| BOOK_EMBEDDABLE_TYPE, | ||
| BOOK_LATEST_VERSION, | ||
| BOOK_SAVED_OBJECT_TYPE, | ||
| } from './book'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import { ContentManagementPublicStart } from '@kbn/content-management-plugin/public'; | ||
| import { CoreStart } from '@kbn/core/public'; | ||
| import type { StartDeps } from './plugin'; | ||
|
|
||
| export let contentManagement: ContentManagementPublicStart; | ||
|
|
||
| export const setKibanaServices = (kibanaCore: CoreStart, deps: StartDeps) => { | ||
| contentManagement = deps.contentManagement; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,11 @@ import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public'; | |
| import { DeveloperExamplesSetup } from '@kbn/developer-examples-plugin/public'; | ||
| import { EmbeddableSetup, EmbeddableStart } from '@kbn/embeddable-plugin/public'; | ||
| import { FieldFormatsStart } from '@kbn/field-formats-plugin/public'; | ||
| import { ADD_PANEL_TRIGGER, UiActionsStart } from '@kbn/ui-actions-plugin/public'; | ||
| import { ADD_PANEL_TRIGGER, UiActionsSetup, UiActionsStart } from '@kbn/ui-actions-plugin/public'; | ||
| import { | ||
| ContentManagementPublicSetup, | ||
| ContentManagementPublicStart, | ||
| } from '@kbn/content-management-plugin/public'; | ||
| import { setupApp } from './app/setup_app'; | ||
| import { DATA_TABLE_ID } from './react_embeddables/data_table/constants'; | ||
| import { registerCreateDataTableAction } from './react_embeddables/data_table/create_data_table_action'; | ||
|
|
@@ -27,18 +31,21 @@ import { | |
| import { FIELD_LIST_ID } from './react_embeddables/field_list/constants'; | ||
| import { registerCreateFieldListAction } from './react_embeddables/field_list/create_field_list_action'; | ||
| import { registerFieldListPanelPlacementSetting } from './react_embeddables/field_list/register_field_list_embeddable'; | ||
| import { SAVED_BOOK_ID } from './react_embeddables/saved_book/constants'; | ||
| import { registerCreateSavedBookAction } from './react_embeddables/saved_book/create_saved_book_action'; | ||
| import { registerAddSearchPanelAction } from './react_embeddables/search/register_add_search_panel_action'; | ||
| import { registerSearchEmbeddable } from './react_embeddables/search/register_search_embeddable'; | ||
| import { setKibanaServices } from './kibana_services'; | ||
| import { setupBookEmbeddable } from './react_embeddables/saved_book/setup_book_embeddable'; | ||
|
|
||
| export interface SetupDeps { | ||
| contentManagement: ContentManagementPublicSetup; | ||
| developerExamples: DeveloperExamplesSetup; | ||
| embeddable: EmbeddableSetup; | ||
| uiActions: UiActionsStart; | ||
| uiActions: UiActionsSetup; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't look like we even use the |
||
| } | ||
|
|
||
| export interface StartDeps { | ||
| contentManagement: ContentManagementPublicStart; | ||
| dataViews: DataViewsPublicPluginStart; | ||
| dataViewFieldEditor: DataViewFieldEditorStart; | ||
| embeddable: EmbeddableStart; | ||
|
|
@@ -50,7 +57,10 @@ export interface StartDeps { | |
| } | ||
|
|
||
| export class EmbeddableExamplesPlugin implements Plugin<void, void, SetupDeps, StartDeps> { | ||
| public setup(core: CoreSetup<StartDeps>, { embeddable, developerExamples }: SetupDeps) { | ||
| public setup( | ||
| core: CoreSetup<StartDeps>, | ||
| { contentManagement, embeddable, developerExamples }: SetupDeps | ||
| ) { | ||
| setupApp(core, developerExamples); | ||
|
|
||
| const startServicesPromise = core.getStartServices(); | ||
|
|
@@ -78,13 +88,7 @@ export class EmbeddableExamplesPlugin implements Plugin<void, void, SetupDeps, S | |
| return getDataTableFactory(coreStart, deps); | ||
| }); | ||
|
|
||
| embeddable.registerReactEmbeddableFactory(SAVED_BOOK_ID, async () => { | ||
| const { getSavedBookEmbeddableFactory } = await import( | ||
| './react_embeddables/saved_book/saved_book_react_embeddable' | ||
| ); | ||
| const [coreStart] = await startServicesPromise; | ||
| return getSavedBookEmbeddableFactory(coreStart); | ||
| }); | ||
| setupBookEmbeddable(core, embeddable, contentManagement); | ||
|
|
||
| registerSearchEmbeddable( | ||
| embeddable, | ||
|
|
@@ -93,6 +97,8 @@ export class EmbeddableExamplesPlugin implements Plugin<void, void, SetupDeps, S | |
| } | ||
|
|
||
| public start(core: CoreStart, deps: StartDeps) { | ||
| setKibanaServices(core, deps); | ||
|
|
||
| registerCreateFieldListAction(deps.uiActions); | ||
| registerFieldListPanelPlacementSetting(deps.dashboard); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.