add null check for sources

This commit is contained in:
Lachlan Kermode
2018-12-26 12:05:30 +01:00
parent f5628e7a79
commit e989e7b6a2
2 changed files with 7 additions and 3 deletions

View File

@@ -7,7 +7,7 @@ const sourceSchema = Joi.object().keys({
affil_1: Joi.string().allow(''),
affil_2: Joi.string().allow(''),
url: Joi.string().allow(''),
title: Joi.string().allow(''),
desc: Joi.string().allow(''),
parent: Joi.string().allow(''),
author: Joi.string().allow(''),
date: Joi.string().allow(''),

View File

@@ -170,8 +170,12 @@ export const selectSelected = createSelector(
// NB: return source object if exists, otherwise null
const srcs = selected
.map(e => e.sources)
.map(_sources =>
_sources.map(id => (sources.hasOwnProperty(id) ? sources[id] : null))
.map(_sources => {
if (!_sources) return [];
return _sources.map(id => (
sources.hasOwnProperty(id) ? sources[id] : null
))
}
)
return selected.map((s, idx) => ({