[Canvas] Fix check for "by-ref" embeddable during migration (#135738) (#135745)

(cherry picked from commit 2aec10c6a5)

Co-authored-by: Gerard Soldevila <gerard.soldevila@elastic.co>
This commit is contained in:
Kibana Machine 2022-07-05 16:12:23 -04:00 committed by GitHub
parent 9b1e19c078
commit 995dc2f52f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 6 deletions

View file

@ -56,12 +56,12 @@ export function embeddableFunctionFactory({
migrateFn: MigrateFunction<EmbeddableStateWithType, EmbeddableStateWithType>
): MigrateFunction<ExpressionAstFunction, ExpressionAstFunction> =>
(state: ExpressionAstFunction): ExpressionAstFunction => {
const embeddableInput = decode(state.arguments.config[0] as string);
const embeddableInput = decode(state.arguments.config[0] as string) as EmbeddableInput;
const embeddableType = state.arguments.type[0];
if (embeddableInput.explicitInput.attributes || embeddableInput.explicitInput.savedVis) {
const migratedInput = migrateFn({ ...embeddableInput, type: embeddableType });
if (embeddableInput.savedObjectId === undefined) {
const migratedInput = migrateFn({ ...embeddableInput, type: embeddableType as string });
state.arguments.config[0] = encode(migratedInput);
state.arguments.type[0] = migratedInput.type as string;
}

File diff suppressed because one or more lines are too long

View file

@ -15,10 +15,10 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
it('imports an 8.2 workpad', async function () {
/*
In 8.1 Canvas introduced by value embeddables, which requires expressions to know about embeddable migrations
Starting in 8.3, we were seeing an error during migration where it would appear that an 8.2 workpad was
from a future version. This was because there were missing embeddable migrations on the expression because
Starting in 8.3, we were seeing an error during migration where it would appear that an 8.2 workpad was
from a future version. This was because there were missing embeddable migrations on the expression because
the Canvas plugin was adding the embeddable expression with all of it's migrations before other embeddables had
registered their own migrations.
registered their own migrations.
This smoke test is intended to import an 8.2 workpad to ensure that we don't hit a similar scenario in the future
*/
@ -31,5 +31,20 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await PageObjects.savedObjects.checkImportSucceeded();
await PageObjects.savedObjects.clickImportDone();
});
it('migrates a workpad from 8.1', async function () {
/*
This is a smoke test to make sure migrations don't fail.
This workpad from 8.1 has both by-val and by-ref embeddables
*/
await PageObjects.settings.navigateTo();
await PageObjects.settings.clickKibanaSavedObjects();
await PageObjects.savedObjects.waitTableIsLoaded();
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '8.1.embeddable_test.ndjson')
);
await PageObjects.savedObjects.checkImportSucceeded();
await PageObjects.savedObjects.clickImportDone();
});
});
}