Skip to content
This repository has been archived by the owner on Dec 2, 2023. It is now read-only.

Commit

Permalink
fix field sort in excel submission export
Browse files Browse the repository at this point in the history
  • Loading branch information
wodka committed Mar 13, 2022
1 parent 23e67c8 commit 30ff2c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Template for next version

### Fixed

- field sort in excel submission export (https://github.com/ohmyform/ohmyform/issues/163)

### Security

## [1.0.1] - 2022-03-01
Expand Down
9 changes: 7 additions & 2 deletions components/form/admin/export.submission.action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export const ExportSubmissionAction: React.FC<Props> = (props) => {
workbook.created = new Date()
workbook.modified = new Date()

const orderedFields = form.data.form.fields
.sort((a, b) => (a.idx ?? 0) - (b.idx ?? 0))

const sheet = workbook.addWorksheet('Submissions')
sheet.getRow(1).values = [
'Submission ID',
Expand All @@ -45,7 +48,7 @@ export const ExportSubmissionAction: React.FC<Props> = (props) => {
'City',
'User Agent',
'Device',
...form.data.form.fields.map((field) => `${field.title} (${field.type})`),
...orderedFields.map((field) => `${field.title} (${field.type})`),
]

const firstPage = await getSubmissions({
Expand All @@ -65,7 +68,9 @@ export const ExportSubmissionAction: React.FC<Props> = (props) => {
data.device.name,
]

data.fields.forEach((field) => {
orderedFields.forEach((formField) => {
const field = data.fields.find(field => field.id === formField.id)

This comment has been minimized.

Copy link
@ccoenen

ccoenen Mar 13, 2022

this comparison fails for me, and then all the export fields are empty, because find will always return undefined.

The problem is, that field.id contains J7Ngzj, but formField.id is "45".
grafik

it would probably need to be field.field.id, but field.field does not currently contain the id, only the title.

This comment has been minimized.

Copy link
@wodka

wodka Mar 14, 2022

Author Contributor

:/ good catch - I did miss the form items here - as all should have their IDs encoded

This comment has been minimized.

Copy link
@wodka

wodka Mar 14, 2022

Author Contributor

ohmyform/api@b3cacb8 should fix that - but will need to test that a bit more before creating another release


try {
fieldTypes[field.type]?.stringifyValue(field.value)

Expand Down

0 comments on commit 30ff2c9

Please sign in to comment.