Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jenbutongit committed Jul 1, 2020
1 parent a007995 commit dba8b3a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
13 changes: 9 additions & 4 deletions engine/src/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,14 @@ class Page {
const sectionStateCount = state.repeats[this.repeatField][this.section.name]
const otherRepeatPagesInSection = this.model.pages.filter(page => page.section === this.section && page.repeatField)

const counts = sectionStateCount.map(page => Object.values(page)[0])
if(counts.length === otherRepeatPagesInSection.length) { //iterated at least once
const counts = Object.values(sectionStateCount)
if(counts.length === otherRepeatPagesInSection.length) { //iterated all pages at least once
const lastInSection = sectionStateCount[sectionStateCount.length -1]
if(Object.value(lastInSection[0]) < requiredCount) {
return this.model.pages.find(page => page.path === Object.entries(sectionStateCount[0]))
let min = Math.min(...counts)
let nextMinPage = Object.entries(sectionStateCount).find((path, count) => count === min )
return nextMinPage[0]
// return this.model.pages.find(page => page.path === Object.entries(sectionStateCount[0]))
}
}
}
Expand Down Expand Up @@ -305,11 +308,13 @@ class Page {
if (this.repeatField) {
let updateValue = update[this.section.name]
let count = repeats[this.repeatField]?.[this.section.name]?.[this.path] ?? 0
let index = count || count - 1
let sectionState = state[this.section.name]
if (!sectionState) {
update = { [this.section.name]: [updateValue]}
} else {
sectionState[count] = merge(sectionState[count], updateValue)
let merged = merge(sectionState[index], updateValue)
sectionState[index] = merge(sectionState[index], updateValue)
update = { [this.section.name]: sectionState }
}
count++
Expand Down
2 changes: 1 addition & 1 deletion runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Digital forms runner",
"main": "src/index.js",
"scripts": {
"start": "NODE_ENV=production node dist/index.js",
"start": "NODE_ENV=development node dist/index.js",
"dev": "yarn babel-build:dev & NODE_ENV=development node dist/index.js",
"build:css": "bin/build-css",
"build": "npm run build:css && npm run babel-build",
Expand Down
5 changes: 3 additions & 2 deletions runner/src/server/forms/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"path": "/applicant-repeatable",
"title": "Applicant",
"section": "applicant",
"repeatField": "numberOfApplicants",
"repeatField": "applicantDetails.numberOfApplicants",
"components": [
{
"type": "Para",
Expand Down Expand Up @@ -116,7 +116,7 @@
{
"path": "/applicant-address",
"section": "applicant",
"repeatField": "numberOfApplicants",
"repeatField": "applicantDetails.numberOfApplicants",
"components": [
{
"type": "UkAddressField",
Expand All @@ -134,6 +134,7 @@
{
"path": "/contact-details",
"section": "applicant",
"repeatField": "applicantDetails.numberOfApplicants",
"components": [
{
"type": "TelephoneNumberField",
Expand Down

0 comments on commit dba8b3a

Please sign in to comment.