restore cpnp values from history

This commit is contained in:
Christian Vidal Wolf
2026-05-20 14:56:55 +02:00
parent d17db2761b
commit cb913b9d72
2 changed files with 22 additions and 8 deletions
+1
View File
@@ -323,6 +323,7 @@ export default function App() {
[COLUMNS.ITEM_TO_LOGISTIC]: 'Item to Logistic', [COLUMNS.ITEM_TO_LOGISTIC]: 'Item to Logistic',
[COLUMNS.ANNA_CHECK]: 'Anna Check', [COLUMNS.ANNA_CHECK]: 'Anna Check',
[COLUMNS.ANNA_NOTE]: 'Anna Note', [COLUMNS.ANNA_NOTE]: 'Anna Note',
[COLUMNS.CPNP_NO]: 'CPNP No.',
}; };
Object.entries(VIRTUAL_COLS).forEach(([idxStr, name]) => { Object.entries(VIRTUAL_COLS).forEach(([idxStr, name]) => {
const idx = Number(idxStr); const idx = Number(idxStr);
+15 -2
View File
@@ -279,8 +279,13 @@ export async function getHistory(): Promise<HistoryEntry[]> {
export async function getHistoryDataForMerge(): Promise<Record<string, ExcelRow>> { export async function getHistoryDataForMerge(): Promise<Record<string, ExcelRow>> {
try { try {
const PAGE_SIZE = 1000;
const entries: HistoryEntry[] = [];
for (let page = 0; page < 20; page++) {
const offset = page * PAGE_SIZE;
const response = await safeFetch( const response = await safeFetch(
`${SUPABASE_URL}/rest/v1/products_history?select=product_id,old_data,new_data,changed_at,id`, `${SUPABASE_URL}/rest/v1/products_history?select=product_id,old_data,new_data,changed_at,id&order=changed_at.asc&limit=${PAGE_SIZE}&offset=${offset}`,
{ cache: 'no-store' } { cache: 'no-store' }
); );
@@ -288,7 +293,15 @@ export async function getHistoryDataForMerge(): Promise<Record<string, ExcelRow>
console.error('[getHistoryDataForMerge] Error:', response.status); console.error('[getHistoryDataForMerge] Error:', response.status);
return {}; return {};
} }
const entries: HistoryEntry[] = (await response.json()).filter((entry: HistoryEntry) => entry.product_id !== CONTROL_DASHBOARD_SNAPSHOT_PRODUCT_ID);
const batch: HistoryEntry[] = await response.json();
entries.push(
...batch.filter((entry: HistoryEntry) => entry.product_id !== CONTROL_DASHBOARD_SNAPSHOT_PRODUCT_ID)
);
if (batch.length < PAGE_SIZE) break;
}
entries.sort((a, b) => { entries.sort((a, b) => {
const timeDelta = new Date(a.changed_at).getTime() - new Date(b.changed_at).getTime(); const timeDelta = new Date(a.changed_at).getTime() - new Date(b.changed_at).getTime();
if (timeDelta !== 0) return timeDelta; if (timeDelta !== 0) return timeDelta;