Skip to content

Commit 835799d

Browse files
committed
feat(ui): replace "clear slo log" popover with a modal
re #RI-7437
1 parent 2ffa2ce commit 835799d

File tree

5 files changed

+179
-67
lines changed

5 files changed

+179
-67
lines changed

redisinsight/ui/src/pages/slow-log/components/Actions/Actions.styles.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,3 @@ export const StyledInfoIcon = styled.span`
55
align-self: center;
66
cursor: pointer;
77
`
8-
9-
export const StyledDatabaseName = styled.span`
10-
color: ${({ theme }) => theme.semantic.color.text.primary500};
11-
`

redisinsight/ui/src/pages/slow-log/components/Actions/Actions.tsx

Lines changed: 17 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,18 @@ import { AutoRefresh } from 'uiSrc/components'
88
import { RiPopover, RiTooltip } from 'uiSrc/components/base'
99
import { Nullable } from 'uiSrc/utils'
1010
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
11-
import {
12-
Col,
13-
FlexGroup,
14-
FlexItem,
15-
Row,
16-
} from 'uiSrc/components/base/layout/flex'
11+
import { FlexItem, Row } from 'uiSrc/components/base/layout/flex'
1712
import { Spacer } from 'uiSrc/components/base/layout/spacer'
1813
import { EraserIcon, SettingsIcon } from 'uiSrc/components/base/icons'
1914
import {
20-
DestructiveButton,
2115
IconButton,
2216
SecondaryButton,
2317
} from 'uiSrc/components/base/forms/buttons'
24-
import { Text, Title } from 'uiSrc/components/base/text'
2518
import { RiIcon } from 'uiSrc/components/base/icons/RiIcon'
2619

2720
import SlowLogConfig from '../SlowLogConfig'
28-
import { StyledDatabaseName, StyledInfoIcon } from './Actions.styles'
21+
import { StyledInfoIcon } from './Actions.styles'
22+
import { ClearSlowLogModal } from '../ClearSlowLogModal/ClearSlowLogModal'
2923

