@@ -83,41 +83,42 @@ const DatabasePanelDialog = (props: Props) => {
83
83
}
84
84
} , [ editMode ] )
85
85
86
+ useEffect ( ( ) => {
87
+ if ( ! isOpen ) {
88
+ // clear state after closing dialog
89
+ setConnectionType ( null )
90
+ if ( connectionType === AddDbType . manual ) return
91
+
92
+ switch ( connectionType ) {
93
+ case AddDbType . cloud : {
94
+ dispatch ( resetDataRedisCluster ( ) )
95
+ dispatch ( resetDataSentinel ( ) )
96
+ break
97
+ }
98
+
99
+ case AddDbType . sentinel : {
100
+ dispatch ( resetDataRedisCloud ( ) )
101
+ dispatch ( resetDataRedisCluster ( ) )
102
+ break
103
+ }
104
+
105
+ case AddDbType . software : {
106
+ dispatch ( resetDataRedisCloud ( ) )
107
+ dispatch ( resetDataSentinel ( ) )
108
+ break
109
+ }
110
+ default :
111
+ break
112
+ }
113
+ }
114
+ } , [ isOpen , connectionType ] )
115
+
86
116
const changeConnectionType = ( connectionType : AddDbType , db : any ) => {
87
117
dispatch ( setUrlHandlingInitialState ( ) )
88
118
setInitialValues ( db )
89
119
setConnectionType ( connectionType )
90
120
}
91
121
92
- const handleClose = ( ) => {
93
- setConnectionType ( null )
94
- onClose ?.( )
95
-
96
- if ( connectionType === AddDbType . manual ) return
97
-
98
- switch ( connectionType ) {
99
- case AddDbType . cloud : {
100
- dispatch ( resetDataRedisCluster ( ) )
101
- dispatch ( resetDataSentinel ( ) )
102
- break
103
- }
104
-
105
- case AddDbType . sentinel : {
106
- dispatch ( resetDataRedisCloud ( ) )
107
- dispatch ( resetDataRedisCluster ( ) )
108
- break
109
- }
110
-
111
- case AddDbType . software : {
112
- dispatch ( resetDataRedisCloud ( ) )
113
- dispatch ( resetDataSentinel ( ) )
114
- break
115
- }
116
- default :
117
- break
118
- }
119
- }
120
-
121
122
const handleClickBack = ( ) => {
122
123
setConnectionType ( null )
123
124
}
@@ -127,29 +128,21 @@ const DatabasePanelDialog = (props: Props) => {
127
128
{ connectionType === null && (
128
129
< ConnectionUrlForm
129
130
onSelectOption = { changeConnectionType }
130
- onClose = { handleClose }
131
131
/>
132
132
) }
133
133
{ connectionType === AddDbType . manual && (
134
134
< ManualConnectionWrapper
135
135
{ ...props }
136
136
initialValues = { initialValues }
137
- onClose = { handleClose }
138
137
onClickBack = { handleClickBack }
139
138
/>
140
139
) }
141
140
{ connectionType === AddDbType . cloud && (
142
- < CloudConnectionFormWrapper { ...props } onClose = { handleClose } />
143
- ) }
144
- { connectionType === AddDbType . import && (
145
- < ImportDatabase onClose = { handleClose } />
146
- ) }
147
- { connectionType === AddDbType . sentinel && (
148
- < SentinelConnectionWrapper { ...props } onClose = { handleClose } />
149
- ) }
150
- { connectionType === AddDbType . software && (
151
- < ClusterConnectionFormWrapper { ...props } onClose = { handleClose } />
141
+ < CloudConnectionFormWrapper { ...props } />
152
142
) }
143
+ { connectionType === AddDbType . import && ( < ImportDatabase onClose = { onClose } /> ) }
144
+ { connectionType === AddDbType . sentinel && ( < SentinelConnectionWrapper { ...props } /> ) }
145
+ { connectionType === AddDbType . software && ( < ClusterConnectionFormWrapper { ...props } /> ) }
153
146
</ >
154
147
)
155
148
@@ -179,7 +172,7 @@ const DatabasePanelDialog = (props: Props) => {
179
172
return (
180
173
< FormDialog
181
174
isOpen = { isOpen }
182
- onClose = { handleClose }
175
+ onClose = { onClose }
183
176
header = { modalHeader ?? ( < EuiTitle size = "s" > < h4 > Add Database</ h4 > </ EuiTitle > ) }
184
177
footer = { < div id = "footerDatabaseForm" /> }
185
178
>
0 commit comments