Skip to content

Commit

Permalink
Don't change sort order when changing performance mode (#7810)
Browse files Browse the repository at this point in the history
* adding an option to no swap order to initiatSort

* debug

* defaulting to desc order for requests if there is not saved order

* adding some common constants

* replace all got into a comment

---------

Co-authored-by: Jesse Mazzella <[email protected]>
  • Loading branch information
jvigliotta and ozyx authored Sep 10, 2024
1 parent 440474b commit fccae3b
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/plugins/telemetryTable/TelemetryTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import _ from 'lodash';

import StalenessUtils from '../../utils/staleness.js';
import TableRowCollection from './collections/TableRowCollection.js';
import { MODE, ORDER } from './constants.js';
import TelemetryTableColumn from './TelemetryTableColumn.js';
import TelemetryTableConfiguration from './TelemetryTableConfiguration.js';
import TelemetryTableNameColumn from './TelemetryTableNameColumn.js';
Expand Down Expand Up @@ -119,7 +120,7 @@ export default class TelemetryTable extends EventEmitter {
this.rowLimit = rowLimit;
}

if (this.telemetryMode === 'performance') {
if (this.telemetryMode === MODE.PERFORMANCE) {
this.tableRows.setLimit(this.rowLimit);
} else {
this.tableRows.removeLimit();
Expand All @@ -135,7 +136,7 @@ export default class TelemetryTable extends EventEmitter {
//If no persisted sort order, default to sorting by time system, descending.
sortOptions = sortOptions || {
key: this.openmct.time.getTimeSystem().key,
direction: 'desc'
direction: ORDER.DESCENDING
};

this.updateRowLimit();
Expand Down Expand Up @@ -172,10 +173,9 @@ export default class TelemetryTable extends EventEmitter {
this.removeTelemetryCollection(keyString);

let sortOptions = this.configuration.getConfiguration().sortOptions;
requestOptions.order =
sortOptions?.direction ?? (this.telemetryMode === 'performance' ? 'desc' : 'asc');
requestOptions.order = sortOptions?.direction ?? ORDER.DESCENDING; // default to descending

if (this.telemetryMode === 'performance') {
if (this.telemetryMode === MODE.PERFORMANCE) {
requestOptions.size = this.rowLimit;
requestOptions.enforceSize = true;
}
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/telemetryTable/TelemetryTableType.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/

import { MODE } from './constants.js';

export default function getTelemetryTableType(options) {
let { telemetryMode, persistModeChange, rowLimit } = options;

Expand All @@ -36,11 +38,11 @@ export default function getTelemetryTableType(options) {
control: 'select',
options: [
{
value: 'performance',
value: MODE.PERFORMANCE,
name: 'Limited (Performance) Mode'
},
{
value: 'unlimited',
value: MODE.UNLIMITED,
name: 'Unlimited Mode'
}
],
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/telemetryTable/collections/TableRowCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import { EventEmitter } from 'eventemitter3';
import _ from 'lodash';

import { ORDER } from '../constants.js';
/**
* @constructor
*/
Expand Down Expand Up @@ -208,7 +209,7 @@ export default class TableRowCollection extends EventEmitter {
const val1 = this.getValueForSortColumn(row1);
const val2 = this.getValueForSortColumn(row2);

if (this.sortOptions.direction === 'asc') {
if (this.sortOptions.direction === ORDER.ASCENDING) {
return val1 <= val2 ? row1 : row2;
} else {
return val1 >= val2 ? row1 : row2;
Expand Down Expand Up @@ -373,7 +374,7 @@ export default class TableRowCollection extends EventEmitter {

getRows() {
if (this.rowLimit && this.rows.length > this.rowLimit) {
if (this.sortOptions.direction === 'desc') {
if (this.sortOptions.direction === ORDER.DESCENDING) {
return this.rows.slice(0, this.rowLimit);
} else {
return this.rows.slice(-this.rowLimit);
Expand Down
20 changes: 11 additions & 9 deletions src/plugins/telemetryTable/components/TableComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ import ProgressBar from '../../../ui/components/ProgressBar.vue';
import Search from '../../../ui/components/SearchComponent.vue';
import ToggleSwitch from '../../../ui/components/ToggleSwitch.vue';
import { useResizeObserver } from '../../../ui/composables/resize.js';
import { MODE, ORDER } from '../constants.js';
import SizingRow from './SizingRow.vue';
import TableColumnHeader from './TableColumnHeader.vue';
import TableFooterIndicator from './TableFooterIndicator.vue';
Expand Down Expand Up @@ -713,7 +714,7 @@ export default {
sortBy(columnKey) {
let timeSystemKey = this.openmct.time.getTimeSystem().key;

if (this.telemetryMode === 'performance' && columnKey !== timeSystemKey) {
if (this.telemetryMode === MODE.PERFORMANCE && columnKey !== timeSystemKey) {
this.confirmUnlimitedMode('Switch to Unlimited Telemetry and Sort', () => {
this.initiateSort(columnKey);
});
Expand All @@ -724,15 +725,15 @@ export default {
initiateSort(columnKey) {
// If sorting by the same column, flip the sort direction.
if (this.sortOptions.key === columnKey) {
if (this.sortOptions.direction === 'asc') {
this.sortOptions.direction = 'desc';
if (this.sortOptions.direction === ORDER.ASCENDING) {
this.sortOptions.direction = ORDER.DESCENDING;
} else {
this.sortOptions.direction = 'asc';
this.sortOptions.direction = ORDER.ASCENDING;
}
} else {
this.sortOptions = {
key: columnKey,
direction: 'desc'
direction: ORDER.DESCENDING
};
}

Expand All @@ -751,7 +752,7 @@ export default {
}
},
shouldAutoScroll() {
if (this.sortOptions.direction === 'desc') {
if (this.sortOptions.direction === ORDER.DESCENDING) {
return false;
}

Expand Down Expand Up @@ -844,7 +845,7 @@ export default {
return justTheData;
},
exportAllDataAsCSV() {
if (this.telemetryMode === 'performance') {
if (this.telemetryMode === MODE.PERFORMANCE) {
this.confirmUnlimitedMode('Switch to Unlimited Telemetry and Export', () => {
const data = this.getTableRowData();

Expand Down Expand Up @@ -1226,7 +1227,8 @@ export default {
});
},
updateTelemetryMode() {
this.telemetryMode = this.telemetryMode === 'unlimited' ? 'performance' : 'unlimited';
this.telemetryMode =
this.telemetryMode === MODE.UNLIMITED ? MODE.PERFORMANCE : MODE.UNLIMITED;

if (this.persistModeChange) {
this.table.configuration.setTelemetryMode(this.telemetryMode);
Expand All @@ -1236,7 +1238,7 @@ export default {

const timeSystemKey = this.openmct.time.getTimeSystem().key;

if (this.telemetryMode === 'performance' && this.sortOptions.key !== timeSystemKey) {
if (this.telemetryMode === MODE.PERFORMANCE && this.sortOptions.key !== timeSystemKey) {
this.openmct.notifications.info(
'Switched to Performance Mode: Table now sorted by time for optimized efficiency.'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
<script>
import _ from 'lodash';

import { MODE } from '../constants.js';

const FILTER_INDICATOR_LABEL = 'Filters:';
const FILTER_INDICATOR_LABEL_MIXED = 'Mixed Filters:';
const FILTER_INDICATOR_TITLE = 'Data filters are being applied to this view.';
Expand All @@ -81,7 +83,7 @@ export default {
},
telemetryMode: {
type: String,
default: 'performance'
default: MODE.PERFORMANCE
}
},
emits: ['telemetry-mode-change'],
Expand All @@ -103,7 +105,7 @@ export default {
});
},
isUnlimitedMode() {
return this.telemetryMode === 'unlimited';
return this.telemetryMode === MODE.UNLIMITED;
},
label() {
if (this.hasMixedFilters) {
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/telemetryTable/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const ORDER = {
ASCENDING: 'asc',
DESCENDING: 'desc'
};

const MODE = {
PERFORMANCE: 'performance',
UNLIMITED: 'unlimited'
};

export { MODE, ORDER };
3 changes: 2 additions & 1 deletion src/plugins/telemetryTable/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/

import { MODE } from './constants.js';
import TableConfigurationViewProvider from './TableConfigurationViewProvider.js';
import getTelemetryTableType from './TelemetryTableType.js';
import TelemetryTableViewProvider from './TelemetryTableViewProvider.js';
import TelemetryTableViewActions from './ViewActions.js';

export default function plugin(
options = { telemetryMode: 'performance', persistModeChange: true, rowLimit: 50 }
options = { telemetryMode: MODE.PERFORMANCE, persistModeChange: true, rowLimit: 50 }
) {
return function install(openmct) {
openmct.objectViews.addProvider(new TelemetryTableViewProvider(openmct, options));
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/telemetryTable/pluginSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from 'utils/testing';
import { nextTick } from 'vue';

import { MODE } from './constants.js';
import TablePlugin from './plugin.js';

class MockDataTransfer {
Expand Down Expand Up @@ -198,7 +199,7 @@ describe('the plugin', () => {
},
persistModeChange: true,
rowLimit: 50,
telemetryMode: 'performance'
telemetryMode: MODE.PERFORMANCE
}
};
const testTelemetry = [
Expand Down

0 comments on commit fccae3b

Please sign in to comment.