Skip to content

Commit

Permalink
✨ Show filters preview
Browse files Browse the repository at this point in the history
  • Loading branch information
foysalit committed Jan 6, 2025
1 parent 50c65f2 commit 5a0957f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
39 changes: 29 additions & 10 deletions components/reports/QueueFilter/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:')) {
Expand All @@ -57,6 +75,7 @@ const FilterSummary = ({
exclusions.push(tag.split(':')[1])
}
})

return (
<>
{!!inclusions.length && inclusions.join(' ')}
Expand Down
1 change: 1 addition & 0 deletions components/tags/SubjectTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ export const SubjectTag = ({
)
}
}

return <LabelChip {...rest}>{tag}</LabelChip>
}

0 comments on commit 5a0957f

Please sign in to comment.