Skip to content

Commit 3a0a83d

Browse files
authored
Merge pull request #2743 from RedisInsight/fe/feature/RI-5009_refactor_database_form
#RI-5009 - refactor database form
2 parents 94a818d + ea881ae commit 3a0a83d

File tree

100 files changed

+1673
-1538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1673
-1538
lines changed

redisinsight/ui/src/pages/home/HomePage.tsx

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { EuiPage, EuiPageBody, EuiResizableContainer, EuiResizeObserver } from '
22
import React, { useEffect, useRef, useState } from 'react'
33
import { useDispatch, useSelector } from 'react-redux'
44
import cx from 'classnames'
5+
import DatabasePanel from 'uiSrc/pages/home/components/database-panel'
56
import { clusterSelector, resetDataRedisCluster, resetInstancesRedisCluster, } from 'uiSrc/slices/instances/cluster'
6-
import { setTitle } from 'uiSrc/utils'
7+
import { Nullable, setTitle } from 'uiSrc/utils'
78
import { PageHeader } from 'uiSrc/components'
89
import { BrowserStorageItem } from 'uiSrc/constants'
910
import { resetKeys } from 'uiSrc/slices/browser/keys'
@@ -25,19 +26,22 @@ import { fetchContentAction as fetchCreateRedisButtonsAction } from 'uiSrc/slice
2526
import { sendEventTelemetry, sendPageViewTelemetry, TelemetryEvent, TelemetryPageView } from 'uiSrc/telemetry'
2627
import { appRedirectionSelector, setUrlHandlingInitialState } from 'uiSrc/slices/app/url-handling'
2728
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'
3233

3334
import './styles.scss'
3435
import styles from './styles.module.scss'
3536

