-
Notifications
You must be signed in to change notification settings - Fork 381
RI-7189: Add SelectionBox component #4702
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
11
commits into
feature/RI-6855/vector-search
Choose a base branch
from
fe/RI-7189/selection-box-component
base: feature/RI-6855/vector-search
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
11 commits
Select commit
Hold shift + click to select a range
a6d5f4c
add component
pawelangelow 860b9f3
export styled components to separate file
pawelangelow d920bb9
rework types
pawelangelow 8b3c203
remove leftover
pawelangelow 4ef800b
get values from the theme
pawelangelow 5c84082
allow text wrap
pawelangelow f6b26b4
remove me
pawelangelow 41f2919
removed
pawelangelow a3d7ae7
asd
pawelangelow a71fd2f
cleanup
pawelangelow 245f7eb
Update redisinsight/ui/src/components/new-index/selection-box/index.tsx
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
65 changes: 65 additions & 0 deletions
65
redisinsight/ui/src/components/new-index/selection-box/SelectionBox.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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from 'react' | ||
import { BoxSelectionGroup } from '@redis-ui/components' | ||
|
||
import { cleanup, render, screen, fireEvent } from 'uiSrc/utils/test-utils' | ||
|
||
import SelectionBox from './SelectionBox' | ||
|
||
const mockBox = { | ||
value: 'rqe', | ||
label: 'Test Label', | ||
text: 'Test Description', | ||
} | ||
|
||
const renderWithBoxSelectionGroup = (ui: React.ReactElement) => | ||
render(<BoxSelectionGroup.Compose>{ui}</BoxSelectionGroup.Compose>) | ||
|
||
describe('SelectionBox', () => { | ||
beforeEach(() => { | ||
cleanup() | ||
}) | ||
|
||
it('should render label and text', () => { | ||
renderWithBoxSelectionGroup(<SelectionBox box={mockBox} />) | ||
|
||
expect(screen.getByText('Test Label')).toBeInTheDocument() | ||
expect(screen.getByText('Test Description')).toBeInTheDocument() | ||
}) | ||
|
||
it('should render label without text when text is not provided', () => { | ||
renderWithBoxSelectionGroup( | ||
<SelectionBox box={{ ...mockBox, text: undefined }} />, | ||
) | ||
|
||
expect(screen.getByText(mockBox.label)).toBeInTheDocument() | ||
expect(screen.queryByText(mockBox.text)).not.toBeInTheDocument() | ||
}) | ||
|
||
it('should show disabled bar when disabled is true', () => { | ||
renderWithBoxSelectionGroup( | ||
<SelectionBox box={{ ...mockBox, disabled: true }} />, | ||
) | ||
|
||
expect(screen.getByText(/coming soon/i)).toBeInTheDocument() | ||
}) | ||
|
||
it('should not show disabled bar when disabled is false', () => { | ||
renderWithBoxSelectionGroup( | ||
<SelectionBox box={{ ...mockBox, disabled: false }} />, | ||
) | ||
|
||
expect(screen.queryByText(/coming soon/i)).not.toBeInTheDocument() | ||
}) | ||
|
||
it('should call onClick handler when clicked', () => { | ||
const onClick = jest.fn() | ||
|
||
renderWithBoxSelectionGroup( | ||
<SelectionBox box={mockBox} onClick={onClick} />, | ||
) | ||
|
||
fireEvent.click(screen.getByText(mockBox.label)) | ||
|
||
expect(onClick).toHaveBeenCalled() | ||
}) | ||
}) |
36 changes: 36 additions & 0 deletions
36
redisinsight/ui/src/components/new-index/selection-box/SelectionBox.styles.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,36 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
import { Text, Title } from 'uiSrc/components/base/text' | ||
|
||
export const StyledBoxContent = styled.div` | ||
padding: ${({ theme }) => theme.core.space.space200}; | ||
text-align: left; | ||
` | ||
|
||
export const StyledTitle = styled(Title)` | ||
margin-top: ${({ theme }) => theme.core.space.space050}; | ||
` | ||
|
||
export const StyledText = styled(Text)` | ||
margin-top: ${({ theme }) => theme.core.space.space050}; | ||
white-space: normal; | ||
overflow-wrap: break-word; | ||
` | ||
|
||
export const StyledDisabledBar = styled.div` | ||
padding: ${({ theme }) => theme.core.space.space025} 0; | ||
background: ${({ theme }) => theme.color.dusk100}; | ||
color: ${({ theme }) => theme.color.dusk400}; | ||
/* Theme adjustments TODO: add radii scale */ | ||
border-radius: ${({ theme }) => theme.core.space.space025}; | ||
/* Theme adjustments TODO: border width scale */ | ||
border-bottom: 1px solid ${({ theme }) => theme.color.gray500}; | ||
border-bottom-left-radius: 0; | ||
border-bottom-right-radius: 0; | ||
` | ||
|
||
export const DisabledBar = () => ( | ||
<StyledDisabledBar> | ||
<Text size="xs">Coming soon</Text> | ||
</StyledDisabledBar> | ||
) |
39 changes: 39 additions & 0 deletions
39
redisinsight/ui/src/components/new-index/selection-box/SelectionBox.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,39 @@ | ||
import React, { HTMLAttributes } from 'react' | ||
import { BoxSelectionGroup, BoxSelectionGroupBox } from '@redis-ui/components' | ||
import { | ||
DisabledBar, | ||
StyledBoxContent, | ||
StyledText, | ||
StyledTitle, | ||
} from './SelectionBox.styles' | ||
|
||
export interface BoxSelectionOption<T extends string = string> | ||
extends BoxSelectionGroupBox<T> { | ||
text?: string | ||
} | ||
|
||
type SelectionBoxProps<T extends string = string> = { | ||
box: BoxSelectionOption<T> | ||
} & HTMLAttributes<HTMLButtonElement> | ||
|
||
const SelectionBox = <T extends string = string>({ | ||
box, | ||
...rest | ||
}: SelectionBoxProps<T>) => { | ||
const { label, text, disabled } = box | ||
|
||
return ( | ||
<BoxSelectionGroup.Item.Compose box={box} {...rest}> | ||
{disabled && <DisabledBar />} | ||
|
||
<StyledBoxContent> | ||
<BoxSelectionGroup.Item.Icon color="neutral700" customSize="32px" /> | ||
|
||
<StyledTitle size="S">{label}</StyledTitle> | ||
{text && <StyledText size="M">{text}</StyledText>} | ||
</StyledBoxContent> | ||
</BoxSelectionGroup.Item.Compose> | ||
) | ||
} | ||
|
||
export default SelectionBox |
1 change: 1 addition & 0 deletions
1
redisinsight/ui/src/components/new-index/selection-box/index.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 @@ | ||
export { default as SelectionBox } './SelectionBox' |
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.
isn't that already exported above?
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.
Not sure if I understand the question properly, but this is an extension to
BoxSelectionGroupBox
as we want to supporttext
as well. So I'm exporting the type for the consumers of this component.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.
I might be missing something, but these look identical - BoxSelectionOption interface

