diff --git a/src/components/StateOptions.jsx b/src/components/StateOptions.jsx index 9422c54..a3c2d28 100644 --- a/src/components/StateOptions.jsx +++ b/src/components/StateOptions.jsx @@ -1,14 +1,14 @@ import React, { useState } from 'react' export default ({ showing, onClickHandler, timelineDims }) => { - const [checked, setChecked] = useState(true) - const handleCheck = () => setChecked(!checked) - const onNarrativise = () => onClickHandler(checked) - if (!showing) { return null } + const [checked, setChecked] = useState(true) + const handleCheck = () => setChecked(!checked) + const onNarrativise = () => onClickHandler(checked) + return
Narrativise
diff --git a/src/components/Toolbar/FilterListPanel.js b/src/components/Toolbar/FilterListPanel.js index 2c39578..53bb31a 100644 --- a/src/components/Toolbar/FilterListPanel.js +++ b/src/components/Toolbar/FilterListPanel.js @@ -2,11 +2,19 @@ import React from 'react' import Checkbox from '../presentational/Checkbox' import copy from '../../common/data/copy.json' -/** recursively get an array of node keys */ -function allAssociatedKeys (node) { - if (!node.children) return [node.key] - const childKeys = Object.values(node.children).flatMap(n => allAssociatedKeys(n)) - childKeys.push(node.key) +/** recursively get an array of node keys to toggle */ +function childrenToToggle (node, activeFilters, parentOn) { + const isOn = activeFilters.includes(node.key) + if (!node.children) { + return [node.key] + } + const childKeys = Object.values(node.children) + .flatMap(n => childrenToToggle(n, activeFilters, isOn)) + // NB: if turning a parent off, don't toggle off children on. + // likewise if turning a parent on, don't toggle on children off + if (!((!parentOn && isOn) || (parentOn && !isOn))) { + childKeys.push(node.key) + } return childKeys } @@ -17,7 +25,7 @@ function FilterListPanel ({ language }) { function createNodeComponent (node, depth) { - const matchingKeys = allAssociatedKeys(node) + const matchingKeys = childrenToToggle(node, activeFilters, activeFilters.includes(node.key)) const children = Object.values(node.children) return (