fix: Column rename persistence and comprehensive logging

Fixed column header renaming by creating new array references.
Added comprehensive console logging for debugging.
This commit is contained in:
sysadmin 2025-11-14 00:20:05 +00:00
parent abe01cb8a0
commit 35ebf58dca
3 changed files with 53 additions and 20 deletions

View File

@ -67,14 +67,14 @@
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");} @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
<!-- Handsontable Spreadsheet Library --> <!-- Handsontable Spreadsheet Library -->
<link rel="stylesheet" href="~/lib/handsontable/handsontable.full.min.css?v=20251113b" /> <link rel="stylesheet" href="~/lib/handsontable/handsontable.full.min.css?v=20251113c" />
<script src="~/lib/handsontable/handsontable.full.min.js?v=20251113b"></script> <script src="~/lib/handsontable/handsontable.full.min.js?v=20251113c"></script>
<!-- Hammer.js for Touch Gestures --> <!-- Hammer.js for Touch Gestures -->
<script src="~/lib/hammerjs/hammer.min.js?v=20251113b"></script> <script src="~/lib/hammerjs/hammer.min.js?v=20251113c"></script>
<!-- Variant Editor Module --> <!-- Variant Editor Module -->
<script src="~/js/variant-editor.js?v=20251113b"></script> <script src="~/js/variant-editor.js?v=20251113c"></script>
<!-- Initialize Variant Editor --> <!-- Initialize Variant Editor -->
<script> <script>

View File

@ -78,14 +78,14 @@
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");} @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
<!-- Handsontable Spreadsheet Library --> <!-- Handsontable Spreadsheet Library -->
<link rel="stylesheet" href="~/lib/handsontable/handsontable.full.min.css?v=20251113b" /> <link rel="stylesheet" href="~/lib/handsontable/handsontable.full.min.css?v=20251113c" />
<script src="~/lib/handsontable/handsontable.full.min.js?v=20251113b"></script> <script src="~/lib/handsontable/handsontable.full.min.js?v=20251113c"></script>
<!-- Hammer.js for Touch Gestures --> <!-- Hammer.js for Touch Gestures -->
<script src="~/lib/hammerjs/hammer.min.js?v=20251113b"></script> <script src="~/lib/hammerjs/hammer.min.js?v=20251113c"></script>
<!-- Variant Editor Module --> <!-- Variant Editor Module -->
<script src="~/js/variant-editor.js?v=20251113b"></script> <script src="~/js/variant-editor.js?v=20251113c"></script>
<!-- Initialize Variant Editor --> <!-- Initialize Variant Editor -->
<script> <script>

View File

@ -245,11 +245,15 @@ class VariantEditor {
// Insert new column // Insert new column
this.hot.alter('insert_col_end', currentColCount, 1); this.hot.alter('insert_col_end', currentColCount, 1);
// Update column header // Update column header with new array reference
const headers = this.hot.getColHeaders(); const currentHeaders = this.hot.getColHeaders();
headers[currentColCount] = presetName; const newHeaders = Array.isArray(currentHeaders)
? [...currentHeaders]
: Array.from({ length: this.hot.countCols() }, (_, i) => this.hot.getColHeader(i));
newHeaders[currentColCount] = presetName;
this.hot.updateSettings({ this.hot.updateSettings({
colHeaders: headers colHeaders: newHeaders
}); });
// Populate with preset values // Populate with preset values
@ -260,6 +264,8 @@ class VariantEditor {
} }
}); });
} }
console.log('Added preset column:', { presetName, columnIndex: currentColCount, valuesCount: presetValues ? presetValues.length : 0 });
} }
/** /**
@ -276,12 +282,18 @@ class VariantEditor {
// Insert new column // Insert new column
this.hot.alter('insert_col_end', currentColCount, 1); this.hot.alter('insert_col_end', currentColCount, 1);
// Update column header // Update column header with new array reference
const headers = this.hot.getColHeaders(); const currentHeaders = this.hot.getColHeaders();
headers[currentColCount] = customName.trim(); const newHeaders = Array.isArray(currentHeaders)
? [...currentHeaders]
: Array.from({ length: this.hot.countCols() }, (_, i) => this.hot.getColHeader(i));
newHeaders[currentColCount] = customName.trim();
this.hot.updateSettings({ this.hot.updateSettings({
colHeaders: headers colHeaders: newHeaders
}); });
console.log('Added custom column:', { columnName: customName.trim(), columnIndex: currentColCount });
} }
/** /**
@ -292,11 +304,24 @@ class VariantEditor {
const newName = prompt('Rename column:', currentHeader); const newName = prompt('Rename column:', currentHeader);
if (newName && newName.trim() !== '') { if (newName && newName.trim() !== '') {
const headers = this.hot.getColHeaders(); // Get current headers and create a new array (force immutability)
headers[colIndex] = newName.trim(); const currentHeaders = this.hot.getColHeaders();
const newHeaders = Array.isArray(currentHeaders)
? [...currentHeaders]
: Array.from({ length: this.hot.countCols() }, (_, i) => this.hot.getColHeader(i));
// Update the specific column header
newHeaders[colIndex] = newName.trim();
// Force update with new array reference
this.hot.updateSettings({ this.hot.updateSettings({
colHeaders: headers colHeaders: newHeaders
}); });
// Render to ensure visual update
this.hot.render();
console.log('Column renamed:', { colIndex, oldName: currentHeader, newName: newName.trim() });
} }
} }
@ -364,12 +389,15 @@ class VariantEditor {
const headers = this.hot.getColHeaders(); const headers = this.hot.getColHeaders();
const properties = []; const properties = [];
console.log('Serializing spreadsheet:', { totalColumns: headers.length, totalRows: data.length });
// Process each column // Process each column
for (let col = 0; col < headers.length; col++) { for (let col = 0; col < headers.length; col++) {
const propertyName = headers[col]; const propertyName = headers[col];
// Skip empty column names // Skip empty column names or default column names
if (!propertyName || propertyName.trim() === '' || propertyName.startsWith('Property ')) { if (!propertyName || propertyName.trim() === '' || propertyName.startsWith('Property ')) {
console.log('Skipping column:', { colIndex: col, name: propertyName, reason: 'empty or default' });
continue; continue;
} }
@ -389,14 +417,19 @@ class VariantEditor {
}; };
properties.push(property); properties.push(property);
console.log('Added property:', { name: property.name, valueCount: values.length });
} }
const jsonString = JSON.stringify(properties, null, 2); const jsonString = JSON.stringify(properties, null, 2);
console.log('Final JSON:', jsonString);
// Update hidden input // Update hidden input
const hiddenInput = document.getElementById('PropertiesJson'); const hiddenInput = document.getElementById('PropertiesJson');
if (hiddenInput) { if (hiddenInput) {
hiddenInput.value = jsonString; hiddenInput.value = jsonString;
console.log('Updated hidden input PropertiesJson');
} else {
console.error('Hidden input PropertiesJson not found!');
} }
return jsonString; return jsonString;