feat(gallery): OR/exclude tag filtering — light chips + advanced builder (#6b/c/d)
CI / lint (push) Successful in 2s
CI / frontend-build (push) Successful in 17s
CI / backend-lint-and-test (push) Successful in 26s
CI / integration (push) Successful in 3m15s

Cluster A, milestone #97. Completes the frontend of the structured tag filter
(backend landed in 23fab98).

#6b store: gallery.filter gains tag_or (OR-groups) + tag_exclude; one model,
serialized via tag_or (repeated key) + tag_not across activeFilterParam/
filterToQuery/applyFilterFromQuery/cloneFilter/loadSimilar; _resolveLabels
resolves names for every referenced id. useApi now appends array param values
as a repeated key (tag_or=a&tag_or=b).

#6c light editor (GalleryFilterBar): autocomplete pick → include chip; click a
chip body to flip include↔exclude (exclude = red minus); ✕ removes. An
"N OR-groups" chip + an Advanced button open the builder.

#6d advanced editor (TagQueryBuilder.vue + common/TagPicker.vue): AND-of-OR
group builder + NOT list. Unifies includes+OR-groups into one groups view,
splits back to tag_ids/tag_or on Apply so the URL stays compact. Writes the
same model the light chips edit.

Store serialization round-trip tests added.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XCUHUGQLrBrkgyk1t49kpX
This commit is contained in:
2026-06-23 01:19:53 -04:00
parent 23fab983a0
commit 73dd301dbb
6 changed files with 500 additions and 3 deletions
+54
View File
@@ -144,6 +144,40 @@ describe('gallery store: composable filter', () => {
expect(urls.some((u) => u.includes('/api/gallery/timeline'))).toBe(false)
})
it('parses tag_or OR-groups + tag_not and forwards them (incl. repeated tag_or)', async () => {
const s = useGalleryStore()
const urls = []
stubFetch((url) => {
urls.push(url)
if (url.includes('/api/tags/')) {
return { status: 200, body: { id: 1, name: 'X', kind: 'general' } }
}
return { status: 200, body: EMPTY }
})
// tag_or arrives as an array (two groups); tag_not as a csv exclude list.
await s.applyFilterFromQuery({ tag_or: ['1,2', '3'], tag_not: '4,5' })
expect(s.filter.tag_or).toEqual([[1, 2], [3]])
expect(s.filter.tag_exclude).toEqual([4, 5])
const scroll = decodeURIComponent(urls.find((u) => u.includes('/api/gallery/scroll')))
expect(scroll).toContain('tag_or=1,2') // first OR-group
expect(scroll).toContain('tag_or=3') // second OR-group (repeated key)
expect(scroll).toContain('tag_not=4,5')
})
it('normalizes a single-string tag_or and drops empty groups', async () => {
const s = useGalleryStore()
stubFetch((url) => {
if (url.includes('/api/tags/')) {
return { status: 200, body: { id: 1, name: 'X', kind: 'general' } }
}
return { status: 200, body: EMPTY }
})
await s.applyFilterFromQuery({ tag_or: '7,8' }) // single string → one group
expect(s.filter.tag_or).toEqual([[7, 8]])
await s.applyFilterFromQuery({ tag_or: ['', '9'] }) // empty group dropped
expect(s.filter.tag_or).toEqual([[9]])
})
it('loadInitial issues exactly one scroll request at the initial limit', async () => {
const s = useGalleryStore()
const urls = []
@@ -181,6 +215,26 @@ describe('filterToQuery / cloneFilter', () => {
expect(filterToQuery({ tag_ids: [], similar_to: null }).similar_to).toBeUndefined()
})
it('serializes tag_or OR-groups (repeated key) + tag_not, dropping empties', () => {
const q = filterToQuery({
tag_ids: [], tag_or: [[1, 2], [3], []], tag_exclude: [4, 5],
})
expect(q.tag_or).toEqual(['1,2', '3']) // empty group dropped → array
expect(q.tag_not).toBe('4,5')
const empty = filterToQuery({ tag_ids: [], tag_or: [], tag_exclude: [] })
expect(empty.tag_or).toBeUndefined()
expect(empty.tag_not).toBeUndefined()
})
it('cloneFilter deep-clones OR-groups + exclude', () => {
const orig = { tag_ids: [], tag_or: [[1, 2]], tag_exclude: [3] }
const c = cloneFilter(orig)
c.tag_or[0].push(9)
c.tag_exclude.push(8)
expect(orig.tag_or).toEqual([[1, 2]]) // group detached
expect(orig.tag_exclude).toEqual([3]) // exclude detached
})
it('cloneFilter copies refine fields and detaches tag_ids', () => {
const orig = {
tag_ids: [1], artist_id: 2, media_type: 'image', sort: 'oldest',