mirror of
https://github.com/nasa/openmct.git
synced 2025-06-17 06:38:17 +00:00
Prevent infinite loop when updating a table row in place (#7154)
* bump index on update row in place * add test * Removing problematic test * spelling
This commit is contained in:
@ -153,40 +153,41 @@ define(['lodash', 'EventEmitter'], function (_, EventEmitter) {
|
||||
});
|
||||
}
|
||||
|
||||
mergeSortedRows(rows) {
|
||||
mergeSortedRows(incomingRows) {
|
||||
const mergedRows = [];
|
||||
let i = 0;
|
||||
let j = 0;
|
||||
let existingRowIndex = 0;
|
||||
let incomingRowIndex = 0;
|
||||
|
||||
while (i < this.rows.length && j < rows.length) {
|
||||
const existingRow = this.rows[i];
|
||||
const incomingRow = rows[j];
|
||||
while (existingRowIndex < this.rows.length && incomingRowIndex < incomingRows.length) {
|
||||
const existingRow = this.rows[existingRowIndex];
|
||||
const incomingRow = incomingRows[incomingRowIndex];
|
||||
|
||||
const index = this.getInPlaceUpdateIndex(incomingRow);
|
||||
if (index > -1) {
|
||||
this.updateRowInPlace(incomingRow, index);
|
||||
const inPlaceIndex = this.getInPlaceUpdateIndex(incomingRow);
|
||||
if (inPlaceIndex > -1) {
|
||||
this.updateRowInPlace(incomingRow, inPlaceIndex);
|
||||
incomingRowIndex++;
|
||||
} else {
|
||||
if (this.firstRowInSortOrder(existingRow, incomingRow) === existingRow) {
|
||||
mergedRows.push(existingRow);
|
||||
i++;
|
||||
existingRowIndex++;
|
||||
} else {
|
||||
mergedRows.push(incomingRow);
|
||||
j++;
|
||||
incomingRowIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// tail of existing rows is all that is left to merge
|
||||
if (i < this.rows.length) {
|
||||
for (i; i < this.rows.length; i++) {
|
||||
mergedRows.push(this.rows[i]);
|
||||
if (existingRowIndex < this.rows.length) {
|
||||
for (existingRowIndex; existingRowIndex < this.rows.length; existingRowIndex++) {
|
||||
mergedRows.push(this.rows[existingRowIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
// tail of incoming rows is all that is left to merge
|
||||
if (j < rows.length) {
|
||||
for (j; j < rows.length; j++) {
|
||||
mergedRows.push(rows[j]);
|
||||
if (incomingRowIndex < incomingRows.length) {
|
||||
for (incomingRowIndex; incomingRowIndex < incomingRows.length; incomingRowIndex++) {
|
||||
mergedRows.push(incomingRows[incomingRowIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user