feat: correcao de deteccao de monopeças no conversor e estilizacao de pecas simples na tabela

This commit is contained in:
2026-09-16 17:52:48 +00:00
parent 2b19a0d443
commit 5168ef3d61
6 changed files with 39 additions and 31 deletions
+3 -5
View File
@@ -618,11 +618,9 @@
} }
if (currentAssembly) { if (currentAssembly) {
const isSubComp = const lastNumberMatch = itemMark.match(/(?:^|-)(\d+)$/);
itemMark === '-' || const itemNum = lastNumberMatch ? parseInt(lastNumberMatch[1], 10) : (parseInt(itemMark, 10) || 0);
itemMark.includes('-100') || const isSubComp = itemMark === '-' || itemNum >= 1000;
itemMark.includes('-10') ||
(itemMark.match(/-\d+$/) && parseInt(itemMark.match(/-(\d+)$/)[1], 10) >= 1000);
if (isSubComp) { if (isSubComp) {
currentAssembly.isComposed = 'SIM'; currentAssembly.isComposed = 'SIM';
+3 -5
View File
@@ -618,11 +618,9 @@
} }
if (currentAssembly) { if (currentAssembly) {
const isSubComp = const lastNumberMatch = itemMark.match(/(?:^|-)(\d+)$/);
itemMark === '-' || const itemNum = lastNumberMatch ? parseInt(lastNumberMatch[1], 10) : (parseInt(itemMark, 10) || 0);
itemMark.includes('-100') || const isSubComp = itemMark === '-' || itemNum >= 1000;
itemMark.includes('-10') ||
(itemMark.match(/-\d+$/) && parseInt(itemMark.match(/-(\d+)$/)[1], 10) >= 1000);
if (isSubComp) { if (isSubComp) {
currentAssembly.isComposed = 'SIM'; currentAssembly.isComposed = 'SIM';
@@ -518,12 +518,12 @@ const AdvanceSteelConverterContent: React.FC = () => {
} }
if (currentAssembly) { if (currentAssembly) {
const isSubComp = // Extrai o número final da marca do item (ex: de "B134-13-1" -> 1, de "B134-13-1000" -> 1000, de "B133-13-1015" -> 1015, de "1000" -> 1000)
itemMark === '-' || const lastNumberMatch = itemMark.match(/(?:^|-)(\d+)$/);
isComponente(itemMark) || const itemNum = lastNumberMatch ? parseInt(lastNumberMatch[1], 10) : (parseInt(itemMark, 10) || 0);
itemMark.includes('-100') ||
itemMark.includes('-10') || // Um item é SUBCOMPONENTE apenas se sua numeração de marca for >= faixaComponenteMin (1000) OU se for explicitamente '-'
(itemMark.match(/-\d+$/) && parseInt(itemMark.match(/-(\d+)$/)![1], 10) >= (labels.faixaComponenteMin || 1000)); const isSubComp = itemMark === '-' || itemNum >= (labels.faixaComponenteMin || 1000);
if (isSubComp) { if (isSubComp) {
currentAssembly.isComposed = 'SIM'; currentAssembly.isComposed = 'SIM';
@@ -72,8 +72,8 @@ export function TableHeaderSortable({
<SortButton field="prioridade">Prioridade</SortButton> <SortButton field="prioridade">Prioridade</SortButton>
</TableHead> </TableHead>
<TableHead className="w-16 px-2 text-center"> <TableHead className="w-24 px-2 text-center">
<SortButton field="tem_componentes">Tipo / {labels.componenteLabel}</SortButton> <SortButton field="tem_componentes">Componentes</SortButton>
</TableHead> </TableHead>
<TableHead className="w-12 px-2 text-right"> <TableHead className="w-12 px-2 text-right">
+9 -5
View File
@@ -13,7 +13,8 @@ import {
ChevronDown, ChevronDown,
Layers, Layers,
Loader2, Loader2,
ExternalLink ExternalLink,
Minus
} from 'lucide-react'; } from 'lucide-react';
import { Peca } from '@/hooks/usePecas'; import { Peca } from '@/hooks/usePecas';
import { useComponentesPeca } from '@/hooks/useComponentesPeca'; import { useComponentesPeca } from '@/hooks/useComponentesPeca';
@@ -110,11 +111,14 @@ export function TableRow({
<PriorityBadge prioridade={peca.prioridade as any} /> <PriorityBadge prioridade={peca.prioridade as any} />
</TableCell> </TableCell>
<TableCell className="w-16 px-2 text-center"> <TableCell className="w-24 px-2 text-center">
<div className="flex justify-center"> <div className="flex justify-center items-center">
{!peca.tem_componentes ? ( {!peca.tem_componentes ? (
<div className="flex items-center justify-center w-5 h-5 bg-green-500 rounded-full shadow-sm" title="Monopeça (sem componentes)"> <div
<Check className="h-3 w-3 text-white font-bold" /> className="flex items-center justify-center w-5 h-5 rounded-full bg-slate-800/90 border border-slate-700 text-slate-400 shadow-sm"
title="Peça única (sem componentes)"
>
<Minus className="h-3 w-3 text-slate-400 font-bold" />
</div> </div>
) : ( ) : (
<div <div
+16 -8
View File
@@ -567,15 +567,17 @@ export function usePecas() {
} }
} }
// 4. Inserir/Sincronizar Componentes // 4. Inserir/Sincronizar Componentes (Limpa resíduos se a peça virou simples ou foi reimportada)
let totalComponentesInseridos = 0; let totalComponentesInseridos = 0;
if (componentesMap.size > 0) { console.log('🔧 Inserindo e sincronizando componentes...');
console.log('🔧 Inserindo e sincronizando componentes...');
for (const peca of pecasParaProcessar) {
for (const [pecaKey, componentes] of componentesMap.entries()) { const pecaKey = `${peca.of_number || ''}-${peca.etapa_fase || ''}-${peca.marca || ''}`;
const pecaId = pecaIdResolvedMap.get(pecaKey); const pecaId = pecaIdResolvedMap.get(pecaKey);
const componentes = componentesMap.get(pecaKey) || [];
if (pecaId && componentes.length > 0) {
if (pecaId) {
if (componentes.length > 0) {
// Limpar componentes antigos desta peça para atualizar de forma limpa // Limpar componentes antigos desta peça para atualizar de forma limpa
await supabase await supabase
.from('componentes_peca') .from('componentes_peca')
@@ -596,6 +598,12 @@ export function usePecas() {
} else { } else {
totalComponentesInseridos += componentesComPecaId.length; totalComponentesInseridos += componentesComPecaId.length;
} }
} else {
// Peça simples sem componentes: limpar componentes residuais antigos caso existissem
await supabase
.from('componentes_peca')
.delete()
.eq('peca_id', pecaId);
} }
} }
} }