mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 11:45:24 +02:00
restore cpnp values from history
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
+21
-8
@@ -279,16 +279,29 @@ 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 response = await safeFetch(
|
const PAGE_SIZE = 1000;
|
||||||
`${SUPABASE_URL}/rest/v1/products_history?select=product_id,old_data,new_data,changed_at,id`,
|
const entries: HistoryEntry[] = [];
|
||||||
{ cache: 'no-store' }
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
for (let page = 0; page < 20; page++) {
|
||||||
console.error('[getHistoryDataForMerge] Error:', response.status);
|
const offset = page * PAGE_SIZE;
|
||||||
return {};
|
const response = await safeFetch(
|
||||||
|
`${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' }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
console.error('[getHistoryDataForMerge] Error:', response.status);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
const entries: HistoryEntry[] = (await response.json()).filter((entry: HistoryEntry) => entry.product_id !== CONTROL_DASHBOARD_SNAPSHOT_PRODUCT_ID);
|
|
||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user