mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 10:40:07 -04:00
[Embeddable] Clientside migration system (#162986)
Changes the versioning scheme used by Dashboard Panels and by value Embeddables, and introduces a new clientside system that can migrate Embeddable Inputs to their latest versions.
This commit is contained in:
parent
10ab42692d
commit
26389e5014
44 changed files with 540 additions and 332 deletions
|
@ -11,20 +11,16 @@ import { EmbeddableInput } from '@kbn/embeddable-plugin/common';
|
|||
import { SimpleEmbeddableInput } from './migrations_embeddable_factory';
|
||||
|
||||
// before 7.3.0 this embeddable received a very simple input with a variable named `number`
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
type SimpleEmbeddableInput_pre7_3_0 = EmbeddableInput & {
|
||||
type SimpleEmbeddableInputV1 = EmbeddableInput & {
|
||||
number: number;
|
||||
};
|
||||
|
||||
type SimpleEmbeddable730MigrateFn = MigrateFunction<
|
||||
SimpleEmbeddableInput_pre7_3_0,
|
||||
SimpleEmbeddableInput
|
||||
>;
|
||||
type SimpleEmbeddable730MigrateFn = MigrateFunction<SimpleEmbeddableInputV1, SimpleEmbeddableInput>;
|
||||
|
||||
// when migrating old state we'll need to set a default title, or we should make title optional in the new state
|
||||
const defaultTitle = 'no title';
|
||||
|
||||
export const migration730: SimpleEmbeddable730MigrateFn = (state) => {
|
||||
export const migrateToVersion2: SimpleEmbeddable730MigrateFn = (state) => {
|
||||
const newState: SimpleEmbeddableInput = { ...state, title: defaultTitle, value: state.number };
|
||||
return newState;
|
||||
};
|
|
@ -15,7 +15,7 @@ import {
|
|||
EmbeddableFactory,
|
||||
} from '@kbn/embeddable-plugin/public';
|
||||
import { SimpleEmbeddable } from './migrations_embeddable';
|
||||
import { migration730 } from './migration.7.3.0';
|
||||
import { migrateToVersion2 } from './migration_definitions';
|
||||
|
||||
export const SIMPLE_EMBEDDABLE = 'SIMPLE_EMBEDDABLE';
|
||||
|
||||
|
@ -30,10 +30,11 @@ export class SimpleEmbeddableFactoryDefinition
|
|||
implements EmbeddableFactoryDefinition<SimpleEmbeddableInput>
|
||||
{
|
||||
public readonly type = SIMPLE_EMBEDDABLE;
|
||||
public latestVersion = '2';
|
||||
|
||||
// we need to provide migration function every time we change the interface of our state
|
||||
public readonly migrations = {
|
||||
'7.3.0': migration730,
|
||||
'2': migrateToVersion2,
|
||||
};
|
||||
|
||||
public extract(state: EmbeddableStateWithType) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue