Emit indices of out of order telemetry collection items (#6342)

* Emit the indices of items added by the telemetry collections
* Handle added item indices for imagery
This commit is contained in:
Shefali Joshi 2023-02-14 15:25:23 -08:00 committed by GitHub
parent 8de24a109a
commit 64f300d466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -180,6 +180,7 @@ export default class TelemetryCollection extends EventEmitter {
let beforeStartOfBounds; let beforeStartOfBounds;
let afterEndOfBounds; let afterEndOfBounds;
let added = []; let added = [];
let addedIndices = [];
// loop through, sort and dedupe // loop through, sort and dedupe
for (let datum of data) { for (let datum of data) {
@ -212,6 +213,7 @@ export default class TelemetryCollection extends EventEmitter {
let index = endIndex || startIndex; let index = endIndex || startIndex;
this.boundedTelemetry.splice(index, 0, datum); this.boundedTelemetry.splice(index, 0, datum);
addedIndices.push(index);
added.push(datum); added.push(datum);
} }
@ -230,7 +232,7 @@ export default class TelemetryCollection extends EventEmitter {
this.emit('add', this.boundedTelemetry); this.emit('add', this.boundedTelemetry);
} }
} else { } else {
this.emit('add', added); this.emit('add', added, addedIndices);
} }
} }
} }
@ -330,7 +332,8 @@ export default class TelemetryCollection extends EventEmitter {
this.boundedTelemetry = added; this.boundedTelemetry = added;
} }
this.emit('add', added); // Assumption is that added will be of length 1 here, so just send the last index of the boundedTelemetry in the add event
this.emit('add', added, [this.boundedTelemetry.length]);
} }
} else { } else {
// user bounds change, reset // user bounds change, reset

View File

@ -76,9 +76,14 @@ export default {
this.telemetryCollection.destroy(); this.telemetryCollection.destroy();
}, },
methods: { methods: {
dataAdded(dataToAdd) { dataAdded(addedItems, addedItemIndices) {
const normalizedDataToAdd = dataToAdd.map(datum => this.normalizeDatum(datum)); const normalizedDataToAdd = addedItems.map(datum => this.normalizeDatum(datum));
this.imageHistory = this.imageHistory.concat(normalizedDataToAdd); let newImageHistory = this.imageHistory.slice();
normalizedDataToAdd.forEach(((datum, index) => {
newImageHistory.splice(addedItemIndices[index] ?? -1, 0, datum);
}));
//Assign just once so imageHistory watchers don't get called too often
this.imageHistory = newImageHistory;
}, },
dataCleared() { dataCleared() {
this.imageHistory = []; this.imageHistory = [];