Skip to content

Commit e8d9c3c

Browse files
authored
Merge pull request #4094 from RedisInsight/fe/feature/RI-6293-update-rdi-form
#RI-6293 - update RDI form
2 parents d875420 + dc8eb7b commit e8d9c3c

File tree

18 files changed

+419
-453
lines changed

18 files changed

+419
-453
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react'
2+
import { render, screen } from 'uiSrc/utils/test-utils'
3+
4+
import FormDialog from './FormDialog'
5+
6+
describe('FormDialog', () => {
7+
it('should render', () => {
8+
render(
9+
<FormDialog
10+
isOpen
11+
onClose={jest.fn()}
12+
header={(<div data-testid="header" />)}
13+
footer={(<div data-testid="footer" />)}
14+
>
15+
<div data-testid="body" />
16+
</FormDialog>
17+
)
18+
19+
expect(screen.getByTestId('header')).toBeInTheDocument()
20+
expect(screen.getByTestId('footer')).toBeInTheDocument()
21+
expect(screen.getByTestId('body')).toBeInTheDocument()
22+
})
23+
})
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react'
2+
import { EuiModal, EuiModalBody, EuiModalFooter, EuiModalHeader, EuiModalHeaderTitle } from '@elastic/eui'
3+
import { Nullable } from 'uiSrc/utils'
4+
5+
import styles from './styles.module.scss'
6+
7+
export interface Props {
8+
isOpen: boolean
9+
onClose: () => void
10+
header: Nullable<React.ReactNode>
11+
footer?: Nullable<React.ReactNode>
12+
children: Nullable<React.ReactNode>
13+
}
14+
15+
const FormDialog = (props: Props) => {
16+
const { isOpen, onClose, header, footer, children } = props
17+
18+
if (!isOpen) return null
19+
20+
return (
21+
<EuiModal
22+
className={styles.modal}
23+
onClose={onClose}
24+
>
25+
<EuiModalHeader>
26+
<EuiModalHeaderTitle id="formModalHeader">
27+
{header}
28+
</EuiModalHeaderTitle>
29+
</EuiModalHeader>
30+
<EuiModalBody>
31+
{children}
32+
</EuiModalBody>
33+
<EuiModalFooter>
34+
{footer}
35+
</EuiModalFooter>
36+
</EuiModal>
37+
)
38+
}
39+
40+
export default FormDialog
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import FormDialog from './FormDialog'
2+
3+
export default FormDialog
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
.modal {
2+
width: 900px !important;
3+
height: 700px !important;
4+
5+
max-width: calc(100vw - 120px) !important;
6+
max-height: calc(100vh - 120px) !important;
7+
8+
&:global(.euiModal) {
9+
background-color: var(--euiColorEmptyShade) !important;
10+
}
11+
12+
:global {
13+
.euiModalHeader {
14+
padding: 18px 24px;
15+
16+
.euiModalHeader__title .euiTitle {
17+
font-size: 18px;
18+
}
19+
}
20+
21+
.euiModalBody__overflow {
22+
padding: 8px 30px;
23+
overflow-y: hidden !important;
24+
mask-image: none !important;
25+
}
26+
27+
.euiModal__closeIcon {
28+
top: 16px !important;
29+
right: 16px !important;
30+
background: none;
31+
}
32+
33+
.euiModalFooter {
34+
display: block;
35+
margin-top: 12px;
36+
}
37+
38+
.footerAddDatabase {
39+
display: flex;
40+
align-items: center;
41+
justify-content: flex-end;
42+
}
43+
}
44+
}
45+
46+
/* form override */
47+
.modal {
48+
:global {
49+
.form__divider {
50+
padding: 18px 0;
51+
}
52+
53+
.euiFieldText,
54+
.euiFieldNumber,
55+
.euiFieldPassword,
56+
.euiFieldSearch,
57+
.euiSelect,
58+
.euiSuperSelectControl,
59+
.euiComboBox .euiComboBox__inputWrap,
60+
.euiTextArea {
61+
background-color: var(--browserTableRowEven) !important;
62+
padding: 12px;
63+
border-color: var(--separatorColor) !important;
64+
}
65+
66+
.euiTextArea {
67+
min-height: 80px;
68+
}
69+
70+
.euiFormControlLayout--group {
71+
border-color: var(--separatorColor) !important;
72+
}
73+
74+
.euiFormRow, .euiFormControlLayout {
75+
max-width: none;
76+
77+
.euiFormControlLayout:not(.euiFormControlLayout--compressed) {
78+
height: 42px !important;
79+
}
80+
81+
.euiSuperSelectControl:not(.euiSuperSelectControl--compressed),
82+
.euiSelect:not(.euiSelect--compressed),
83+
.euiFieldText:not(.euiFieldText--compressed),
84+
.euiFieldNumber:not(.euiFieldNumber--compressed),
85+
.euiFieldPassword {
86+
height: 40px !important;
87+
}
88+
}
89+
90+
.euiCheckbox__input~.euiCheckbox__label {
91+
line-height: 24px !important;
92+
font-size: 14px !important;
93+
}
94+
}
95+
}

redisinsight/ui/src/components/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
} from './recommendation'
3636
import { FormatedDate } from './formated-date'
3737
import { UploadWarning } from './upload-warning'
38+
import FormDialog from './form-dialog'
3839

