The minimalistic document archiving platform.
fix(demo): support select and multi_select in demo mock (#1293)
Corentin Thomasseta38efcca7cf1
diff --git a/apps/papra-client/src/modules/demo/search/demo.search.services.test.ts b/apps/papra-client/src/modules/demo/search/demo.search.services.test.tsindex 27a5eebc..d3d4585a 100644--- a/apps/papra-client/src/modules/demo/search/demo.search.services.test.ts+++ b/apps/papra-client/src/modules/demo/search/demo.search.services.test.ts@@ -62,6 +62,28 @@ describe('demo search services', () => {createdAt: new Date('2023-07-01'),customProperties: [{ key: 'invoicenumber', type: 'text', value: 'INV-001' }],},+ {+ id: 'doc_8',+ name: 'Case File',+ content: 'Reviewed case file.',+ tags: [],+ createdAt: new Date('2023-08-01'),+ customProperties: [+ {+ key: 'status',+ type: 'select',+ value: { optionId: 'opt_status_archived', name: 'Archived' },+ },+ {+ key: 'labels',+ type: 'multi_select',+ value: [+ { optionId: 'opt_label_urgent', name: 'Urgent' },+ { optionId: 'opt_label_review', name: 'Review' },+ ],+ },+ ],+ },] as unknown as Document[];const queries = [@@ -71,17 +93,27 @@ describe('demo search services', () => {{ query: 'tag:cooking', expectedIds: ['doc_1', 'doc_4'] },{ query: 'tag:cooking butter', expectedIds: ['doc_4'] },{ query: 'tag:work created:>2023-03-01', expectedIds: ['doc_5', 'doc_7'] },- { query: '-tag:work', expectedIds: ['doc_1', 'doc_3', 'doc_4', 'doc_6'] },+ { query: '-tag:work', expectedIds: ['doc_1', 'doc_3', 'doc_4', 'doc_6', 'doc_8'] },{ query: 'has:tags', expectedIds: ['doc_1', 'doc_2', 'doc_3', 'doc_4', 'doc_5', 'doc_7'] },- { query: '-has:tags', expectedIds: ['doc_6'] },- { query: 'NOT has:tags', expectedIds: ['doc_6'] },- { query: '-has:tags OR tag:personal', expectedIds: ['doc_3', 'doc_4', 'doc_6'] },+ { query: '-has:tags', expectedIds: ['doc_6', 'doc_8'] },+ { query: 'NOT has:tags', expectedIds: ['doc_6', 'doc_8'] },+ { query: '-has:tags OR tag:personal', expectedIds: ['doc_3', 'doc_4', 'doc_6', 'doc_8'] },{ query: 'ncakes', expectedIds: [] },{ query: 'name:ncakes', expectedIds: [] },{ query: 'content:ncakes', expectedIds: [] },{ query: 'InvoiceNumber:INV', expectedIds: ['doc_7'] },{ query: 'invoicenumber:INV', expectedIds: ['doc_7'] },{ query: 'INVOICENUMBER:INV', expectedIds: ['doc_7'] },+ // select custom property — matched by option key (lowercased option name) or option id+ { query: 'status:archived', expectedIds: ['doc_8'] },+ { query: 'status:Archived', expectedIds: ['doc_8'] },+ { query: 'status:opt_status_archived', expectedIds: ['doc_8'] },+ { query: 'status:pending', expectedIds: [] },+ { query: 'has:status', expectedIds: ['doc_8'] },+ // multi_select custom property — matches if any option matches+ { query: 'labels:urgent', expectedIds: ['doc_8'] },+ { query: 'labels:review', expectedIds: ['doc_8'] },+ { query: 'labels:missing', expectedIds: [] },];for (const { query, expectedIds } of queries) {diff --git a/apps/papra-client/src/modules/demo/search/demo.search.services.ts b/apps/papra-client/src/modules/demo/search/demo.search.services.tsindex f1d0c141..8fa8354c 100644--- a/apps/papra-client/src/modules/demo/search/demo.search.services.ts+++ b/apps/papra-client/src/modules/demo/search/demo.search.services.ts@@ -217,6 +217,21 @@ function buildHasCustomPropertyFilter({ propertyKey }: { propertyKey: string }):};}+function selectOptionMatches({ option, value }: { option: unknown; value: string }): boolean {+ // Hydrated select values are shaped like `{ optionId, name }` (mirroring the real API),+ // but raw seed/string values are also tolerated. Match against any available identifier.+ const candidates =+ typeof option === 'object' && option !== null+ ? [(option as { optionId?: unknown }).optionId, (option as { name?: unknown }).name]+ : [option];++ const lowerValue = value.toLowerCase();++ return candidates.some(+ (candidate) => typeof candidate === 'string' && candidate.toLowerCase() === lowerValue,+ );+}+function buildCustomPropertyFilterCondition({field,expression,@@ -304,23 +319,16 @@ function buildCustomPropertyFilterCondition({return false;}- const propValue = prop.value as { key: string; name: string } | string;- const propKey = typeof propValue === 'object' ? propValue.key : propValue;-- return propKey.toLowerCase() === value.toLowerCase();+ return selectOptionMatches({ option: prop.value, value });}case 'multi_select': {if (operator !== '=') {return false;}- const propValues = prop.value as Array<{ key: string; name: string } | string>;-- return propValues.some((v) => {- const optKey = typeof v === 'object' ? v.key : v;+ const propValues = prop.value as unknown[];- return optKey.toLowerCase() === value.toLowerCase();- });+ return propValues.some((option) => selectOptionMatches({ option, value }));}default: {if (operator !== '=') {