Import saved searches first (#10740)

* import saved searches first
* move saved object type grouping into a helper
This commit is contained in:
Joe Fleming 2017-03-27 14:49:05 -07:00
parent 6587cc178e
commit 6cee4ec8f1

View file

@ -133,7 +133,7 @@ uiModules.get('apps/management')
notify.error('The file could not be processed.');
}
return Promise.map(docs, function (doc) {
function importDocument(doc) {
const { service } = find($scope.services, { type: doc._type }) || {};
if (!service) {
@ -153,7 +153,30 @@ uiModules.get('apps/management')
return obj.save();
});
});
})
}
function groupByType(docs) {
const defaultDocTypes = {
searches: [],
other: [],
};
return docs.reduce((types, doc) => {
switch (doc._type) {
case 'search':
types.searches.push(doc);
break;
default:
types.other.push(doc);
}
return types;
}, defaultDocTypes);
}
const docTypes = groupByType(docs);
return Promise.map(docTypes.searches, importDocument)
.then(() => Promise.map(docTypes.other, importDocument))
.then(refreshIndex)
.then(refreshData)
.catch(notify.error);