-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIO-9241: Correctly set current page after conditionally hiding page in sibling nested wizard #5913
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,6 @@ export default class Wizard extends Webform { | |
this.originalComponents = []; | ||
this.page = 0; | ||
this.currentPanel = null; | ||
this.currentPanels = null; | ||
this.currentNextPage = 0; | ||
this._seenPages = [0]; | ||
this.subWizards = []; | ||
|
@@ -60,14 +59,14 @@ export default class Wizard extends Webform { | |
|
||
getPages(args = {}) { | ||
const { all = false } = args; | ||
const pages = this.hasExtraPages ? this.components : this.pages; | ||
const pages = this.hasSubWizards ? this.components : this.pages; | ||
const filteredPages = pages | ||
.filter(all ? _.identity : (p, index) => this._seenPages.includes(index)); | ||
|
||
return filteredPages; | ||
} | ||
|
||
get hasExtraPages() { | ||
get hasSubWizards() { | ||
return !_.isEmpty(this.subWizards); | ||
} | ||
|
||
|
@@ -216,9 +215,9 @@ export default class Wizard extends Webform { | |
render() { | ||
const ctx = this.renderContext; | ||
|
||
if (this.component.key) { | ||
ctx.panels.map(panel => { | ||
if (panel.key === this.component.key) { | ||
if (this.component.id) { | ||
ctx.panels.forEach(panel => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (panel.id === this.component.id) { | ||
this.currentPanel = panel; | ||
ctx.wizardPageTooltip = this.getFormattedTooltip(panel.tooltip); | ||
} | ||
|
@@ -676,7 +675,7 @@ export default class Wizard extends Webform { | |
this.getNextPage(); | ||
|
||
let parentNum = num; | ||
if (this.hasExtraPages) { | ||
if (this.hasSubWizards) { | ||
const pageFromPages = this.pages[num]; | ||
const pageFromComponents = this.components[num]; | ||
if (!pageFromComponents || pageFromPages?.id !== pageFromComponents.id) { | ||
|
@@ -1006,24 +1005,18 @@ export default class Wizard extends Webform { | |
} | ||
|
||
// If the pages change, need to redraw the header. | ||
let currentPanels; | ||
let panels; | ||
const currentPanels = this.pages; | ||
// calling this.establishPages() updates/mutates this.pages to be the current pages | ||
this.establishPages(); | ||
const newPanels = this.pages; | ||
const currentNextPage = this.currentNextPage; | ||
if (this.hasExtraPages) { | ||
currentPanels = this.pages.map(page => page.component.key); | ||
this.establishPages(); | ||
panels = this.pages.map(page => page.component.key); | ||
const panelsUpdated = !_.isEqual(newPanels, currentPanels); | ||
|
||
if (this.currentPanel?.id && this.pages.length && (!this.hasSubWizards || (this.hasSubWizards && panelsUpdated))) { | ||
const newIndex = this.pages.findIndex(page => page.id === this.currentPanel.id); | ||
if (newIndex !== -1) this.setPage(newIndex); | ||
} | ||
else { | ||
currentPanels = this.currentPanels || this.pages.map(page => page.component.key); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
From what I can tell, I think the reason why For comparison: this.currentPanels = [{ title: 'A', ... }, { title: 'B', ... }, { title: 'C', ... }]
this.pages = [{ title: 'A1', ... }, { title: 'A2', ... }, { title: 'A3', ... }, { title: 'B1', ... }, ...] |
||
panels = this.establishPages().map(panel => panel.key); | ||
this.currentPanels = panels; | ||
if (this.currentPanel?.key && this.currentPanels?.length) { | ||
this.setPage(this.currentPanels.findIndex(panel => panel === this.currentPanel.key)); | ||
} | ||
} | ||
|
||
if (!_.isEqual(panels, currentPanels) || (flags && flags.fromSubmission)) { | ||
if (panelsUpdated || (flags && flags.fromSubmission)) { | ||
this.redrawHeader(); | ||
} | ||
|
||
|
@@ -1074,7 +1067,7 @@ export default class Wizard extends Webform { | |
} | ||
|
||
showErrors(errors, triggerEvent) { | ||
if (this.hasExtraPages) { | ||
if (this.hasSubWizards) { | ||
this.subWizards.forEach((subWizard) => { | ||
if(Array.isArray(subWizard.errors)) { | ||
errors = [...errors, ...subWizard.errors] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was an additional bug here:
If you had multiple/sibling nested wizards and conditional logic controlling the visibility of a nested wizard page, this was setting the currentPanel to the wrong page on render (i.e. both forms have a 'page1' key and the wizard would navigate to 'page1' on nested form C instead of 'page1' on nested form B. This is fixed by using a unique id to set the currentPanel.