3024
export interface Props {
3125
width: number
@@ -67,11 +61,6 @@ const Actions = (props: Props) => {
6761
setIsPopoverConfigOpen(false)
6862
}
6963

70-
const handleClearClick = () => {
71-
onClear()
72-
closePopoverClear()
73-
}
74-
7564
const handleEnableAutoRefresh = (
7665
enableAutoRefresh: boolean,
7766
refreshRate: string,
@@ -102,35 +91,6 @@ const Actions = (props: Props) => {
10291
}
10392
}
10493

105-
const ToolTipContent = (
106-
<FlexGroup direction="column" gap="l">
107-
<Col gap="m">
108-
<Title size="S" color="primary">
109-
Clear Slow Log?
110-
</Title>
111-
<Col>
112-
<Text size="m" color="primary">
113-
Slow Log will be cleared for&nbsp;
114-
<StyledDatabaseName>{name}</StyledDatabaseName>
115-
</Text>
116-
<Text size="xs" color="secondary">
117-
NOTE: This is server configuration
118-
</Text>
119-
</Col>
120-
</Col>
121-
<Row justify="end">
122-
<DestructiveButton
123-
size="small"
124-
icon={EraserIcon}
125-
onClick={() => handleClearClick()}
126-
data-testid="reset-confirm-btn"
127-
>
128-
Clear
129-
</DestructiveButton>
130-
</Row>
131-
</FlexGroup>
132-
)
133-
13494
return (
13595
<Row gap="s" align="center">
13696
<FlexItem>
@@ -174,27 +134,21 @@ const Actions = (props: Props) => {
174134
</FlexItem>
175135

176136
{!isEmptySlowLog && (
177-
<FlexItem>
178-
<RiPopover
179-
anchorPosition="leftCenter"
180-
ownFocus
137+
<>
138+
<IconButton
139+
icon={EraserIcon}
140+
aria-label="Clear Slow Log"
141+
onClick={() => showClearPopover()}
142+
data-testid="clear-btn"
143+
/>
144+
145+
<ClearSlowLogModal
146+
name={name}
181147
isOpen={isPopoverClearOpen}
182-
closePopover={closePopoverClear}
183-
panelPaddingSize="m"
184-
button={
185-
<RiTooltip position="left" content="Clear Slow Log">
186-
<IconButton
187-
icon={EraserIcon}
188-
aria-label="Clear Slow Log"
189-
onClick={() => showClearPopover()}
190-
data-testid="clear-btn"
191-
/>
192-
</RiTooltip>
193-
}
194-
>
195-
{ToolTipContent}
196-
</RiPopover>
197-
</FlexItem>
148+
onClose={closePopoverClear}
149+
onClear={onClear}
150+
/>
151+
</>
198152
)}
199153

200154
<FlexItem>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import React from 'react'
2+
3+
import { ClearSlowLogModal, ClearSlowLogModalProps } from './ClearSlowLogModal'
4+
import { render, screen, fireEvent } from 'uiSrc/utils/test-utils'
5+
6+
const renderClearSlowLogModal = (props?: Partial<ClearSlowLogModalProps>) => {
7+
const defaultProps: ClearSlowLogModalProps = {
8+
name: 'test-database',
9+
isOpen: true,
10+
onClose: jest.fn(),
11+
onClear: jest.fn(),
12+
}
13+
14+
return render(<ClearSlowLogModal {...defaultProps} {...props} />)
15+
}
16+
17+
describe('ClearSlowLogModal', () => {
18+
beforeEach(() => {
19+
jest.clearAllMocks()
20+
})
21+
22+
it('should render the modal when isOpen is true', () => {
23+
const props: Partial<ClearSlowLogModalProps> = {
24+
name: 'test-database',
25+
isOpen: true,
26+
}
27+
28+
renderClearSlowLogModal(props)
29+
30+
const title = screen.getByText('Clear slow log')
31+
expect(title).toBeInTheDocument()
32+
33+
const message = screen.getByText(
34+
/Slow Log will be cleared for\s+test-database/,
35+
)
36+
expect(message).toBeInTheDocument()
37+
38+
const note = screen.getByText('NOTE: This is server configuration')
39+
expect(note).toBeInTheDocument()
40+
41+
const cancelButton = screen.getByTestId('reset-cancel-btn')
42+
expect(cancelButton).toBeInTheDocument()
43+
expect(cancelButton).toHaveTextContent('Cancel')
44+
45+
const clearButton = screen.getByTestId('reset-confirm-btn')
46+
expect(clearButton).toBeInTheDocument()
47+
expect(clearButton).toHaveTextContent('Clear')
48+
})
49+
50+
it('should not render the modal when isOpen is false', () => {
51+
renderClearSlowLogModal({ isOpen: false })
52+
53+
const modal = screen.queryByTestId('clear-slow-log-modal')
54+
expect(modal).not.toBeInTheDocument()
55+
})
56+
57+
it('should call onClose when Cancel button is clicked', () => {
58+
const props: Partial<ClearSlowLogModalProps> = {
59+
onClose: jest.fn(),
60+
onClear: jest.fn(),
61+
}
62+
63+
renderClearSlowLogModal(props)
64+
65+
const cancelButton = screen.getByTestId('reset-cancel-btn')
66+
fireEvent.click(cancelButton)
67+
68+
expect(props.onClose).toHaveBeenCalledTimes(1)
69+
expect(props.onClear).not.toHaveBeenCalled()
70+
})
71+
72+
it('should call onClear and onClose when Clear button is clicked', () => {
73+
const props: Partial<ClearSlowLogModalProps> = {
74+
onClose: jest.fn(),
75+
onClear: jest.fn(),
76+
}
77+
78+
renderClearSlowLogModal(props)
79+
80+
const clearButton = screen.getByTestId('reset-confirm-btn')
81+
fireEvent.click(clearButton)
82+
83+
expect(props.onClear).toHaveBeenCalledTimes(1)
84+
expect(props.onClose).toHaveBeenCalledTimes(1)
85+
})
86+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import styled from 'styled-components'
2+
import FormDialog from 'uiSrc/components/form-dialog/FormDialog'
3+
4+
export const StyledFormDialog = styled(FormDialog)`
5+
width: 402px;
6+
height: auto;
7+
`
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React from 'react'
2+
3+
import { Button, DestructiveButton } from 'uiSrc/components/base/forms/buttons'
4+
import { Col, FlexGroup, Row } from 'uiSrc/components/base/layout/flex'
5+
import { Title, Text } from 'uiSrc/components/base/text'
6+
import { EraserIcon } from 'uiSrc/components/base/icons'
7+
import { Spacer } from 'uiSrc/components/base/layout'
8+
9+
import { StyledFormDialog } from './ClearSlowLogModal.styles'
10+
11+
export interface ClearSlowLogModalProps {
12+
name: string
13+
isOpen: boolean
14+
onClose: () => void
15+
onClear: () => void
16+
}
17+
18+
export const ClearSlowLogModal = ({
19+
name,
20+
isOpen,
21+
onClose,
22+
onClear,
23+
}: ClearSlowLogModalProps) => {
24+
const handleClearClick = () => {
25+
onClear()
26+
onClose()
27+
}
28+
29+
return (
30+
<StyledFormDialog
31+
isOpen={isOpen}
32+
onClose={onClose}
33+
data-testid="clear-slow-log-modal"
34+
header={<Title size="XL">Clear slow log</Title>}
35+
footer={
36+
<Row justify="end" gap="m">
37+
<Button
38+
variant="secondary-ghost"
39+
size="large"
40+
onClick={onClose}
41+
data-testid="reset-cancel-btn"
42+
>
43+
Cancel
44+
</Button>
45+
<DestructiveButton
46+
size="large"
47+
icon={EraserIcon}
48+
onClick={() => handleClearClick()}
49+
data-testid="reset-confirm-btn"
50+
>
51+
Clear
52+
</DestructiveButton>
53+
</Row>
54+
}
55+
>
56+
<Spacer size="l" />
57+
<FlexGroup direction="column" gap="l">
58+
<Col>
59+
<Text size="m" color="primary">
60+
Slow Log will be cleared for&nbsp;{name}
61+
</Text>
62+
<Text size="m" color="secondary">
63+
NOTE: This is server configuration
64+
</Text>
65+
</Col>
66+
</FlexGroup>
67+
</StyledFormDialog>
68+
)
69+
}

0 commit comments

Comments
 (0)