From 8ed19f2c428ce0b26afc7ea4d74998846351102d Mon Sep 17 00:00:00 2001 From: Stacey Gammon Date: Thu, 10 Oct 2019 10:03:49 -0400 Subject: [PATCH] Don't throw an error is panel is added, then removed, before embeddable finishes loading (#46788) (#47818) * Remove this error being thrown as it can be expected in certain situations * change test after change in logic --- src/plugins/embeddable/public/lib/containers/container.ts | 5 ++--- src/plugins/embeddable/public/tests/container.test.ts | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/plugins/embeddable/public/lib/containers/container.ts b/src/plugins/embeddable/public/lib/containers/container.ts index f4fca4bbd8d6e..bce16747ed48e 100644 --- a/src/plugins/embeddable/public/lib/containers/container.ts +++ b/src/plugins/embeddable/public/lib/containers/container.ts @@ -181,11 +181,10 @@ export abstract class Container< resolve(this.children[id] as TEmbeddable); } - // If a panel is removed before the embeddable was loaded there is a chance this will - // never resolve. + // If we hit this, the panel was removed before the embeddable finished loading. if (this.input.panels[id] === undefined) { subscription.unsubscribe(); - reject(new PanelNotFoundError()); + resolve(undefined); } }); }); diff --git a/src/plugins/embeddable/public/tests/container.test.ts b/src/plugins/embeddable/public/tests/container.test.ts index c2044057786ae..3bdbcbad857d6 100644 --- a/src/plugins/embeddable/public/tests/container.test.ts +++ b/src/plugins/embeddable/public/tests/container.test.ts @@ -27,7 +27,6 @@ import { } from '../lib/test_samples/embeddables/filterable_embeddable'; import { ERROR_EMBEDDABLE_TYPE } from '../lib/embeddables/error_embeddable'; import { Filter, FilterStateStore } from '@kbn/es-query'; -import { PanelNotFoundError } from '../lib/errors'; import { FilterableEmbeddableFactory } from '../lib/test_samples/embeddables/filterable_embeddable_factory'; import { CONTACT_CARD_EMBEDDABLE } from '../lib/test_samples/embeddables/contact_card/contact_card_embeddable_factory'; import { SlowContactCardEmbeddableFactory } from '../lib/test_samples/embeddables/contact_card/slow_contact_card_embeddable_factory'; @@ -753,7 +752,7 @@ test('untilEmbeddableLoaded() resolves if child is loaded in the container', asy done(); }); -test('untilEmbeddableLoaded rejects with an error if child is subsequently removed', async done => { +test('untilEmbeddableLoaded resolves with undefined if child is subsequently removed', async done => { const { doStart, coreStart, uiActions } = testPlugin( coreMock.createSetup(), coreMock.createStart() @@ -785,8 +784,8 @@ test('untilEmbeddableLoaded rejects with an error if child is subsequently remov } ); - container.untilEmbeddableLoaded('123').catch(error => { - expect(error).toBeInstanceOf(PanelNotFoundError); + container.untilEmbeddableLoaded('123').then(embed => { + expect(embed).toBeUndefined(); done(); });