mirror of
https://github.com/bellingcat/ukraine-timemap.git
synced 2026-06-11 21:08:36 +03:00
show error for invalid dates
it srsly messes with binary search!
This commit is contained in:
@@ -21,6 +21,10 @@ function makeError (type, id, message) {
|
||||
}
|
||||
}
|
||||
|
||||
function isValidDate (d) {
|
||||
return d instanceof Date && !isNaN(d)
|
||||
}
|
||||
|
||||
const isLeaf = node => (Object.keys(node.children).length === 0)
|
||||
const isDuplicate = (node, set) => { return (set.has(node.key)) }
|
||||
|
||||
@@ -136,18 +140,6 @@ export function validateDomain (domain) {
|
||||
})
|
||||
)
|
||||
|
||||
// Message the number of failed items in domain
|
||||
Object.keys(discardedDomain).forEach(disc => {
|
||||
const len = discardedDomain[disc].length
|
||||
if (len) {
|
||||
sanitizedDomain.notifications.push({
|
||||
message: `${len} invalid ${disc} not displayed.`,
|
||||
items: discardedDomain[disc],
|
||||
type: 'error'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// Validate uniqueness of filters
|
||||
const filterSet = new Set([])
|
||||
const duplicateFilters = []
|
||||
@@ -167,9 +159,24 @@ export function validateDomain (domain) {
|
||||
sanitizedDomain.events.forEach((event, idx) => {
|
||||
event.id = idx
|
||||
event.datetime = calcDatetime(event.date, event.time)
|
||||
if (!isValidDate(event.datetime)) {
|
||||
discardedDomain['events'].push({ ...event, error: makeError('events', event.id, `Invalid date. This will break timemap! Please fix.`) })
|
||||
}
|
||||
})
|
||||
|
||||
sanitizedDomain.events.sort((a, b) => a.datetime - b.datetime)
|
||||
|
||||
// Message the number of failed items in domain
|
||||
Object.keys(discardedDomain).forEach(disc => {
|
||||
const len = discardedDomain[disc].length
|
||||
if (len) {
|
||||
sanitizedDomain.notifications.push({
|
||||
message: `${len} invalid ${disc} not displayed.`,
|
||||
items: discardedDomain[disc],
|
||||
type: 'error'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return sanitizedDomain
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user