Skip to content

Commit 336a609

Browse files
committed
feat(ui): added title for the new vector search page
1 parent a4c07fa commit 336a609

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import React from 'react'
22
import * as reactRedux from 'react-redux'
3-
import { cleanup, render, screen } from 'uiSrc/utils/test-utils'
3+
import {
4+
cleanup,
5+
initialStateDefault,
6+
mockStore,
7+
render,
8+
screen,
9+
} from 'uiSrc/utils/test-utils'
410
import { TelemetryPageView } from 'uiSrc/telemetry/pageViews'
511
import { sendPageViewTelemetry } from 'uiSrc/telemetry'
612
import {
@@ -11,6 +17,7 @@ import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
1117
import { redisearchListSelector } from 'uiSrc/slices/browser/redisearch'
1218
import VectorSearchPage from './VectorSearchPage'
1319
import useRedisInstanceCompatibility from '../create-index/hooks/useRedisInstanceCompatibility'
20+
import { RootState } from 'uiSrc/slices/store'
1421

1522
// Mock the telemetry module, so we don't send actual telemetry data during tests
1623
jest.mock('uiSrc/telemetry', () => ({
@@ -22,7 +29,24 @@ jest.mock('../create-index/hooks/useRedisInstanceCompatibility', () =>
2229
jest.fn(),
2330
)
2431

25-
const renderVectorSearchPageComponent = () => render(<VectorSearchPage />)
32+
const renderVectorSearchPageComponent = () => {
33+
const testState: RootState = {
34+
...initialStateDefault,
35+
connections: {
36+
...initialStateDefault.connections,
37+
instances: {
38+
...initialStateDefault.connections.instances,
39+
connectedInstance: {
40+
...initialStateDefault.connections.instances.connectedInstance,
41+
...INSTANCES_MOCK[0],
42+
},
43+
},
44+
},
45+
}
46+
const store = mockStore(testState)
47+
48+
return render(<VectorSearchPage />, { store })
49+
}
2650

2751
describe('VectorSearchPage', () => {
2852
const mockUseRedisInstanceCompatibility =
@@ -49,6 +73,11 @@ describe('VectorSearchPage', () => {
4973

5074
const vectorSearchQuery = screen.getByTestId('vector-search-query')
5175
expect(vectorSearchQuery).toBeInTheDocument()
76+
77+
// Verify the title of the page
78+
expect(document.title).toBe(
79+
`${INSTANCES_MOCK[0].name} [db${INSTANCES_MOCK[0].db}] - Vector Search`,
80+
)
5281
})
5382

5483
it('should render loader while checking the database compatibility', () => {

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import { useLocation, useParams } from 'react-router-dom'
3+
import { useSelector } from 'react-redux'
34

45
import { TelemetryPageView } from 'uiSrc/telemetry'
56
import { usePageViewTelemetry } from 'uiSrc/telemetry/usePageViewTelemetry'
@@ -10,6 +11,8 @@ import { Loader } from 'uiSrc/components/base/display'
1011
import useRedisInstanceCompatibility from '../create-index/hooks/useRedisInstanceCompatibility'
1112
import { Spacer } from 'uiSrc/components/base/layout'
1213
import { RqeNotAvailableCard } from '../components/rqe-not-available/RqeNotAvailableCard'
14+
import { formatLongName, getDbIndex, setTitle } from 'uiSrc/utils'
15+
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
1316

1417
type Params = {
1518
instanceId: string
@@ -20,17 +23,20 @@ const VectorSearchPage = () => {
2023
const { search } = useLocation()
2124
const { hasRedisearch, loading } = useRedisInstanceCompatibility()
2225

26+
const { name: connectedInstanceName, db } = useSelector(
27+
connectedInstanceSelector,
28+
)
29+
2330
const defaultSavedQueriesIndex =
2431
new URLSearchParams(search).get('defaultSavedQueriesIndex') || undefined
2532

2633
usePageViewTelemetry({
2734
page: TelemetryPageView.VECTOR_SEARCH_PAGE,
2835
})
2936

30-
// TODO: Set title, once we know the name of the page
31-
// setTitle(
32-
// `${formatLongName(connectedInstanceName, 33, 0, '...')} ${getDbIndex(db)} - Vector Search`,
33-
// )
37+
setTitle(
38+
`${formatLongName(connectedInstanceName, 33, 0, '...')} ${getDbIndex(db)} - Vector Search`,
39+
)
3440

3541
if (loading) {
3642
return (

0 commit comments

Comments
 (0)