fix: harden quotes search runtime lint#169
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
Caution Review failedPull request was closed or merged during review WalkthroughPR refatora cinco componentes/hooks com foco em remover non-null assertions ( ChangesNull-safety em componentes de Quotes
Melhorias em SharePreviewDialog
Reescrita do hook useGlobalSearch
Ajustes de re-exports em useProducts
🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR hardens runtime behavior in quotes UI flows and the global search/voice navigation hook by removing unsafe non-null assertions and adding guards, primarily to prevent crashes and satisfy stricter linting.
Changes:
- Added ID guards in quotes configurable list and Kanban interactions to avoid unsafe operations on missing quote IDs.
- Refactored
useGlobalSearchto avoid unsafeaction.data!.route!usage and improved resilience/cleanup of unused imports. - Removed dead imports and replaced unsafe fallbacks in product sharing/related-products code paths.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/hooks/products/useProducts.ts | Removes unused import and avoids non-null assertion in related-products query function. |
| src/components/search/useGlobalSearch.ts | Refactors global search + voice action handling; adds safer navigation/data access and reorganizes logic. |
| src/components/quotes/QuotesConfigurableList.tsx | Adds selection/ID guards and cleans up list UI interactions for quotes. |
| src/components/quotes/QuoteKanbanBoard.tsx | Removes unsafe non-null assertions and adjusts DnD logic around quote IDs. |
| src/components/products/share/SharePreviewDialog.tsx | Removes unsafe template fallback and tightens message/template selection behavior. |
Comments suppressed due to low confidence (1)
src/components/quotes/QuoteKanbanBoard.tsx:139
QuoteCardnavigates to/orcamentos/${quote.id}without checkingquote.id. Ifquote.idcan be missing (as suggested by the new guards), this still allows navigation to an invalid route. Disable/guard navigation when there is no id (e.g., disable the button and/or no-op onClick).
aria-label="Visualizar"
className="h-6 w-6"
onClick={(e) => {
e.stopPropagation();
navigate(`/orcamentos/${quote.id}`);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <div | ||
| key={quoteId ?? quote.quote_number} | ||
| className={`group grid cursor-pointer items-center gap-4 border-b border-border/40 px-4 py-3 transition-all duration-150 hover:border-l-2 hover:border-l-primary/60 hover:bg-muted/40 ${ | ||
| selected ? 'border-l-2 border-l-primary bg-primary/5' : '' | ||
| }`} | ||
| style={{ gridTemplateColumns: gridTemplate }} | ||
| onClick={() => navigate(`/orcamentos/${quote.id}`)} | ||
| > |
| <DropdownMenuItem onClick={() => navigate(`/orcamentos/${quote.id}`)}> | ||
| <Eye className="mr-2 h-4 w-4" /> Visualizar | ||
| </DropdownMenuItem> | ||
| <DropdownMenuItem onClick={() => navigate(`/orcamentos/${quote.id}/editar`)}> | ||
| <Edit className="mr-2 h-4 w-4" /> Editar | ||
| </DropdownMenuItem> |
| function SortableQuoteCard({ quote }: SortableQuoteCardProps) { | ||
| const { | ||
| attributes, | ||
| listeners, | ||
| setNodeRef, | ||
| transform, | ||
| transition, | ||
| isDragging, | ||
| } = useSortable({ id: quote.id! }); | ||
| const sortableId = quote.id ?? `quote-${quote.quote_number}`; | ||
| const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ | ||
| id: sortableId, | ||
| }); | ||
|
|
| <ScrollArea className="max-h-[calc(100vh-320px)] min-h-[400px] flex-1"> | ||
| <SortableContext items={sortableQuoteIds} strategy={verticalListSortingStrategy}> | ||
| <div className="space-y-2 p-1"> | ||
| {quotes.map((quote) => ( | ||
| <SortableQuoteCard key={quote.id} quote={quote} /> | ||
| ))} |
| async (searchQuery: string) => { | ||
| if (!searchQuery.trim() || searchQuery.length < 2) { | ||
| setResults([]); | ||
| setSearchIntent(null); | ||
| return; | ||
| } |
| if (searchQuery.length < 3) { | ||
| setResults([]); | ||
| setSearchIntent(null); | ||
| return; | ||
| } |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 41fc91273c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!controller.signal.aborted) setIsSearching(false); | ||
| } | ||
| }, | ||
| [commands], |
There was a problem hiding this comment.
Stabilize semantic search callback dependencies
Avoid depending on commands here, because useSlashCommands creates a new commands array on every render; that makes performSemanticSearch get a new identity every render and retriggers the useEffect that calls it even when debouncedQuery is unchanged. With a query of 3+ chars, this causes repeated abort/restart cycles and redundant Supabase function calls while the palette is open, which is a performance regression introduced by this change.
Useful? React with 👍 / 👎.
| metadata: { iconName: c.icon }, | ||
| })); | ||
|
|
||
| setResults(matchedCommands); |
There was a problem hiding this comment.
Prevent slash command mode from entering a render loop
When the query starts with / (for example /c), this branch always builds a fresh matchedCommands array and calls setResults, and because performSemanticSearch is recreated every render (via the new commands dependency), the effect re-runs immediately and writes results again. In practice this can cause continuous re-renders/high CPU while command search is open, even without any new input.
Useful? React with 👍 / 👎.
|
|
||
| function KanbanColumn({ column, quotes, totalValue }: KanbanColumnProps) { | ||
| const Icon = column.icon; | ||
| const sortableQuoteIds = quotes.map((q) => q.id).filter((id): id is string => Boolean(id)); |
There was a problem hiding this comment.
Keep sortable IDs consistent with sortable context items
This list now gives useSortable a fallback id (quote-${quote.quote_number}) when quote.id is missing, but SortableContext still receives only truthy quote.id values. For quotes without persisted ids (the exact case this commit tries to harden), the card id is absent from items, so drag-and-drop behavior becomes inconsistent (item cannot be managed correctly by dnd-kit). Build sortableQuoteIds with the same fallback mapping used by SortableQuoteCard.
Useful? React with 👍 / 👎.
Resumo
action.data!.route!e limpa imports mortos.!em template de compartilhamento e produto relacionado.Validação
npx.cmd eslint src/components/quotes/QuotesConfigurableList.tsx src/components/quotes/QuoteKanbanBoard.tsx src/components/search/useGlobalSearch.ts src/components/products/share/SharePreviewDialog.tsx src/hooks/products/useProducts.ts src/pages/admin/AdminProductFormPage.tsxnpx.cmd vitest run src/components/quotes/__tests__/QuoteBuilderDiscount.test.tsx src/components/products/ProductGrid.test.tsx- 2 arquivos / 6 testes passandogit diff --check HEAD~1..HEADnpm.cmd run buildcomVITE_SUPABASE_URLeVITE_SUPABASE_PUBLISHABLE_KEYObservação
git pushnormal ainda falha no hook locallint:baselinecomeslint falhou com status null; a branch foi publicada comHUSKY=0após validação manual focada.ProductGridcontinuam emitindo warnings conhecidos de React Router/fetchPriority/key, mas passam.Summary by cubic
Hardened quotes flows and global search to prevent crashes from missing IDs and routes. Removed unsafe non-null assertions and dead imports to improve runtime safety and satisfy linting.
Bug Fixes
action.data!.route!and handling missing data safely.Refactors
useProductscleanup and typing improvements with no behavior changes.Written for commit 41fc912. Summary will update on new commits. Review in cubic
Summary by CodeRabbit
Melhorias de Busca e Gestão de Orçamentos
Novas Funcionalidades
Melhorias