From fb243cdd20b1a5bc26b633307da1d6fe69408406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Wed, 26 Aug 2026 14:40:07 -0300 Subject: [PATCH] Add searchable consumption reference selectors --- src/pages/Registrations.tsx | 102 ++++++++++++++++++++++++++++++++---- 1 file changed, 93 insertions(+), 9 deletions(-) diff --git a/src/pages/Registrations.tsx b/src/pages/Registrations.tsx index 063d795..e728f58 100644 --- a/src/pages/Registrations.tsx +++ b/src/pages/Registrations.tsx @@ -1,6 +1,6 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { Link, useSearchParams } from 'react-router-dom'; -import { ClipboardList, CloudDownload, Loader2, Package, Pencil, RefreshCw, Ruler, Save, Tags, Trash2, Upload } from 'lucide-react'; +import { ChevronDown, ClipboardList, CloudDownload, Loader2, Package, Pencil, RefreshCw, Ruler, Save, Search, Tags, Trash2, Upload } from 'lucide-react'; import { deleteCatalogCategory, deleteCatalogProduct, @@ -101,6 +101,84 @@ const getAverageYield = (reference: ConsumptionReference) => { return reference.generalYield; }; +const CatalogProductPicker = ({ + value, + products, + emptyLabel, + searchPlaceholder, + onChange, +}: { + value: string; + products: CatalogProduct[]; + emptyLabel: string; + searchPlaceholder: string; + onChange: (value: string) => void; +}) => { + const [isOpen, setIsOpen] = useState(false); + const [query, setQuery] = useState(''); + const selectedProduct = products.find(product => String(product.id) === value); + const normalizedQuery = query.trim().toLocaleLowerCase('pt-BR'); + const visibleProducts = useMemo(() => products + .filter(product => !normalizedQuery || `${product.name} ${product.sku} ${product.color || ''}`.toLocaleLowerCase('pt-BR').includes(normalizedQuery)) + .slice(0, 60), [products, normalizedQuery]); + + return ( +
+ + {isOpen && ( +
+
+ +
+
+ + {visibleProducts.map(product => ( + + ))} + {!visibleProducts.length &&

Nenhum item encontrado.

} +
+
+ )} +
+ ); +}; + const getReferenceSourceLabel = (reference: ConsumptionReference) => ( reference.source === 'tiny_op' ? 'Tiny OP' @@ -1011,17 +1089,23 @@ const Registrations = () => {