restore cosmetic cpnp merge logic

This commit is contained in:
Christian Vidal Wolf
2026-05-20 15:06:12 +02:00
parent 1d5f918a0a
commit 528d859742
+54 -10
View File
@@ -337,6 +337,37 @@ export default function App() {
}
const resolvedCols = resolveColumnIndices(extendedHeaders);
const editableColumns = new Set([
resolvedCols.CLASSIFICATION,
resolvedCols.LONG_DE,
resolvedCols.LONG_EN,
resolvedCols.SHORT_DE,
resolvedCols.SHORT_EN,
resolvedCols.DETAILS_DE,
resolvedCols.DETAILS_EN,
resolvedCols.INNER_L,
resolvedCols.INNER_W,
resolvedCols.INNER_H,
resolvedCols.OUTER_L,
resolvedCols.OUTER_W,
resolvedCols.OUTER_H,
resolvedCols.UNITS_OUTER,
resolvedCols.MOQ,
resolvedCols.VERIFIED_DIMS,
resolvedCols.VALIDATED_CHECK,
resolvedCols.VALIDATED_NOTE,
resolvedCols.PRODUCT_TYPE,
resolvedCols.ITEM_TO_LOGISTIC,
resolvedCols.CPNP_NO
]);
headers.forEach((h: any, i: number) => {
const headerText = String(h || '').toLowerCase();
if (headerText.includes('srp') || headerText.includes('uvp') || headerText.includes('40') || headerText.includes('price')) {
editableColumns.add(i);
}
});
const articleNoIdx = resolvedCols.ARTICLE_NO;
const processedRows = rows.map(row => {
const articleNo = String(row[articleNoIdx]);
@@ -351,17 +382,20 @@ export default function App() {
finalRow.push(null);
}
// Merge logic:
// - Use the Dropbox row as the base for master data and prices.
// - Restore internal control columns from history when available.
// This is critical because some synced rows still have empty internal
// slots even when the change history already contains the corrected value.
const mergedInternalSource = hist || synced?.data;
const syncedHasInternalCols = Boolean(
synced?.data && (
synced.data.length > 100 ||
Object.values(COLUMNS).some(idx =>
idx >= 100 &&
synced.data?.[idx] !== undefined &&
synced.data?.[idx] !== null &&
synced.data?.[idx] !== ''
)
)
);
const sourceForInternal = syncedHasInternalCols ? synced!.data : (hist || synced?.data);
if (mergedInternalSource) {
// 1. Restore internal control columns (indices >= 100)
// These are the "TYPE", "Item to Logistic", "Checking", etc.
// We use hardcoded indices from COLUMNS to keep them stable.
if (sourceForInternal) {
Object.values(COLUMNS).forEach(idx => {
if (idx < 100) return;
@@ -379,6 +413,16 @@ export default function App() {
}
});
// When a row is still in an edited/pending state, restore editable business fields too.
// This includes historical CPNP edits that were persisted directly in products.
if (synced?.status === 'pending' || synced?.status === 'edited') {
editableColumns.forEach(idx => {
if (idx < 100 && sourceForInternal[idx] !== undefined && sourceForInternal[idx] !== null) {
finalRow[idx] = sourceForInternal[idx];
}
});
}
// Update row status in UI if it's not the default 'excel'
if (synced?.status && synced.status !== 'excel') {
setRowStatuses(prev => ({ ...prev, [articleNo]: synced.status! }));