Discard old telemetry values in tables when date is formatted as a string (#2400)

* Parse date values before comparison in BoundedTableRowCollection

* Reset table size when filter changes
This commit is contained in:
Andrew Henry 2019-05-23 14:42:37 -07:00 committed by Deep Tailor
parent abd7506b45
commit 35d0c02bc5
3 changed files with 36 additions and 23 deletions

View File

@ -31,7 +31,7 @@ define(
) { ) {
class BoundedTableRowCollection extends SortedTableRowCollection { class BoundedTableRowCollection extends SortedTableRowCollection {
constructor (openmct) { constructor(openmct) {
super(); super();
this.futureBuffer = new SortedTableRowCollection(); this.futureBuffer = new SortedTableRowCollection();
@ -46,12 +46,13 @@ define(
openmct.time.on('bounds', this.bounds); openmct.time.on('bounds', this.bounds);
} }
addOne (item) { addOne(item) {
let parsedValue = this.getValueForSortColumn(item);
// Insert into either in-bounds array, or the future buffer. // Insert into either in-bounds array, or the future buffer.
// Data in the future buffer will be re-evaluated for possible // Data in the future buffer will be re-evaluated for possible
// insertion on next bounds change // insertion on next bounds change
let beforeStartOfBounds = this.parseTime(item.datum[this.sortOptions.key]) < this.lastBounds.start; let beforeStartOfBounds = parsedValue < this.lastBounds.start;
let afterEndOfBounds = this.parseTime(item.datum[this.sortOptions.key]) > this.lastBounds.end; let afterEndOfBounds = parsedValue > this.lastBounds.end;
if (!afterEndOfBounds && !beforeStartOfBounds) { if (!afterEndOfBounds && !beforeStartOfBounds) {
return super.addOne(item); return super.addOne(item);
@ -86,7 +87,7 @@ define(
* @fires TelemetryCollection#discarded * @fires TelemetryCollection#discarded
* @param bounds * @param bounds
*/ */
bounds (bounds) { bounds(bounds) {
let startChanged = this.lastBounds.start !== bounds.start; let startChanged = this.lastBounds.start !== bounds.start;
let endChanged = this.lastBounds.end !== bounds.end; let endChanged = this.lastBounds.end !== bounds.end;
@ -135,9 +136,13 @@ define(
} }
} }
getValueForSortColumn(row) {
return this.parseTime(row.datum[this.sortOptions.key]);
}
destroy() { destroy() {
this.openmct.time.off('bounds', this.bounds); this.openmct.time.off('bounds', this.bounds);
} }
} }
return BoundedTableRowCollection; return BoundedTableRowCollection;
}); });

View File

@ -116,10 +116,9 @@ define(
return 0; return 0;
} }
const sortOptionsKey = this.sortOptions.key; const testRowValue = this.getValueForSortColumn(testRow);
const testRowValue = testRow.datum[sortOptionsKey]; const firstValue = this.getValueForSortColumn(this.rows[0]);
const firstValue = this.rows[0].datum[sortOptionsKey]; const lastValue = this.getValueForSortColumn(this.rows[this.rows.length - 1]);
const lastValue = this.rows[this.rows.length - 1].datum[sortOptionsKey];
lodashFunction = lodashFunction || _.sortedIndex; lodashFunction = lodashFunction || _.sortedIndex;
@ -133,7 +132,7 @@ define(
return 0; return 0;
} else { } else {
return lodashFunction(rows, testRow, (thisRow) => { return lodashFunction(rows, testRow, (thisRow) => {
return thisRow.datum[sortOptionsKey]; return this.getValueForSortColumn(thisRow);
}); });
} }
} else { } else {
@ -147,7 +146,7 @@ define(
} else { } else {
// Use a custom comparison function to support descending sort. // Use a custom comparison function to support descending sort.
return lodashFunction(rows, testRow, (thisRow) => { return lodashFunction(rows, testRow, (thisRow) => {
const thisRowValue = thisRow.datum[sortOptionsKey]; const thisRowValue = this.getValueForSortColumn(thisRow);
if (testRowValue === thisRowValue) { if (testRowValue === thisRowValue) {
return EQUAL; return EQUAL;
} else if (testRowValue < thisRowValue) { } else if (testRowValue < thisRowValue) {
@ -218,25 +217,32 @@ define(
} }
return true; return true;
}); });
this.emit('remove', removed); this.emit('remove', removed);
} }
getValueForSortColumn(row) {
return row.datum[this.sortOptions.key];
}
remove(removedRows) { remove(removedRows) {
this.rows = this.rows.filter(row => { this.rows = this.rows.filter(row => {
return removedRows.indexOf(row) === -1; return removedRows.indexOf(row) === -1;
}); });
this.emit('remove', removedRows); this.emit('remove', removedRows);
} }
getRows () { getRows() {
return this.rows; return this.rows;
} }
clear() { clear() {
let removedRows = this.rows; let removedRows = this.rows;
this.rows = []; this.rows = [];
this.emit('remove', removedRows); this.emit('remove', removedRows);
} }
} }
return SortedTableRowCollection; return SortedTableRowCollection;
}); });

View File

@ -472,10 +472,12 @@ export default {
}, },
filterChanged(columnKey) { filterChanged(columnKey) {
this.table.filteredRows.setColumnFilter(columnKey, this.filters[columnKey]); this.table.filteredRows.setColumnFilter(columnKey, this.filters[columnKey]);
this.setHeight();
}, },
clearFilter(columnKey) { clearFilter(columnKey) {
this.filters[columnKey] = ''; this.filters[columnKey] = '';
this.table.filteredRows.setColumnFilter(columnKey, ''); this.table.filteredRows.setColumnFilter(columnKey, '');
this.setHeight();
}, },
rowsAdded (rows) { rowsAdded (rows) {
this.setHeight(); this.setHeight();