Skip to content

Commit 173ca01

Browse files
committed
Support DataTables-style quoted search tokens
1 parent ea0474b commit 173ca01

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/archivematica/dashboard/vue/lib/fpr-tables/useFprSearch.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,23 @@ describe('useFprSearch', () => {
7878
expect(search.tokenizedGlobalFilter(secondRow!, 'jpeg yes')).toBe(false)
7979
})
8080

81+
it('supports DataTables-style quoted search terms', () => {
82+
const rows = makeRows()
83+
const search = useFprSearch({
84+
rows,
85+
columns: computed(() => columns.value),
86+
displayValueForColumn,
87+
})
88+
89+
const firstRow = rows.value[0]
90+
const secondRow = rows.value[1]
91+
expect(firstRow).toBeDefined()
92+
expect(secondRow).toBeDefined()
93+
94+
expect(search.tokenizedGlobalFilter(firstRow!, '"jpeg" "1.02"')).toBe(true)
95+
expect(search.tokenizedGlobalFilter(secondRow!, '"jpeg" "1.02"')).toBe(false)
96+
})
97+
8198
it('clearSearch resets immediately and cancels stale debounced updates', async () => {
8299
vi.useFakeTimers()
83100
try {

src/archivematica/dashboard/vue/lib/fpr-tables/useFprSearch.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,27 @@ export const useFprSearch = ({
3737

3838
let lastFilterValue = ''
3939
let lastFilterTokens: string[] = []
40+
41+
const tokenPattern = /"([^"]+)"|(\S+)/g
42+
43+
const tokenizeFilterValue = (value: string): string[] => {
44+
const lowered = value.toLowerCase().trim()
45+
const tokens: string[] = []
46+
for (const match of lowered.matchAll(tokenPattern)) {
47+
const candidate = (match[1] ?? match[2] ?? '').replace(/^"+|"+$/g, '').trim()
48+
if (candidate) {
49+
tokens.push(candidate)
50+
}
51+
}
52+
return tokens
53+
}
54+
4055
const tokensForFilterValue = (filterValue: string): string[] => {
4156
if (filterValue === lastFilterValue) {
4257
return lastFilterTokens
4358
}
4459
lastFilterValue = filterValue
45-
lastFilterTokens = filterValue
46-
.toLowerCase()
47-
.trim()
48-
.split(/\s+/)
49-
.filter(Boolean)
60+
lastFilterTokens = tokenizeFilterValue(filterValue)
5061
return lastFilterTokens
5162
}
5263

0 commit comments

Comments
 (0)