mirror of
https://github.com/bellingcat/ukraine-timemap.git
synced 2026-06-11 21:08:36 +03:00
add USE_FILTER_DESCRIPTIONS option
This commit is contained in:
@@ -137,10 +137,10 @@ export function fetchError (message) {
|
||||
}
|
||||
|
||||
export const UPDATE_DOMAIN = 'UPDATE_DOMAIN'
|
||||
export function updateDomain (domain) {
|
||||
export function updateDomain (payload) {
|
||||
return {
|
||||
type: UPDATE_DOMAIN,
|
||||
domain
|
||||
payload
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,12 +40,10 @@ class Dashboard extends React.Component {
|
||||
componentDidMount () {
|
||||
if (!this.props.app.isMobile) {
|
||||
this.props.actions.fetchDomain()
|
||||
.then(domain => this.props.actions.updateDomain(domain))
|
||||
.then(({ domain }) => {
|
||||
if (domain.categories.length >= 4) {
|
||||
this.props.actions.updateDimensions({ marginTop: 0 })
|
||||
}
|
||||
})
|
||||
.then(domain => this.props.actions.updateDomain({
|
||||
domain,
|
||||
features: this.props.features
|
||||
}))
|
||||
}
|
||||
// NOTE: hack to get the timeline to always show. Not entirely sure why
|
||||
// this is necessary.
|
||||
|
||||
@@ -6,7 +6,7 @@ import { validateDomain } from './validate/validators.js'
|
||||
function updateDomain (domainState, action) {
|
||||
return {
|
||||
...domainState,
|
||||
...validateDomain(action.domain)
|
||||
...validateDomain(action.payload.domain, action.payload.features)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,10 +29,30 @@ const isLeaf = node => (Object.keys(node.children).length === 0)
|
||||
const isDuplicate = (node, set) => { return (set.has(node.key)) }
|
||||
|
||||
/*
|
||||
* Traverse a filter tree and check its duplicates
|
||||
* Traverse a filter tree and check its duplicates. Also recompose as
|
||||
* description if `features.USE_FILTER_DESCRIPTIONS` is true.
|
||||
*/
|
||||
function validateTree (node, parent, set, duplicates) {
|
||||
if (!Array.isArray(node) || !node.length) {
|
||||
function validateFilterTree (node, parent, set, duplicates, hasFilterDescriptions) {
|
||||
if (hasFilterDescriptions) {
|
||||
if (node.key === '_root') {
|
||||
node.isDescription = true // setting first set of nodes to values
|
||||
} else if (!parent.isDescription) {
|
||||
node.isDescription = true
|
||||
} else {
|
||||
node.isDescription = false
|
||||
}
|
||||
|
||||
if (node.isDescription && node.key !== 'root') {
|
||||
parent.description = node.key
|
||||
parent.children = node.children
|
||||
delete parent.isDescription
|
||||
}
|
||||
if (isLeaf(node)) {
|
||||
delete parent.isDescription
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof (node) !== 'object' || typeof (node.children) !== 'object') {
|
||||
return
|
||||
}
|
||||
// If it's a leaf, check that it's not duplicate
|
||||
@@ -49,7 +69,7 @@ function validateTree (node, parent, set, duplicates) {
|
||||
} else {
|
||||
// If it's not a leaf, simply keep going
|
||||
Object.values(node.children).forEach((childNode) => {
|
||||
validateTree(childNode, node, set, duplicates)
|
||||
validateFilterTree(childNode, node, set, duplicates, hasFilterDescriptions)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -57,7 +77,7 @@ function validateTree (node, parent, set, duplicates) {
|
||||
/*
|
||||
* Validate domain schema
|
||||
*/
|
||||
export function validateDomain (domain) {
|
||||
export function validateDomain (domain, features) {
|
||||
const sanitizedDomain = {
|
||||
events: [],
|
||||
categories: [],
|
||||
@@ -143,7 +163,7 @@ export function validateDomain (domain) {
|
||||
// Validate uniqueness of filters
|
||||
const filterSet = new Set([])
|
||||
const duplicateFilters = []
|
||||
validateTree(domain.filters, {}, filterSet, duplicateFilters)
|
||||
validateFilterTree(domain.filters, {}, filterSet, duplicateFilters, features.USE_FILTER_DESCRIPTIONS)
|
||||
|
||||
// Duplicated filters
|
||||
if (duplicateFilters.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user