move get/set of sort options to where it should be in table configuration class

This commit is contained in:
Jamie V 2024-10-11 11:06:12 -07:00
parent 142805b827
commit 978b2ee3f9
2 changed files with 30 additions and 24 deletions

View File

@ -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);
}
}

View File

@ -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();
}