mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 12:25:23 +02:00
fix: restore internal control columns and protect them from Dropbox sync overrides
This commit is contained in:
+2
-2
@@ -45,10 +45,10 @@ export default async function handler(req, res) {
|
|||||||
.from('products')
|
.from('products')
|
||||||
.select('product_id, status');
|
.select('product_id, status');
|
||||||
|
|
||||||
// Protect products with status 'edited' or 'pending'
|
// Protect ALL products that are not 'excel' status (i.e. they have manual edits or special status)
|
||||||
const manuallyEditedIds = new Set(
|
const manuallyEditedIds = new Set(
|
||||||
(existingProducts || [])
|
(existingProducts || [])
|
||||||
.filter(p => p.status === 'edited' || p.status === 'pending')
|
.filter(p => p.status && p.status !== 'excel')
|
||||||
.map(p => p.product_id)
|
.map(p => p.product_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
+7
-4
@@ -191,9 +191,10 @@ const articleNoIdx = resolvedCols.ARTICLE_NO;
|
|||||||
let finalRow = [...row];
|
let finalRow = [...row];
|
||||||
|
|
||||||
// Merge logic: Prioritize internal control columns and active session edits
|
// Merge logic: Prioritize internal control columns and active session edits
|
||||||
if (synced && (synced.status === 'edited' || synced.status === 'pending' || synced.status === 'synced')) {
|
if (synced && synced.data) {
|
||||||
// 1. ALWAYS restore Internal Control Columns (indices >= 100)
|
// 1. ALWAYS restore Internal Control Columns (indices >= 100)
|
||||||
// These are the "TYPE", "Item to Logistic", "Checking", etc.
|
// These are the "TYPE", "Item to Logistic", "Checking", etc.
|
||||||
|
// We use hardcoded indices from COLUMNS to ensure they stay at the end.
|
||||||
Object.values(COLUMNS).forEach(idx => {
|
Object.values(COLUMNS).forEach(idx => {
|
||||||
if (idx >= 100 && synced.data[idx] !== undefined && synced.data[idx] !== null) {
|
if (idx >= 100 && synced.data[idx] !== undefined && synced.data[idx] !== null) {
|
||||||
finalRow[idx] = synced.data[idx];
|
finalRow[idx] = synced.data[idx];
|
||||||
@@ -210,8 +211,10 @@ const articleNoIdx = resolvedCols.ARTICLE_NO;
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update row status in UI
|
// Update row status in UI if it's not the default 'excel'
|
||||||
setRowStatuses(prev => ({ ...prev, [articleNo]: synced.status }));
|
if (synced.status && synced.status !== 'excel') {
|
||||||
|
setRowStatuses(prev => ({ ...prev, [articleNo]: synced.status! }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return finalRow.map((val: any, idx: number) => {
|
return finalRow.map((val: any, idx: number) => {
|
||||||
|
|||||||
+2
-8
@@ -74,14 +74,8 @@ export const COLUMN_PATTERNS: Record<keyof typeof COLUMNS, string[]> = {
|
|||||||
OUTER_W: ['outer', 'w'],
|
OUTER_W: ['outer', 'w'],
|
||||||
OUTER_L: ['outer', 'l'],
|
OUTER_L: ['outer', 'l'],
|
||||||
OUTER_H: ['outer', 'h'],
|
OUTER_H: ['outer', 'h'],
|
||||||
// Virtual/Extra columns stay hardcoded or managed elsewhere
|
// Virtual/Extra columns stay hardcoded and are NOT auto-detected from headers
|
||||||
VERIFIED_DIMS: ['verified'],
|
// to prevent internal data from being shifted or overwritten by Excel column shifts.
|
||||||
VALIDATED_CHECK: ['validated'],
|
|
||||||
VALIDATED_NOTE: ['note'],
|
|
||||||
PRODUCT_TYPE: ['type'],
|
|
||||||
ITEM_TO_LOGISTIC: ['item', 'to', 'logistic'],
|
|
||||||
ANNA_CHECK: ['anna', 'check'],
|
|
||||||
ANNA_NOTE: ['anna', 'note']
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function resolveColumnIndices(headers: string[]): typeof COLUMNS {
|
export function resolveColumnIndices(headers: string[]): typeof COLUMNS {
|
||||||
|
|||||||
Reference in New Issue
Block a user