Skip to content

Commit

Permalink
FIO-9241 Wizard: Set page after conditional eval in nested wizard
Browse files Browse the repository at this point in the history
- this.setPage wasn't being called after conditional logic was evaluated on the page of a nested wizard form having a sibling nested wizard form, causing the main wizard page index not to update to the correct page
- Clean up onChange logic
  - this.currentPanels was only being referenced in onChange() and didn't seem like a necessary piece of state in addition to this.pages
  • Loading branch information
blakekrammes committed Nov 21, 2024
1 parent efabe18 commit d415fcc
Show file tree
Hide file tree
Showing 3 changed files with 502 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/Wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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.hasSubWizards) {
currentPanels = this.pages.map(page => page.component.key);
this.establishPages();
panels = this.pages.map(page => page.component.key);
}
else {
currentPanels = this.currentPanels || this.pages.map(page => page.component.key);
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));
}
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);
}

if (!_.isEqual(panels, currentPanels) || (flags && flags.fromSubmission)) {
if (panelsUpdated || (flags && flags.fromSubmission)) {
this.redrawHeader();
}

Expand Down
Loading

0 comments on commit d415fcc

Please sign in to comment.