mirror of
https://github.com/nasa/openmct.git
synced 2024-12-20 05:37:53 +00:00
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:
parent
6e79e5e2b0
commit
e386036dbf
@ -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 () {
|
TelemetryMetadataManager.prototype.getDefaultDisplayValue = function () {
|
||||||
let valueMetadata = this.valuesForHints(['range'])[0];
|
let valueMetadata = this.valuesForHints(['range'])[0];
|
||||||
|
|
||||||
|
@ -215,8 +215,13 @@ define([
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const metadataValue = this.openmct.telemetry
|
||||||
|
.getMetadata(this.telemetryObjects[keyString].telemetryObject)
|
||||||
|
.getUseToUpdateInPlaceValue();
|
||||||
|
|
||||||
let telemetryRows = telemetry.map(
|
let telemetryRows = telemetry.map(
|
||||||
(datum) => new TelemetryTableRow(datum, columnMap, keyString, limitEvaluator)
|
(datum) =>
|
||||||
|
new TelemetryTableRow(datum, columnMap, keyString, limitEvaluator, metadataValue?.key)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.paused) {
|
if (this.paused) {
|
||||||
@ -268,8 +273,14 @@ define([
|
|||||||
Object.keys(this.telemetryCollections).forEach((keyString) => {
|
Object.keys(this.telemetryCollections).forEach((keyString) => {
|
||||||
let { columnMap, limitEvaluator } = this.telemetryObjects[keyString];
|
let { columnMap, limitEvaluator } = this.telemetryObjects[keyString];
|
||||||
|
|
||||||
|
const metadataValue = this.openmct.telemetry
|
||||||
|
.getMetadata(this.telemetryObjects[keyString].telemetryObject)
|
||||||
|
.getUseToUpdateInPlaceValue();
|
||||||
|
|
||||||
this.telemetryCollections[keyString].getAll().forEach((datum) => {
|
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) {
|
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);
|
this.addNameColumn(telemetryObject, metadataValues);
|
||||||
metadataValues.forEach((metadatum) => {
|
metadataValues.forEach((metadatum) => {
|
||||||
if (metadatum.key === 'name') {
|
if (metadatum.key === 'name' || metadata.isInPlaceUpdateValue(metadatum)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,13 +22,14 @@
|
|||||||
|
|
||||||
define([], function () {
|
define([], function () {
|
||||||
class TelemetryTableRow {
|
class TelemetryTableRow {
|
||||||
constructor(datum, columns, objectKeyString, limitEvaluator) {
|
constructor(datum, columns, objectKeyString, limitEvaluator, inPlaceUpdateKey) {
|
||||||
this.columns = columns;
|
this.columns = columns;
|
||||||
|
|
||||||
this.datum = createNormalizedDatum(datum, columns);
|
this.datum = createNormalizedDatum(datum, columns);
|
||||||
this.fullDatum = datum;
|
this.fullDatum = datum;
|
||||||
this.limitEvaluator = limitEvaluator;
|
this.limitEvaluator = limitEvaluator;
|
||||||
this.objectKeyString = objectKeyString;
|
this.objectKeyString = objectKeyString;
|
||||||
|
this.inPlaceUpdateKey = inPlaceUpdateKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormattedDatum(headers) {
|
getFormattedDatum(headers) {
|
||||||
@ -88,6 +89,18 @@ define([], function () {
|
|||||||
getContextMenuActions() {
|
getContextMenuActions() {
|
||||||
return ['viewDatumAction', 'viewHistoricalData'];
|
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));
|
const normalizedDatum = JSON.parse(JSON.stringify(datum));
|
||||||
|
|
||||||
Object.values(columns).forEach((column) => {
|
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;
|
return normalizedDatum;
|
||||||
|
@ -85,28 +85,49 @@ define(['lodash', 'EventEmitter'], function (_, EventEmitter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sortAndMergeRows(rows) {
|
sortAndMergeRows(rows) {
|
||||||
const sortedRowsToAdd = this.sortCollection(rows);
|
const sortedRows = this.sortCollection(rows);
|
||||||
|
|
||||||
if (this.rows.length === 0) {
|
if (this.rows.length === 0) {
|
||||||
this.rows = sortedRowsToAdd;
|
this.rows = sortedRows;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const firstIncomingRow = sortedRowsToAdd[0];
|
const firstIncomingRow = sortedRows[0];
|
||||||
const lastIncomingRow = sortedRowsToAdd[sortedRowsToAdd.length - 1];
|
const lastIncomingRow = sortedRows[sortedRows.length - 1];
|
||||||
const firstExistingRow = this.rows[0];
|
const firstExistingRow = this.rows[0];
|
||||||
const lastExistingRow = this.rows[this.rows.length - 1];
|
const lastExistingRow = this.rows[this.rows.length - 1];
|
||||||
|
|
||||||
if (this.firstRowInSortOrder(lastIncomingRow, firstExistingRow) === lastIncomingRow) {
|
if (this.firstRowInSortOrder(lastIncomingRow, firstExistingRow) === lastIncomingRow) {
|
||||||
this.rows = [...sortedRowsToAdd, ...this.rows];
|
this.insertOrUpdateRows(sortedRows, true);
|
||||||
} else if (this.firstRowInSortOrder(lastExistingRow, firstIncomingRow) === lastExistingRow) {
|
} else if (this.firstRowInSortOrder(lastExistingRow, firstIncomingRow) === lastExistingRow) {
|
||||||
this.rows = [...this.rows, ...sortedRowsToAdd];
|
this.insertOrUpdateRows(sortedRows, false);
|
||||||
} else {
|
} 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) {
|
sortCollection(rows) {
|
||||||
const sortedRows = _.orderBy(
|
const sortedRows = _.orderBy(
|
||||||
rows,
|
rows,
|
||||||
@ -117,6 +138,21 @@ define(['lodash', 'EventEmitter'], function (_, EventEmitter) {
|
|||||||
return sortedRows;
|
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) {
|
mergeSortedRows(rows) {
|
||||||
const mergedRows = [];
|
const mergedRows = [];
|
||||||
let i = 0;
|
let i = 0;
|
||||||
@ -126,12 +162,17 @@ define(['lodash', 'EventEmitter'], function (_, EventEmitter) {
|
|||||||
const existingRow = this.rows[i];
|
const existingRow = this.rows[i];
|
||||||
const incomingRow = rows[j];
|
const incomingRow = rows[j];
|
||||||
|
|
||||||
if (this.firstRowInSortOrder(existingRow, incomingRow) === existingRow) {
|
const index = this.getInPlaceUpdateIndex(incomingRow);
|
||||||
mergedRows.push(existingRow);
|
if (index > -1) {
|
||||||
i++;
|
this.updateRowInPlace(incomingRow, index);
|
||||||
} else {
|
} else {
|
||||||
mergedRows.push(incomingRow);
|
if (this.firstRowInSortOrder(existingRow, incomingRow) === existingRow) {
|
||||||
j++;
|
mergedRows.push(existingRow);
|
||||||
|
i++;
|
||||||
|
} else {
|
||||||
|
mergedRows.push(incomingRow);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user