@@ -92,32 +92,46 @@ const WorkspaceForm: React.FC = () => {
92
92
[ currentStep ] ,
93
93
) ;
94
94
95
+ const isStepValid = useCallback (
96
+ ( step : WorkspaceFormSteps ) => {
97
+ switch ( step ) {
98
+ case WorkspaceFormSteps . KindSelection :
99
+ return ! ! data . kind ;
100
+ case WorkspaceFormSteps . ImageSelection :
101
+ return ! ! data . image ;
102
+ case WorkspaceFormSteps . PodConfigSelection :
103
+ return ! ! data . podConfig ;
104
+ case WorkspaceFormSteps . Properties :
105
+ return ! ! data . properties . workspaceName . trim ( ) ;
106
+ default :
107
+ return false ;
108
+ }
109
+ } ,
110
+ [ data . kind , data . image , data . podConfig , data . properties . workspaceName ] ,
111
+ ) ;
112
+
113
+ const showDrawer = useCallback (
114
+ ( step : WorkspaceFormSteps ) =>
115
+ // Only show drawer for steps that have drawer content
116
+ step !== WorkspaceFormSteps . Properties && isStepValid ( step ) ,
117
+ [ isStepValid ] ,
118
+ ) ;
119
+
95
120
const previousStep = useCallback ( ( ) => {
96
- setCurrentStep ( currentStep - 1 ) ;
97
- setDrawerExpanded ( false ) ;
98
- } , [ currentStep ] ) ;
121
+ const newStep = currentStep - 1 ;
122
+ setCurrentStep ( newStep ) ;
123
+ setDrawerExpanded ( showDrawer ( newStep ) ) ;
124
+ } , [ currentStep , showDrawer ] ) ;
99
125
100
126
const nextStep = useCallback ( ( ) => {
101
- setCurrentStep ( currentStep + 1 ) ;
102
- setDrawerExpanded ( false ) ;
103
- } , [ currentStep ] ) ;
127
+ const newStep = currentStep + 1 ;
128
+ setCurrentStep ( newStep ) ;
129
+ setDrawerExpanded ( showDrawer ( newStep ) ) ;
130
+ } , [ currentStep , showDrawer ] ) ;
104
131
105
132
const canGoToPreviousStep = useMemo ( ( ) => currentStep > 0 , [ currentStep ] ) ;
106
133
107
- const isCurrentStepValid = useMemo ( ( ) => {
108
- switch ( currentStep ) {
109
- case WorkspaceFormSteps . KindSelection :
110
- return ! ! data . kind ;
111
- case WorkspaceFormSteps . ImageSelection :
112
- return ! ! data . image ;
113
- case WorkspaceFormSteps . PodConfigSelection :
114
- return ! ! data . podConfig ;
115
- case WorkspaceFormSteps . Properties :
116
- return ! ! data . properties . workspaceName . trim ( ) ;
117
- default :
118
- return false ;
119
- }
120
- } , [ currentStep , data ] ) ;
134
+ const isCurrentStepValid = useMemo ( ( ) => isStepValid ( currentStep ) , [ isStepValid , currentStep ] ) ;
121
135
122
136
const canGoToNextStep = useMemo (
123
137
( ) => currentStep < Object . keys ( WorkspaceFormSteps ) . length / 2 - 1 ,
0 commit comments