Table migration (#2327)

* Added table migration code

* First working version

* Fixed issues with objects missing from composition
This commit is contained in:
Andrew Henry 2019-03-25 22:19:33 -07:00 committed by Deep Tailor
parent c7ffcbf7e0
commit e3f4da19f9
2 changed files with 226 additions and 180 deletions

View File

@ -25,6 +25,26 @@ define([
], function ( ], function (
uuid uuid
) { ) {
return function Migrations(openmct) {
function getColumnNameKeyMap(domainObject) {
let composition = openmct.composition.get(domainObject);
if (composition) {
return composition.load().then(composees => {
return composees.reduce((nameKeyMap, composee) => {
let metadata = openmct.telemetry.getMetadata(composee);
if (metadata !== undefined) {
metadata.values().forEach(value => {
nameKeyMap[value.name] = value.key;
});
}
return nameKeyMap;
}, {});
});
} else {
return Promise.resolve([]);
}
}
function isTelemetry(domainObject) { function isTelemetry(domainObject) {
if (openmct.telemetry.isTelemetryObject(domainObject) if (openmct.telemetry.isTelemetryObject(domainObject)
&& domainObject.type !== 'summary-widget' && domainObject.type !== 'summary-widget'
@ -158,7 +178,7 @@ define([
.then(function () { .then(function () {
return migrateDisplayLayout(domainObject, childObjects); return migrateDisplayLayout(domainObject, childObjects);
}); });
}, }
}, },
{ {
check(domainObject) { check(domainObject) {
@ -195,6 +215,30 @@ define([
return newLayoutObject; return newLayoutObject;
}); });
} }
},
{
check(domainObject) {
return domainObject.type === 'table' &&
domainObject.configuration.table;
},
migrate(domainObject) {
let currentTableConfiguration = domainObject.configuration.table || {};
let currentColumnConfiguration = currentTableConfiguration.columns || {};
return getColumnNameKeyMap(domainObject).then(nameKeyMap => {
let hiddenColumns = Object.keys(currentColumnConfiguration).filter(columnName => {
return currentColumnConfiguration[columnName] === false;
}).reduce((hiddenColumnsMap, hiddenColumnName) => {
let key = nameKeyMap[hiddenColumnName];
hiddenColumnsMap[key] = true;
return hiddenColumnsMap;
}, {});
domainObject.configuration.hiddenColumns = hiddenColumns;
delete domainObject.configuration.table;
return domainObject;
});
}
} }
]; ];
}
}); });

View File

@ -20,9 +20,12 @@
* at runtime from the About dialog for additional information. * at runtime from the About dialog for additional information.
*****************************************************************************/ *****************************************************************************/
import migrations from './Migrations.js' import Migrations from './Migrations.js'
export default function () { export default function () {
return function (openmct) {
let migrations = Migrations(openmct);
function needsMigration(domainObject) { function needsMigration(domainObject) {
return migrations.some(m => m.check(domainObject)); return migrations.some(m => m.check(domainObject));
} }
@ -32,7 +35,6 @@ export default function () {
.migrate(domainObject); .migrate(domainObject);
} }
return function (openmct) {
let wrappedFunction = openmct.objects.get; let wrappedFunction = openmct.objects.get;
openmct.objects.get = function migrate(identifier) { openmct.objects.get = function migrate(identifier) {
return wrappedFunction.apply(openmct.objects, [identifier]) return wrappedFunction.apply(openmct.objects, [identifier])
@ -48,4 +50,4 @@ export default function () {
}); });
} }
}; };
} }