fix: HistoryEntry.id type changed from number to string (Supabase returns UUID)

This commit is contained in:
Christian Vidal Wolf
2026-04-23 18:58:52 +02:00
parent be2adbfe68
commit ee94926d04
2 changed files with 11 additions and 19 deletions
+1 -5
View File
@@ -8,7 +8,7 @@ import { cn } from '../lib/utils';
interface HistoryViewProps { interface HistoryViewProps {
headers: string[]; headers: string[];
data: ExcelRow[]; data: ExcelRow[];
onRevert: (articleNo: string, oldData: ExcelRow, historyId?: number) => void; onRevert: (articleNo: string, oldData: ExcelRow, historyId?: string) => void;
onEdit?: (rowIndex: number) => void; onEdit?: (rowIndex: number) => void;
} }
@@ -21,22 +21,18 @@ export function HistoryView({ headers, data, onRevert, onEdit }: HistoryViewProp
const [isFullscreen, setIsFullscreen] = useState(false); const [isFullscreen, setIsFullscreen] = useState(false);
useEffect(() => { useEffect(() => {
console.log('[HistoryView] Mounting, data length:', data.length);
loadHistory(); loadHistory();
}, []); }, []);
useEffect(() => { useEffect(() => {
console.log('[HistoryView] data changed, length:', data.length);
if (data.length > 0) { if (data.length > 0) {
loadHistory(); loadHistory();
} }
}, [data]); }, [data]);
const loadHistory = async () => { const loadHistory = async () => {
console.log('[HistoryView] loadHistory called');
setLoading(true); setLoading(true);
const historyData = await getHistory(); const historyData = await getHistory();
console.log('[HistoryView] getHistory returned:', historyData.length, 'entries', historyData[0]?.id === -1 || historyData[0]?.id === -2 ? '(ERROR)' : '');
setHistory(historyData); setHistory(historyData);
setLoading(false); setLoading(false);
}; };
+10 -14
View File
@@ -108,7 +108,7 @@ export async function saveRowToSupabase(articleNo: string, rowData: ExcelRow): P
} }
export interface HistoryEntry { export interface HistoryEntry {
id?: number; id?: string;
product_id: string; product_id: string;
article_name: string; article_name: string;
old_data: ExcelRow; old_data: ExcelRow;
@@ -161,18 +161,16 @@ export async function saveHistoryEntry(
export async function getHistory(): Promise<HistoryEntry[]> { export async function getHistory(): Promise<HistoryEntry[]> {
try { try {
const url = `${SUPABASE_URL}/rest/v1/products_history?select=*&order=changed_at.desc&limit=500`; const response = await safeFetch(
console.log('[getHistory] Fetching from:', url); `${SUPABASE_URL}/rest/v1/products_history?select=*&order=changed_at.desc&limit=500`,
console.log('[getHistory] Session:', !!getStoredSession(), 'ANON_KEY available:', !!SUPABASE_ANON_KEY); { cache: 'no-store' }
const response = await safeFetch(url, { cache: 'no-store' }); );
console.log('[getHistory] Response status:', response.status);
console.log('[getHistory] Response ok:', response.ok);
if (!response.ok) { if (!response.ok) {
const errText = await response.text(); const errText = await response.text();
console.error('[getHistory] Error response:', errText); console.error('[getHistory] Error:', response.status, errText.substring(0, 200));
return [{ return [{
id: -1, id: 'ERROR',
product_id: 'ERROR', product_id: 'ERROR',
article_name: `Failed: ${response.status} ${errText.substring(0, 200)}`, article_name: `Failed: ${response.status} ${errText.substring(0, 200)}`,
old_data: [], old_data: [],
@@ -181,13 +179,11 @@ export async function getHistory(): Promise<HistoryEntry[]> {
changed_by: 'system' changed_by: 'system'
}]; }];
} }
const data = await response.json(); return await response.json();
console.log('[getHistory] Received entries:', Array.isArray(data) ? data.length : data);
return data;
} catch (error: any) { } catch (error: any) {
console.error('[getHistory] Exception:', error.message); console.error('[getHistory] Exception:', error.message);
return [{ return [{
id: -2, id: 'EXCEPTION',
product_id: 'EXCEPTION', product_id: 'EXCEPTION',
article_name: `Message: ${error.message}`, article_name: `Message: ${error.message}`,
old_data: [], old_data: [],
@@ -201,7 +197,7 @@ export async function getHistory(): Promise<HistoryEntry[]> {
export async function deleteHistoryEntry(id: string): Promise<boolean> { export async function deleteHistoryEntry(id: string): Promise<boolean> {
try { try {
const response = await safeFetch( const response = await safeFetch(
`${SUPABASE_URL}/rest/v1/products_history?id=eq.${encodeURIComponent(id)}`, `${SUPABASE_URL}/rest/v1/products_history?id=eq.${encodeURIComponent(String(id))}`,
{ method: 'DELETE' } { method: 'DELETE' }
); );