Skip to content

Commit 68b6536

Browse files
authored
RI-7517 Hide custom indexes from "Saved Queries" list (#4993)
- show only indexes for the preset sample data in the "Saved Queries" panel on the new Vector Search page
1 parent 2388ff1 commit 68b6536

File tree

2 files changed

+47
-15
lines changed

2 files changed

+47
-15
lines changed

redisinsight/ui/src/pages/vector-search/saved-queries/SavedQueriesScreen.spec.tsx

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { render, screen, fireEvent } from 'uiSrc/utils/test-utils'
77
import { SavedQueriesScreen } from './SavedQueriesScreen'
88
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
99
import { useRedisearchListData } from '../useRedisearchListData'
10+
import { PresetDataType } from '../create-index/types'
1011

1112
// Mock the telemetry sender once for this spec file
1213
jest.mock('uiSrc/telemetry', () => ({
@@ -39,7 +40,7 @@ describe('SavedQueriesScreen', () => {
3940
;(useRedisearchListData as jest.Mock).mockReturnValue({
4041
loading: false,
4142
data: [],
42-
stringData: ['idx:bikes_vss', 'idx:restaurants_vss'],
43+
stringData: [PresetDataType.BIKES, PresetDataType.MOVIES],
4344
})
4445
})
4546

@@ -83,14 +84,43 @@ describe('SavedQueriesScreen', () => {
8384

8485
it('should select the first index by default', () => {
8586
renderComponent()
86-
expect(screen.queryByText('idx:bikes_vss')).toBeInTheDocument()
87+
expect(screen.queryByText(PresetDataType.BIKES)).toBeInTheDocument()
8788
})
8889

8990
it('should select the default index if provided', () => {
90-
renderComponent('idx:restaurants_vss')
91+
renderComponent(PresetDataType.MOVIES)
92+
9193
// The Select component isn't a native <select>, so assert by displayed text
92-
expect(screen.queryByText('idx:bikes_vss')).not.toBeInTheDocument()
93-
expect(screen.queryByText('idx:restaurants_vss')).toBeInTheDocument()
94+
expect(screen.queryByText(PresetDataType.BIKES)).not.toBeInTheDocument()
95+
expect(screen.queryByText(PresetDataType.MOVIES)).toBeInTheDocument()
96+
})
97+
98+
it('should not render queries if the there is no index with preset data', () => {
99+
;(useRedisearchListData as jest.Mock).mockReturnValue({
100+
loading: false,
101+
data: [],
102+
stringData: ['idx:unknown_index'],
103+
})
104+
105+
renderComponent()
106+
107+
expect(screen.queryByText('idx:unknown_index')).not.toBeInTheDocument()
108+
expect(screen.queryByText(PresetDataType.BIKES)).not.toBeInTheDocument()
109+
expect(screen.queryByText(PresetDataType.MOVIES)).not.toBeInTheDocument()
110+
})
111+
112+
it('should render only saved queries related to preset data', () => {
113+
;(useRedisearchListData as jest.Mock).mockReturnValue({
114+
loading: false,
115+
data: [],
116+
stringData: ['idx:unknown_index', PresetDataType.BIKES],
117+
})
118+
119+
renderComponent()
120+
121+
expect(screen.queryByText('idx:unknown_index')).not.toBeInTheDocument()
122+
expect(screen.queryByText(PresetDataType.MOVIES)).not.toBeInTheDocument()
123+
expect(screen.queryByText(PresetDataType.BIKES)).toBeInTheDocument()
94124
})
95125

96126
it('should call onClose when close button is clicked', () => {

redisinsight/ui/src/pages/vector-search/saved-queries/SavedQueriesScreen.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,18 @@ export const SavedQueriesScreen = ({
5959
const { stringData, loading } = useRedisearchListData()
6060
const savedIndexes = useMemo(
6161
() =>
62-
stringData.map(
63-
(index) =>
64-
({
65-
value: index,
66-
// Hardcoded values for the preset index, else empty arrays:
67-
tags: mockSavedIndexes.find((i) => i.value === index)?.tags || [],
68-
queries:
69-
mockSavedIndexes.find((i) => i.value === index)?.queries || [],
70-
}) as SavedIndex,
71-
),
62+
stringData
63+
.filter((index) => mockSavedIndexes.some((i) => i.value === index))
64+
.map(
65+
(index) =>
66+
({
67+
value: index,
68+
// Hardcoded values for the preset index, else empty arrays:
69+
tags: mockSavedIndexes.find((i) => i.value === index)?.tags || [],
70+
queries:
71+
mockSavedIndexes.find((i) => i.value === index)?.queries || [],
72+
}) as SavedIndex,
73+
),
7274
[stringData],
7375
)
7476
const selectedIndexItem = savedIndexes.find(

0 commit comments

Comments
 (0)