Skip to content

Commit 44de788

Browse files
authored
Fix a bad merge with missing fields in message (#308)
* Fix a bad merge with missing fields in message * Fix tests now field has moved
1 parent 3ac54ad commit 44de788

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

lib/importer/src/dudk/sheets.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,11 @@ const remapErrorStructure = (errors, row_data, mappingIndices, headerRangeOffset
377377

378378
const errorObj = messageMap.get(key);
379379
errorObj.type = error.type;
380-
errorObj.type.field = error.field;
381380

382-
if( !errorObj.fields) {
383-
errorObj.fields = new Set();
384-
}
385381
if( !errorObj.rows) {
386382
errorObj.rows = new Map();
387383
}
388-
errorObj.fields.add(error.field);
384+
errorObj.field = error.field;
389385
errorObj.context = new Set();
390386

391387
// Convert to 0-based index
@@ -438,7 +434,7 @@ const remapErrorStructure = (errors, row_data, mappingIndices, headerRangeOffset
438434
first: errorRows[0]?.index || 0,
439435
count: errorRows?.length || 0
440436
},
441-
fields: Array.from(errorObj.fields),
437+
field: errorObj.field,
442438
rows: Array.from(errorObj.rows.values())
443439
}
444440
}));

lib/importer/src/dudk/sheets.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ describe('remapErrorStructure', () => {
3838
const result = sheets_lib.RemapErrorStructure(errors, row_data, RewrittenMapping);
3939
expect(result).toEqual([
4040
{
41-
type: {variant: "IncorrectType", field: "A"},
42-
fields: [ "A"],
41+
type: {variant: "IncorrectType"},
42+
field: "A",
4343
// Only 1 error (in the two rows) because A appears twice but in
4444
// rows 1 and 3 and here we have rows 1 and 2
4545
meta: { first: 1, count: 1 },
@@ -49,8 +49,8 @@ describe('remapErrorStructure', () => {
4949
]
5050
},
5151
{
52-
type: {variant: "IncorrectType", field: "B"},
53-
fields: ["B"],
52+
type: {variant: "IncorrectType"},
53+
field: "B",
5454
meta: { first: 1, count: 2 },
5555
rows: [
5656
{index:1, error: true, row: [{value:"0", error: true},{value:"1", error: true}]},
@@ -73,7 +73,7 @@ describe('remapErrorStructure', () => {
7373
expect(result).toEqual([
7474
{
7575
type: "Error 1",
76-
fields: ["A"],
76+
field: "A",
7777
meta: {first: 1, count: 2},
7878
rows: [
7979
{index: 1, error: true, row: [{value:"0", error: true},{value:"1"}]},
@@ -99,7 +99,7 @@ describe('remapErrorStructure', () => {
9999
expect(result).toEqual([
100100
{
101101
type: "Error 1",
102-
fields: ["A"],
102+
field: "A",
103103
meta: { first: 1, count: 1 },
104104
rows: [
105105
{index: 1, error: true, row: [{value:"0", error: true},{value:"1"}]},
@@ -125,7 +125,7 @@ describe('remapErrorStructure', () => {
125125
];
126126
const result = sheets_lib.RemapErrorStructure(errors, row_data, RewrittenMapping);
127127
expect(result).toEqual([
128-
{ type: "Error 1", meta: { count: 0, first: 0}, fields: ["A"], rows: [] }
128+
{ type: "Error 1", meta: { count: 0, first: 0}, field: "A", rows: [] }
129129
]);
130130
});
131131

@@ -159,8 +159,8 @@ describe('remapErrorStructure', () => {
159159
const result = sheets_lib.RemapErrorStructure(errors, row_data, mappingIndices, headerRangeOffset);
160160
expect(result).toEqual([
161161
{
162-
type: {variant: "FieldRequired", field: "Salary"},
163-
fields: ['Salary'],
162+
type: {variant: "FieldRequired"},
163+
field: 'Salary',
164164
meta: { first: 3, count: 3 },
165165
rows: [
166166
// errors in index 3, 5 and 6
@@ -213,7 +213,7 @@ describe('remapErrorStructure', () => {
213213
{
214214
type: { variant: "FieldRequired" },
215215
meta: { first: 4, count: 4 },
216-
fields: [ 'Salary' ],
216+
field: 'Salary',
217217
rows:[
218218
{ index: 4, row: [ {value: "Kris"}, {value: "1-1-24"}, {value: "1:00"}, {value: "5.5"}, {value: "Pink"}, {value: "Splotches"}, {value: " ", error: true} ]},
219219
{ index: 5, row: [ {value: "Alex"}, {value: "2-4-24"}, {value: "4:34"}, {value: "6"}, {value: "Beige"}, {value: "N/A"}, {value: "My fave <3"} ]},
@@ -226,7 +226,7 @@ describe('remapErrorStructure', () => {
226226
{
227227
type: { variant: "IncorrectType" },
228228
meta: { first: 5, count: 2 },
229-
fields: [ 'Salary' ],
229+
field: 'Salary',
230230
rows: [
231231
{ index: 4, row: [ {value: "Kris"}, {value: "1-1-24"}, {value: "1:00"}, {value: "5.5"}, {value: "Pink"}, {value: "Splotches"}, undefined ]},
232232
{ index: 5, row: [ {value: "Alex"}, {value: "2-4-24"}, {value: "4:34"}, {value: "6"}, {value: "Beige"}, {value: "N/A"}, {value: "My fave <3", error: true} ]},

lib/importer/templates/review.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ <h2 class="govuk-heading-m">Errors</h2>
2929
<h2 class="govuk-heading-m validation-error-message">
3030
{% switch error.variant %}
3131
{% case 'FieldRequired' %}
32-
'{{error.field}}' must be supplied
32+
'{{errorObject.field}}' must be supplied
3333
{% case 'IncorrectType' %}
34-
'{{error.field}}' must be a '{{error.type}}'
34+
'{{errorObject.field}}' must be a '{{error.type}}'
3535
{% case 'MonthUnrecognised' %}
3636
Months must either be numbers or recognised names
3737
{% case 'MonthOutOfRange' %}

prototypes/basic/app/views/review.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ <h2 class="govuk-heading-m">Errors</h2>
6464
<h2 class="govuk-heading-m validation-error-message">
6565
{% switch error.variant %}
6666
{% case 'FieldRequired' %}
67-
'{{error.field}}' must be supplied
67+
'{{errorObject.field}}' must be supplied
6868
{% case 'IncorrectType' %}
69-
'{{error.field}}' must be a '{{error.type}}'
69+
'{{errorObject.field}}' must be a '{{error.type}}'
7070
{% case 'MonthUnrecognised' %}
7171
Months must either be numbers or recognised names
7272
{% case 'MonthOutOfRange' %}

0 commit comments

Comments
 (0)