Skip to content

Commit fd8541a

Browse files
BUGFIX: multiple reloads when template the same accidentally cleared data harmonizers.
1 parent 1b701ab commit fd8541a

File tree

6 files changed

+222
-115
lines changed

6 files changed

+222
-115
lines changed

lib/AppContext.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ export default class AppContext {
226226
const isForcedSchemaProvided = overrides.forced_schema !== null;
227227
const isLocaleChange = overrides.locale !== null;
228228

229+
229230
const clearAndSetup = async (
230231
data_harmonizers = {},
231232
forced_schema = null
@@ -245,7 +246,7 @@ export default class AppContext {
245246

246247
// Handle same template path without uploaded template
247248
if (isSameTemplatePath) {
248-
return clearAndSetup();
249+
return clearAndSetup(this.dhs);
249250
}
250251

251252
// Handle forced schema case

lib/DataHarmonizer.js

+43-32
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,32 @@ class DataHarmonizer {
14071407
return false;
14081408
}
14091409

1410+
/**
1411+
* Construct a dictionary of source field names pointing to column index
1412+
* @param {Object} fields A flat version of data.js.
1413+
* @return {Map<String, Integer>} Dictionary of all fields.
1414+
*/
1415+
getFieldNameMap(fields) {
1416+
const map = {};
1417+
for (const [fieldIndex, field] of fields.entries()) {
1418+
map[field.name] = fieldIndex;
1419+
}
1420+
return map;
1421+
}
1422+
1423+
/**
1424+
* Construct a dictionary of source field TITLES pointing to column index
1425+
* @param {Object} fields A flat version of data.js.
1426+
* @return {Map<String, Integer>} Dictionary of all fields.
1427+
*/
1428+
getFieldTitleMap(fields) {
1429+
const map = {};
1430+
for (const [fieldIndex, field] of fields.entries()) {
1431+
map[field.title] = fieldIndex;
1432+
}
1433+
return map;
1434+
}
1435+
14101436
/**
14111437
* Create a matrix containing the grid's headers. Empty strings are used to
14121438
* indicate merged cells.
@@ -2074,32 +2100,6 @@ class DataHarmonizer {
20742100
*
20752101
*/
20762102

2077-
/**
2078-
* Get a dictionary of source field names pointing to column index
2079-
* @param {Object} fields A flat version of data.js.
2080-
* @return {Dictionary<Integer>} Dictionary of all fields.
2081-
*/
2082-
getFieldNameMap(fields) {
2083-
const map = {};
2084-
for (const [fieldIndex, field] of fields.entries()) {
2085-
map[field.name] = fieldIndex;
2086-
}
2087-
return map;
2088-
}
2089-
2090-
/**
2091-
* Get a dictionary of source field TITLES pointing to column index
2092-
* @param {Object} fields A flat version of data.js.
2093-
* @return {Dictionary<Integer>} Dictionary of all fields.
2094-
*/
2095-
getFieldTitleMap(fields) {
2096-
const map = {};
2097-
for (const [fieldIndex, field] of fields.entries()) {
2098-
map[field.title] = fieldIndex;
2099-
}
2100-
return map;
2101-
}
2102-
21032103
/**
21042104
* Modifies exportHeaders map of fields so that each field contains an array
21052105
* of one or more source fields by name that are used to compose it.
@@ -2852,21 +2852,30 @@ class DataHarmonizer {
28522852
toJSON() {
28532853
const handsontableInstance = this.hot;
28542854
const tableData = this.fullData(handsontableInstance);
2855-
const columnHeaders = handsontableInstance.getColHeader().map(stripDiv);
2855+
const columnHeaders = handsontableInstance.getColHeader().map(stripDiv); // TODO: use fields() or this.getFlatHeaders()[1];
2856+
console.log(columnHeaders);
28562857

28572858
function createStruct(row) {
28582859
const structInstance = {};
2860+
// iterate over the columns in a row
28592861
for (let i = 0; i < row.length; i++) {
2862+
2863+
const columnHeader = columnHeaders[i];
2864+
console.log(columnHeader);
2865+
28602866
// Optional type checking (adjust data types as needed)
2861-
if (typeof columnHeaders[i] === 'string') {
2862-
structInstance[columnHeaders[i]] = row[i];
2863-
} else if (typeof columnHeaders[i] === 'number') {
2864-
structInstance[columnHeaders[i]] = Number(row[i]); // Convert to number
2867+
if (typeof columnHeader === 'string') {
2868+
structInstance[columnHeader] = row[i];
2869+
} else if (typeof columnHeader === 'number') {
2870+
structInstance[columnHeader] = Number(row[i]); // Convert to number
28652871
} else {
28662872
// Handle other data types if needed
2867-
structInstance[columnHeaders[i]] = row[i];
2873+
structInstance[columnHeader] = row[i];
28682874
}
28692875
}
2876+
2877+
console.log(structInstance);
2878+
28702879
return structInstance;
28712880
}
28722881

@@ -2880,6 +2889,8 @@ class DataHarmonizer {
28802889
}
28812890
}
28822891

2892+
console.log(arrayOfStructs);
2893+
28832894
return arrayOfStructs;
28842895
}
28852896
}

0 commit comments

Comments
 (0)