@@ -227,7 +227,7 @@ const props = defineProps({
227227 }
228228});
229229
230- onBeforeMount ( async () => {
230+ function computeMaxSampleSize () {
231231 let maxSampleSize = 20 ;
232232 if (parameters .value ) {
233233 maxSampleSize =
@@ -238,15 +238,31 @@ onBeforeMount(async () => {
238238 return max;
239239 }, 0 ) + 20 ;
240240 }
241+ return maxSampleSize;
242+ }
241243
244+ function createOutputTelemetryCollection (maxSampleSize ) {
242245 const telemetryOptions = {
243246 strategy: ' minmax' ,
244247 size: maxSampleSize
245248 };
249+
246250 // TODO: we should dynamically set size to the largest comp input window
247- outputTelemetryCollection = openmct .telemetry .requestCollection (domainObject, telemetryOptions);
248- outputTelemetryCollection .on (' add' , telemetryProcessor);
249- outputTelemetryCollection .on (' clear' , clearData);
251+ const collection = openmct .telemetry .requestCollection (
252+ domainObject,
253+ telemetryOptions
254+ );
255+
256+ collection .on (' add' , telemetryProcessor);
257+ collection .on (' clear' , clearData);
258+
259+ return collection;
260+ }
261+
262+ onBeforeMount (async () => {
263+ const maxSampleSize = computeMaxSampleSize ();
264+
265+ outputTelemetryCollection = createOutputTelemetryCollection (maxSampleSize);
250266 compsManager .on (' parameterAdded' , reloadParameters);
251267 compsManager .on (' parameterRemoved' , reloadParameters);
252268 compsManager .on (' outputFormatChanged' , updateOutputFormat);
@@ -265,9 +281,9 @@ onBeforeMount(async () => {
265281 resolve ();
266282 }
267283 });
268- // If no requests were started, resolve immediately
269- outputTelemetryCollection .load (telemetryOptions); // will implicitly load compsManager
284+ outputTelemetryCollection .load (); // will implicitly load compsManager
270285
286+ // If no requests were started, resolve immediately
271287 if (outstandingRequests === 0 ) {
272288 resolve ();
273289 }
@@ -283,12 +299,12 @@ onBeforeMount(async () => {
283299});
284300
285301onBeforeUnmount (() => {
286- outputTelemetryCollection .off (' add' , telemetryProcessor);
287- outputTelemetryCollection .off (' clear' , clearData);
288302 compsManager .off (' parameterAdded' , reloadParameters);
289303 compsManager .off (' parameterRemoved' , reloadParameters);
290304 compsManager .off (' outputFormatChanged' , updateOutputFormat);
291- outputTelemetryCollection .destroy ();
305+ if (outputTelemetryCollection) {
306+ outputTelemetryCollection .destroy ();
307+ }
292308});
293309
294310watch (
@@ -410,7 +426,14 @@ function telemetryProcessor(data) {
410426
411427function reload () {
412428 clearData ();
413- outputTelemetryCollection ._requestHistoricalTelemetry ();
429+ if (outputTelemetryCollection) {
430+ outputTelemetryCollection .destroy ();
431+ }
432+
433+ const maxSampleSize = computeMaxSampleSize ();
434+
435+ outputTelemetryCollection = createOutputTelemetryCollection (maxSampleSize);
436+ outputTelemetryCollection .load ();
414437}
415438
416439function clearData () {
0 commit comments