Skip to content

Commit e386036

Browse files
shefalijoshijvigliottaakhenryunlikelyzero
authored
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 <[email protected]> * 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 <[email protected]> Co-authored-by: Andrew Henry <[email protected]> Co-authored-by: John Hill <[email protected]>
1 parent 6e79e5e commit e386036

File tree

4 files changed

+95
-18
lines changed

4 files changed

+95
-18
lines changed

src/api/telemetry/TelemetryMetadataManager.js

+8
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ define(['lodash'], function (_) {
134134
);
135135
};
136136

137+
TelemetryMetadataManager.prototype.getUseToUpdateInPlaceValue = function () {
138+
return this.valueMetadatas.find(this.isInPlaceUpdateValue);
139+
};
140+
141+
TelemetryMetadataManager.prototype.isInPlaceUpdateValue = function (metadatum) {
142+
return metadatum.useToUpdateInPlace === true;
143+
};
144+
137145
TelemetryMetadataManager.prototype.getDefaultDisplayValue = function () {
138146
let valueMetadata = this.valuesForHints(['range'])[0];
139147

src/plugins/telemetryTable/TelemetryTable.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,13 @@ define([
215215
return;
216216
}
217217

218+
const metadataValue = this.openmct.telemetry
219+
.getMetadata(this.telemetryObjects[keyString].telemetryObject)
220+
.getUseToUpdateInPlaceValue();
221+
218222
let telemetryRows = telemetry.map(
219-
(datum) => new TelemetryTableRow(datum, columnMap, keyString, limitEvaluator)
223+
(datum) =>
224+
new TelemetryTableRow(datum, columnMap, keyString, limitEvaluator, metadataValue?.key)
220225
);
221226

222227
if (this.paused) {
@@ -268,8 +273,14 @@ define([
268273
Object.keys(this.telemetryCollections).forEach((keyString) => {
269274
let { columnMap, limitEvaluator } = this.telemetryObjects[keyString];
270275

276+
const metadataValue = this.openmct.telemetry
277+
.getMetadata(this.telemetryObjects[keyString].telemetryObject)
278+
.getUseToUpdateInPlaceValue();
279+
271280
this.telemetryCollections[keyString].getAll().forEach((datum) => {
272-
allRows.push(new TelemetryTableRow(datum, columnMap, keyString, limitEvaluator));
281+
allRows.push(
282+
new TelemetryTableRow(datum, columnMap, keyString, limitEvaluator, metadataValue?.key)
283+
);
273284
});
274285
});
275286

@@ -321,11 +332,12 @@ define([
321332
}
322333

323334
addColumnsForObject(telemetryObject) {
324-
let metadataValues = this.openmct.telemetry.getMetadata(telemetryObject).values();
335+
const metadata = this.openmct.telemetry.getMetadata(telemetryObject);
336+
let metadataValues = metadata.values();
325337

326338
this.addNameColumn(telemetryObject, metadataValues);
327339
metadataValues.forEach((metadatum) => {
328-
if (metadatum.key === 'name') {
340+
if (metadatum.key === 'name' || metadata.isInPlaceUpdateValue(metadatum)) {
329341
return;
330342
}
331343

src/plugins/telemetryTable/TelemetryTableRow.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222

2323
define([], function () {
2424
class TelemetryTableRow {
25-
constructor(datum, columns, objectKeyString, limitEvaluator) {
25+
constructor(datum, columns, objectKeyString, limitEvaluator, inPlaceUpdateKey) {
2626
this.columns = columns;
2727

2828
this.datum = createNormalizedDatum(datum, columns);
2929
this.fullDatum = datum;
3030
this.limitEvaluator = limitEvaluator;
3131
this.objectKeyString = objectKeyString;
32+
this.inPlaceUpdateKey = inPlaceUpdateKey;
3233
}
3334

3435
getFormattedDatum(headers) {
@@ -88,6 +89,18 @@ define([], function () {
8889
getContextMenuActions() {
8990
return ['viewDatumAction', 'viewHistoricalData'];
9091
}
92+
93+
updateWithDatum(updatesToDatum) {
94+
const normalizedUpdatesToDatum = createNormalizedDatum(updatesToDatum, this.columns);
95+
this.datum = {
96+
...this.datum,
97+
...normalizedUpdatesToDatum
98+
};
99+
this.fullDatum = {
100+
...this.fullDatum,
101+
...updatesToDatum
102+
};
103+
}
91104
}
92105

93106
/**
@@ -101,7 +114,10 @@ define([], function () {
101114
const normalizedDatum = JSON.parse(JSON.stringify(datum));
102115

103116
Object.values(columns).forEach((column) => {
104-
normalizedDatum[column.getKey()] = column.getRawValue(datum);
117+
const rawValue = column.getRawValue(datum);
118+
if (rawValue !== undefined) {
119+
normalizedDatum[column.getKey()] = rawValue;
120+
}
105121
});
106122

107123
return normalizedDatum;

src/plugins/telemetryTable/collections/TableRowCollection.js

+53-12
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,49 @@ define(['lodash', 'EventEmitter'], function (_, EventEmitter) {
8585
}
8686

8787
sortAndMergeRows(rows) {
88-
const sortedRowsToAdd = this.sortCollection(rows);
88+
const sortedRows = this.sortCollection(rows);
8989

9090
if (this.rows.length === 0) {
91-
this.rows = sortedRowsToAdd;
91+
this.rows = sortedRows;
9292

9393
return;
9494
}
9595

96-
const firstIncomingRow = sortedRowsToAdd[0];
97-
const lastIncomingRow = sortedRowsToAdd[sortedRowsToAdd.length - 1];
96+
const firstIncomingRow = sortedRows[0];
97+
const lastIncomingRow = sortedRows[sortedRows.length - 1];
9898
const firstExistingRow = this.rows[0];
9999
const lastExistingRow = this.rows[this.rows.length - 1];
100100

101101
if (this.firstRowInSortOrder(lastIncomingRow, firstExistingRow) === lastIncomingRow) {
102-
this.rows = [...sortedRowsToAdd, ...this.rows];
102+
this.insertOrUpdateRows(sortedRows, true);
103103
} else if (this.firstRowInSortOrder(lastExistingRow, firstIncomingRow) === lastExistingRow) {
104-
this.rows = [...this.rows, ...sortedRowsToAdd];
104+
this.insertOrUpdateRows(sortedRows, false);
105105
} else {
106-
this.mergeSortedRows(sortedRowsToAdd);
106+
this.mergeSortedRows(sortedRows);
107107
}
108108
}
109109

110+
getInPlaceUpdateIndex(row) {
111+
const inPlaceUpdateKey = row.inPlaceUpdateKey;
112+
if (!inPlaceUpdateKey) {
113+
return -1;
114+
}
115+
116+
const foundIndex = this.rows.findIndex(
117+
(existingRow) =>
118+
existingRow.datum[inPlaceUpdateKey] &&
119+
existingRow.datum[inPlaceUpdateKey] === row.datum[inPlaceUpdateKey]
120+
);
121+
122+
return foundIndex;
123+
}
124+
125+
updateRowInPlace(row, index) {
126+
const foundRow = this.rows[index];
127+
foundRow.updateWithDatum(row.datum);
128+
this.rows[index] = foundRow;
129+
}
130+
110131
sortCollection(rows) {
111132
const sortedRows = _.orderBy(
112133
rows,
@@ -117,6 +138,21 @@ define(['lodash', 'EventEmitter'], function (_, EventEmitter) {
117138
return sortedRows;
118139
}
119140

141+
insertOrUpdateRows(rowsToAdd, addToBeginning) {
142+
rowsToAdd.forEach((row) => {
143+
const index = this.getInPlaceUpdateIndex(row);
144+
if (index > -1) {
145+
this.updateRowInPlace(row, index);
146+
} else {
147+
if (addToBeginning) {
148+
this.rows.unshift(row);
149+
} else {
150+
this.rows.push(row);
151+
}
152+
}
153+
});
154+
}
155+
120156
mergeSortedRows(rows) {
121157
const mergedRows = [];
122158
let i = 0;
@@ -126,12 +162,17 @@ define(['lodash', 'EventEmitter'], function (_, EventEmitter) {
126162
const existingRow = this.rows[i];
127163
const incomingRow = rows[j];
128164

129-
if (this.firstRowInSortOrder(existingRow, incomingRow) === existingRow) {
130-
mergedRows.push(existingRow);
131-
i++;
165+
const index = this.getInPlaceUpdateIndex(incomingRow);
166+
if (index > -1) {
167+
this.updateRowInPlace(incomingRow, index);
132168
} else {
133-
mergedRows.push(incomingRow);
134-
j++;
169+
if (this.firstRowInSortOrder(existingRow, incomingRow) === existingRow) {
170+
mergedRows.push(existingRow);
171+
i++;
172+
} else {
173+
mergedRows.push(incomingRow);
174+
j++;
175+
}
135176
}
136177
}
137178

0 commit comments

Comments
 (0)