37+
enum RightPanelName {
38+
AddDatabase = 'add',
39+
EditDatabase = 'edit'
40+
}
41+
3642
const HomePage = () => {
3743
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)
4145
const [welcomeIsShow, setWelcomeIsShow] = useState(
4246
!localStorageService.get(BrowserStorageItem.instancesCount)
4347
)
@@ -86,8 +90,7 @@ const HomePage = () => {
8690

8791
useEffect(() => {
8892
if (isChangedInstance) {
89-
setAddDialogIsOpen(!isChangedInstance)
90-
setEditDialogIsOpen(!isChangedInstance)
93+
setOpenRightPanel(null)
9194
dispatch(setEditedInstance(null))
9295
// send page view after adding database from welcome page
9396
sendPageViewTelemetry({
@@ -107,29 +110,25 @@ const HomePage = () => {
107110

108111
useEffect(() => {
109112
if (clusterCredentials || cloudCredentials || sentinelInstance) {
110-
setAddDialogIsOpen(true)
113+
setOpenRightPanel(RightPanelName.AddDatabase)
111114
}
112115
}, [clusterCredentials, cloudCredentials, sentinelInstance])
113116

114117
useEffect(() => {
115118
if (action === UrlHandlingActions.Connect) {
116-
setAddDialogIsOpen(true)
119+
setOpenRightPanel(RightPanelName.AddDatabase)
117120
}
118121
}, [action, dbConnection])
119122

120123
useEffect(() => {
121-
const isDialogOpen = !!instances.length && (addDialogIsOpen || editDialogIsOpen)
122-
123124
const instancesCashCount = JSON.parse(
124125
localStorageService.get(BrowserStorageItem.instancesCount) ?? '0'
125126
)
126127

127-
const isShowWelcome = !instances.length && !addDialogIsOpen && !editDialogIsOpen && !instancesCashCount
128-
129-
setDialogIsOpen(isDialogOpen)
128+
const isShowWelcome = !instances.length && !openRightPanel && !instancesCashCount
130129

131130
setWelcomeIsShow(isShowWelcome)
132-
}, [addDialogIsOpen, editDialogIsOpen, instances, loading])
131+
}, [openRightPanel, instances, loading])
133132

134133
useEffect(() => {
135134
if (editedInstance) {
@@ -152,7 +151,7 @@ const HomePage = () => {
152151

153152
const closeEditDialog = () => {
154153
dispatch(setEditedInstance(null))
155-
setEditDialogIsOpen(false)
154+
setOpenRightPanel(null)
156155

157156
sendEventTelemetry({
158157
event: TelemetryEvent.CONFIG_DATABASES_DATABASE_EDIT_CANCELLED_CLICKED,
@@ -166,9 +165,8 @@ const HomePage = () => {
166165
dispatch(resetDataRedisCluster())
167166
dispatch(resetDataSentinel())
168167

169-
setAddDialogIsOpen(false)
168+
setOpenRightPanel(null)
170169
dispatch(setEditedInstance(null))
171-
setEditDialogIsOpen(false)
172170

173171
if (action === UrlHandlingActions.Connect) {
174172
dispatch(setUrlHandlingInitialState())
@@ -181,22 +179,23 @@ const HomePage = () => {
181179

182180
const handleAddInstance = (addDbType = AddDbType.manual) => {
183181
initialDbTypeRef.current = addDbType
184-
setAddDialogIsOpen(true)
182+
setOpenRightPanel(RightPanelName.AddDatabase)
185183
dispatch(setEditedInstance(null))
186-
setEditDialogIsOpen(false)
187184
}
188185

189186
const handleEditInstance = (editedInstance: Instance) => {
190187
if (editedInstance) {
191188
dispatch(fetchEditedInstanceAction(editedInstance))
192-
setEditDialogIsOpen(true)
193-
setAddDialogIsOpen(false)
189+
setOpenRightPanel(RightPanelName.EditDatabase)
194190
}
195191
}
196192
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+
) {
198197
dispatch(setEditedInstance(null))
199-
setEditDialogIsOpen(false)
198+
setOpenRightPanel(null)
200199
}
201200

202201
instances.forEach((instance) => {
@@ -227,7 +226,7 @@ const HomePage = () => {
227226
onAddInstance={handleAddInstance}
228227
direction="row"
229228
/>
230-
{dialogIsOpen ? (
229+
{openRightPanel && instances.length ? (
231230
<div key="homePage" className="homePage">
232231
<EuiResizableContainer style={{ height: '100%' }}>
233232
{(EuiResizablePanel, EuiResizableButton) => (
@@ -242,7 +241,7 @@ const HomePage = () => {
242241
<div ref={resizeRef}>
243242
<DatabasesList
244243
width={width}
245-
dialogIsOpen={dialogIsOpen}
244+
dialogIsOpen={!!openRightPanel}
246245
editedInstance={editedInstance}
247246
onEditInstance={handleEditInstance}
248247
onDeleteInstances={handleDeleteInstances}
@@ -256,32 +255,30 @@ const HomePage = () => {
256255
scrollable={false}
257256
initialSize={38}
258257
className={cx({
259-
[styles.contentActive]: editDialogIsOpen,
258+
[styles.contentActive]: openRightPanel === RightPanelName.EditDatabase,
260259
})}
261260
id="form"
262261
paddingSize="none"
263262
style={{ minWidth: '494px' }}
264263
>
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}
279267
width={width}
280268
isResizablePanel
281269
urlHandlingAction={action}
282270
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}
285282
isFullWidth={!instances.length}
286283
/>
287284
)}
@@ -297,14 +294,14 @@ const HomePage = () => {
297294
<DatabasesList
298295
width={width}
299296
editedInstance={editedInstance}
300-
dialogIsOpen={dialogIsOpen}
297+
dialogIsOpen={!!openRightPanel}
301298
onEditInstance={handleEditInstance}
302299
onDeleteInstances={handleDeleteInstances}
303300
/>
304301
) : (
305302
<>
306-
{addDialogIsOpen && (
307-
<AddDatabaseContainer
303+
{openRightPanel === RightPanelName.AddDatabase && (
304+
<DatabasePanel
308305
editMode={false}
309306
width={width}
310307
isResizablePanel

redisinsight/ui/src/pages/home/components/AddInstanceForm/InstanceForm/index.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)