From 978b2ee3f92e045dea6201b0d326952ff3be6ea1 Mon Sep 17 00:00:00 2001 From: Jamie V Date: Fri, 11 Oct 2024 11:06:12 -0700 Subject: [PATCH] move get/set of sort options to where it should be in table configuration class --- src/plugins/telemetryTable/TelemetryTable.js | 30 ++++--------------- .../TelemetryTableConfiguration.js | 24 +++++++++++++++ 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/plugins/telemetryTable/TelemetryTable.js b/src/plugins/telemetryTable/TelemetryTable.js index a72ce89d9f..785bfeb869 100644 --- a/src/plugins/telemetryTable/TelemetryTable.js +++ b/src/plugins/telemetryTable/TelemetryTable.js @@ -25,7 +25,7 @@ import _ from 'lodash'; import StalenessUtils from '../../utils/staleness.js'; import TableRowCollection from './collections/TableRowCollection.js'; -import { MODE, ORDER } from './constants.js'; +import { MODE } from './constants.js'; import TelemetryTableColumn from './TelemetryTableColumn.js'; import TelemetryTableConfiguration from './TelemetryTableConfiguration.js'; import TelemetryTableNameColumn from './TelemetryTableNameColumn.js'; @@ -53,11 +53,6 @@ export default class TelemetryTable extends EventEmitter { this.outstandingRequests = 0; this.stalenessSubscription = {}; - this.sortOptions = { - key: this.openmct.time.getTimeSystem().key, - direction: ORDER.DESCENDING - }; - this.addTelemetryObject = this.addTelemetryObject.bind(this); this.removeTelemetryObject = this.removeTelemetryObject.bind(this); this.removeTelemetryCollection = this.removeTelemetryCollection.bind(this); @@ -135,15 +130,9 @@ export default class TelemetryTable extends EventEmitter { createTableRowCollections() { this.tableRows = new TableRowCollection(); - //Fetch any persisted default sort - const configSortOptions = this.configuration.getConfiguration().sortOptions; - - //If no persisted sort order, use the in-memory sort options - this.sortOptions = configSortOptions || this.sortOptions; - this.updateRowLimit(); - this.tableRows.sortBy(this.sortOptions); + this.tableRows.sortBy(this.configuration.getSortOptions()); this.tableRows.on('resetRowsFromAllData', this.resetRowsFromAllData); } @@ -174,8 +163,7 @@ export default class TelemetryTable extends EventEmitter { this.removeTelemetryCollection(keyString); - let sortOptions = this.configuration.getConfiguration().sortOptions; - requestOptions.order = sortOptions?.direction ?? this.sortOptions.direction; + requestOptions.order = this.configuration.getSortOptions().direction; if (this.telemetryMode === MODE.PERFORMANCE) { requestOptions.size = this.rowLimit; @@ -444,19 +432,13 @@ export default class TelemetryTable extends EventEmitter { } sortBy(sortOptions) { - this.sortOptions = sortOptions; + this.configuration.setSortOptions(sortOptions); if (this.telemetryMode === MODE.PERFORMANCE) { - this.tableRows.setSortOptions(this.sortOptions); + this.tableRows.setSortOptions(sortOptions); this.clearAndResubscribe(); } else { - this.tableRows.sortBy(this.sortOptions); - } - - if (this.openmct.editor.isEditing()) { - let configuration = this.configuration.getConfiguration(); - configuration.sortOptions = this.sortOptions; - this.configuration.updateConfiguration(configuration); + this.tableRows.sortBy(sortOptions); } } diff --git a/src/plugins/telemetryTable/TelemetryTableConfiguration.js b/src/plugins/telemetryTable/TelemetryTableConfiguration.js index 6b9af55f14..2fd42ae9f0 100644 --- a/src/plugins/telemetryTable/TelemetryTableConfiguration.js +++ b/src/plugins/telemetryTable/TelemetryTableConfiguration.js @@ -23,7 +23,11 @@ import { EventEmitter } from 'eventemitter3'; import _ from 'lodash'; +import { ORDER } from './constants'; + export default class TelemetryTableConfiguration extends EventEmitter { + #sortOptions; + constructor(domainObject, openmct, options) { super(); @@ -211,6 +215,26 @@ export default class TelemetryTableConfiguration extends EventEmitter { this.updateConfiguration(configuration); } + getSortOptions() { + return ( + this.#sortOptions || + this.getConfiguration().sortOptions || { + key: this.openmct.time.getTimeSystem().key, + direction: ORDER.DESCENDING + } + ); + } + + setSortOptions(sortOptions) { + this.#sortOptions = sortOptions; + + if (this.openmct.editor.isEditing()) { + let configuration = this.getConfiguration(); + configuration.sortOptions = sortOptions; + this.updateConfiguration(configuration); + } + } + destroy() { this.unlistenFromMutation(); }