@@ -0,0 +1,55 @@
|
||||
import type { ProcurementGroup } from '@/lib/procurement-navigation';
|
||||
|
||||
const terms: Record<string, string> = {
|
||||
supply_agreements:
|
||||
'acordo acordos contrato contratos vigência fornecimento',
|
||||
supply_imports:
|
||||
'importação alfândega aduaneira despachante transitário pauta',
|
||||
receipts: 'receber entrega recepção divergência',
|
||||
operational_orders: 'produção manutenção oficina ordem',
|
||||
capital_register:
|
||||
'projecto projeto imobilizado activo ativo património cadastro',
|
||||
my_workflow_tasks: 'tarefa pendência próxima acção',
|
||||
pending_approvals: 'aprovar aprovação decidir decisão',
|
||||
suppliers: 'fornecedor cadastro documento',
|
||||
supplier_evaluations: 'avaliar avaliação fornecedor',
|
||||
invoices: 'factura conferir conferência fornecedor',
|
||||
payments: 'pagamento liquidar liquidação saldo confirmação',
|
||||
budgets: 'orçamento reforço dotação saldo',
|
||||
stock_operations: 'inventário contagem saída entrega',
|
||||
inventory_lots: 'lote validade quarentena',
|
||||
audit_private: 'auditoria exportar exportação privada',
|
||||
audit_metadata: 'auditoria evento histórico metadados',
|
||||
};
|
||||
|
||||
export const normalizeMenuText = (value: string) =>
|
||||
value
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.toLocaleLowerCase('pt');
|
||||
|
||||
export const matchesMenuSearch = (text: string, query: string) => {
|
||||
const haystack = normalizeMenuText(text);
|
||||
return normalizeMenuText(query)
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.every((word) => haystack.includes(word));
|
||||
};
|
||||
|
||||
/** Search only the already authorised navigation; never introduce a route or grant. */
|
||||
export function searchProcurementMenu(
|
||||
groups: ProcurementGroup[],
|
||||
query: string,
|
||||
): ProcurementGroup[] {
|
||||
return groups
|
||||
.map((group) => ({
|
||||
...group,
|
||||
entries: group.entries.filter((entry) =>
|
||||
matchesMenuSearch(
|
||||
`${group.label} ${entry.section ?? ''} ${entry.label} ${terms[entry.id] ?? ''}`,
|
||||
query,
|
||||
),
|
||||
),
|
||||
}))
|
||||
.filter((group) => group.entries.length > 0);
|
||||
}
|
||||
Reference in New Issue
Block a user