From 5a0957f97acd3d5be6ed66dbff78a8875e62669f Mon Sep 17 00:00:00 2001 From: Foysal Ahamed Date: Mon, 6 Jan 2025 17:50:05 +0000 Subject: [PATCH] :sparkles: Show filters preview --- components/reports/QueueFilter/Panel.tsx | 39 ++++++++++++++++++------ components/tags/SubjectTag.tsx | 1 + 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/components/reports/QueueFilter/Panel.tsx b/components/reports/QueueFilter/Panel.tsx index 2404c6c..9ee4855 100644 --- a/components/reports/QueueFilter/Panel.tsx +++ b/components/reports/QueueFilter/Panel.tsx @@ -9,6 +9,31 @@ import { getCollectionName } from '../helpers/subject' import { classNames } from '@/lib/util' import { QueueFilterTags } from './Tag' +const buildTagFilterSummary = (tags: string[]) => { + if (!tags.filter(Boolean).length) { + return '' + } + + const list = tags.map((tag) => { + return tag + .split('&&') + .map((t) => { + if (t.startsWith('lang:')) { + const langCode = t.split(':')[1] + return getLanguageFlag(langCode) || langCode + } + return t + }) + .join(' && ') + }) + + if (list.length === 1) { + return list[0] + } + + return `(${list.join(') OR (')})` +} + // Takes all the queue filters manageable in the panel and displays a summary of selections made const FilterSummary = ({ queueFilters, @@ -36,16 +61,9 @@ const FilterSummary = ({ inclusions.push('Only Records') } - tags?.forEach((tag) => { - if (tag.startsWith('lang:')) { - const langCode = tag.split(':')[1] - inclusions.push(getLanguageFlag(langCode) || langCode) - } - - if (tag.startsWith('embed:')) { - inclusions.push(tag.split(':')[1]) - } - }) + if (tags?.length) { + inclusions.push(buildTagFilterSummary(tags)) + } excludeTags?.forEach((tag) => { if (tag.startsWith('lang:')) { @@ -57,6 +75,7 @@ const FilterSummary = ({ exclusions.push(tag.split(':')[1]) } }) + return ( <> {!!inclusions.length && inclusions.join(' ')} diff --git a/components/tags/SubjectTag.tsx b/components/tags/SubjectTag.tsx index 604dfd9..41817de 100644 --- a/components/tags/SubjectTag.tsx +++ b/components/tags/SubjectTag.tsx @@ -25,5 +25,6 @@ export const SubjectTag = ({ ) } } + return {tag} }