Skip to content

Commit 2b5b005

Browse files
committed
#RI-4669 - fe part for clear workbench history
1 parent 1c64269 commit 2b5b005

File tree

15 files changed

+340
-23
lines changed

15 files changed

+340
-23
lines changed

redisinsight/ui/src/components/query-card/QueryCard.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface Props {
3939
summary?: ResultsSummary
4040
createdAt?: Date
4141
loading?: boolean
42+
clearing?: boolean
4243
isNotStored?: boolean
4344
executionTime?: number
4445
db?: number
@@ -80,6 +81,7 @@ const QueryCard = (props: Props) => {
8081
onQueryProfile,
8182
onQueryReRun,
8283
loading,
84+
clearing,
8385
emptyCommand,
8486
isNotStored,
8587
executionTime,
@@ -173,6 +175,7 @@ const QueryCard = (props: Props) => {
173175
isFullScreen={isFullScreen}
174176
query={command}
175177
loading={loading}
178+
clearing={clearing}
176179
createdAt={createdAt}
177180
message={message}
178181
queryType={queryType}

redisinsight/ui/src/components/query-card/QueryCardHeader/QueryCardHeader.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export interface Props {
6262
queryType: WBQueryType
6363
selectedValue: string
6464
loading?: boolean
65+
clearing?: boolean
6566
executionTime?: number
6667
emptyCommand?: boolean
6768
db?: number
@@ -96,6 +97,7 @@ const QueryCardHeader = (props: Props) => {
9697
toggleFullScreen,
9798
query = '',
9899
loading,
100+
clearing,
99101
message,
100102
createdAt,
101103
mode,
@@ -169,6 +171,7 @@ const QueryCardHeader = (props: Props) => {
169171
const handleQueryDelete = (event: React.MouseEvent) => {
170172
eventStop(event)
171173
onQueryDelete()
174+
sendEvent(TelemetryEvent.WORKBENCH_CLEAR_RESULT_CLICKED, query)
172175
}
173176

174177
const handleQueryReRun = (event: React.MouseEvent) => {
@@ -404,7 +407,7 @@ const QueryCardHeader = (props: Props) => {
404407
</EuiFlexItem>
405408
<EuiFlexItem grow={false} className={styles.buttonIcon}>
406409
<EuiButtonIcon
407-
disabled={loading}
410+
disabled={loading || clearing}
408411
iconType="trash"
409412
aria-label="Delete command"
410413
data-testid="delete-command"

redisinsight/ui/src/constants/api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ enum ApiEndpoints {
7777
SETTINGS_AGREEMENTS_SPEC = 'settings/agreements/spec',
7878

7979
WORKBENCH_COMMAND_EXECUTIONS = 'workbench/command-executions',
80-
WORKBENCH_COMMANDS_EXECUTION = 'workbench/commands-execution',
8180

8281
PROFILER = 'profiler',
8382
PROFILER_LOGS = 'profiler/logs',

redisinsight/ui/src/pages/workbench/WorkbenchPage.spec.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,39 @@ describe('Telemetry', () => {
240240
rawMode: true,
241241
}
242242
})
243+
244+
sendEventTelemetry.mockRestore()
245+
})
246+
247+
it('should call proper telemetry on delete', async () => {
248+
const sendEventTelemetryMock = jest.fn()
249+
250+
sendEventTelemetry.mockImplementation(() => sendEventTelemetryMock)
251+
252+
render(<WorkbenchPage />)
253+
254+
fireEvent.click(screen.getByTestId('delete-command'))
255+
256+
expect(sendEventTelemetry).toBeCalledWith({
257+
event: TelemetryEvent.WORKBENCH_CLEAR_RESULT_CLICKED,
258+
eventData: {
259+
databaseId: 'instanceId',
260+
command: 'info'
261+
}
262+
})
263+
264+
sendEventTelemetry.mockRestore()
265+
266+
fireEvent.click(screen.getByTestId('clear-history-btn'))
267+
268+
expect(sendEventTelemetry).toBeCalledWith({
269+
event: TelemetryEvent.WORKBENCH_CLEAR_ALL_RESULTS_CLICKED,
270+
eventData: {
271+
databaseId: 'instanceId'
272+
}
273+
})
274+
275+
sendEventTelemetry.mockRestore()
243276
})
244277
})
245278
describe('Raw mode', () => {

redisinsight/ui/src/pages/workbench/components/wb-results/WBResults/WBResults.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useContext } from 'react'
22
import cx from 'classnames'
3-
import { EuiIcon, EuiText } from '@elastic/eui'
3+
import { EuiButtonEmpty, EuiIcon, EuiText } from '@elastic/eui'
44

55
import { Theme } from 'uiSrc/constants'
66
import { ProfileQueryType } from 'uiSrc/pages/workbench/constants'
@@ -17,22 +17,26 @@ import styles from './styles.module.scss'
1717

1818
export interface Props {
1919
items: CommandExecutionUI[]
20+
clearing: boolean
2021
activeMode: RunQueryMode
2122
activeResultsMode?: ResultsMode
2223
scrollDivRef: React.Ref<HTMLDivElement>
2324
onQueryReRun: (query: string, commandId?: Nullable<string>, executeParams?: CodeButtonParams) => void
2425
onQueryDelete: (commandId: string) => void
26+
onAllQueriesDelete: () => void
2527
onQueryOpen: (commandId: string) => void
2628
onQueryProfile: (query: string, commandId?: Nullable<string>, executeParams?: CodeButtonParams) => void
2729
}
2830
const WBResults = (props: Props) => {
2931
const {
3032
items = [],
33+
clearing,
3134
activeMode,
3235
activeResultsMode,
3336
onQueryReRun,
3437
onQueryProfile,
3538
onQueryDelete,
39+
onAllQueriesDelete,
3640
onQueryOpen,
3741
scrollDivRef
3842
} = props
@@ -69,6 +73,20 @@ const WBResults = (props: Props) => {
6973

7074
return (
7175
<div className={cx(styles.container)}>
76+
{!!items.length && (
77+
<div className={styles.header}>
78+
<EuiButtonEmpty
79+
size="s"
80+
iconType="trash"
81+
iconSize="s"
82+
className={styles.clearAllBtn}
83+
onClick={() => onAllQueriesDelete?.()}
84+
data-testid="clear-history-btn"
85+
>
86+
Clear Results
87+
</EuiButtonEmpty>
88+
</div>
89+
)}
7290
<div ref={scrollDivRef} />
7391
{items.map((
7492
{
@@ -93,6 +111,7 @@ const WBResults = (props: Props) => {
93111
isOpen={isOpen}
94112
result={result}
95113
summary={summary}
114+
clearing={clearing}
96115
loading={loading}
97116
command={command}
98117
createdAt={createdAt}

redisinsight/ui/src/pages/workbench/components/wb-results/WBResults/styles.module.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
overflow: auto;
1515
}
1616

17+
.header {
18+
height: 42px;
19+
display: flex;
20+
align-items: center;
21+
justify-content: flex-end;
22+
padding: 0 12px;
23+
}
24+
1725
.noResults {
1826
width: 326px;
1927
height: 100%;
@@ -42,3 +50,14 @@
4250
width: 42px !important;
4351
height: 42px !important;
4452
}
53+
54+
.clearAllBtn {
55+
font-size: 14px !important;
56+
57+
:global {
58+
.euiIcon {
59+
width: 14px !important;
60+
height: 14px !important;
61+
}
62+
}
63+
}

redisinsight/ui/src/pages/workbench/components/wb-results/WBResultsWrapper.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import WBResults from './WBResults'
77

88
export interface Props {
99
items: CommandExecutionUI[]
10+
clearing: boolean
1011
activeMode: RunQueryMode
1112
activeResultsMode: ResultsMode
1213
scrollDivRef: React.Ref<HTMLDivElement>
1314
onQueryReRun: (query: string, commandId?: Nullable<string>, executeParams?: CodeButtonParams) => void
1415
onQueryOpen: (commandId: string) => void
1516
onQueryDelete: (commandId: string) => void
17+
onAllQueriesDelete: () => void
1618
onQueryProfile: (query: string, commandId?: Nullable<string>, executeParams?: CodeButtonParams) => void
1719
}
1820

redisinsight/ui/src/pages/workbench/components/wb-view/WBView/WBView.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const verticalPanelIds = {
3434
export interface Props {
3535
script: string
3636
items: CommandExecutionUI[]
37+
clearing: boolean
3738
setScript: (script: string) => void
3839
setScriptEl: Function
3940
scriptEl: Nullable<monacoEditor.editor.IStandaloneCodeEditor>
@@ -43,6 +44,7 @@ export interface Props {
4344
onSubmit: (query?: string, commandId?: Nullable<string>, executeParams?: CodeButtonParams) => void
4445
onQueryOpen: (commandId?: string) => void
4546
onQueryDelete: (commandId: string) => void
47+
onAllQueriesDelete: () => void
4648
onQueryChangeMode: () => void
4749
onChangeGroupMode: () => void
4850
}
@@ -61,6 +63,7 @@ const WBView = (props: Props) => {
6163
const {
6264
script = '',
6365
items,
66+
clearing,
6467
setScript,
6568
setScriptEl,
6669
scriptEl,
@@ -69,6 +72,7 @@ const WBView = (props: Props) => {
6972
onSubmit,
7073
onQueryOpen,
7174
onQueryDelete,
75+
onAllQueriesDelete,
7276
onQueryChangeMode,
7377
onChangeGroupMode,
7478
scrollDivRef,
@@ -228,13 +232,15 @@ const WBView = (props: Props) => {
228232
>
229233
<WBResultsWrapper
230234
items={items}
235+
clearing={clearing}
231236
activeMode={activeMode}
232237
activeResultsMode={resultsMode}
233238
scrollDivRef={scrollDivRef}
234239
onQueryReRun={handleReRun}
235240
onQueryProfile={handleProfile}
236241
onQueryOpen={onQueryOpen}
237242
onQueryDelete={onQueryDelete}
243+
onAllQueriesDelete={onAllQueriesDelete}
238244
/>
239245
</EuiResizablePanel>
240246
</>

redisinsight/ui/src/pages/workbench/components/wb-view/WBViewWrapper.spec.tsx

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ import {
1313
import QueryWrapper from 'uiSrc/components/query'
1414
import { Props as QueryProps } from 'uiSrc/components/query/QueryWrapper'
1515
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
16-
import { loadWBHistory, sendWBCommandAction } from 'uiSrc/slices/workbench/wb-results'
17-
import { getWBGuides } from 'uiSrc/slices/workbench/wb-guides'
18-
import { getWBTutorials } from 'uiSrc/slices/workbench/wb-tutorials'
16+
import {
17+
clearWbResults,
18+
loadWBHistory,
19+
processWBCommand,
20+
sendWBCommandAction,
21+
workbenchResultsSelector
22+
} from 'uiSrc/slices/workbench/wb-results'
1923

2024
import { getWBCustomTutorials } from 'uiSrc/slices/workbench/wb-custom-tutorials'
2125
import WBViewWrapper from './WBViewWrapper'
@@ -71,6 +75,10 @@ jest.mock('uiSrc/slices/workbench/wb-results', () => ({
7175
sendWBCommandClusterAction: jest.fn(),
7276
processUnsupportedCommand: jest.fn(),
7377
updateCliCommandHistory: jest.fn,
78+
workbenchResultsSelector: jest.fn().mockReturnValue({
79+
loading: false,
80+
items: []
81+
})
7482
}))
7583

7684
jest.mock('uiSrc/slices/workbench/wb-guides', () => {
@@ -111,6 +119,39 @@ describe('WBViewWrapper', () => {
111119
)
112120
})
113121

122+
it('should call delete command', () => {
123+
(workbenchResultsSelector as jest.Mock).mockImplementation(() => ({
124+
items: [
125+
{ id: '1' },
126+
],
127+
}))
128+
render(<WBViewWrapper />)
129+
130+
fireEvent.click(screen.getByTestId('delete-command'))
131+
expect(clearStoreActions(store.getActions().slice(-1))).toEqual(clearStoreActions([processWBCommand('1')]))
132+
})
133+
134+
it('should call delete all command', () => {
135+
(workbenchResultsSelector as jest.Mock).mockImplementation(() => ({
136+
items: [
137+
{ id: '1' },
138+
],
139+
}))
140+
render(<WBViewWrapper />)
141+
142+
fireEvent.click(screen.getByTestId('clear-history-btn'))
143+
expect(clearStoreActions(store.getActions().slice(-1))).toEqual(clearStoreActions([clearWbResults()]))
144+
})
145+
146+
it('should not display clear results when with empty history', () => {
147+
(workbenchResultsSelector as jest.Mock).mockImplementation(() => ({
148+
items: [],
149+
}))
150+
render(<WBViewWrapper />)
151+
152+
expect(screen.queryByTestId('clear-history-btn')).not.toBeInTheDocument()
153+
})
154+
114155
it.skip('"onSubmit" for Cluster connection should call "sendWBCommandClusterAction"', async () => {
115156
(connectedInstanceSelector as jest.Mock).mockImplementation(() => ({
116157
id: '123',

0 commit comments

Comments
 (0)