Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { schema } from '@kbn/config-schema';
export const BOOK_LATEST_VERSION = 1;

export const bookAttributesSchema = schema.object({
bookTitle: schema.string(),
author: schema.string(),
pages: schema.number(),
synopsis: schema.maybe(schema.string()),
published: schema.nullable(schema.number()),
});
export const BOOK_CONTENT_ID = 'book';
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
*/

export { bookAttributesDefinition } from './schema';
export { BOOK_CONTENT_ID, BOOK_LATEST_VERSION } from './constants';
export { itemToSavedObject, savedObjectToItem } from './transforms';
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,13 @@

import type { VersionableEmbeddableObject } from '@kbn/embeddable-plugin/common';
import type { SavedBookAttributes } from '../../../../server/types';
import type { BookAttributes } from '../../../../server/book/content_management/schema';
import type { BookAttributes } from '../../../../server/book/content_management/v1';
import { itemToSavedObject, savedObjectToItem } from './transforms';

export const bookAttributesDefinition: VersionableEmbeddableObject<
SavedBookAttributes,
BookAttributes
> = {
itemToSavedObject: ({ attributes, references }) => ({
attributes: {
bookTitleAsArray: [...attributes.bookTitle],
metadata: {
numbers: {
numberOfPages: attributes.pages,
publicationYear: attributes.published ?? undefined,
},
text: {
authorName: attributes.author,
bookSynopsis: attributes.synopsis,
},
},
// Generate a string of random letters and numbers to demonstrate simplifying a savedObject
uselessGarbage: Array.from(Array(10), () => Math.random().toString(36).substring(2)).join(''),
},
references,
}),
savedObjectToItem: ({ attributes, references }) => ({
attributes: {
bookTitle: attributes.bookTitleAsArray.join(''),
author: attributes.metadata.text.authorName,
pages: attributes.metadata.numbers.numberOfPages,
synopsis: attributes.metadata.text.bookSynopsis,
published: attributes.metadata.numbers.publicationYear ?? null,
},
references,
}),
itemToSavedObject,
savedObjectToItem,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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 { itemToSavedObject } from './item_to_saved_object';
export { savedObjectToItem } from './saved_object_to_item';
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 {
ItemAttributesWithReferences,
SavedObjectAttributesWithReferences,
} from '@kbn/embeddable-plugin/common/types';
import type { BookAttributes } from '../../../../../server/book/content_management/latest';
import type { SavedBookAttributes } from '../../../../../server/book/saved_object';

export const itemToSavedObject = ({
attributes,
references,
}: ItemAttributesWithReferences<BookAttributes>): SavedObjectAttributesWithReferences<SavedBookAttributes> => ({
attributes: {
bookTitleAsArray: [...attributes.bookTitle],
metadata: {
numbers: {
numberOfPages: attributes.pages,
publicationYear: attributes.published ?? undefined,
},
text: {
authorName: attributes.author,
bookSynopsis: attributes.synopsis,
},
},
// Generate a string of random letters and numbers to demonstrate simplifying a savedObject
uselessGarbage: Array.from(Array(10), () => Math.random().toString(36).substring(2)).join(''),
},
references,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 {
ItemAttributesWithReferences,
SavedObjectAttributesWithReferences,
} from '@kbn/embeddable-plugin/common/types';
import type { SavedBookAttributes } from '../../../../../server/book/saved_object';
import type { BookAttributes } from '../../../../../server/book/content_management/latest';

export const savedObjectToItem = ({
attributes,
references,
}: SavedObjectAttributesWithReferences<SavedBookAttributes>): ItemAttributesWithReferences<BookAttributes> => ({
attributes: {
bookTitle: attributes.bookTitleAsArray.join(''),
author: attributes.metadata.text.authorName,
pages: attributes.metadata.numbers.numberOfPages,
synopsis: attributes.metadata.text.bookSynopsis,
published: attributes.metadata.numbers.publicationYear ?? null,
},
references,
});
1 change: 1 addition & 0 deletions examples/embeddable_examples/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"server": true,
"browser": true,
"requiredPlugins": [
"contentManagement",
"dataViews",
"embeddable",
"uiActions",
Expand Down
36 changes: 36 additions & 0 deletions examples/embeddable_examples/public/kibana_services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 { BehaviorSubject } from 'rxjs';

import type { CoreStart } from '@kbn/core/public';
import type { StartDeps } from './plugin';

export let core: CoreStart;
export let contentManagement: StartDeps['contentManagement'];

const servicesReady$ = new BehaviorSubject(false);
export const untilPluginStartServicesReady = () => {
if (servicesReady$.value) return Promise.resolve();
return new Promise<void>((resolve) => {
const subscription = servicesReady$.subscribe((isInitialized) => {
if (isInitialized) {
subscription.unsubscribe();
resolve();
}
});
});
};

export const setKibanaServices = (kibanaCore: CoreStart, deps: StartDeps) => {
core = kibanaCore;
contentManagement = deps.contentManagement;

servicesReady$.next(true);
};
21 changes: 20 additions & 1 deletion examples/embeddable_examples/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ 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 { 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';
Expand All @@ -31,14 +35,18 @@ import { registerAddSearchPanelAction } from './react_embeddables/search/registe
import { registerSearchEmbeddable } from './react_embeddables/search/register_search_embeddable';
import { bookCmDefinitions } from '../common/book/content_management/cm_services';
import { fieldListCmDefinitions } from '../common/field_list/content_management/cm_services';
import { BOOK_CONTENT_ID, BOOK_LATEST_VERSION } from '../common/book/content_management/schema';
import { setKibanaServices } from './kibana_services';

export interface SetupDeps {
contentManagement: ContentManagementPublicSetup;
developerExamples: DeveloperExamplesSetup;
embeddable: EmbeddableSetup;
uiActions: UiActionsStart;
}

export interface StartDeps {
contentManagement: ContentManagementPublicStart;
dataViews: DataViewsPublicPluginStart;
dataViewFieldEditor: DataViewFieldEditorStart;
embeddable: EmbeddableStart;
Expand All @@ -50,7 +58,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();
Expand Down Expand Up @@ -93,9 +104,17 @@ export class EmbeddableExamplesPlugin implements Plugin<void, void, SetupDeps, S

embeddable.registerEmbeddableContentManagementDefinition(bookCmDefinitions);
embeddable.registerEmbeddableContentManagementDefinition(fieldListCmDefinitions);

contentManagement.registry.register({
id: BOOK_CONTENT_ID,
version: {
latest: BOOK_LATEST_VERSION,
},
});
}

public start(core: CoreStart, deps: StartDeps) {
setKibanaServices(core, deps);
registerCreateFieldListAction(deps.uiActions);
registerFieldListPanelPlacementSetting(deps.dashboard);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 {
ContentManagementServicesDefinition as ServicesDefinition,
Version,
} from '@kbn/object-versioning';

import { serviceDefinition as v1 } from './v1';

export const cmServicesDefinition: { [version: Version]: ServicesDefinition } = {
1: v1,
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export type { BookAttributes } from './types';
export { bookAttributesSchema } from './schema';
export { SavedBookStorage } from './saved_book_storage';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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 * from './v1';
Loading