mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 13:35:25 +02:00
debug: add detailed logging to trace history loading
This commit is contained in:
@@ -21,19 +21,23 @@ 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 data = await getHistory();
|
const historyData = await getHistory();
|
||||||
setHistory(data);
|
console.log('[HistoryView] getHistory returned:', historyData.length, 'entries', historyData[0]?.id === -1 || historyData[0]?.id === -2 ? '(ERROR)' : '');
|
||||||
|
setHistory(historyData);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+13
-8
@@ -161,26 +161,31 @@ export async function saveHistoryEntry(
|
|||||||
|
|
||||||
export async function getHistory(): Promise<HistoryEntry[]> {
|
export async function getHistory(): Promise<HistoryEntry[]> {
|
||||||
try {
|
try {
|
||||||
const response = await safeFetch(
|
const url = `${SUPABASE_URL}/rest/v1/products_history?select=*&order=changed_at.desc&limit=500`;
|
||||||
`${SUPABASE_URL}/rest/v1/products_history?select=*&order=changed_at.desc&limit=500`,
|
console.log('[getHistory] Fetching from:', url);
|
||||||
{ cache: 'no-store' }
|
console.log('[getHistory] Session:', !!getStoredSession(), 'ANON_KEY available:', !!SUPABASE_ANON_KEY);
|
||||||
);
|
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 err = await response.text();
|
const errText = await response.text();
|
||||||
|
console.error('[getHistory] Error response:', errText);
|
||||||
return [{
|
return [{
|
||||||
id: -1,
|
id: -1,
|
||||||
product_id: 'ERROR',
|
product_id: 'ERROR',
|
||||||
article_name: `Failed: ${response.status} ${err}`,
|
article_name: `Failed: ${response.status} ${errText.substring(0, 200)}`,
|
||||||
old_data: [],
|
old_data: [],
|
||||||
new_data: [],
|
new_data: [],
|
||||||
changed_at: new Date().toISOString(),
|
changed_at: new Date().toISOString(),
|
||||||
changed_by: 'system'
|
changed_by: 'system'
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
return await response.json();
|
const data = await response.json();
|
||||||
|
console.log('[getHistory] Received entries:', Array.isArray(data) ? data.length : data);
|
||||||
|
return data;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Error fetching history:', error);
|
console.error('[getHistory] Exception:', error.message);
|
||||||
return [{
|
return [{
|
||||||
id: -2,
|
id: -2,
|
||||||
product_id: 'EXCEPTION',
|
product_id: 'EXCEPTION',
|
||||||
|
|||||||
Reference in New Issue
Block a user