Skip to content

Commit bb18d5d

Browse files
pawelangelowKrumTy
andauthored
RI-7195: Add search screen (#4788)
* add hideFields for QueryCard * add tests --------- Co-authored-by: Krum Tyukenov <[email protected]>
1 parent 71bcb66 commit bb18d5d

File tree

13 files changed

+1163
-57
lines changed

13 files changed

+1163
-57
lines changed

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from 'uiSrc/utils/test-utils'
1313
import { TelemetryEvent, sendEventTelemetry } from 'uiSrc/telemetry'
1414
import { INSTANCE_ID_MOCK } from 'uiSrc/mocks/handlers/instances/instancesHandlers'
15-
import QueryCardHeader, { Props } from './QueryCardHeader'
15+
import QueryCardHeader, { HIDE_FIELDS, Props } from './QueryCardHeader'
1616

1717
const mockedProps = mock<Props>()
1818

@@ -34,7 +34,16 @@ jest.mock('uiSrc/services', () => ({
3434
jest.mock('uiSrc/slices/app/plugins', () => ({
3535
...jest.requireActual('uiSrc/slices/app/plugins'),
3636
appPluginsSelector: jest.fn().mockReturnValue({
37-
visualizations: [],
37+
visualizations: [
38+
{
39+
id: '1',
40+
uniqId: '1',
41+
name: 'test',
42+
plugin: '',
43+
activationMethod: 'render',
44+
matchCommands: ['FT.SEARCH'],
45+
}
46+
],
3847
}),
3948
}))
4049

@@ -80,6 +89,32 @@ describe('QueryCardHeader', () => {
8089
expect(screen.getByTestId('copy-command')).toBeDisabled()
8190
})
8291

92+
it('should hide Profiler button', async () => {
93+
render(
94+
<QueryCardHeader
95+
{...instance(mockedProps)}
96+
query="FT.GET something"
97+
isOpen
98+
hideFields={[HIDE_FIELDS.profiler]}
99+
/>,
100+
)
101+
102+
expect(screen.queryByTestId('run-profile-type')).not.toBeInTheDocument()
103+
})
104+
105+
it('should hide Change View Type button', async () => {
106+
render(
107+
<QueryCardHeader
108+
{...instance(mockedProps)}
109+
query="FT.SEARCH index somethingCool"
110+
isOpen
111+
hideFields={[HIDE_FIELDS.viewType]}
112+
/>,
113+
)
114+
115+
expect(screen.queryByTestId('select-view-type')).not.toBeInTheDocument()
116+
})
117+
83118
it('event telemetry WORKBENCH_COMMAND_COPIED should be call after click on copy btn', async () => {
84119
const command = 'info'
85120
const sendEventTelemetryMock = jest.fn()

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

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export interface Props {
7272
executionTime?: number
7373
emptyCommand?: boolean
7474
db?: number
75+
hideFields?: string[]
7576
toggleOpen: () => void
7677
toggleFullScreen: () => void
7778
setSelectedValue: (type: WBQueryType, value: string) => void
@@ -80,6 +81,11 @@ export interface Props {
8081
onQueryProfile: (type: ProfileQueryType) => void
8182
}
8283

84+
export const HIDE_FIELDS = {
85+
viewType: 'viewType',
86+
profiler: 'profiler',
87+
}
88+
8389
const getExecutionTimeString = (value: number): string => {
8490
if (value < 1) {
8591
return '0.001 msec'
@@ -137,6 +143,7 @@ const QueryCardHeader = (props: Props) => {
137143
onQueryReRun,
138144
onQueryProfile,
139145
db,
146+
hideFields = [],
140147
} = props
141148

142149
const { visualizations = [] } = useSelector(appPluginsSelector)
@@ -410,54 +417,58 @@ const QueryCardHeader = (props: Props) => {
410417
</RiTooltip>
411418
)}
412419
</FlexItem>
413-
<FlexItem
414-
className={cx(styles.buttonIcon, styles.viewTypeIcon)}
415-
onClick={onDropDownViewClick}
416-
>
417-
{isOpen && canCommandProfile && !summaryText && (
418-
<div className={styles.dropdownWrapper}>
419-
<div className={styles.dropdown}>
420-
<ProfileSelect
421-
placeholder={profileOptions[0].inputDisplay}
422-
onChange={(value: ProfileQueryType | string) =>
423-
onQueryProfile(value as ProfileQueryType)
424-
}
425-
options={profileOptions}
426-
data-testid="run-profile-type"
427-
valueRender={({ option, isOptionValue }) => {
428-
if (isOptionValue) {
429-
return option.dropdownDisplay as JSX.Element
420+
{!hideFields?.includes(HIDE_FIELDS.profiler) && (
421+
<FlexItem
422+
className={cx(styles.buttonIcon, styles.viewTypeIcon)}
423+
onClick={onDropDownViewClick}
424+
>
425+
{isOpen && canCommandProfile && !summaryText && (
426+
<div className={styles.dropdownWrapper}>
427+
<div className={styles.dropdown}>
428+
<ProfileSelect
429+
placeholder={profileOptions[0].inputDisplay}
430+
onChange={(value: ProfileQueryType | string) =>
431+
onQueryProfile(value as ProfileQueryType)
430432
}
431-
return option.inputDisplay as JSX.Element
432-
}}
433-
/>
433+
options={profileOptions}
434+
data-testid="run-profile-type"
435+
valueRender={({ option, isOptionValue }) => {
436+
if (isOptionValue) {
437+
return option.dropdownDisplay as JSX.Element
438+
}
439+
return option.inputDisplay as JSX.Element
440+
}}
441+
/>
442+
</div>
434443
</div>
435-
</div>
436-
)}
437-
</FlexItem>
438-
<FlexItem
439-
className={cx(styles.buttonIcon, styles.viewTypeIcon)}
440-
onClick={onDropDownViewClick}
441-
>
442-
{isOpen && options.length > 1 && !summaryText && (
443-
<div className={styles.dropdownWrapper}>
444-
<div className={styles.dropdown}>
445-
<ProfileSelect
446-
options={modifiedOptions}
447-
valueRender={({ option, isOptionValue }) => {
448-
if (isOptionValue) {
449-
return option.dropdownDisplay as JSX.Element
450-
}
451-
return option.inputDisplay as JSX.Element
452-
}}
453-
value={selectedValue}
454-
onChange={(value: string) => onChangeView(value)}
455-
data-testid="select-view-type"
456-
/>
444+
)}
445+
</FlexItem>
446+
)}
447+
{!hideFields?.includes(HIDE_FIELDS.viewType) && (
448+
<FlexItem
449+
className={cx(styles.buttonIcon, styles.viewTypeIcon)}
450+
onClick={onDropDownViewClick}
451+
>
452+
{isOpen && options.length > 1 && !summaryText && (
453+
<div className={styles.dropdownWrapper}>
454+
<div className={styles.dropdown}>
455+
<ProfileSelect
456+
options={modifiedOptions}
457+
valueRender={({ option, isOptionValue }) => {
458+
if (isOptionValue) {
459+
return option.dropdownDisplay as JSX.Element
460+
}
461+
return option.inputDisplay as JSX.Element
462+
}}
463+
value={selectedValue}
464+
onChange={(value: string) => onChangeView(value)}
465+
data-testid="select-view-type"
466+
/>
467+
</div>
457468
</div>
458-
</div>
459-
)}
460-
</FlexItem>
469+
)}
470+
</FlexItem>
471+
)}
461472
<FlexItem
462473
className={styles.buttonIcon}
463474
onClick={onDropDownViewClick}

redisinsight/ui/src/pages/vector-search/VectorSearchPage.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import { VectorSearchCreateIndex } from './create-index/VectorSearchCreateIndex'
44
import { VectorSearchQuery } from './query/VectorSearchQuery'
55

66
export const VectorSearchPage = () => {
7-
const hasIndexes = false
7+
const hasIndexes = true
88

99
if (!hasIndexes) {
1010
return <VectorSearchCreateIndex />
1111
}
1212

13-
// TODO: QueryScreen
14-
1513
return <VectorSearchQuery />
1614
}

0 commit comments

Comments
 (0)