From 8655434e4b98dd60c8999c9bb4ee8906d5a22f74 Mon Sep 17 00:00:00 2001
From: Jamie V <jamie.j.vigliotta@nasa.gov>
Date: Mon, 3 Mar 2025 14:23:25 -0800
Subject: [PATCH] update previous interceptors and add for stacked plot

---
 .../conditionWidgetStylesInterceptor.js       |  5 ++--
 .../overlayPlotStylesInterceptor.js           |  5 ++--
 src/plugins/plot/plugin.js                    |  4 ++--
 src/plugins/plot/stackedPlot/StackedPlot.vue  |  5 ----
 .../stackedPlotConfigurationInterceptor.js    | 23 +++++++++++++++----
 5 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/src/plugins/conditionWidget/conditionWidgetStylesInterceptor.js b/src/plugins/conditionWidget/conditionWidgetStylesInterceptor.js
index a6e29ff4eb..6a8aa4bf71 100644
--- a/src/plugins/conditionWidget/conditionWidgetStylesInterceptor.js
+++ b/src/plugins/conditionWidget/conditionWidgetStylesInterceptor.js
@@ -23,7 +23,7 @@
 export default function conditionWidgetStylesInterceptor(openmct) {
   return {
     appliesTo: (identifier, domainObject) => {
-      return identifier.key === 'conditionWidget' && !domainObject.configuration?.objectStyles;
+      return domainObject.type === 'conditionWidget' && !domainObject?.configuration?.objectStyles;
     },
     invoke: (identifier, domainObject) => {
       if (!domainObject.configuration) {
@@ -35,7 +35,6 @@ export default function conditionWidgetStylesInterceptor(openmct) {
       openmct.objects.save(domainObject);
 
       return domainObject;
-    },
-    priority: openmct.priority.DEFAULT
+    }
   };
 }
diff --git a/src/plugins/plot/overlayPlot/overlayPlotStylesInterceptor.js b/src/plugins/plot/overlayPlot/overlayPlotStylesInterceptor.js
index 88a56e5f6a..d910f66f23 100644
--- a/src/plugins/plot/overlayPlot/overlayPlotStylesInterceptor.js
+++ b/src/plugins/plot/overlayPlot/overlayPlotStylesInterceptor.js
@@ -24,7 +24,7 @@ export default function overlayPlotStylesInterceptor(openmct) {
   return {
     appliesTo: (identifier, domainObject) => {
       return (
-        identifier.key === 'telemetry.plot.overlay' && !domainObject.configuration?.objectStyles
+        domainObject.type === 'telemetry.plot.overlay' && !domainObject?.configuration?.objectStyles
       );
     },
     invoke: (identifier, domainObject) => {
@@ -37,7 +37,6 @@ export default function overlayPlotStylesInterceptor(openmct) {
       openmct.objects.save(domainObject);
 
       return domainObject;
-    },
-    priority: openmct.priority.DEFAULT
+    }
   };
 }
diff --git a/src/plugins/plot/plugin.js b/src/plugins/plot/plugin.js
index ac3fbd047e..49fa6ece57 100644
--- a/src/plugins/plot/plugin.js
+++ b/src/plugins/plot/plugin.js
@@ -32,8 +32,6 @@ import StackedPlotViewProvider from './stackedPlot/StackedPlotViewProvider.js';
 
 export default function () {
   return function install(openmct) {
-    openmct.objects.addGetInterceptor(overlayPlotStylesInterceptor(openmct));
-
     openmct.types.addType('telemetry.plot.overlay', {
       key: 'telemetry.plot.overlay',
       name: 'Overlay Plot',
@@ -53,6 +51,8 @@ export default function () {
       priority: 891
     });
 
+    openmct.objects.addGetInterceptor(overlayPlotStylesInterceptor(openmct));
+
     openmct.types.addType('telemetry.plot.stacked', {
       key: 'telemetry.plot.stacked',
       name: 'Stacked Plot',
diff --git a/src/plugins/plot/stackedPlot/StackedPlot.vue b/src/plugins/plot/stackedPlot/StackedPlot.vue
index d3fe03d332..b87fb0d8b9 100644
--- a/src/plugins/plot/stackedPlot/StackedPlot.vue
+++ b/src/plugins/plot/stackedPlot/StackedPlot.vue
@@ -147,11 +147,6 @@ export default {
     this.config = this.getConfig(configId);
     this.showLegendsForChildren = this.config.legend.get('showLegendsForChildren');
 
-    // Initialize objectStyles if it doesn't exist
-    if (!this.domainObject.configuration.objectStyles) {
-      this.domainObject.configuration.objectStyles = {};
-    }
-
     this.loaded = true;
     this.imageExporter = new ImageExporter(this.openmct);
 
diff --git a/src/plugins/plot/stackedPlot/stackedPlotConfigurationInterceptor.js b/src/plugins/plot/stackedPlot/stackedPlotConfigurationInterceptor.js
index e1dbc1c808..43e59a155c 100644
--- a/src/plugins/plot/stackedPlot/stackedPlotConfigurationInterceptor.js
+++ b/src/plugins/plot/stackedPlot/stackedPlotConfigurationInterceptor.js
@@ -23,14 +23,27 @@
 export default function stackedPlotConfigurationInterceptor(openmct) {
   openmct.objects.addGetInterceptor({
     appliesTo: (identifier, domainObject) => {
-      return domainObject && domainObject.type === 'telemetry.plot.stacked';
+      return (
+        domainObject.type === 'telemetry.plot.stacked' &&
+        (!domainObject.configuration?.series || !domainObject.configuration?.objectStyles)
+      );
     },
-    invoke: (identifier, object) => {
-      if (object && object.configuration && object.configuration.series === undefined) {
-        object.configuration.series = [];
+    invoke: (identifier, domainObject) => {
+      if (!domainObject.configuration) {
+        domainObject.configuration = {};
       }
 
-      return object;
+      if (!domainObject.configuration.series) {
+        domainObject.configuration.series = [];
+      }
+
+      if (!domainObject.configuration.objectStyles) {
+        domainObject.configuration.objectStyles = {};
+      }
+
+      openmct.objects.save(domainObject);
+
+      return domainObject;
     }
   });
 }