Enhance telemetry tables to allow in place updates for data (#6694)

* cherry-pick(#6602) : [ExportAsJson] Multiple Aliases in Export and Co… (#6658)

cherry-pick(#6602) : [ExportAsJson] Multiple Aliases in Export and Conditional Styles Fixes (#6602)

Fixes issues that prevent import and export from being completed successfully. Specifically:

* if multiple aliases are detected, the first is created as a new object and and added to it's parent's composition, any subsequent aliases of the same object will not be recreated, but the originally created one will be added to the current parent's composition, creating an alias.

* Also, there are cases were conditionSetIdentifiers are stored in an object keyed by an item id in the configuration.objectstyles object, this fix will handle these as well.

* Replaces an errant `return` statement with a `continue` statement to prevent early exit from a recursive function.

---------

Co-authored-by: Andrew Henry <akhenry@gmail.com>

* chore: bump version to `2.2.3` (#6685)

* Add configuration detection to update table rows in place

* Fix typo for datum access

* First add new rows to the table and then update rows in place

* Each row much be checked for in place updates and inserted as needed

* Fix typo. Remove unused code.

* Update datum only. And don't allow undefined values for columns

* Fix typo

* Rename function for clarity

* Use telemetry metadata to indicate datum property to use for in place updates

* Fix typo for method call

* Fix typo for return value

* fullDatum is the datum BEFORE normalizing.

---------

Co-authored-by: Jamie V <jamie.j.vigliotta@nasa.gov>
Co-authored-by: Andrew Henry <akhenry@gmail.com>
Co-authored-by: John Hill <john.c.hill@nasa.gov>
This commit is contained in:
Shefali Joshi 2023-07-14 14:51:23 -07:00 committed by GitHub
parent 6e79e5e2b0
commit e386036dbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 95 additions and 18 deletions

View File

@ -134,6 +134,14 @@ define(['lodash'], function (_) {
);
};
TelemetryMetadataManager.prototype.getUseToUpdateInPlaceValue = function () {
return this.valueMetadatas.find(this.isInPlaceUpdateValue);
};
TelemetryMetadataManager.prototype.isInPlaceUpdateValue = function (metadatum) {
return metadatum.useToUpdateInPlace === true;
};
TelemetryMetadataManager.prototype.getDefaultDisplayValue = function () {
let valueMetadata = this.valuesForHints(['range'])[0];

View File

@ -215,8 +215,13 @@ define([
return;
}
const metadataValue = this.openmct.telemetry
.getMetadata(this.telemetryObjects[keyString].telemetryObject)
.getUseToUpdateInPlaceValue();
let telemetryRows = telemetry.map(
(datum) => new TelemetryTableRow(datum, columnMap, keyString, limitEvaluator)
(datum) =>
new TelemetryTableRow(datum, columnMap, keyString, limitEvaluator, metadataValue?.key)
);
if (this.paused) {
@ -268,8 +273,14 @@ define([
Object.keys(this.telemetryCollections).forEach((keyString) => {
let { columnMap, limitEvaluator } = this.telemetryObjects[keyString];
const metadataValue = this.openmct.telemetry
.getMetadata(this.telemetryObjects[keyString].telemetryObject)
.getUseToUpdateInPlaceValue();
this.telemetryCollections[keyString].getAll().forEach((datum) => {
allRows.push(new TelemetryTableRow(datum, columnMap, keyString, limitEvaluator));
allRows.push(
new TelemetryTableRow(datum, columnMap, keyString, limitEvaluator, metadataValue?.key)
);
});
});
@ -321,11 +332,12 @@ define([
}
addColumnsForObject(telemetryObject) {
let metadataValues = this.openmct.telemetry.getMetadata(telemetryObject).values();
const metadata = this.openmct.telemetry.getMetadata(telemetryObject);
let metadataValues = metadata.values();
this.addNameColumn(telemetryObject, metadataValues);
metadataValues.forEach((metadatum) => {
if (metadatum.key === 'name') {
if (metadatum.key === 'name' || metadata.isInPlaceUpdateValue(metadatum)) {
return;
}

View File

@ -22,13 +22,14 @@
define([], function () {
class TelemetryTableRow {
constructor(datum, columns, objectKeyString, limitEvaluator) {
constructor(datum, columns, objectKeyString, limitEvaluator, inPlaceUpdateKey) {
this.columns = columns;
this.datum = createNormalizedDatum(datum, columns);
this.fullDatum = datum;
this.limitEvaluator = limitEvaluator;
this.objectKeyString = objectKeyString;
this.inPlaceUpdateKey = inPlaceUpdateKey;
}
getFormattedDatum(headers) {
@ -88,6 +89,18 @@ define([], function () {
getContextMenuActions() {
return ['viewDatumAction', 'viewHistoricalData'];
}
updateWithDatum(updatesToDatum) {
const normalizedUpdatesToDatum = createNormalizedDatum(updatesToDatum, this.columns);
this.datum = {
...this.datum,
...normalizedUpdatesToDatum
};
this.fullDatum = {
...this.fullDatum,
...updatesToDatum
};
}
}
/**
@ -101,7 +114,10 @@ define([], function () {
const normalizedDatum = JSON.parse(JSON.stringify(datum));
Object.values(columns).forEach((column) => {
normalizedDatum[column.getKey()] = column.getRawValue(datum);
const rawValue = column.getRawValue(datum);
if (rawValue !== undefined) {
normalizedDatum[column.getKey()] = rawValue;
}
});
return normalizedDatum;

View File

@ -85,28 +85,49 @@ define(['lodash', 'EventEmitter'], function (_, EventEmitter) {
}
sortAndMergeRows(rows) {
const sortedRowsToAdd = this.sortCollection(rows);
const sortedRows = this.sortCollection(rows);
if (this.rows.length === 0) {
this.rows = sortedRowsToAdd;
this.rows = sortedRows;
return;
}
const firstIncomingRow = sortedRowsToAdd[0];
const lastIncomingRow = sortedRowsToAdd[sortedRowsToAdd.length - 1];
const firstIncomingRow = sortedRows[0];
const lastIncomingRow = sortedRows[sortedRows.length - 1];
const firstExistingRow = this.rows[0];
const lastExistingRow = this.rows[this.rows.length - 1];
if (this.firstRowInSortOrder(lastIncomingRow, firstExistingRow) === lastIncomingRow) {
this.rows = [...sortedRowsToAdd, ...this.rows];
this.insertOrUpdateRows(sortedRows, true);
} else if (this.firstRowInSortOrder(lastExistingRow, firstIncomingRow) === lastExistingRow) {
this.rows = [...this.rows, ...sortedRowsToAdd];
this.insertOrUpdateRows(sortedRows, false);
} else {
this.mergeSortedRows(sortedRowsToAdd);
this.mergeSortedRows(sortedRows);
}
}
getInPlaceUpdateIndex(row) {
const inPlaceUpdateKey = row.inPlaceUpdateKey;
if (!inPlaceUpdateKey) {
return -1;
}
const foundIndex = this.rows.findIndex(
(existingRow) =>
existingRow.datum[inPlaceUpdateKey] &&
existingRow.datum[inPlaceUpdateKey] === row.datum[inPlaceUpdateKey]
);
return foundIndex;
}
updateRowInPlace(row, index) {
const foundRow = this.rows[index];
foundRow.updateWithDatum(row.datum);
this.rows[index] = foundRow;
}
sortCollection(rows) {
const sortedRows = _.orderBy(
rows,
@ -117,6 +138,21 @@ define(['lodash', 'EventEmitter'], function (_, EventEmitter) {
return sortedRows;
}
insertOrUpdateRows(rowsToAdd, addToBeginning) {
rowsToAdd.forEach((row) => {
const index = this.getInPlaceUpdateIndex(row);
if (index > -1) {
this.updateRowInPlace(row, index);
} else {
if (addToBeginning) {
this.rows.unshift(row);
} else {
this.rows.push(row);
}
}
});
}
mergeSortedRows(rows) {
const mergedRows = [];
let i = 0;
@ -126,12 +162,17 @@ define(['lodash', 'EventEmitter'], function (_, EventEmitter) {
const existingRow = this.rows[i];
const incomingRow = rows[j];
if (this.firstRowInSortOrder(existingRow, incomingRow) === existingRow) {
mergedRows.push(existingRow);
i++;
const index = this.getInPlaceUpdateIndex(incomingRow);
if (index > -1) {
this.updateRowInPlace(incomingRow, index);
} else {
mergedRows.push(incomingRow);
j++;
if (this.firstRowInSortOrder(existingRow, incomingRow) === existingRow) {
mergedRows.push(existingRow);
i++;
} else {
mergedRows.push(incomingRow);
j++;
}
}
}