Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Telemetry Tables] Fix sort issues #7875

Merged
merged 12 commits into from
Oct 10, 2024
26 changes: 10 additions & 16 deletions src/plugins/telemetryTable/TelemetryTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

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';
Expand Down Expand Up @@ -130,14 +130,7 @@
createTableRowCollections() {
this.tableRows = new TableRowCollection();

//Fetch any persisted default sort
let sortOptions = this.configuration.getConfiguration().sortOptions;

//If no persisted sort order, default to sorting by time system, descending.
sortOptions = sortOptions || {
key: this.openmct.time.getTimeSystem().key,
direction: ORDER.DESCENDING
};
const sortOptions = this.configuration.getSortOptions();

this.updateRowLimit();

Expand Down Expand Up @@ -172,8 +165,8 @@

this.removeTelemetryCollection(keyString);

let sortOptions = this.configuration.getConfiguration().sortOptions;
requestOptions.order = sortOptions?.direction ?? ORDER.DESCENDING; // default to descending
let sortOptions = this.configuration.getSortOptions();
requestOptions.order = sortOptions.direction;

if (this.telemetryMode === MODE.PERFORMANCE) {
requestOptions.size = this.rowLimit;
Expand Down Expand Up @@ -442,12 +435,13 @@
}

sortBy(sortOptions) {
this.tableRows.sortBy(sortOptions);
this.configuration.setSortOptions(sortOptions);

if (this.openmct.editor.isEditing()) {
let configuration = this.configuration.getConfiguration();
configuration.sortOptions = sortOptions;
this.configuration.updateConfiguration(configuration);
if (this.telemetryMode === MODE.PERFORMANCE) {
this.tableRows.setSortOptions(sortOptions);
this.clearAndResubscribe();
} else {
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
6 changes: 5 additions & 1 deletion src/plugins/telemetryTable/collections/TableRowCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export default class TableRowCollection extends EventEmitter {
*/
sortBy(sortOptions) {
if (arguments.length > 0) {
this.sortOptions = sortOptions;
this.setSortOptions(sortOptions);
this.rows = _.orderBy(
this.rows,
(row) => row.getParsedValue(sortOptions.key),
Expand All @@ -286,6 +286,10 @@ export default class TableRowCollection extends EventEmitter {
return Object.assign({}, this.sortOptions);
}

setSortOptions(sortOptions) {
this.sortOptions = sortOptions;
}

setColumnFilter(columnKey, filter) {
filter = filter.trim().toLowerCase();
let wasBlank = this.columnFilters[columnKey] === undefined;
Expand Down
Loading