Skip to content

Commit 1c4ac32

Browse files
authored
RI-7317: Add Wizard flow start button (#4845)
1 parent 68f3258 commit 1c4ac32

File tree

4 files changed

+86
-3
lines changed

4 files changed

+86
-3
lines changed

redisinsight/ui/src/pages/vector-search/query/HeaderActions.styles.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ export const StyledHeaderAction = styled(FlexGroup)`
66
flex-direction: row;
77
justify-content: flex-end;
88
gap: ${({ theme }) => theme.core.space.space100};
9+
`
10+
11+
export const StyledWrapper = styled(FlexGroup)`
912
margin-bottom: ${({ theme }) => theme.core.space.space100};
1013
`

redisinsight/ui/src/pages/vector-search/query/HeaderActions.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import React from 'react'
22
import { useParams } from 'react-router-dom'
3-
import { StyledHeaderAction } from './HeaderActions.styles'
3+
4+
import { StyledHeaderAction, StyledWrapper } from './HeaderActions.styles'
45
import { ManageIndexesDrawer } from '../manage-indexes/ManageIndexesDrawer'
56
import { collectSavedQueriesPanelToggleTelemetry } from '../telemetry'
7+
import { StartWizardButton } from './StartWizardButton'
68
import { EmptyButton } from 'uiSrc/components/base/forms/buttons'
79

810
export type HeaderActionsProps = {
@@ -30,7 +32,9 @@ export const HeaderActions = ({
3032
}
3133

3234
return (
33-
<>
35+
<StyledWrapper>
36+
<StartWizardButton />
37+
3438
<StyledHeaderAction data-testid="vector-search-header-actions">
3539
<EmptyButton onClick={handleSavedQueriesClick}>
3640
Saved queries
@@ -44,6 +48,6 @@ export const HeaderActions = ({
4448
open={isManageIndexesDrawerOpen}
4549
onOpenChange={setIsManageIndexesDrawerOpen}
4650
/>
47-
</>
51+
</StyledWrapper>
4852
)
4953
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from 'react'
2+
import { cleanup, render, screen, userEvent } from 'uiSrc/utils/test-utils'
3+
import { Pages } from 'uiSrc/constants'
4+
5+
import { StartWizardButton } from './StartWizardButton'
6+
7+
const renderComponent = () => render(<StartWizardButton />)
8+
9+
describe('StartWizardButton', () => {
10+
beforeEach(() => {
11+
cleanup()
12+
jest.clearAllMocks()
13+
})
14+
15+
it('should navigate to vector search create index page when "Get started" is clicked', async () => {
16+
const mockPush = jest.fn()
17+
18+
const useHistoryMock = jest.spyOn(require('react-router-dom'), 'useHistory')
19+
useHistoryMock.mockImplementation(() => ({
20+
push: mockPush,
21+
}))
22+
23+
renderComponent()
24+
25+
const getStartedButton = screen.getByText('Get started')
26+
await userEvent.click(getStartedButton)
27+
28+
expect(mockPush).toHaveBeenCalledWith(
29+
Pages.vectorSearchCreateIndex('instanceId'),
30+
)
31+
expect(mockPush).toHaveBeenCalledTimes(1)
32+
33+
useHistoryMock.mockRestore()
34+
})
35+
36+
it('should maintain callback reference stability with useCallback', () => {
37+
const { rerender } = renderComponent()
38+
39+
const firstRenderButton = screen.getByText('Get started')
40+
41+
rerender(<StartWizardButton />)
42+
43+
const secondRenderButton = screen.getByText('Get started')
44+
45+
// Both buttons should exist (they're the same element after rerender)
46+
expect(firstRenderButton).toBeInTheDocument()
47+
expect(secondRenderButton).toBeInTheDocument()
48+
})
49+
})
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { useCallback } from 'react'
2+
import { useHistory, useParams } from 'react-router-dom'
3+
import { CallOut } from 'uiSrc/components/base/display/call-out/CallOut'
4+
import { Pages } from 'uiSrc/constants'
5+
6+
export const StartWizardButton = () => {
7+
const history = useHistory()
8+
const { instanceId } = useParams<{ instanceId: string }>()
9+
10+
const startCreateIndexWizard = useCallback(() => {
11+
history.push(Pages.vectorSearchCreateIndex(instanceId))
12+
}, [history, instanceId])
13+
14+
return (
15+
<CallOut
16+
variant="success"
17+
actions={{
18+
primary: {
19+
label: 'Get started',
20+
onClick: startCreateIndexWizard,
21+
},
22+
}}
23+
>
24+
Power fast, real-time semantic AI search with vector search.
25+
</CallOut>
26+
)
27+
}

0 commit comments

Comments
 (0)