From 8a294dd28de7db52970535c7867eef0dd58873fa Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Mon, 17 Aug 2026 15:24:06 +0200 Subject: [PATCH] fix: search accountings for filter composer subjects --- src/i18n/locales/es.json | 4 +++- src/utils/filterComposer.ts | 9 ++++----- src/utils/filterSuggestions.ts | 24 ++++++++++-------------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/i18n/locales/es.json b/src/i18n/locales/es.json index 9fdd2bb9..bcd31ff5 100644 --- a/src/i18n/locales/es.json +++ b/src/i18n/locales/es.json @@ -78,7 +78,9 @@ "budgetAmount": "Importe", "gateway": "Pasarela", "type": "Tipo", - "origin": "Origen", + "checkout": { + "origin": "Origen" + }, "target": "Destino", "currency": "Moneda", "amount": "Importe", diff --git a/src/utils/filterComposer.ts b/src/utils/filterComposer.ts index 252e7a52..0130f4db 100644 --- a/src/utils/filterComposer.ts +++ b/src/utils/filterComposer.ts @@ -4,8 +4,7 @@ import { getDefaultLanguage } from "./consts"; import { currencySymbols } from "./currencyData"; import { suggestGateways, - suggestTarget, - suggestOrigin, + suggestAccounting, suggestOwner, suggestCategories, suggestProjects, @@ -188,15 +187,15 @@ const filterSubjects: Record = { type: "string", compatibleOperators: ["equals", "is_any_of"], resources: ["gateway_charges"], - suggest: suggestTarget, + suggest: suggestAccounting, allowsMultipleEquals: true, }, origin: { - key: "origin", + key: "checkout.origin", type: "string", compatibleOperators: ["equals", "is_any_of"], resources: ["gateway_charges"], - suggest: suggestOrigin, + suggest: suggestAccounting, allowsMultipleEquals: true, }, currency: { diff --git a/src/utils/filterSuggestions.ts b/src/utils/filterSuggestions.ts index d881be5d..fcf2b728 100644 --- a/src/utils/filterSuggestions.ts +++ b/src/utils/filterSuggestions.ts @@ -30,35 +30,31 @@ export async function suggestGateways(q: string): Promise { })); } -export async function suggestTarget(q: string): Promise { +export async function suggestAccounting(q: string): Promise { const trimmed = q.trim(); if (trimmed.length < 2) return []; - const [projects, tipjars, users] = await Promise.all([ - apiProjectsGetCollection({ query: { title: trimmed } }), - apiTipjarsGetCollection({ query: { name: trimmed } }), - apiUsersGetCollection({ query: { handle: trimmed } }), + const [tipjars, users, projects] = await Promise.all([ + apiTipjarsGetCollection({ query: { name: trimmed, itemsPerPage: 1 } }), + apiUsersGetCollection({ query: { q: trimmed, itemsPerPage: 5 } }), + apiProjectsGetCollection({ query: { title: trimmed, itemsPerPage: 4 } }), ]); const options: FilterOption[] = []; - for (const p of projects.data ?? []) { - options.push({ value: p.accounting ?? "", label: p.title ?? "" }); - } for (const t of tipjars.data ?? []) { - options.push({ value: t.accounting ?? "", label: t.name ?? "" }); + options.push({ value: t.accounting!, label: `${t.name} (tipjar)` }); } for (const u of users.data ?? []) { - options.push({ value: u.handle ?? "", label: u.handle ?? "" }); + options.push({ value: u.accounting!, label: `${u.email} (user)` }); + } + for (const p of projects.data ?? []) { + options.push({ value: p.accounting!, label: `${p.title} (project)` }); } return options; } -export async function suggestOrigin(q: string): Promise { - return suggestTarget(q); -} - export async function suggestOwner(q: string): Promise { const trimmed = q.trim(); if (trimmed.length < 2) return [];