From 57818dd971b291055683cb4a233d17c0571d31b5 Mon Sep 17 00:00:00 2001 From: efarooqui Date: Thu, 10 Sep 2020 22:39:29 -0700 Subject: [PATCH] Events now only have associations; when filters and narratives are needed fromevents, interpolate from evt.associations --- src/components/Layout.js | 2 +- src/reducers/validate/eventSchema.js | 4 +--- src/reducers/validate/validators.js | 10 +++++----- src/selectors/index.js | 27 ++++++++++++++------------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/components/Layout.js b/src/components/Layout.js index 72cd0bf..feaaa80 100644 --- a/src/components/Layout.js +++ b/src/components/Layout.js @@ -142,7 +142,7 @@ class Dashboard extends React.Component { let hasOne = false // add event if it has at least one matching filter for (let i = 0; i < activeFilters.length; i++) { - if (ev.filters.includes(activeFilters[i].name)) { + if (ev.associations.includes(activeFilters[i].name)) { hasOne = true break } diff --git a/src/reducers/validate/eventSchema.js b/src/reducers/validate/eventSchema.js index 5608b95..112f07e 100644 --- a/src/reducers/validate/eventSchema.js +++ b/src/reducers/validate/eventSchema.js @@ -24,10 +24,8 @@ function createEventSchema (custom) { category: Joi.string().allow(''), category_full: Joi.string().allow(''), associations: Joi.array(), - // narratives: Joi.array(), sources: Joi.array(), - // filters: Joi.array().allow(''), - tags: Joi.array().allow(''), + // tags: Joi.array().allow(''), comments: Joi.string().allow(''), time_display: Joi.string().allow(''), // nested diff --git a/src/reducers/validate/validators.js b/src/reducers/validate/validators.js index ba22fcd..305ceb0 100644 --- a/src/reducers/validate/validators.js +++ b/src/reducers/validate/validators.js @@ -84,11 +84,11 @@ export function validateDomain (domain, features) { function validateArray (items, domainKey, schema) { items.forEach(item => { // NB: backwards compatibility with 'tags' for 'filters' - if (domainKey === 'events') { - if (!item.filters && !!item.tags) { - item.filters = item.tags - } - } + // if (domainKey === 'events') { + // if (!item.filters && !!item.tags) { + // item.filters = item.tags + // } + // } validateArrayItem(item, domainKey, schema) }) } diff --git a/src/selectors/index.js b/src/selectors/index.js index c8ad30e..c9592ed 100644 --- a/src/selectors/index.js +++ b/src/selectors/index.js @@ -49,9 +49,9 @@ export const selectEvents = createSelector( [getEvents, getActiveFilters, getActiveCategories, getTimeRange, getFeatures], (events, activeFilters, activeCategories, timeRange, features) => { return events.reduce((acc, event) => { - const isMatchingFilter = (event.filters && - event.filters.map(filter => - activeFilters.includes(filter)) + const isMatchingFilter = (event.associations && + event.associations.map(association => + activeFilters.includes(association)) .some(s => s) ) || activeFilters.length === 0 const isActiveFilter = isMatchingFilter || activeFilters.length === 0 @@ -84,12 +84,16 @@ export const selectNarratives = createSelector( /* populate narratives dict with events */ events.forEach(evt => { - evt.narratives.forEach(narrative => { - // initialise - if (!narratives[narrative]) { narratives[narrative] = narrativeSkeleton(narrative) } - // add evt to steps - // NB: insetSourceFrom is a 'curried' function to allow with maps - narratives[narrative].steps.push(insetSourceFrom(sources)(evt)) + evt.associations.forEach(association => { + const foundNarrative = narrativesMeta.find(narr => narr.id === association) + if (!!foundNarrative) { + const { id: narrId } = foundNarrative + // initialise + if (!narratives[narrId]) { narratives[narrId] = narrativeSkeleton(narrId) } + // add evt to steps + // NB: insetSourceFrom is a 'curried' function to allow with maps + narratives[narrId].steps.push(insetSourceFrom(sources)(evt)) + } }) }) /* sort steps by time */ @@ -100,14 +104,11 @@ export const selectNarratives = createSelector( const existingAssociatedNarrative = narrativesMeta.find(n => n.id === key) - if (existingAssociatedNarrative) { + if (!!existingAssociatedNarrative) { narratives[key] = { ...existingAssociatedNarrative, ...narratives[key] } - } else { - // Associations dont contain this narrative - delete narratives[key] } }) // Return narratives in original order