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 afterEndOfBounds;
let added = [];
let addedIndices = [];
// loop through, sort and dedupe
for (let datum of data) {
@ -212,6 +213,7 @@ export default class TelemetryCollection extends EventEmitter {
let index = endIndex || startIndex;
this.boundedTelemetry.splice(index, 0, datum);
addedIndices.push(index);
added.push(datum);
}
@ -230,7 +232,7 @@ export default class TelemetryCollection extends EventEmitter {
this.emit('add', this.boundedTelemetry);
}
} else {
this.emit('add', added);
this.emit('add', added, addedIndices);
}
}
}
@ -330,7 +332,8 @@ export default class TelemetryCollection extends EventEmitter {
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 {
// user bounds change, reset

View File

@ -76,9 +76,14 @@ export default {
this.telemetryCollection.destroy();
},
methods: {
dataAdded(dataToAdd) {
const normalizedDataToAdd = dataToAdd.map(datum => this.normalizeDatum(datum));
this.imageHistory = this.imageHistory.concat(normalizedDataToAdd);
dataAdded(addedItems, addedItemIndices) {
const normalizedDataToAdd = addedItems.map(datum => this.normalizeDatum(datum));
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() {
this.imageHistory = [];