@@ -37,7 +37,6 @@ export default class Wizard extends Webform {
37
37
this . originalComponents = [ ] ;
38
38
this . page = 0 ;
39
39
this . currentPanel = null ;
40
- this . currentPanels = null ;
41
40
this . currentNextPage = 0 ;
42
41
this . _seenPages = [ 0 ] ;
43
42
this . subWizards = [ ] ;
@@ -60,14 +59,14 @@ export default class Wizard extends Webform {
60
59
61
60
getPages ( args = { } ) {
62
61
const { all = false } = args ;
63
- const pages = this . hasExtraPages ? this . components : this . pages ;
62
+ const pages = this . hasSubWizards ? this . components : this . pages ;
64
63
const filteredPages = pages
65
64
. filter ( all ? _ . identity : ( p , index ) => this . _seenPages . includes ( index ) ) ;
66
65
67
66
return filteredPages ;
68
67
}
69
68
70
- get hasExtraPages ( ) {
69
+ get hasSubWizards ( ) {
71
70
return ! _ . isEmpty ( this . subWizards ) ;
72
71
}
73
72
@@ -216,9 +215,9 @@ export default class Wizard extends Webform {
216
215
render ( ) {
217
216
const ctx = this . renderContext ;
218
217
219
- if ( this . component . key ) {
220
- ctx . panels . map ( panel => {
221
- if ( panel . key === this . component . key ) {
218
+ if ( this . component . id ) {
219
+ ctx . panels . forEach ( panel => {
220
+ if ( panel . id === this . component . id ) {
222
221
this . currentPanel = panel ;
223
222
ctx . wizardPageTooltip = this . getFormattedTooltip ( panel . tooltip ) ;
224
223
}
@@ -676,7 +675,7 @@ export default class Wizard extends Webform {
676
675
this . getNextPage ( ) ;
677
676
678
677
let parentNum = num ;
679
- if ( this . hasExtraPages ) {
678
+ if ( this . hasSubWizards ) {
680
679
const pageFromPages = this . pages [ num ] ;
681
680
const pageFromComponents = this . components [ num ] ;
682
681
if ( ! pageFromComponents || pageFromPages ?. id !== pageFromComponents . id ) {
@@ -1018,24 +1017,18 @@ export default class Wizard extends Webform {
1018
1017
}
1019
1018
1020
1019
// If the pages change, need to redraw the header.
1021
- let currentPanels ;
1022
- let panels ;
1020
+ const currentPanels = this . pages ;
1021
+ // calling this.establishPages() updates/mutates this.pages to be the current pages
1022
+ this . establishPages ( ) ;
1023
+ const newPanels = this . pages ;
1023
1024
const currentNextPage = this . currentNextPage ;
1024
- if ( this . hasExtraPages ) {
1025
- currentPanels = this . pages . map ( page => page . component . key ) ;
1026
- this . establishPages ( ) ;
1027
- panels = this . pages . map ( page => page . component . key ) ;
1025
+ const panelsUpdated = ! _ . isEqual ( newPanels , currentPanels ) ;
1026
+
1027
+ if ( this . currentPanel ?. id && this . pages . length && ( ! this . hasSubWizards || ( this . hasSubWizards && panelsUpdated ) ) ) {
1028
+ const newIndex = this . pages . findIndex ( page => page . id === this . currentPanel . id ) ;
1029
+ if ( newIndex !== - 1 ) this . setPage ( newIndex ) ;
1028
1030
}
1029
- else {
1030
- currentPanels = this . currentPanels || this . pages . map ( page => page . component . key ) ;
1031
- panels = this . establishPages ( ) . map ( panel => panel . key ) ;
1032
- this . currentPanels = panels ;
1033
- if ( this . currentPanel ?. key && this . currentPanels ?. length ) {
1034
- this . setPage ( this . currentPanels . findIndex ( panel => panel === this . currentPanel . key ) ) ;
1035
- }
1036
- }
1037
-
1038
- if ( ! _ . isEqual ( panels , currentPanels ) || ( flags && flags . fromSubmission ) ) {
1031
+ if ( panelsUpdated || ( flags && flags . fromSubmission ) ) {
1039
1032
this . redrawHeader ( ) ;
1040
1033
}
1041
1034
0 commit comments