From bd4f61e7edc900dd7cb1b4f1d11b0d70258c3742 Mon Sep 17 00:00:00 2001 From: efarooqui Date: Mon, 7 Sep 2020 16:10:09 -0700 Subject: [PATCH] Working narrative feature minus getNarrativeLinks (need further clarification); working on modifying narrativise filters feature --- example.config.js | 1 + src/components/Layout.js | 8 +++++--- src/components/Toolbar/FilterListPanel.js | 1 - src/components/Toolbar/Layout.js | 4 ++-- src/reducers/app.js | 3 +-- src/selectors/index.js | 16 +++++++++------- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/example.config.js b/example.config.js index 8b0e1ed..3467996 100644 --- a/example.config.js +++ b/example.config.js @@ -24,6 +24,7 @@ module.exports = { }, features: { USE_CATEGORIES: true, + USE_NARRATIVES: true, CATEGORIES_AS_FILTERS: true, USE_ASSOCIATIONS: true, USE_ASSOCIATION_DESCRIPTIONS: true, diff --git a/src/components/Layout.js b/src/components/Layout.js index 4e493f3..ded3ed4 100644 --- a/src/components/Layout.js +++ b/src/components/Layout.js @@ -119,8 +119,9 @@ class Dashboard extends React.Component { } } + // Broken for time being; need clarification on function getNarrativeLinks (event) { - const narrative = this.props.domain.narratives.find(nv => nv.id === event.narrative) + const narrative = this.props.narratives.find(nv => nv.id === event.narratives[0]) if (narrative) return narrative.byId[event.id] return null } @@ -196,7 +197,7 @@ class Dashboard extends React.Component { } } - const { narrative } = this.props.app + const { narrative } = this.props.app.associations if (narrative === null) return if (idx < narrative.steps.length && idx >= 0) { @@ -363,7 +364,8 @@ function mapDispatchToProps (dispatch) { export default connect( state => ({ ...state, - narrativeIdx: selectors.selectNarrativeIdx(state) + narrativeIdx: selectors.selectNarrativeIdx(state), + narratives: selectors.selectNarratives(state) }), mapDispatchToProps )(Dashboard) diff --git a/src/components/Toolbar/FilterListPanel.js b/src/components/Toolbar/FilterListPanel.js index 9c14c10..c4f4d22 100644 --- a/src/components/Toolbar/FilterListPanel.js +++ b/src/components/Toolbar/FilterListPanel.js @@ -66,7 +66,6 @@ function FilterListPanel ({ function renderTree (filters) { const aggregatedFilterPaths = aggregatePaths(filters) - console.info(aggregatedFilterPaths) return (
{Object.entries(aggregatedFilterPaths).map(filter => createNodeComponent(filter, 1))} diff --git a/src/components/Toolbar/Layout.js b/src/components/Toolbar/Layout.js index a2df306..dc61ce7 100644 --- a/src/components/Toolbar/Layout.js +++ b/src/components/Toolbar/Layout.js @@ -62,8 +62,8 @@ class Toolbar extends React.Component { return (
) diff --git a/src/reducers/app.js b/src/reducers/app.js index 4039f8a..6498eb1 100644 --- a/src/reducers/app.js +++ b/src/reducers/app.js @@ -82,11 +82,10 @@ function updateNarrative (appState, action) { minTime = minTime - Math.abs((maxTime - minTime) / 10) maxTime = maxTime + Math.abs((maxTime - minTime) / 10) } - return { ...appState, associations: { - ...appState.filters, + ...appState.associations, narrative: action.narrative }, map: { diff --git a/src/selectors/index.js b/src/selectors/index.js index d328da1..d5f319c 100644 --- a/src/selectors/index.js +++ b/src/selectors/index.js @@ -1,12 +1,12 @@ import { createSelector } from 'reselect' import { insetSourceFrom, dateMin, dateMax } from '../common/utilities' import { isTimeRangedIn } from './helpers' -import { FILTER_MODE } from '../common/constants' +import { FILTER_MODE, NARRATIVE_MODE } from '../common/constants' // Input selectors export const getEvents = state => state.domain.events export const getCategories = state => state.domain.categories -export const getNarratives = state => state.domain.narratives +export const getNarratives = state => state.domain.associations.filter(item => item.mode === NARRATIVE_MODE) export const getActiveNarrative = state => state.app.associations.narrative export const getSelected = state => state.app.selected export const getSites = state => state.domain.sites @@ -87,27 +87,29 @@ export const selectNarratives = createSelector( 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)) }) }) - /* sort steps by time */ Object.keys(narratives).forEach(key => { const steps = narratives[key].steps steps.sort((a, b) => a.datetime - b.datetime) - if (narrativesMeta.find(n => n.id === key)) { + const existingAssociatedNarrative = narrativesMeta.find(n => n.id === key) + + if (existingAssociatedNarrative) { narratives[key] = { - ...narrativesMeta.find(n => n.id === key), + ...existingAssociatedNarrative, ...narratives[key] } + } else { + // Associations dont contain this narrative + delete narratives[key] } }) - // Return narratives in original order // + filter those that are undefined return narrativesMeta.map(n => narratives[n.id]).filter(d => d)