@defra/forms-engine-plugin 4.21.0 → 4.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -16,10 +16,11 @@ export function buildMainRecords(items) {
|
|
|
16
16
|
} else if (item.field instanceof GeospatialField) {
|
|
17
17
|
// Stringify of GeoJSON is done here rather than inside `getContextValueFromState`
|
|
18
18
|
// so we don't incur the overhead of JSON.stringify on every request when building context
|
|
19
|
+
const value = item.field.getFormValueFromState(item.state);
|
|
19
20
|
records.push({
|
|
20
21
|
name: item.name,
|
|
21
22
|
title: item.label,
|
|
22
|
-
value: JSON.stringify(
|
|
23
|
+
value: value === undefined ? '' : JSON.stringify(value)
|
|
23
24
|
});
|
|
24
25
|
} else {
|
|
25
26
|
records.push({
|
|
@@ -74,16 +75,24 @@ export function buildRepeaterRecords(items) {
|
|
|
74
75
|
return items.filter(item => 'subItems' in item).map(item => ({
|
|
75
76
|
name: item.name,
|
|
76
77
|
title: item.label,
|
|
77
|
-
value: item.subItems.map(detailItems => detailItems.map(subItem =>
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
78
|
+
value: item.subItems.map(detailItems => detailItems.map(subItem => {
|
|
79
|
+
let value;
|
|
80
|
+
if (subItem.field instanceof GeospatialField) {
|
|
81
|
+
// Stringify of GeoJSON is done here rather than inside `getContextValueFromState`
|
|
82
|
+
// so we don't incur the overhead of JSON.stringify on every request when building context
|
|
83
|
+
const formValue = subItem.field.getFormValueFromState(subItem.state);
|
|
84
|
+
value = formValue === undefined ? '' : JSON.stringify(formValue);
|
|
85
|
+
} else {
|
|
86
|
+
value = getAnswer(subItem.field, subItem.state, {
|
|
87
|
+
format: 'data'
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
name: subItem.name,
|
|
92
|
+
title: subItem.label,
|
|
93
|
+
value
|
|
94
|
+
};
|
|
95
|
+
}))
|
|
87
96
|
}));
|
|
88
97
|
}
|
|
89
98
|
//# sourceMappingURL=submission.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"submission.js","names":["GeospatialField","PaymentField","getAnswer","formatCurrency","formatPaymentDate","buildMainRecords","items","fieldItems","filter","item","records","field","push","buildPaymentRecords","
|
|
1
|
+
{"version":3,"file":"submission.js","names":["GeospatialField","PaymentField","getAnswer","formatCurrency","formatPaymentDate","buildMainRecords","items","fieldItems","filter","item","records","field","push","buildPaymentRecords","value","getFormValueFromState","state","name","title","label","undefined","JSON","stringify","format","paymentState","getPaymentStateFromState","description","amount","reference","preAuth","createdAt","buildRepeaterRecords","map","subItems","detailItems","subItem","formValue"],"sources":["../../../../../../src/server/plugins/engine/pageControllers/helpers/submission.ts"],"sourcesContent":["import { type SubmitPayload } from '@defra/forms-model'\n\nimport { GeospatialField } from '~/src/server/plugins/engine/components/GeospatialField.js'\nimport { PaymentField } from '~/src/server/plugins/engine/components/PaymentField.js'\nimport { getAnswer } from '~/src/server/plugins/engine/components/helpers/components.js'\nimport {\n type DetailItem,\n type DetailItemField\n} from '~/src/server/plugins/engine/models/types.js'\nimport {\n formatCurrency,\n formatPaymentDate\n} from '~/src/server/plugins/payment/helper.js'\n\nexport interface SubmitRecord {\n name: string\n title: string\n value: string\n}\n\n/**\n * Builds the main submission records from field items.\n * Regular fields are converted to single records, while PaymentField\n * components are expanded into four separate records.\n */\nexport function buildMainRecords(items: DetailItem[]): SubmitRecord[] {\n const fieldItems = items.filter(\n (item): item is DetailItemField => 'field' in item\n )\n\n const records: SubmitRecord[] = []\n\n for (const item of fieldItems) {\n if (item.field instanceof PaymentField) {\n records.push(...buildPaymentRecords(item))\n } else if (item.field instanceof GeospatialField) {\n // Stringify of GeoJSON is done here rather than inside `getContextValueFromState`\n // so we don't incur the overhead of JSON.stringify on every request when building context\n const value = item.field.getFormValueFromState(item.state)\n records.push({\n name: item.name,\n title: item.label,\n value: value === undefined ? '' : JSON.stringify(value)\n })\n } else {\n records.push({\n name: item.name,\n title: item.label,\n value: getAnswer(item.field, item.state, { format: 'data' })\n })\n }\n }\n\n return records\n}\n\n/**\n * Expands a PaymentField into four submission records:\n * - Payment description\n * - Payment amount (formatted with currency symbol)\n * - Payment reference\n * - Payment date (formatted date/time)\n *\n * Returns an empty array if no payment state exists.\n */\nexport function buildPaymentRecords(item: DetailItemField): SubmitRecord[] {\n const paymentState = (item.field as PaymentField).getPaymentStateFromState(\n item.state\n )\n\n if (!paymentState) {\n return []\n }\n\n return [\n {\n name: `${item.name}_paymentDescription`,\n title: 'Payment description',\n value: paymentState.description\n },\n {\n name: `${item.name}_paymentAmount`,\n title: 'Payment amount',\n value: formatCurrency(paymentState.amount)\n },\n {\n name: `${item.name}_paymentReference`,\n title: 'Payment reference',\n value: paymentState.reference\n },\n {\n name: `${item.name}_paymentDate`,\n title: 'Payment date',\n value: paymentState.preAuth?.createdAt\n ? formatPaymentDate(paymentState.preAuth.createdAt)\n : ''\n }\n ]\n}\n\n/**\n * Builds the repeater submission records from repeater items.\n */\nexport function buildRepeaterRecords(\n items: DetailItem[]\n): SubmitPayload['repeaters'] {\n return items\n .filter((item) => 'subItems' in item)\n .map((item) => ({\n name: item.name,\n title: item.label,\n value: item.subItems.map((detailItems) =>\n detailItems.map((subItem) => {\n let value\n\n if (subItem.field instanceof GeospatialField) {\n // Stringify of GeoJSON is done here rather than inside `getContextValueFromState`\n // so we don't incur the overhead of JSON.stringify on every request when building context\n const formValue = subItem.field.getFormValueFromState(subItem.state)\n value = formValue === undefined ? '' : JSON.stringify(formValue)\n } else {\n value = getAnswer(subItem.field, subItem.state, { format: 'data' })\n }\n\n return {\n name: subItem.name,\n title: subItem.label,\n value\n }\n })\n )\n }))\n}\n"],"mappings":"AAEA,SAASA,eAAe;AACxB,SAASC,YAAY;AACrB,SAASC,SAAS;AAKlB,SACEC,cAAc,EACdC,iBAAiB;AASnB;AACA;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sB,SAAS,KAAKhB,SAAS,GAAG,EAAE,GAAGC,IAAI,CAACC,SAAS,CAACc,SAAS,CAAC;MAClE,CAAC,MAAM;QACLtB,KAAK,GAAGZ,SAAS,CAACiC,OAAO,CAACxB,KAAK,EAAEwB,OAAO,CAACnB,KAAK,EAAE;UAAEO,MAAM,EAAE;QAAO,CAAC,CAAC;MACrE;MAEA,OAAO;QACLN,IAAI,EAAEkB,OAAO,CAAClB,IAAI;QAClBC,KAAK,EAAEiB,OAAO,CAAChB,KAAK;QACpBL;MACF,CAAC;IACH,CAAC,CACH;EACF,CAAC,CAAC,CAAC;AACP","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -36,10 +36,11 @@ export function buildMainRecords(items: DetailItem[]): SubmitRecord[] {
|
|
|
36
36
|
} else if (item.field instanceof GeospatialField) {
|
|
37
37
|
// Stringify of GeoJSON is done here rather than inside `getContextValueFromState`
|
|
38
38
|
// so we don't incur the overhead of JSON.stringify on every request when building context
|
|
39
|
+
const value = item.field.getFormValueFromState(item.state)
|
|
39
40
|
records.push({
|
|
40
41
|
name: item.name,
|
|
41
42
|
title: item.label,
|
|
42
|
-
value: JSON.stringify(
|
|
43
|
+
value: value === undefined ? '' : JSON.stringify(value)
|
|
43
44
|
})
|
|
44
45
|
} else {
|
|
45
46
|
records.push({
|
|
@@ -109,18 +110,24 @@ export function buildRepeaterRecords(
|
|
|
109
110
|
name: item.name,
|
|
110
111
|
title: item.label,
|
|
111
112
|
value: item.subItems.map((detailItems) =>
|
|
112
|
-
detailItems.map((subItem) =>
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
detailItems.map((subItem) => {
|
|
114
|
+
let value
|
|
115
|
+
|
|
116
|
+
if (subItem.field instanceof GeospatialField) {
|
|
116
117
|
// Stringify of GeoJSON is done here rather than inside `getContextValueFromState`
|
|
117
118
|
// so we don't incur the overhead of JSON.stringify on every request when building context
|
|
118
|
-
subItem.field
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
const formValue = subItem.field.getFormValueFromState(subItem.state)
|
|
120
|
+
value = formValue === undefined ? '' : JSON.stringify(formValue)
|
|
121
|
+
} else {
|
|
122
|
+
value = getAnswer(subItem.field, subItem.state, { format: 'data' })
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
name: subItem.name,
|
|
127
|
+
title: subItem.label,
|
|
128
|
+
value
|
|
129
|
+
}
|
|
130
|
+
})
|
|
124
131
|
)
|
|
125
132
|
}))
|
|
126
133
|
}
|