@@ -2,8 +2,9 @@ import { EuiPage, EuiPageBody, EuiResizableContainer, EuiResizeObserver } from '
2
2
import React , { useEffect , useRef , useState } from 'react'
3
3
import { useDispatch , useSelector } from 'react-redux'
4
4
import cx from 'classnames'
5
+ import DatabasePanel from 'uiSrc/pages/home/components/database-panel'
5
6
import { clusterSelector , resetDataRedisCluster , resetInstancesRedisCluster , } from 'uiSrc/slices/instances/cluster'
6
- import { setTitle } from 'uiSrc/utils'
7
+ import { Nullable , setTitle } from 'uiSrc/utils'
7
8
import { PageHeader } from 'uiSrc/components'
8
9
import { BrowserStorageItem } from 'uiSrc/constants'
9
10
import { resetKeys } from 'uiSrc/slices/browser/keys'
@@ -25,19 +26,22 @@ import { fetchContentAction as fetchCreateRedisButtonsAction } from 'uiSrc/slice
25
26
import { sendEventTelemetry , sendPageViewTelemetry , TelemetryEvent , TelemetryPageView } from 'uiSrc/telemetry'
26
27
import { appRedirectionSelector , setUrlHandlingInitialState } from 'uiSrc/slices/app/url-handling'
27
28
import { UrlHandlingActions } from 'uiSrc/slices/interfaces/urlHandling'
28
- import AddDatabaseContainer , { AddDbType } from './components/AddDatabases/AddDatabasesContainer '
29
- import DatabasesList from './components/DatabasesListComponent/DatabasesListWrapper '
30
- import WelcomeComponent from './components/WelcomeComponent/WelcomeComponent '
31
- import HomeHeader from './components/HomeHeader '
29
+ import { AddDbType } from 'uiSrc/pages/home/constants '
30
+ import DatabasesList from './components/databases-list-component '
31
+ import WelcomeComponent from './components/welcome-component '
32
+ import HomeHeader from './components/home-header '
32
33
33
34
import './styles.scss'
34
35
import styles from './styles.module.scss'
35
36
37
+ enum RightPanelName {
38
+ AddDatabase = 'add' ,
39
+ EditDatabase = 'edit'
40
+ }
41
+
36
42
const HomePage = ( ) => {
37
43
const [ width , setWidth ] = useState ( 0 )
38
- const [ addDialogIsOpen , setAddDialogIsOpen ] = useState ( false )
39
- const [ editDialogIsOpen , setEditDialogIsOpen ] = useState ( false )
40
- const [ dialogIsOpen , setDialogIsOpen ] = useState ( false )
44
+ const [ openRightPanel , setOpenRightPanel ] = useState < Nullable < RightPanelName > > ( null )
41
45
const [ welcomeIsShow , setWelcomeIsShow ] = useState (
42
46
! localStorageService . get ( BrowserStorageItem . instancesCount )
43
47
)
@@ -86,8 +90,7 @@ const HomePage = () => {
86
90
87
91
useEffect ( ( ) => {
88
92
if ( isChangedInstance ) {
89
- setAddDialogIsOpen ( ! isChangedInstance )
90
- setEditDialogIsOpen ( ! isChangedInstance )
93
+ setOpenRightPanel ( null )
91
94
dispatch ( setEditedInstance ( null ) )
92
95
// send page view after adding database from welcome page
93
96
sendPageViewTelemetry ( {
@@ -107,29 +110,25 @@ const HomePage = () => {
107
110
108
111
useEffect ( ( ) => {
109
112
if ( clusterCredentials || cloudCredentials || sentinelInstance ) {
110
- setAddDialogIsOpen ( true )
113
+ setOpenRightPanel ( RightPanelName . AddDatabase )
111
114
}
112
115
} , [ clusterCredentials , cloudCredentials , sentinelInstance ] )
113
116
114
117
useEffect ( ( ) => {
115
118
if ( action === UrlHandlingActions . Connect ) {
116
- setAddDialogIsOpen ( true )
119
+ setOpenRightPanel ( RightPanelName . AddDatabase )
117
120
}
118
121
} , [ action , dbConnection ] )
119
122
120
123
useEffect ( ( ) => {
121
- const isDialogOpen = ! ! instances . length && ( addDialogIsOpen || editDialogIsOpen )
122
-
123
124
const instancesCashCount = JSON . parse (
124
125
localStorageService . get ( BrowserStorageItem . instancesCount ) ?? '0'
125
126
)
126
127
127
- const isShowWelcome = ! instances . length && ! addDialogIsOpen && ! editDialogIsOpen && ! instancesCashCount
128
-
129
- setDialogIsOpen ( isDialogOpen )
128
+ const isShowWelcome = ! instances . length && ! openRightPanel && ! instancesCashCount
130
129
131
130
setWelcomeIsShow ( isShowWelcome )
132
- } , [ addDialogIsOpen , editDialogIsOpen , instances , loading ] )
131
+ } , [ openRightPanel , instances , loading ] )
133
132
134
133
useEffect ( ( ) => {
135
134
if ( editedInstance ) {
@@ -152,7 +151,7 @@ const HomePage = () => {
152
151
153
152
const closeEditDialog = ( ) => {
154
153
dispatch ( setEditedInstance ( null ) )
155
- setEditDialogIsOpen ( false )
154
+ setOpenRightPanel ( null )
156
155
157
156
sendEventTelemetry ( {
158
157
event : TelemetryEvent . CONFIG_DATABASES_DATABASE_EDIT_CANCELLED_CLICKED ,
@@ -166,9 +165,8 @@ const HomePage = () => {
166
165
dispatch ( resetDataRedisCluster ( ) )
167
166
dispatch ( resetDataSentinel ( ) )
168
167
169
- setAddDialogIsOpen ( false )
168
+ setOpenRightPanel ( null )
170
169
dispatch ( setEditedInstance ( null ) )
171
- setEditDialogIsOpen ( false )
172
170
173
171
if ( action === UrlHandlingActions . Connect ) {
174
172
dispatch ( setUrlHandlingInitialState ( ) )
@@ -181,22 +179,23 @@ const HomePage = () => {
181
179
182
180
const handleAddInstance = ( addDbType = AddDbType . manual ) => {
183
181
initialDbTypeRef . current = addDbType
184
- setAddDialogIsOpen ( true )
182
+ setOpenRightPanel ( RightPanelName . AddDatabase )
185
183
dispatch ( setEditedInstance ( null ) )
186
- setEditDialogIsOpen ( false )
187
184
}
188
185
189
186
const handleEditInstance = ( editedInstance : Instance ) => {
190
187
if ( editedInstance ) {
191
188
dispatch ( fetchEditedInstanceAction ( editedInstance ) )
192
- setEditDialogIsOpen ( true )
193
- setAddDialogIsOpen ( false )
189
+ setOpenRightPanel ( RightPanelName . EditDatabase )
194
190
}
195
191
}
196
192
const handleDeleteInstances = ( instances : Instance [ ] ) => {
197
- if ( instances . find ( ( instance ) => instance . id === editedInstance ?. id ) ) {
193
+ if (
194
+ instances . find ( ( instance ) => instance . id === editedInstance ?. id )
195
+ && openRightPanel === RightPanelName . EditDatabase
196
+ ) {
198
197
dispatch ( setEditedInstance ( null ) )
199
- setEditDialogIsOpen ( false )
198
+ setOpenRightPanel ( null )
200
199
}
201
200
202
201
instances . forEach ( ( instance ) => {
@@ -227,7 +226,7 @@ const HomePage = () => {
227
226
onAddInstance = { handleAddInstance }
228
227
direction = "row"
229
228
/>
230
- { dialogIsOpen ? (
229
+ { openRightPanel && instances . length ? (
231
230
< div key = "homePage" className = "homePage" >
232
231
< EuiResizableContainer style = { { height : '100%' } } >
233
232
{ ( EuiResizablePanel , EuiResizableButton ) => (
@@ -242,7 +241,7 @@ const HomePage = () => {
242
241
< div ref = { resizeRef } >
243
242
< DatabasesList
244
243
width = { width }
245
- dialogIsOpen = { dialogIsOpen }
244
+ dialogIsOpen = { ! ! openRightPanel }
246
245
editedInstance = { editedInstance }
247
246
onEditInstance = { handleEditInstance }
248
247
onDeleteInstances = { handleDeleteInstances }
@@ -256,32 +255,30 @@ const HomePage = () => {
256
255
scrollable = { false }
257
256
initialSize = { 38 }
258
257
className = { cx ( {
259
- [ styles . contentActive ] : editDialogIsOpen ,
258
+ [ styles . contentActive ] : openRightPanel === RightPanelName . EditDatabase ,
260
259
} ) }
261
260
id = "form"
262
261
paddingSize = "none"
263
262
style = { { minWidth : '494px' } }
264
263
>
265
- { editDialogIsOpen && (
266
- < AddDatabaseContainer
267
- editMode
268
- width = { width }
269
- isResizablePanel
270
- editedInstance = { editedInstance }
271
- onClose = { closeEditDialog }
272
- onDbEdited = { onDbEdited }
273
- />
274
- ) }
275
-
276
- { addDialogIsOpen && (
277
- < AddDatabaseContainer
278
- editMode = { false }
264
+ { ! ! openRightPanel && (
265
+ < DatabasePanel
266
+ editMode = { openRightPanel === RightPanelName . EditDatabase }
279
267
width = { width }
280
268
isResizablePanel
281
269
urlHandlingAction = { action }
282
270
initialValues = { dbConnection ?? null }
283
- editedInstance = { sentinelInstance ?? null }
284
- onClose = { handleClose }
271
+ editedInstance = {
272
+ openRightPanel === RightPanelName . EditDatabase
273
+ ? editedInstance
274
+ : sentinelInstance ?? null
275
+ }
276
+ onClose = {
277
+ openRightPanel === RightPanelName . EditDatabase
278
+ ? closeEditDialog
279
+ : handleClose
280
+ }
281
+ onDbEdited = { onDbEdited }
285
282
isFullWidth = { ! instances . length }
286
283
/>
287
284
) }
@@ -297,14 +294,14 @@ const HomePage = () => {
297
294
< DatabasesList
298
295
width = { width }
299
296
editedInstance = { editedInstance }
300
- dialogIsOpen = { dialogIsOpen }
297
+ dialogIsOpen = { ! ! openRightPanel }
301
298
onEditInstance = { handleEditInstance }
302
299
onDeleteInstances = { handleDeleteInstances }
303
300
/>
304
301
) : (
305
302
< >
306
- { addDialogIsOpen && (
307
- < AddDatabaseContainer
303
+ { openRightPanel === RightPanelName . AddDatabase && (
304
+ < DatabasePanel
308
305
editMode = { false }
309
306
width = { width }
310
307
isResizablePanel
0 commit comments