diff --git a/ui/src/Components/Grid/AlertGrid/index.js b/ui/src/Components/Grid/AlertGrid/index.js index 6d2e498ae..7827e0b44 100644 --- a/ui/src/Components/Grid/AlertGrid/index.js +++ b/ui/src/Components/Grid/AlertGrid/index.js @@ -44,7 +44,7 @@ const AlertGrid = observer( // used to call forcePack() which will repack all grid elements // (alert groups), this needs to be called if any group size changes masonryRepack = action(() => { - if (this.masonryComponentReference.ref !== false) { + if (this.masonryComponentReference.ref) { this.masonryComponentReference.ref.forcePack(); } }); diff --git a/ui/src/Components/Grid/AlertGrid/index.test.js b/ui/src/Components/Grid/AlertGrid/index.test.js index f9d765d24..60d3c36ac 100644 --- a/ui/src/Components/Grid/AlertGrid/index.test.js +++ b/ui/src/Components/Grid/AlertGrid/index.test.js @@ -104,6 +104,24 @@ describe("", () => { expect(repackSpy).toHaveBeenCalled(); }); + it("masonryRepack() doesn't crash when masonryComponentReference.ref=null`", () => { + const tree = ShallowAlertGrid(); + const instance = tree.instance(); + const repackSpy = jest.spyOn(instance, "masonryRepack"); + instance.masonryComponentReference.ref = null; + instance.componentDidUpdate(); + expect(repackSpy).toHaveBeenCalled(); + }); + + it("masonryRepack() doesn't crash when masonryComponentReference.ref=undefined`", () => { + const tree = ShallowAlertGrid(); + const instance = tree.instance(); + const repackSpy = jest.spyOn(instance, "masonryRepack"); + instance.masonryComponentReference.ref = undefined; + instance.componentDidUpdate(); + expect(repackSpy).toHaveBeenCalled(); + }); + it("calling storeMasonryRef() saves the ref in local store", () => { const tree = ShallowAlertGrid(); const instance = tree.instance();