filterTree: DropdownTreeNode<Filter>[] = [
{
type: 'root',
title: 'Presents',
children: [
{
type: 'child',
title: t('manage.answered'),
value: {
key: 'surveyAnswers.answered',
filter: {commentsCount: {$gt: 0}}
},
checked: (node) => checked(node.value),
onClick: (node) => toggleFilter(node.value)
},
{
type: 'child',
title: t('manage.unanswered'),
value: {
key: 'surveyAnswers.unanswered',
filter: {
$or: [{commentsCount: 0}, {commentsCount: {$exists: false}}],
email: {$exists: true}
}
},
checked: (node) => checked(node.value),
onClick: (node) => toggleFilter(node.value)
}
]
},
surveyQuestions.length && {
type: 'root',
title: 'Survey',
children: surveyQuestions.map(({_id, name, type, ratingType, options}) => {
if (type === 'rating') {
const ratings: DropdownTreeNode<Filter>[] = rating(ratingType).map((ratingNum) => ({
type: 'child',
title: ratingNum.toString(),
value: {
key: `surveyAnswers.${_id}.rating.${ratingNum}`,
filter: {[`surveyAnswers.${_id}.rating`]: ratingNum}
},
checked: (node) => checked(node.value),
onClick: (node) => toggleFilter(node.value)
}));
return {
type: 'root',
title: name,
children: [createToggleAllNode(ratings), ...ratings]
};
}
if (type === 'multipleChoice') {
const choices = options.map(({id, value}) => ({
type: 'child',
title: value,
value: {
key: `surveyAnswers.${_id}.${id}`,
filter: {[`surveyAnswers.${_id}.choiceIds`]: id}
},
checked: (node) => checked(node.value),
onClick: (node) => toggleFilter(node.value)
}));
return {
type: 'root',
title: name,
children: [createToggleAllNode(choices), ...choices]
};
}
if (type === 'singleChoice') {
const choices = options.map(({id, value}) => ({
type: 'child',
title: value,
value: {
key: `surveyQuestions.${_id}.${id}`,
filter: {[`surveyAnswers.${_id}.choiceId`]: id}
},
checked: (node) => checked(node.value),
onClick: (node) => toggleFilter(node.value)
}));
return {
type: 'root',
title: name,
children: [createToggleAllNode(choices), ...choices]
};
}
return {
type: 'child',
title: name,
value: {
key: `surveyQuestions.${_id}`,
filter: {[`surveyAnswers.${_id}`]: {$exists: true}}
},
checked: (node) => checked(node.value),
onClick: (node) => toggleFilter(node.value)
};
})
},
highlightTypes.length && {
type: 'root',
title: 'Highlights',
children: highlightTypes.map(({type, color}) => ({
type: 'child',
title: type,
color,
value: {
key: `highlights.type.${type}`,
filter: {'highlights.type': type}
},
checked: (node) => checked(node.value),
onClick: (node) => toggleFilter(node.value)
}))
}
];