Skip to content

Commit

Permalink
Move sort order boilerplate to configuration class
Browse files Browse the repository at this point in the history
  • Loading branch information
akhenry committed Oct 10, 2024
1 parent 142805b commit bffae44
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
29 changes: 7 additions & 22 deletions src/plugins/telemetryTable/TelemetryTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -135,15 +130,11 @@ 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;
const sortOptions = this.configuration.getSortOptions();

this.updateRowLimit();

this.tableRows.sortBy(this.sortOptions);
this.tableRows.sortBy(sortOptions);
this.tableRows.on('resetRowsFromAllData', this.resetRowsFromAllData);
}

Expand Down Expand Up @@ -174,8 +165,8 @@ export default class TelemetryTable extends EventEmitter {

this.removeTelemetryCollection(keyString);

let sortOptions = this.configuration.getConfiguration().sortOptions;
requestOptions.order = sortOptions?.direction ?? this.sortOptions.direction;
let sortOptions = this.configuration.getSortOptions();
requestOptions.order = sortOptions.direction;

if (this.telemetryMode === MODE.PERFORMANCE) {
requestOptions.size = this.rowLimit;
Expand Down Expand Up @@ -444,19 +435,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);

Check warning on line 444 in src/plugins/telemetryTable/TelemetryTable.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/telemetryTable/TelemetryTable.js#L444

Added line #L444 was not covered by tests
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/plugins/telemetryTable/TelemetryTableConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -44,6 +48,26 @@ export default class TelemetryTableConfiguration extends EventEmitter {
this.notPersistable = !this.openmct.objects.isPersistable(this.domainObject.identifier);
}

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

getConfiguration() {
let configuration = this.domainObject.configuration || {};
configuration.hiddenColumns = configuration.hiddenColumns || {};
Expand Down

0 comments on commit bffae44

Please sign in to comment.