Skip to content

Commit 59d793f

Browse files
RI-7687: rework menu and modals
1 parent 3476c58 commit 59d793f

File tree

20 files changed

+269
-340
lines changed

20 files changed

+269
-340
lines changed

redisinsight/ui/src/components/base/forms/file-picker/RiFilePicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export const RiFilePicker = ({
184184
size={normalFormControl ? 'L' : 'XL'}
185185
aria-hidden="true"
186186
/>
187-
<FilePickerPromptText size="XS" className="RI-File-Picker__promptText">
187+
<FilePickerPromptText size="s" className="RI-File-Picker__promptText">
188188
{promptText || initialPromptText}
189189
</FilePickerPromptText>
190190
{clearButton}

redisinsight/ui/src/components/import-file-modal/ImportFileModal.spec.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,6 @@ describe('ImportFileModal', () => {
155155
expect(screen.getByTestId('submit-btn')).toHaveTextContent('Import')
156156
})
157157

158-
it('should render warning message', () => {
159-
render(
160-
<ImportFileModal
161-
{...mockProps}
162-
warning={<div data-testid="warning">warning</div>}
163-
/>,
164-
)
165-
166-
expect(screen.getByTestId('warning')).toHaveTextContent('warning')
167-
})
168-
169158
it('should contain the upload warning text', () => {
170159
render(<ImportFileModal {...mockProps} />)
171160

redisinsight/ui/src/components/import-file-modal/ImportFileModal.tsx

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import React from 'react'
22

33
import { Nullable } from 'uiSrc/utils'
44
import { RiFilePicker, UploadWarning } from 'uiSrc/components'
5-
import { Col, FlexItem, Row } from 'uiSrc/components/base/layout/flex'
5+
import { Col, FlexItem } from 'uiSrc/components/base/layout/flex'
66
import { ColorText, Text } from 'uiSrc/components/base/text'
77
import { Loader, Modal } from 'uiSrc/components/base/display'
88
import { RiIcon } from 'uiSrc/components/base/icons/RiIcon'
99
import { CancelIcon } from 'uiSrc/components/base/icons'
10-
import { Button } from 'uiSrc/components/base/forms/buttons'
10+
import {
11+
PrimaryButton,
12+
SecondaryButton,
13+
} from 'uiSrc/components/base/forms/buttons'
1114
import styles from './styles.module.scss'
1215

1316
export interface Props<T> {
@@ -19,7 +22,6 @@ export interface Props<T> {
1922
submitResults: JSX.Element
2023
loading: boolean
2124
data: Nullable<T>
22-
warning?: JSX.Element | null
2325
error?: string
2426
errorMessage?: string
2527
invalidMessage?: string
@@ -38,7 +40,6 @@ const ImportFileModal = <T,>({
3840
submitResults,
3941
loading,
4042
data,
41-
warning,
4243
error,
4344
errorMessage,
4445
invalidMessage,
@@ -50,17 +51,21 @@ const ImportFileModal = <T,>({
5051
const isShowForm = !loading && !data && !error
5152
return (
5253
<Modal.Compose open>
53-
<Modal.Content.Compose className={styles.modal}>
54-
<Modal.Content.Close icon={CancelIcon} onClick={onClose} data-testid="import-file-modal-close-btn" />
55-
<Modal.Content.Header.Title
56-
data-testid="import-file-modal-title"
57-
className={styles.marginTop2}
58-
>
59-
{!data && !error ? title : resultsTitle || 'Import Results'}
60-
</Modal.Content.Header.Title>
61-
<Modal.Content.Body.Compose className={styles.marginTop2}>
54+
<Modal.Content.Compose persistent>
55+
<Modal.Content.Close
56+
icon={CancelIcon}
57+
onClick={onClose}
58+
data-testid="import-file-modal-close-btn"
59+
/>
60+
61+
<Modal.Content.Header.Compose>
62+
<Modal.Content.Header.Title data-testid="import-file-modal-title">
63+
{!data && !error ? title : resultsTitle || 'Import Results'}
64+
</Modal.Content.Header.Title>
65+
</Modal.Content.Header.Compose>
66+
67+
<Modal.Content.Body.Compose>
6268
<Col align="center">
63-
{warning && <FlexItem>{warning}</FlexItem>}
6469
<FlexItem>
6570
{isShowForm && (
6671
<>
@@ -114,36 +119,33 @@ const ImportFileModal = <T,>({
114119
</FlexItem>
115120
</Col>
116121
{data && (
117-
<Row justify="center">
118-
<FlexItem>{submitResults}</FlexItem>
119-
</Row>
122+
<Modal.Content.Body
123+
content={submitResults}
124+
data-testid="result-succeeded"
125+
/>
120126
)}
121127
</Modal.Content.Body.Compose>
122128
<Modal.Content.Footer.Compose>
123129
{isShowForm && (
124130
<>
125-
<Button
126-
variant="secondary-invert"
131+
<SecondaryButton
132+
size="l"
127133
onClick={onClose}
128134
data-testid="cancel-btn"
129135
>
130136
Cancel
131-
</Button>
132-
<Button
133-
variant="primary"
137+
</SecondaryButton>
138+
<PrimaryButton
139+
size="l"
134140
onClick={onSubmit}
135141
disabled={isSubmitDisabled}
136142
data-testid="submit-btn"
137143
>
138144
{submitBtnText || 'Import'}
139-
</Button>
145+
</PrimaryButton>
140146
</>
141147
)}
142-
{data && (
143-
<Button variant="primary" onClick={onClose}>
144-
OK
145-
</Button>
146-
)}
148+
{data && <PrimaryButton onClick={onClose}>OK</PrimaryButton>}
147149
</Modal.Content.Footer.Compose>
148150
</Modal.Content.Compose>
149151
</Modal.Compose>

redisinsight/ui/src/components/import-file-modal/styles.module.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.marginTop2 {
2-
margin-top: 2rem !important;
3-
}
4-
51
.uploadWarningContainer {
62
align-self: flex-start;
73
text-wrap: wrap;

redisinsight/ui/src/pages/rdi/instance/components/download/Download.spec.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React from 'react'
22

33
import { rdiPipelineSelector } from 'uiSrc/slices/rdi/pipeline'
44
import { TelemetryEvent, sendEventTelemetry } from 'uiSrc/telemetry'
5-
import { act, fireEvent, render, screen } from 'uiSrc/utils/test-utils'
6-
import Download from './Download'
5+
import { render, screen, userEvent } from 'uiSrc/utils/test-utils'
6+
import Download, { Props } from './Download'
77

88
jest.mock('uiSrc/slices/rdi/pipeline', () => ({
99
...jest.requireActual('uiSrc/slices/rdi/pipeline'),
@@ -22,18 +22,27 @@ jest.mock('uiSrc/telemetry', () => ({
2222
sendEventTelemetry: jest.fn(),
2323
}))
2424

25+
const button = (
26+
<button type="button" data-testid="download-pipeline-btn">
27+
test
28+
</button>
29+
)
30+
31+
const renderDownload = (props: Partial<Props> = {}) => {
32+
const { trigger = button, ...rest } = props
33+
return render(<Download trigger={trigger} {...rest} />)
34+
}
35+
2536
describe('Download', () => {
2637
it('should render', () => {
27-
expect(render(<Download />)).toBeTruthy()
38+
expect(renderDownload()).toBeTruthy()
2839
})
2940

3041
it('should call onClose when download clicked', async () => {
3142
const onClose = jest.fn()
32-
render(<Download onClose={onClose} />)
43+
renderDownload({ onClose })
3344

34-
await act(() => {
35-
fireEvent.click(screen.getByTestId('download-pipeline-btn'))
36-
})
45+
await userEvent.click(screen.getByTestId('download-pipeline-btn'))
3746

3847
expect(onClose).toBeCalledTimes(1)
3948
})
@@ -44,11 +53,9 @@ describe('Download', () => {
4453
() => sendEventTelemetryMock,
4554
)
4655

47-
render(<Download />)
56+
renderDownload()
4857

49-
await act(() => {
50-
fireEvent.click(screen.getByTestId('download-pipeline-btn'))
51-
})
58+
await userEvent.click(screen.getByTestId('download-pipeline-btn'))
5259

5360
expect(sendEventTelemetry).toBeCalledWith({
5461
event: TelemetryEvent.RDI_PIPELINE_DOWNLOAD_CLICKED,
@@ -64,7 +71,7 @@ describe('Download', () => {
6471
loading: true,
6572
}))
6673

67-
render(<Download />)
74+
renderDownload()
6875

6976
expect(screen.getByTestId('download-pipeline-btn')).toBeDisabled()
7077
})

redisinsight/ui/src/pages/rdi/instance/components/download/Download.tsx

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,15 @@ import React from 'react'
44
import { useSelector } from 'react-redux'
55
import { useParams } from 'react-router-dom'
66

7-
import { SaveIcon } from 'uiSrc/components/base/icons'
87
import { rdiPipelineSelector } from 'uiSrc/slices/rdi/pipeline'
98
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
109

11-
import { EmptyButton } from 'uiSrc/components/base/forms/buttons'
12-
import styles from './styles.module.scss'
13-
14-
interface Props {
15-
dataTestid?: string
10+
export interface Props {
11+
trigger: React.ReactElement
1612
onClose?: () => void
1713
}
1814

19-
const Download = ({ dataTestid, onClose }: Props) => {
15+
const Download = ({ onClose, trigger }: Props) => {
2016
const { loading, jobs, config } = useSelector(rdiPipelineSelector)
2117

2218
const { rdiInstanceId } = useParams<{ rdiInstanceId: string }>()
@@ -43,19 +39,14 @@ const Download = ({ dataTestid, onClose }: Props) => {
4339
onClose?.()
4440
}
4541

46-
return (
47-
<EmptyButton
48-
color="text"
49-
className={styles.downloadBtn}
50-
icon={SaveIcon}
51-
disabled={loading}
52-
onClick={handleDownloadClick}
53-
aria-labelledby="Download pipeline button"
54-
data-testid={dataTestid || 'download-pipeline-btn'}
55-
>
56-
Save to file
57-
</EmptyButton>
58-
)
42+
const button = trigger
43+
? React.cloneElement(trigger, {
44+
disabled: loading,
45+
onClick: handleDownloadClick,
46+
})
47+
: null
48+
49+
return <>{button}</>
5950
}
6051

6152
export default Download

redisinsight/ui/src/pages/rdi/instance/components/download/styles.module.scss

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

redisinsight/ui/src/pages/rdi/instance/components/header/components/fetch-pipeline-popover/FetchPipelinePopover.tsx

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

redisinsight/ui/src/pages/rdi/instance/components/header/components/fetch-pipeline-popover/index.ts

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

redisinsight/ui/src/pages/rdi/instance/components/header/components/fetch-pipeline-popover/styles.module.scss

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

0 commit comments

Comments
 (0)