Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@aws-sdk/client-s3": "^3.679.0",
"@aws-sdk/client-sqs": "^3.982.0",
"@aws-sdk/s3-request-presigner": "^3.679.0",
"@defra/forms-engine-plugin": "^4.5.5",
"@defra/forms-engine-plugin": "^4.7.3",
"@defra/forms-model": "^3.0.642",
"@defra/hapi-tracing": "^1.12.0",
"@elastic/ecs-pino-format": "^1.5.0",
Expand Down
25 changes: 15 additions & 10 deletions src/services/submission-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export function addCellToRow(row, columnName, columnValue, options) {
* Coerce the value from text if the component is a
* DatePartsField, MonthYearField or NumberField
* @param {string | undefined} asText - the value as text
* @param {Component} component - the form component
* @param {{ type: ComponentType }} component - the form component
* @returns {CellValue} the spreadsheet cell value
*/
export function coerceDataValue(asText, component) {
Expand All @@ -247,7 +247,7 @@ export function coerceDataValue(asText, component) {
* Extracts the component value from the provided data and coerces to the appropriate type
* @param {Record<string, any>} data - the answers data
* @param {string} key - the component key (name)
* @param {Component} component - the form component
* @param {Field} component - the form component
* @returns {CellValue}
*/
export function getValue(data, key, component) {
Expand All @@ -260,7 +260,7 @@ export function getValue(data, key, component) {
/**
* Adds component and column header to the maps
* @param {SpreadsheetContext} context - the context for spreadsheet generation
* @param {Component} component - the form component
* @param {Field} component - the form component
* @param {string} [key] - the header key
* @param {string} [value] - the header value
*/
Expand Down Expand Up @@ -377,12 +377,14 @@ export async function addFirstCellsToRow(
* @param {SpreadsheetOptions | undefined} [options] - spreadsheet options
*/
function addFormComponentCellsToRow(formModel, row, context, record, options) {
formModel?.componentMap.forEach((component, key) => {
if (!component.isFormComponent) {
formModel?.componentMap.forEach((comp, key) => {
if (!comp.isFormComponent) {
return
}

if (hasRepeater(component.page.pageDef)) {
const component = /** @type {Field} */ (comp)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you intend to cast here, or are you typing the variable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, intending to cast it. Could argue to rename the variable as well, but doing the smallest possible changes.


if (component.page && hasRepeater(component.page.pageDef)) {
const repeaterName = component.page.pageDef.repeat.options.name
const hasRepeaterData = repeaterName in record.data.repeaters
const items = hasRepeaterData ? record.data.repeaters[repeaterName] : []
Expand Down Expand Up @@ -503,11 +505,11 @@ export async function generateSubmissionsFile(
const { components, headers, rows } = caches
const context = { caches, options }

/** @type {string} */
for await (const record of getSubmissionRecords(formId, options?.filter)) {
const recordFormId = record.data.main.formId
const formNameFromId = await lookupFormNameById(
context,
record.data.main.formId ?? record.meta.formId
typeof recordFormId === 'string' ? recordFormId : record.meta.formId
)
if (!formNameFromId) {
// Exclude feedback submissions where the form no longer exists
Expand Down Expand Up @@ -628,7 +630,10 @@ function sortHeaders(components, headers) {
const repeaterComponentA = components.get(nameA)
const repeaterComponentB = components.get(nameB)

if (repeaterComponentA.page === repeaterComponentB.page) {
if (
repeaterComponentA?.page &&
repeaterComponentA.page === repeaterComponentB?.page
) {
return Number(partsA[1]) - Number(partsB[1])
}
}
Expand Down Expand Up @@ -825,6 +830,6 @@ export function constructEmailContent(emailAddress, fileId, formTitle) {
* @import { UserCredentials } from '@hapi/hapi'
* @import { FormMetadata, FormStatus } from '@defra/forms-model'
* @import { WithId } from 'mongodb'
* @import { Component } from '@defra/forms-engine-plugin/engine/components/helpers/components.js'
* @import { Component, Field } from '@defra/forms-engine-plugin/engine/components/helpers/components.js'
* @import { FormSubmissionDocument } from '~/src/api/types.js'
*/
Loading