Skip to content

Commit bfb53d3

Browse files
committed
#RI-3479 - fix pr comments
1 parent 334cf1c commit bfb53d3

File tree

9 files changed

+38
-39
lines changed

9 files changed

+38
-39
lines changed

redisinsight/ui/src/pages/workbench/components/enablement-area/EnablementArea/EnablementArea.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ export interface Props {
2828
loading: boolean
2929
openScript: (
3030
script: string,
31-
execute?: ExecuteButtonMode,
32-
params?: CodeButtonParams,
33-
path?: string,
34-
name?: string
31+
execute?: { mode?: ExecuteButtonMode, params?: CodeButtonParams },
32+
file?: { path?: string, name?: string }
3533
) => void
3634
onOpenInternalPage: (page: IInternalPage) => void
3735
isCodeBtnDisabled?: boolean

redisinsight/ui/src/pages/workbench/components/enablement-area/EnablementArea/components/Code/Code.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('Code', () => {
3030

3131
const link = queryByTestId(`preselect-${label}`)
3232
fireEvent.click(link as Element)
33-
expect(setScript).toBeCalledWith(MONACO_MANUAL, ExecuteButtonMode.Manual, undefined)
33+
expect(setScript).toBeCalledWith(MONACO_MANUAL, {}, undefined)
3434
})
3535

3636
it('should correctly set script with auto execute', () => {
@@ -39,12 +39,12 @@ describe('Code', () => {
3939

4040
render(
4141
<EnablementAreaProvider value={{ ...defaultValue, setScript }}>
42-
<Code {...instance(mockedProps)} label={label} execute={ExecuteButtonMode.Auto}>{MONACO_MANUAL}</Code>
42+
<Code {...instance(mockedProps)} label={label} mode={ExecuteButtonMode.Auto}>{MONACO_MANUAL}</Code>
4343
</EnablementAreaProvider>
4444
)
4545

4646
screen.debug()
4747
fireEvent.click(screen.queryByTestId(`preselect-auto-${label}`) as Element)
48-
expect(setScript).toBeCalledWith(MONACO_MANUAL, ExecuteButtonMode.Auto, undefined)
48+
expect(setScript).toBeCalledWith(MONACO_MANUAL, { mode: ExecuteButtonMode.Auto }, undefined)
4949
})
5050
})

redisinsight/ui/src/pages/workbench/components/enablement-area/EnablementArea/components/Code/Code.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React, { useContext } from 'react'
21
import { startCase } from 'lodash'
2+
import React, { useContext } from 'react'
33
import { useLocation } from 'react-router-dom'
4-
import { parseParams, getFileInfo } from 'uiSrc/pages/workbench/components/enablement-area/EnablementArea/utils'
4+
import { getFileInfo, parseParams } from 'uiSrc/pages/workbench/components/enablement-area/EnablementArea/utils'
55
import { CodeButtonParams, ExecuteButtonMode } from 'uiSrc/pages/workbench/components/enablement-area/interfaces'
66

77
import EnablementAreaContext from 'uiSrc/pages/workbench/contexts/enablementAreaContext'
@@ -12,29 +12,34 @@ export interface Props {
1212
label: string
1313
children: string
1414
params?: string
15-
execute?: ExecuteButtonMode
15+
mode?: ExecuteButtonMode
1616
}
1717

18-
const Code = ({ children, params, execute, ...rest }: Props) => {
18+
const Code = ({ children, params, mode, ...rest }: Props) => {
1919
const { search } = useLocation()
2020
const { setScript, isCodeBtnDisabled } = useContext(EnablementAreaContext)
2121

22-
const loadContent = (execute = ExecuteButtonMode.Manual, params?: CodeButtonParams) => {
22+
const loadContent = (execute: { mode?: ExecuteButtonMode, params?: CodeButtonParams }) => {
2323
const pagePath = new URLSearchParams(search).get('item')
24+
let file: { path: string, name: string } | undefined
25+
2426
if (pagePath) {
2527
const pageInfo = getFileInfo(pagePath)
26-
setScript(children, execute, params, `${pageInfo.location}/${pageInfo.name}`, startCase(rest.label))
27-
} else {
28-
setScript(children, execute, params)
28+
file = {
29+
path: `${pageInfo.location}/${pageInfo.name}`,
30+
name: startCase(rest.label)
31+
}
2932
}
33+
34+
setScript(children, execute, file)
3035
}
3136

3237
return (
3338
<CodeButton
3439
className="mb-s mt-s"
3540
onClick={loadContent}
3641
params={parseParams(params)}
37-
execute={execute}
42+
mode={mode}
3843
disabled={isCodeBtnDisabled}
3944
{...rest}
4045
/>

redisinsight/ui/src/pages/workbench/components/enablement-area/EnablementArea/components/CodeButton/CodeButton.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ describe('CodeButton', () => {
4242
{...instance(mockedProps)}
4343
label={label}
4444
onClick={onClick}
45-
execute={ExecuteButtonMode.Auto}
45+
mode={ExecuteButtonMode.Auto}
4646
params={{}}
4747
/>
4848
)
4949
fireEvent.click(screen.getByTestId(`preselect-auto-${label}`))
5050

51-
expect(onClick).toBeCalledWith(ExecuteButtonMode.Auto, {})
51+
expect(onClick).toBeCalledWith({ mode: ExecuteButtonMode.Auto, params: {} })
5252
})
5353
})

redisinsight/ui/src/pages/workbench/components/enablement-area/EnablementArea/components/CodeButton/CodeButton.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
import { EuiButton, EuiIcon } from '@elastic/eui'
2+
import cx from 'classnames'
23
import React from 'react'
34
import { CodeButtonParams, ExecuteButtonMode } from 'uiSrc/pages/workbench/components/enablement-area/interfaces'
45
import { truncateText } from 'uiSrc/utils'
56

67
import styles from './styles.module.scss'
78

89
export interface Props {
9-
onClick: (execute?: ExecuteButtonMode, params?: CodeButtonParams) => void
10+
onClick: (execute: { mode?: ExecuteButtonMode, params?: CodeButtonParams }) => void
1011
label: string
1112
isLoading?: boolean
1213
disabled?: boolean
1314
className?: string
1415
params?: CodeButtonParams
15-
execute?: ExecuteButtonMode
16+
mode?: ExecuteButtonMode
1617
}
17-
const CodeButton = ({ onClick, label, isLoading, className, disabled, params, execute, ...rest }: Props) => {
18-
const isAutoExecute = execute === ExecuteButtonMode.Auto
18+
const CodeButton = ({ onClick, label, isLoading, className, disabled, params, mode, ...rest }: Props) => {
19+
const isAutoExecute = mode === ExecuteButtonMode.Auto
1920

2021
return (
2122
<EuiButton
2223
iconSide="right"
2324
isLoading={isLoading}
2425
size="s"
25-
onClick={() => onClick(execute, params)}
26+
onClick={() => onClick({ mode, params })}
2627
fullWidth
2728
color="secondary"
28-
className={[className, styles.button].join(' ')}
29+
className={cx(className, styles.button)}
2930
textProps={{ className: styles.buttonText }}
3031
data-testid={`preselect-${isAutoExecute ? 'auto-' : ''}${label}`}
3132
disabled={disabled}

redisinsight/ui/src/pages/workbench/components/enablement-area/EnablementArea/utils/remarkRedisCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const remarkRedisCode = (): (tree: Node) => void => (tree: any) => {
2424

2525
codeNode.type = 'html'
2626
// Replace it with our custom component
27-
codeNode.value = `<Code label="${meta}" params="${params}" execute="${execute}">{${JSON.stringify(value)}}</Code>`
27+
codeNode.value = `<Code label="${meta}" params="${params}" mode="${execute}">{${JSON.stringify(value)}}</Code>`
2828
}
2929
})
3030
}

redisinsight/ui/src/pages/workbench/components/enablement-area/EnablementArea/utils/tests/remarkRedisCode.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { remarkRedisCode } from '../remarkRedisCode'
55
jest.mock('unist-util-visit')
66

77
const getValue = (meta: string, execute = ExecuteButtonMode.Manual, params?: string, value?: string) =>
8-
`<Code label="${meta}" params="${params}" execute="${execute}">{${JSON.stringify(value)}}</Code>`
8+
`<Code label="${meta}" params="${params}" mode="${execute}">{${JSON.stringify(value)}}</Code>`
99

1010
describe('remarkRedisCode', () => {
1111
it('should not modify codeNode if lang not redis', () => {

redisinsight/ui/src/pages/workbench/components/enablement-area/EnablementAreaWrapper.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import { fetchTutorials, workbenchTutorialsSelector } from 'uiSrc/slices/workben
1111
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
1212

1313
import { Nullable, } from 'uiSrc/utils'
14+
import { IInternalPage } from '../../contexts/enablementAreaContext'
1415

1516
import EnablementArea from './EnablementArea'
1617
import EnablementAreaCollapse from './EnablementAreaCollapse/EnablementAreaCollapse'
17-
import { IInternalPage } from '../../contexts/enablementAreaContext'
1818

1919
import styles from './styles.module.scss'
2020

@@ -42,7 +42,7 @@ const EnablementAreaWrapper = (props: Props) => {
4242
dispatch(fetchTutorials())
4343
}, [])
4444

45-
const sendEventButtonClickedTelemetry = (data: Record<string, any>) => {
45+
const sendEventButtonClickedTelemetry = (data?: Record<string, any>) => {
4646
sendEventTelemetry({
4747
event: TelemetryEvent.WORKBENCH_ENABLEMENT_AREA_COMMAND_CLICKED,
4848
eventData: {
@@ -54,15 +54,12 @@ const EnablementAreaWrapper = (props: Props) => {
5454

5555
const openScript = (
5656
script: string,
57-
execute = ExecuteButtonMode.Manual,
58-
// for future implementation
59-
_params?: CodeButtonParams,
60-
path?: string,
61-
name?: string
57+
execute: { mode?: ExecuteButtonMode, params?: CodeButtonParams } = { mode: ExecuteButtonMode.Manual },
58+
file?: { path?: string, name?: string }
6259
) => {
63-
sendEventButtonClickedTelemetry({ path, name })
60+
sendEventButtonClickedTelemetry(file)
6461

65-
if (execute === ExecuteButtonMode.Auto) {
62+
if (execute.mode === ExecuteButtonMode.Auto) {
6663
onSubmit(script, null, false)
6764
return
6865
}

redisinsight/ui/src/pages/workbench/contexts/enablementAreaContext.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import { CodeButtonParams, ExecuteButtonMode } from 'uiSrc/pages/workbench/compo
44
interface IContext {
55
setScript: (
66
script: string,
7-
execute?: ExecuteButtonMode,
8-
params?: CodeButtonParams,
9-
path?: string,
10-
name?: string
7+
execute?: { mode?: ExecuteButtonMode, params?: CodeButtonParams },
8+
file?: { path?: string, name?: string }
119
) => void
1210
openPage: (page: IInternalPage) => void
1311
isCodeBtnDisabled?: boolean

0 commit comments

Comments
 (0)