|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0 and the Server Side Public License, v 1; you may not use this file except |
| 5 | + * in compliance with, at your election, the Elastic License 2.0 or the Server |
| 6 | + * Side Public License, v 1. |
| 7 | + */ |
| 8 | + |
| 9 | +import { i18n } from '@kbn/i18n'; |
| 10 | +import { |
| 11 | + IContainer, |
| 12 | + EmbeddableInput, |
| 13 | + EmbeddableFactoryDefinition, |
| 14 | + EmbeddableFactory, |
| 15 | +} from '../../../../src/plugins/embeddable/public'; |
| 16 | +import { SimpleEmbeddable } from './migrations_embeddable'; |
| 17 | +import { migration730 } from './migration.7.3.0'; |
| 18 | + |
| 19 | +export const SIMPLE_EMBEDDABLE = 'SIMPLE_EMBEDDABLE'; |
| 20 | + |
| 21 | +// in 7.3.0 we added `title` to the input and renamed the `number` variable to `value` |
| 22 | +export type SimpleEmbeddableInput = EmbeddableInput & { |
| 23 | + title: string; |
| 24 | + value: number; |
| 25 | +}; |
| 26 | + |
| 27 | +export type SimpleEmbeddableFactory = EmbeddableFactory; |
| 28 | +export class SimpleEmbeddableFactoryDefinition |
| 29 | + implements EmbeddableFactoryDefinition<SimpleEmbeddableInput> { |
| 30 | + public readonly type = SIMPLE_EMBEDDABLE; |
| 31 | + |
| 32 | + // we need to provide migration function every time we change the interface of our state |
| 33 | + public readonly migrations = { |
| 34 | + '7.3.0': migration730, |
| 35 | + }; |
| 36 | + |
| 37 | + /** |
| 38 | + * In our simple example, we let everyone have permissions to edit this. Most |
| 39 | + * embeddables should check the UI Capabilities service to be sure of |
| 40 | + * the right permissions. |
| 41 | + */ |
| 42 | + public async isEditable() { |
| 43 | + return true; |
| 44 | + } |
| 45 | + |
| 46 | + public async create(initialInput: SimpleEmbeddableInput, parent?: IContainer) { |
| 47 | + return new SimpleEmbeddable(initialInput, parent); |
| 48 | + } |
| 49 | + |
| 50 | + public getDisplayName() { |
| 51 | + return i18n.translate('embeddableExamples.migrations.displayName', { |
| 52 | + defaultMessage: 'hello world', |
| 53 | + }); |
| 54 | + } |
| 55 | +} |
0 commit comments