Skip to content

Commit 0a9bf65

Browse files
authored
refactor(ui): export the bulk actions status display (#5185)
1 parent 3f186b3 commit 0a9bf65

File tree

5 files changed

+155
-63
lines changed

5 files changed

+155
-63
lines changed

redisinsight/ui/src/pages/browser/components/bulk-actions/BulkActionsInfo/BulkActionsInfo.styles.tsx

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ import styled from 'styled-components'
22
import React from 'react'
33
import { ColorText, Text } from 'uiSrc/components/base/text'
44
import { Theme } from 'uiSrc/components/base/theme/types'
5-
import { getApproximatePercentage, Maybe } from 'uiSrc/utils'
6-
import { isUndefined } from 'lodash'
7-
import { isProcessedBulkAction } from 'uiSrc/pages/browser/components/bulk-actions/utils'
8-
import { Banner } from 'uiSrc/components/base/display'
9-
import { BulkActionsStatus } from 'uiSrc/constants'
10-
import { Props } from './BulkActionsInfo'
115

126
export const BulkActionsInfoFilter = styled.div<{
137
className?: string
@@ -33,8 +27,6 @@ export const BulkActionsInfoSearch = styled(ColorText).attrs({
3327
word-break: break-all;
3428
`
3529

36-
export const BulkActionsProgress = styled(Banner)``
37-
3830
export const BulkActionsProgressLine = styled.div<{
3931
children?: React.ReactNode
4032
}>`
@@ -57,57 +49,3 @@ export const BulkActionsContainer = styled.div<{ children: React.ReactNode }>`
5749
display: flex;
5850
flex-direction: column;
5951
`
60-
61-
export const BulkActionsStatusDisplay = ({
62-
status,
63-
total,
64-
scanned,
65-
}: {
66-
status: Props['status']
67-
total: Maybe<number>
68-
scanned: Maybe<number>
69-
}) => {
70-
if (!isUndefined(status) && !isProcessedBulkAction(status)) {
71-
return (
72-
<BulkActionsProgress
73-
message={
74-
<>
75-
In progress:
76-
<ColorText size="XS">{` ${getApproximatePercentage(total, scanned)}`}</ColorText>
77-
</>
78-
}
79-
data-testid="bulk-status-progress"
80-
/>
81-
)
82-
}
83-
if (status === BulkActionsStatus.Aborted) {
84-
return (
85-
<BulkActionsProgress
86-
variant="danger"
87-
message={<>Stopped: {getApproximatePercentage(total, scanned)}</>}
88-
data-testid="bulk-status-stopped"
89-
/>
90-
)
91-
}
92-
93-
if (status === BulkActionsStatus.Completed) {
94-
return (
95-
<BulkActionsProgress
96-
showIcon
97-
variant="success"
98-
message="Action completed"
99-
data-testid="bulk-status-completed"
100-
/>
101-
)
102-
}
103-
if (status === BulkActionsStatus.Disconnected) {
104-
return (
105-
<BulkActionsProgress
106-
variant="danger"
107-
message={`Connection Lost: ${getApproximatePercentage(total, scanned)}`}
108-
data-testid="bulk-status-disconnected"
109-
/>
110-
)
111-
}
112-
return null
113-
}

redisinsight/ui/src/pages/browser/components/bulk-actions/BulkActionsInfo/BulkActionsInfo.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import { BulkActionsStatus, KeyTypes, RedisDataType } from 'uiSrc/constants'
66
import GroupBadge from 'uiSrc/components/group-badge/GroupBadge'
77
import { Col, Row } from 'uiSrc/components/base/layout/flex'
88
import { Text } from 'uiSrc/components/base/text'
9+
10+
import BulkActionsStatusDisplay from '../BulkActionsStatusDisplay'
911
import {
1012
BulkActionsContainer,
1113
BulkActionsInfoFilter,
1214
BulkActionsInfoSearch,
1315
BulkActionsProgressLine,
14-
BulkActionsStatusDisplay,
1516
BulkActionsTitle,
1617
} from './BulkActionsInfo.styles'
1718

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import React from 'react'
2+
import { render, screen } from 'uiSrc/utils/test-utils'
3+
import BulkActionsStatusDisplay, {
4+
BulkActionsStatusDisplayProps,
5+
} from './BulkActionsStatusDisplay'
6+
import { faker } from '@faker-js/faker/locale/af_ZA'
7+
import { BulkActionsStatus } from 'uiSrc/constants'
8+
9+
const renderBulkActionsStatusDisplay = (
10+
props?: Partial<BulkActionsStatusDisplayProps>,
11+
) => {
12+
const defaultProps: BulkActionsStatusDisplayProps = {
13+
status: faker.helpers.enumValue(BulkActionsStatus),
14+
total: faker.number.int({ min: 0, max: 1000 }),
15+
scanned: faker.number.int({ min: 0, max: 1000 }),
16+
}
17+
18+
return render(<BulkActionsStatusDisplay {...defaultProps} {...props} />)
19+
}
20+
21+
describe('BulkActionsStatusDisplay', () => {
22+
beforeEach(() => {
23+
jest.clearAllMocks()
24+
})
25+
26+
it('should render banner when status is in progress', () => {
27+
const props: BulkActionsStatusDisplayProps = {
28+
status: BulkActionsStatus.Running,
29+
total: 200,
30+
scanned: 50,
31+
}
32+
33+
renderBulkActionsStatusDisplay(props)
34+
35+
const banner = screen.getByTestId('bulk-status-progress')
36+
37+
expect(banner).toBeInTheDocument()
38+
expect(banner).toHaveTextContent('In progress: 25%')
39+
})
40+
41+
it('should render banner when status is in Aborted', () => {
42+
const props: BulkActionsStatusDisplayProps = {
43+
status: BulkActionsStatus.Aborted,
44+
total: 100,
45+
scanned: 30,
46+
}
47+
48+
renderBulkActionsStatusDisplay(props)
49+
50+
const banner = screen.getByTestId('bulk-status-stopped')
51+
52+
expect(banner).toBeInTheDocument()
53+
expect(banner).toHaveTextContent('Stopped: 30%')
54+
})
55+
56+
it('should render banner when status is Completed', () => {
57+
renderBulkActionsStatusDisplay({ status: BulkActionsStatus.Completed })
58+
59+
const banner = screen.getByTestId('bulk-status-completed')
60+
61+
expect(banner).toBeInTheDocument()
62+
expect(banner).toHaveTextContent('Action completed')
63+
})
64+
65+
it('should render banner when status is Disconnected', () => {
66+
const props: BulkActionsStatusDisplayProps = {
67+
status: BulkActionsStatus.Disconnected,
68+
total: 100,
69+
scanned: 50,
70+
}
71+
72+
renderBulkActionsStatusDisplay(props)
73+
74+
const banner = screen.getByTestId('bulk-status-disconnected')
75+
76+
expect(banner).toBeInTheDocument()
77+
expect(banner).toHaveTextContent('Connection Lost: 50%')
78+
})
79+
})
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import React from 'react'
2+
import { isUndefined } from 'lodash'
3+
4+
import { BulkActionsStatus } from 'uiSrc/constants'
5+
import { getApproximatePercentage, Maybe } from 'uiSrc/utils'
6+
import { ColorText } from 'uiSrc/components/base/text'
7+
8+
import { isProcessedBulkAction } from '../utils'
9+
import { Props } from '../BulkActionsInfo/BulkActionsInfo'
10+
import { Banner } from 'uiSrc/components/base/display'
11+
12+
export interface BulkActionsStatusDisplayProps {
13+
status: Props['status']
14+
total: Maybe<number>
15+
scanned: Maybe<number>
16+
}
17+
18+
export const BulkActionsStatusDisplay = ({
19+
status,
20+
total,
21+
scanned,
22+
}: BulkActionsStatusDisplayProps) => {
23+
if (!isUndefined(status) && !isProcessedBulkAction(status)) {
24+
return (
25+
<Banner
26+
message={
27+
<>
28+
In progress:
29+
<ColorText size="XS">{` ${getApproximatePercentage(total, scanned)}`}</ColorText>
30+
</>
31+
}
32+
data-testid="bulk-status-progress"
33+
/>
34+
)
35+
}
36+
37+
if (status === BulkActionsStatus.Aborted) {
38+
return (
39+
<Banner
40+
variant="danger"
41+
message={<>Stopped: {getApproximatePercentage(total, scanned)}</>}
42+
data-testid="bulk-status-stopped"
43+
/>
44+
)
45+
}
46+
47+
if (status === BulkActionsStatus.Completed) {
48+
return (
49+
<Banner
50+
showIcon
51+
variant="success"
52+
message="Action completed"
53+
data-testid="bulk-status-completed"
54+
/>
55+
)
56+
}
57+
58+
if (status === BulkActionsStatus.Disconnected) {
59+
return (
60+
<Banner
61+
variant="danger"
62+
message={`Connection Lost: ${getApproximatePercentage(total, scanned)}`}
63+
data-testid="bulk-status-disconnected"
64+
/>
65+
)
66+
}
67+
68+
return null
69+
}
70+
71+
export default BulkActionsStatusDisplay
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import BulkActionsStatusDisplay from './BulkActionsStatusDisplay'
2+
3+
export default BulkActionsStatusDisplay

0 commit comments

Comments
 (0)