Skip to content

Commit

Permalink
wip2
Browse files Browse the repository at this point in the history
  • Loading branch information
blakekrammes committed Nov 19, 2024
1 parent 5777d3d commit 2093f30
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/Wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,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);
}

Expand Down Expand Up @@ -217,7 +217,7 @@ export default class Wizard extends Webform {
const ctx = this.renderContext;

if (this.component.key) {
ctx.panels.map(panel => {
ctx.panels.forEach(panel => {
if (panel.key === this.component.key) {
this.currentPanel = panel;
ctx.wizardPageTooltip = this.getFormattedTooltip(panel.tooltip);
Expand Down Expand Up @@ -676,7 +676,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) {
Expand Down Expand Up @@ -1005,25 +1005,26 @@ export default class Wizard extends Webform {
this.showErrors(errors, true, true);
}

// If the pages change, need to redraw the header.
let currentPanels;
let panels;
let newlyEstablishedPanels;
const currentNextPage = this.currentNextPage;
if (this.hasExtraPages) {
if (this.hasSubWizards) {
currentPanels = this.pages.map(page => page.component.key);
this.establishPages();
panels = this.pages.map(page => page.component.key);
newlyEstablishedPanels = 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;
newlyEstablishedPanels = this.establishPages().map(panel => panel.key);
this.currentPanels = newlyEstablishedPanels;
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 (!_.isEqual(newlyEstablishedPanels, currentPanels) || (flags && flags.fromSubmission)) {
// if (this.hasSubWizards) {
this.setPage(this.pages.findIndex(page => page.component.id === this.currentPanel.id));
// }
this.redrawHeader();
}

Expand Down Expand Up @@ -1074,7 +1075,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]
Expand Down

0 comments on commit 2093f30

Please sign in to comment.