Some checks failed
/ Deploy to Cloudflare Pages (push) Has been cancelled
Fix 4 Parte A: .maybeSingle() ya estaba aplicado (lo hiciste vos/el linter). Encontré y arreglé un bug adicional: con data === null (sin simulaciones), el código llamaba fromRow(null) y explotaba al leer row.id. Ahora getLatestByProcess retorna undefined limpiamente cuando no hay filas. Fix 4 Parte B: revisé ProcessCardWithSim en LibraryPage.tsx — ya tiene guard de cancelación y dependencias estables (process.id + acción de Zustand, que es una referencia fija). No encontré un loop real; lo más probable es que "~6 queries" correspondan a 6 procesos distintos disparando una query cada uno (correcto), posiblemente duplicado visualmente en dev por StrictMode (inocuo, no pasa en producción). Fixes 1, 2, 3 ya estaban implementados de antes y siguen verdes. Falta tu validación visual — en particular confirmar que el network tab ya no muestra 406 en simulations.
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { supabase } from '@/lib/supabase'
|
|
import type { Simulation, SimulationResult } from '@/domain/types'
|
|
|
|
function fromRow(row: Record<string, unknown>): Simulation {
|
|
return {
|
|
id: row.id as string,
|
|
processId: row.process_id as string,
|
|
executedAt: Number(row.executed_at),
|
|
result: row.result as SimulationResult,
|
|
resultAutomated: row.result_automated != null
|
|
? (row.result_automated as SimulationResult)
|
|
: undefined,
|
|
}
|
|
}
|
|
|
|
export const supabaseSimulationRepo = {
|
|
async save(simulation: Simulation): Promise<void> {
|
|
const { error } = await supabase.from('simulations').insert({
|
|
id: simulation.id,
|
|
process_id: simulation.processId,
|
|
executed_at: simulation.executedAt,
|
|
result: simulation.result,
|
|
result_automated: simulation.resultAutomated ?? null,
|
|
})
|
|
if (error) throw error
|
|
},
|
|
|
|
async getLatestByProcess(processId: string): Promise<Simulation | undefined> {
|
|
const { data, error } = await supabase
|
|
.from('simulations')
|
|
.select('*')
|
|
.eq('process_id', processId)
|
|
.order('executed_at', { ascending: false })
|
|
.limit(1)
|
|
.maybeSingle()
|
|
if (error || !data) return undefined
|
|
return fromRow(data as Record<string, unknown>)
|
|
},
|
|
|
|
async getByProcess(processId: string): Promise<Simulation[]> {
|
|
const { data, error } = await supabase
|
|
.from('simulations')
|
|
.select('*')
|
|
.eq('process_id', processId)
|
|
.order('executed_at', { ascending: false })
|
|
if (error) throw error
|
|
return (data ?? []).map(fromRow)
|
|
},
|
|
}
|