3940
export { FullScreen } from './full-screen'
4041

@@ -81,4 +82,5 @@ export {
8182
RecommendationBadgesLegend,
8283
FormatedDate,
8384
UploadWarning,
85+
FormDialog
8486
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React, { createContext, useContext } from 'react'
2+
import { Nullable } from 'uiSrc/utils'
3+
4+
interface ModalHeaderContextType {
5+
modalHeader: Nullable<React.ReactNode>
6+
setModalHeader: (content: Nullable<React.ReactNode>) => void
7+
}
8+
9+
// Create a context
10+
const ModalHeaderContext = createContext<ModalHeaderContextType>({
11+
modalHeader: null,
12+
setModalHeader: () => {}
13+
})
14+
15+
// Custom hook to access the header context
16+
export const useModalHeader = () => useContext(ModalHeaderContext)
17+
export const ModalHeaderProvider = ModalHeaderContext.Provider

redisinsight/ui/src/pages/home/components/database-panel-dialog/DatabasePanelDialog.tsx

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ import {
44
EuiFlexGroup,
55
EuiFlexItem,
66
EuiForm,
7-
EuiModal,
8-
EuiModalBody,
9-
EuiModalFooter,
10-
EuiModalHeader,
11-
EuiModalHeaderTitle,
127
EuiRadioGroup,
13-
EuiRadioGroupOption, EuiSpacer,
8+
EuiRadioGroupOption,
9+
EuiSpacer,
1410
EuiText,
1511
EuiTitle
1612
} from '@elastic/eui'
@@ -31,7 +27,8 @@ import AddDatabaseFlowTabs from 'uiSrc/pages/home/components/add-database-flow-t
3127

3228
import CloudConnectionFormWrapper from 'uiSrc/pages/home/components/cloud-connection'
3329
import ImportDatabase from 'uiSrc/pages/home/components/import-database'
34-
import { HeaderProvider } from './ModalTitleProvider'
30+
import { FormDialog } from 'uiSrc/components'
31+
import { ModalHeaderProvider } from 'uiSrc/contexts/ModalTitleProvider'
3532
import styles from './styles.module.scss'
3633

3734
export interface Props {
@@ -57,7 +54,7 @@ const DatabasePanelDialog = (props: Props) => {
5754
InstanceType.RedisEnterpriseCluster
5855
)
5956
const [connectionType, setConnectionType] = useState<AddDbType>(initConnectionType)
60-
const [headerContent, setHeaderContent] = useState<Nullable<React.ReactNode>>(null)
57+
const [modalHeader, setModalHeader] = useState<Nullable<React.ReactNode>>(null)
6158

6259
const { credentials: clusterCredentials } = useSelector(clusterSelector)
6360
const { credentials: cloudCredentials } = useSelector(cloudSelector)
@@ -189,38 +186,28 @@ const DatabasePanelDialog = (props: Props) => {
189186
</>
190187
)
191188

192-
if (!isOpen) return null
193-
194189
return (
195-
<EuiModal
196-
className={styles.modal}
190+
<FormDialog
191+
isOpen={isOpen}
197192
onClose={onClose}
193+
header={modalHeader ?? (<EuiTitle size="s"><h4>Discover and Add Redis Databases</h4></EuiTitle>)}
194+
footer={<div id="footerDatabaseForm" />}
198195
>
199-
<EuiModalHeader>
200-
<EuiModalHeaderTitle id="formModalHeader">
201-
{headerContent ?? (<EuiTitle size="s"><h4>Discover and Add Redis Databases</h4></EuiTitle>)}
202-
</EuiModalHeaderTitle>
203-
</EuiModalHeader>
204-
<EuiModalBody>
205-
<div className={cx(styles.bodyWrapper, 'container relative', { addDbWrapper: !editMode })}>
206-
{!editMode && (
207-
<AddDatabaseFlowTabs
208-
connectionType={connectionType}
209-
onChange={changeConnectionType}
210-
/>
211-
)}
212-
<div className={styles.formWrapper}>
196+
<div className={cx(styles.bodyWrapper, 'container relative', { addDbWrapper: !editMode })}>
197+
{!editMode && (
198+
<AddDatabaseFlowTabs
199+
connectionType={connectionType}
200+
onChange={changeConnectionType}
201+
/>
202+
)}
203+
<div className={styles.formWrapper}>
204+
<ModalHeaderProvider value={{ modalHeader, setModalHeader }}>
213205
{connectionType === AddDbType.auto && <InstanceTypes />}
214-
<HeaderProvider value={{ headerContent, setHeaderContent }}>
215-
{Form()}
216-
</HeaderProvider>
217-
</div>
206+
{Form()}
207+
</ModalHeaderProvider>
218208
</div>
219-
</EuiModalBody>
220-
<EuiModalFooter>
221-
<div id="footerDatabaseForm" />
222-
</EuiModalFooter>
223-
</EuiModal>
209+
</div>
210+
</FormDialog>
224211
)
225212
}
226213

redisinsight/ui/src/pages/home/components/database-panel-dialog/ModalTitleProvider.tsx

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

0 commit comments

Comments
 (0)