-
Notifications
You must be signed in to change notification settings - Fork 390
RI-7365: Show no indexes message #4870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pawelangelow
wants to merge
6
commits into
main
Choose a base branch
from
fe/RI-7365/show-no-indexes-message
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a52ddcf
introduce hook
pawelangelow 134aff8
add no index message
pawelangelow 9cb6f14
add tests
pawelangelow 6a81071
change shape
pawelangelow 4f8644f
rework tests
pawelangelow d077040
drop de facto duplicate test
pawelangelow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
redisinsight/ui/src/pages/vector-search/hooks/useStartWizard.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { renderHook, act } from '@testing-library/react-hooks' | ||
import { Pages } from 'uiSrc/constants' | ||
import useStartWizard from './useStartWizard' | ||
|
||
describe('useStartWizard', () => { | ||
let mockPush: jest.Mock | ||
let useHistoryMock: jest.SpyInstance | ||
let useParamsMock: jest.SpyInstance | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
mockPush = jest.fn() | ||
|
||
useHistoryMock = jest.spyOn(require('react-router-dom'), 'useHistory') | ||
useHistoryMock.mockImplementation(() => ({ | ||
push: mockPush, | ||
})) | ||
|
||
useParamsMock = jest.spyOn(require('react-router-dom'), 'useParams') | ||
useParamsMock.mockImplementation(() => ({ | ||
instanceId: 'test-instance-id', | ||
})) | ||
}) | ||
|
||
afterEach(() => { | ||
useHistoryMock.mockRestore() | ||
useParamsMock.mockRestore() | ||
}) | ||
|
||
it('should navigate to vector search create index page when start is called', () => { | ||
const { result } = renderHook(() => useStartWizard()) | ||
|
||
act(() => { | ||
result.current() | ||
}) | ||
|
||
expect(mockPush).toHaveBeenCalledWith( | ||
Pages.vectorSearchCreateIndex('test-instance-id'), | ||
) | ||
expect(mockPush).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it('should use instanceId from useParams in navigation', () => { | ||
const customInstanceId = 'custom-instance-123' | ||
useParamsMock.mockImplementation(() => ({ instanceId: customInstanceId })) | ||
|
||
const { result } = renderHook(() => useStartWizard()) | ||
|
||
act(() => { | ||
result.current() | ||
}) | ||
|
||
expect(mockPush).toHaveBeenCalledWith( | ||
Pages.vectorSearchCreateIndex(customInstanceId), | ||
) | ||
}) | ||
|
||
it('should handle missing instanceId gracefully', () => { | ||
useParamsMock.mockImplementation(() => ({ instanceId: undefined })) | ||
|
||
const { result } = renderHook(() => useStartWizard()) | ||
|
||
act(() => { | ||
result.current() | ||
}) | ||
|
||
expect(mockPush).toHaveBeenCalledWith( | ||
Pages.vectorSearchCreateIndex(undefined as any), | ||
) | ||
}) | ||
}) |
14 changes: 14 additions & 0 deletions
14
redisinsight/ui/src/pages/vector-search/hooks/useStartWizard.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useCallback } from 'react' | ||
import { useHistory, useParams } from 'react-router-dom' | ||
import { Pages } from 'uiSrc/constants' | ||
|
||
const useStartWizard = () => { | ||
const history = useHistory() | ||
const { instanceId } = useParams<{ instanceId: string }>() | ||
|
||
return useCallback(() => { | ||
history.push(Pages.vectorSearchCreateIndex(instanceId)) | ||
}, [history, instanceId]) | ||
} | ||
|
||
export default useStartWizard |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
redisinsight/ui/src/pages/vector-search/manage-indexes/NoIndexesMessage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react' | ||
import { Button } from 'uiSrc/components/base/forms/buttons' | ||
import { Col } from 'uiSrc/components/base/layout/flex' | ||
import { Text } from 'uiSrc/components/base/text' | ||
import useStartWizard from '../hooks/useStartWizard' | ||
|
||
const NoIndexesMessage = () => { | ||
const start = useStartWizard() | ||
|
||
return ( | ||
<Col gap="m"> | ||
<Text size="L">No indexes to display yet.</Text> | ||
|
||
<Text> | ||
Complete vector search onboarding to create your first index with sample | ||
data, or create one manually. | ||
</Text> | ||
|
||
<Button onClick={start}>Get started</Button> | ||
</Col> | ||
) | ||
} | ||
|
||
export default NoIndexesMessage |
49 changes: 19 additions & 30 deletions
49
redisinsight/ui/src/pages/vector-search/query/StartWizardButton.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,38 @@ | ||
import React from 'react' | ||
import { cleanup, render, screen, userEvent } from 'uiSrc/utils/test-utils' | ||
import { Pages } from 'uiSrc/constants' | ||
|
||
import { StartWizardButton } from './StartWizardButton' | ||
import useStartWizard from '../hooks/useStartWizard' | ||
|
||
jest.mock('../hooks/useStartWizard', () => ({ | ||
__esModule: true, | ||
default: jest.fn(), | ||
})) | ||
|
||
const renderComponent = () => render(<StartWizardButton />) | ||
const mockedUseStartWizard = useStartWizard as jest.Mock | ||
|
||
describe('StartWizardButton', () => { | ||
beforeEach(() => { | ||
cleanup() | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('should navigate to vector search create index page when "Get started" is clicked', async () => { | ||
const mockPush = jest.fn() | ||
|
||
const useHistoryMock = jest.spyOn(require('react-router-dom'), 'useHistory') | ||
useHistoryMock.mockImplementation(() => ({ | ||
push: mockPush, | ||
})) | ||
it('renders the CTA and calls the start function on click', async () => { | ||
const startMock = jest.fn() | ||
mockedUseStartWizard.mockReturnValue(startMock) | ||
|
||
renderComponent() | ||
|
||
const getStartedButton = screen.getByText('Get started') | ||
await userEvent.click(getStartedButton) | ||
|
||
expect(mockPush).toHaveBeenCalledWith( | ||
Pages.vectorSearchCreateIndex('instanceId'), | ||
) | ||
expect(mockPush).toHaveBeenCalledTimes(1) | ||
|
||
useHistoryMock.mockRestore() | ||
}) | ||
|
||
it('should maintain callback reference stability with useCallback', () => { | ||
const { rerender } = renderComponent() | ||
|
||
const firstRenderButton = screen.getByText('Get started') | ||
|
||
rerender(<StartWizardButton />) | ||
expect( | ||
screen.getByText( | ||
'Power fast, real-time semantic AI search with vector search.', | ||
), | ||
).toBeInTheDocument() | ||
|
||
const secondRenderButton = screen.getByText('Get started') | ||
const btn = screen.getByRole('button', { name: /get started/i }) | ||
expect(btn).toBeInTheDocument() | ||
|
||
// Both buttons should exist (they're the same element after rerender) | ||
expect(firstRenderButton).toBeInTheDocument() | ||
expect(secondRenderButton).toBeInTheDocument() | ||
await userEvent.click(btn) | ||
expect(startMock).toHaveBeenCalledTimes(1) | ||
}) | ||
}) |
14 changes: 4 additions & 10 deletions
14
redisinsight/ui/src/pages/vector-search/query/StartWizardButton.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,17 @@ | ||
import React, { useCallback } from 'react' | ||
import { useHistory, useParams } from 'react-router-dom' | ||
import React from 'react' | ||
import { CallOut } from 'uiSrc/components/base/display/call-out/CallOut' | ||
import { Pages } from 'uiSrc/constants' | ||
import useStartWizard from '../hooks/useStartWizard' | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can probably simplify this component's tests by mocking '../hooks/useStartWizard' as opposed to it's internals ('react-router-dom') since you've already tested them; not mandatory ofc |
||
export const StartWizardButton = () => { | ||
const history = useHistory() | ||
const { instanceId } = useParams<{ instanceId: string }>() | ||
|
||
const startCreateIndexWizard = useCallback(() => { | ||
history.push(Pages.vectorSearchCreateIndex(instanceId)) | ||
}, [history, instanceId]) | ||
const start = useStartWizard() | ||
|
||
return ( | ||
<CallOut | ||
variant="success" | ||
actions={{ | ||
primary: { | ||
label: 'Get started', | ||
onClick: startCreateIndexWizard, | ||
onClick: start, | ||
}, | ||
}} | ||
> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe worth adding a test for the empty list