Skip to content

Commit a0c099a

Browse files
authored
RI-7197 Introduce vector search actions panel (#4741)
- added a simple component to present the different actions on the vector search page - added button for "manage indexes" to open the corresponding drawer - added a placeholder button for "saved queries" drawer re #RI-7197
1 parent edbd45b commit a0c099a

File tree

6 files changed

+174
-6
lines changed

6 files changed

+174
-6
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React from 'react'
2+
import { cleanup, render, screen } from 'uiSrc/utils/test-utils'
3+
import {
4+
ManageIndexesDrawer,
5+
ManageIndexesDrawerProps,
6+
} from './ManageIndexesDrawer'
7+
8+
// Workaround for @redis-ui/components Title component issue with react-children-utilities
9+
// TypeError: react_utils.childrenToString is not a function
10+
jest.mock('uiSrc/components/base/layout/drawer', () => ({
11+
...jest.requireActual('uiSrc/components/base/layout/drawer'),
12+
DrawerHeader: jest.fn().mockReturnValue(null),
13+
}))
14+
15+
const renderComponent = (props?: Partial<ManageIndexesDrawerProps>) => {
16+
const defaultProps: ManageIndexesDrawerProps = {
17+
open: true,
18+
onOpenChange: jest.fn(),
19+
}
20+
21+
return render(<ManageIndexesDrawer {...defaultProps} {...props} />)
22+
}
23+
24+
describe('ManageIndexesDrawer', () => {
25+
beforeEach(() => {
26+
cleanup()
27+
})
28+
29+
it('should render', () => {
30+
const { container } = renderComponent()
31+
32+
expect(container).toBeTruthy()
33+
34+
const drawer = screen.getByTestId('manage-indexes-drawer')
35+
expect(drawer).toBeInTheDocument()
36+
37+
// Note: Since we mocked DrawerHeader, we can't check its presence
38+
// const header = screen.getByText('Manage indexes')
39+
// expect(header).toBeInTheDocument()
40+
41+
// TODO: Check the body content, once implemented
42+
const body = screen.getByTestId('manage-indexes-drawer-body')
43+
expect(body).toBeInTheDocument()
44+
})
45+
})
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react'
2+
import { DrawerProps } from '@redis-ui/components'
3+
import {
4+
Drawer,
5+
DrawerBody,
6+
DrawerHeader,
7+
} from 'uiSrc/components/base/layout/drawer'
8+
9+
export interface ManageIndexesDrawerProps extends DrawerProps {}
10+
11+
export const ManageIndexesDrawer = ({
12+
open,
13+
onOpenChange,
14+
...rest
15+
}: ManageIndexesDrawerProps) => (
16+
<Drawer
17+
open={open}
18+
onOpenChange={onOpenChange}
19+
data-testid="manage-indexes-drawer"
20+
{...rest}
21+
>
22+
<DrawerHeader title="Manage indexes" />
23+
<DrawerBody data-testid="manage-indexes-drawer-body">
24+
<p>Manage indexes info will be added later</p>
25+
</DrawerBody>
26+
</Drawer>
27+
)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from 'react'
2+
import { cleanup, render, screen, userEvent } from 'uiSrc/utils/test-utils'
3+
4+
import { HeaderActions } from './HeaderActions'
5+
6+
// Workaround for @redis-ui/components Title component issue with react-children-utilities
7+
// TypeError: react_utils.childrenToString is not a function
8+
jest.mock('uiSrc/components/base/layout/drawer', () => ({
9+
...jest.requireActual('uiSrc/components/base/layout/drawer'),
10+
DrawerHeader: jest.fn().mockReturnValue(null),
11+
}))
12+
13+
const renderComponent = () => render(<HeaderActions />)
14+
15+
describe('ManageIndexesDrawer', () => {
16+
beforeEach(() => {
17+
cleanup()
18+
})
19+
20+
it('should render', () => {
21+
const { container } = renderComponent()
22+
23+
expect(container).toBeTruthy()
24+
25+
const headerActions = screen.getByTestId('vector-search-header-actions')
26+
expect(headerActions).toBeInTheDocument()
27+
28+
// Verify the presence of the actions
29+
const savedQueriesButton = screen.getByText('Saved queries')
30+
expect(savedQueriesButton).toBeInTheDocument()
31+
32+
const manageIndexesButton = screen.getByText('Manage indexes')
33+
expect(manageIndexesButton).toBeInTheDocument()
34+
})
35+
36+
it('should open a drawer when "Manage indexes" is clicked', async () => {
37+
renderComponent()
38+
39+
const manageIndexesButton = screen.getByText('Manage indexes')
40+
expect(manageIndexesButton).toBeInTheDocument()
41+
42+
// Simulate clicking the "Manage indexes" button
43+
await userEvent.click(manageIndexesButton)
44+
45+
// Check if the drawer is opened
46+
const drawer = screen.getByTestId('manage-indexes-drawer')
47+
expect(drawer).toBeInTheDocument()
48+
49+
// Simulate clicking outside the drawer to close it
50+
await userEvent.click(document.body, { pointerEventsCheck: 0 })
51+
expect(drawer).not.toBeInTheDocument()
52+
})
53+
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TextButton } from '@redis-ui/components'
2+
import styled from 'styled-components'
3+
import { FlexGroup } from 'uiSrc/components/base/layout/flex'
4+
5+
export const StyledHeaderAction = styled(FlexGroup)`
6+
display: flex;
7+
flex-direction: row;
8+
justify-content: flex-end;
9+
`
10+
11+
export const StyledTextButton = styled(TextButton)`
12+
color: ${({ theme }) => theme.color.blue400};
13+
&:hover {
14+
color: ${({ theme }) => theme.color.blue500};
15+
}
16+
`
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React, { useState } from 'react'
2+
import { StyledHeaderAction, StyledTextButton } from './HeaderActions.styles'
3+
import { ManageIndexesDrawer } from '../manage-indexes/ManageIndexesDrawer'
4+
5+
export const HeaderActions = () => {
6+
const [isManageIndexesDrawerOpen, setIsManageIndexesDrawerOpen] =
7+
useState<boolean>(false)
8+
9+
return (
10+
<>
11+
<StyledHeaderAction data-testid="vector-search-header-actions">
12+
<StyledTextButton>Saved queries</StyledTextButton>
13+
<StyledTextButton onClick={() => setIsManageIndexesDrawerOpen(true)}>
14+
Manage indexes
15+
</StyledTextButton>
16+
</StyledHeaderAction>
17+
18+
<ManageIndexesDrawer
19+
open={isManageIndexesDrawerOpen}
20+
onOpenChange={setIsManageIndexesDrawerOpen}
21+
/>
22+
</>
23+
)
24+
}
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import React from 'react'
2+
import { HeaderActions } from './HeaderActions'
3+
import { CreateIndexWrapper } from '../create-index/styles'
24

3-
export const VectorSearchQuery = () => {
4-
// TODO: implement this component
5-
// https://www.figma.com/design/oO2eYRuuLmfzUYLkvCkFhM/Search-page?node-id=645-37412&t=TSwcttCYa4Ld9WzC-4
6-
;
7-
return <h4>TODO</h4>
8-
}
5+
// TODO: implement this component
6+
// https://www.figma.com/design/oO2eYRuuLmfzUYLkvCkFhM/Search-page?node-id=645-37412&t=TSwcttCYa4Ld9WzC-4
7+
export const VectorSearchQuery = () => (
8+
<CreateIndexWrapper direction="column" justify="between">
9+
<HeaderActions />
10+
</CreateIndexWrapper>
11+
)

0 commit comments

Comments
 (0)