Skip to content

Commit

Permalink
fixes embeddables migrate function (elastic#101470)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Jun 9, 2021
1 parent 207e950 commit 24f9c40
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/plugins/embeddable/common/lib/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ export const getMigrateFunction = (embeddables: CommonEmbeddableStartContract) =
updatedInput.enhancements = {};
Object.keys(enhancements).forEach((key) => {
if (!enhancements[key]) return;
(updatedInput.enhancements! as Record<string, any>)[key] = embeddables
.getEnhancement(key)
.migrations[version](enhancements[key] as SerializableState);
const enhancementDefinition = embeddables.getEnhancement(key);
const migratedEnhancement = enhancementDefinition?.migrations?.[version]
? enhancementDefinition.migrations[version](enhancements[key] as SerializableState)
: enhancements[key];
(updatedInput.enhancements! as Record<string, any>)[key] = migratedEnhancement;
});

return updatedInput;
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/embeddable/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,12 @@ describe('embeddable enhancements', () => {
embeddableState.enhancements.test
);
});

test('doesnt fail if there is no migration function registered for specific version', () => {
expect(() => {
start.migrate(embeddableState, '7.10.0');
}).not.toThrow();

expect(start.migrate(embeddableState, '7.10.0')).toEqual(embeddableState);
});
});

0 comments on commit 24f9c40

Please sign in to comment.