From 384e36920ca49c551817181dd97ef2806d0d3475 Mon Sep 17 00:00:00 2001 From: Michael Rogers Date: Fri, 18 Feb 2022 08:48:48 -0600 Subject: [PATCH] 3175 - Enable listening to clearData action for Imagery (#4733) * Add clearData listener for imageryData module * Remove commented out code * Updated imagery clear data test * Adjusted telemetry stub to return empty array if data cleared * Remove forced test * Restub telemetry before * Cleanup and reset clear data boolean after * Remove double blank line Co-authored-by: Scott Bell Co-authored-by: Andrew Henry --- index.html | 2 +- src/plugins/clearData/pluginSpec.js | 12 ++++--- src/plugins/imagery/mixins/imageryData.js | 21 ++++++++++++ src/plugins/imagery/pluginSpec.js | 42 +++++++++++++++++++---- 4 files changed, 65 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index 7cbb564cde..3f97d323b8 100644 --- a/index.html +++ b/index.html @@ -190,7 +190,7 @@ openmct.install(openmct.plugins.Filters(['table', 'telemetry.plot.overlay'])); openmct.install(openmct.plugins.ObjectMigration()); openmct.install(openmct.plugins.ClearData( - ['table', 'telemetry.plot.overlay', 'telemetry.plot.stacked'], + ['table', 'telemetry.plot.overlay', 'telemetry.plot.stacked', 'example.imagery'], {indicator: true} )); openmct.install(openmct.plugins.Clock({ enableClockIndicator: true })); diff --git a/src/plugins/clearData/pluginSpec.js b/src/plugins/clearData/pluginSpec.js index 8607899d68..d1bcb195ac 100644 --- a/src/plugins/clearData/pluginSpec.js +++ b/src/plugins/clearData/pluginSpec.js @@ -185,10 +185,14 @@ describe('The Clear Data Plugin:', () => { beforeEach((done) => { openmct = createOpenMct(); - clearDataPlugin = new ClearDataPlugin( - ['table', 'telemetry.plot.overlay', 'telemetry.plot.stacked'], - {indicator: true} - ); + clearDataPlugin = new ClearDataPlugin([ + 'table', + 'telemetry.plot.overlay', + 'telemetry.plot.stacked', + 'example.imagery' + ], { + indicator: true + }); openmct.install(clearDataPlugin); appHolder = document.createElement('div'); document.body.appendChild(appHolder); diff --git a/src/plugins/imagery/mixins/imageryData.js b/src/plugins/imagery/mixins/imageryData.js index ae150ea592..933df01c17 100644 --- a/src/plugins/imagery/mixins/imageryData.js +++ b/src/plugins/imagery/mixins/imageryData.js @@ -30,6 +30,7 @@ export default { this.timeSystemChange = this.timeSystemChange.bind(this); this.setDataTimeContext = this.setDataTimeContext.bind(this); this.setDataTimeContext(); + this.openmct.objectViews.on('clearData', this.clearData); // set this.keyString = this.openmct.objects.makeKeyString(this.domainObject.identifier); @@ -54,6 +55,7 @@ export default { } this.stopFollowingDataTimeContext(); + this.openmct.objectViews.off('clearData', this.clearData); }, methods: { setDataTimeContext() { @@ -151,6 +153,25 @@ export default { this.imageHistory = imagery; } }, + clearData(domainObjectToClear) { + // global clearData button is accepted therefore no truthy check on inputted param + const clearDataForObjectSelected = Boolean(domainObjectToClear); + if (clearDataForObjectSelected) { + const idsEqual = this.openmct.objects.areIdsEqual( + domainObjectToClear.identifier, + this.domainObject.identifier + ); + if (!idsEqual) { + return; + } + } + + // splice array to encourage garbage collection + this.imageHistory.splice(0, this.imageHistory.length); + + // requesting history effectively clears imageHistory array + return this.requestHistory(); + }, timeSystemChange() { this.timeSystem = this.timeContext.timeSystem(); this.timeKey = this.timeSystem.key; diff --git a/src/plugins/imagery/pluginSpec.js b/src/plugins/imagery/pluginSpec.js index 6491a7095f..b41f32072b 100644 --- a/src/plugins/imagery/pluginSpec.js +++ b/src/plugins/imagery/pluginSpec.js @@ -27,6 +27,7 @@ import { resetApplicationState, simulateKeyEvent } from 'utils/testing'; +import ClearDataPlugin from '../clearData/plugin'; const ONE_MINUTE = 1000 * 60; const TEN_MINUTES = ONE_MINUTE * 10; @@ -83,6 +84,7 @@ describe("The Imagery View Layouts", () => { let telemetryPromise; let telemetryPromiseResolve; let cleanupFirst; + let isClearDataTriggered; let openmct; let parent; @@ -201,6 +203,10 @@ describe("The Imagery View Layouts", () => { }); spyOn(openmct.telemetry, 'request').and.callFake(() => { + if (isClearDataTriggered) { + return []; + } + telemetryPromiseResolve(imageTelemetry); return telemetryPromise; @@ -323,6 +329,8 @@ describe("The Imagery View Layouts", () => { let applicableViews; let imageryViewProvider; let imageryView; + let clearDataPlugin; + let clearDataAction; beforeEach(() => { @@ -330,16 +338,21 @@ describe("The Imagery View Layouts", () => { imageryViewProvider = applicableViews.find(viewProvider => viewProvider.key === imageryKey); imageryView = imageryViewProvider.view(imageryObject, [imageryObject]); imageryView.show(child); + clearDataPlugin = new ClearDataPlugin( + ['example.imagery'], + {indicator: true} + ); + openmct.install(clearDataPlugin); + clearDataAction = openmct.actions.getAction('clear-data-action'); return Vue.nextTick(); }); - - // afterEach(() => { - // openmct.time.stopClock(); - // openmct.router.removeListener('change:hash', resolveFunction); - // - // imageryView.destroy(); - // }); + afterEach(() => { + isClearDataTriggered = false; + // openmct.time.stopClock(); + // openmct.router.removeListener('change:hash', resolveFunction); + // imageryView.destroy(); + }); it("on mount should show the the most recent image", (done) => { //Looks like we need Vue.nextTick here so that computed properties settle down @@ -470,6 +483,21 @@ describe("The Imagery View Layouts", () => { }); }); }); + it('clear data action is installed', () => { + expect(clearDataAction).toBeDefined(); + }); + + it('on clearData action should clear data for object is selected', (done) => { + expect(parent.querySelectorAll('.c-imagery__thumb').length).not.toBe(0); + openmct.objectViews.on('clearData', async (_domainObject) => { + await Vue.nextTick(); + expect(parent.querySelectorAll('.c-imagery__thumb').length).toBe(0); + done(); + }); + // stubbed telemetry data will return empty array when true + isClearDataTriggered = true; + clearDataAction.invoke(imageryObject); + }); }); describe("imagery time strip view", () => {