Skip to content

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
wants to merge 11 commits into
base: feature/RI-6855/vector-search
Choose a base branch
from

Conversation

pawelangelow
Copy link
Collaborator

@pawelangelow pawelangelow commented Jul 9, 2025

This is a component based on: BoxSelectionGroup with some adjustments on the style.

Preview

Screenshot 2025-07-09 at 18 32 03

Usage

It's intended to be used within <BoxSelectionGroup />.

Example form:

type IndexTypeValue = 'rqe' | 'vector-set'
const indexType: BoxSelectionOption<IndexTypeValue>[] = [
  {
    value: 'rqe',
    label: 'Redis Query Engine',
    text: 'For advanced, large-scale search needs',
    icon: VectorSearchIcon,
  },
  {
    value: 'vector-set',
    label: 'Vector Set',
    text: 'For quick and simple vector use cases',
    icon: WandIcon,
    disabled: true,
  },
]

type DataTypeValue =
  | 'e-commerce-discovery'
  | 'ai-assistants'
  | 'content-recommendations'
const dataType: BoxSelectionOption<DataTypeValue>[] = [
  {
    value: 'e-commerce-discovery',
    label: 'E-commerce Discovery',
    text: 'Find products by meaning, not just keywords.',
    icon: UniversityIcon,
  },
  {
    value: 'ai-assistants',
    label: 'AI Assistants',
    text: 'Find products by meaning, not just keywords.',
    icon: DatabaseIcon,
  },
  {
    value: 'content-recommendations',
    label: 'Content Recommendations',
    text: 'Find products by meaning, not just keywords.',
    icon: UniversityIcon,
    disabled: true,
  },
]

const BrowserPage = () => {
  const [indexTypeSelected, setIndexTypeSelected] = useState<
    IndexTypeValue | undefined
  >()
  const [dataTypeSelected, setDataTypeSelected] = useState<
    DataTypeValue | undefined
  >()

  return (
    <div className={`browserPage ${styles.container}`}>
      <form style={{ width: '50%', textAlign: 'center', margin: '0 auto' }}>
        <BoxSelectionGroup.Compose defaultValue={indexTypeSelected}>
          {indexType.map((type) => (
            <SelectionBox
              box={type}
              key={type.value}
              onClick={() => setIndexTypeSelected(type.value)}
            />
          ))}
        </BoxSelectionGroup.Compose>
      </form>

      <br />

      <form style={{ width: '50%', textAlign: 'center', margin: '0 auto' }}>
        <BoxSelectionGroup.Compose defaultValue={dataTypeSelected}>
          {dataType.map((type) => (
            <SelectionBox
              box={type}
              key={type.value}
              onClick={() => setDataTypeSelected(type.value)}
            />
          ))}
        </BoxSelectionGroup.Compose>
      </form>
    </div>
  )
}

}

export const StyledBoxContent = styled.div`
padding: 16px;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should strive to use the design system of redis-ui, or make our own, but in any case, avoid hardcoding random values. This goes for color values, for spacings, border radii etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm definitely in favor of using them, but I couldn't find where they’re defined (or how to use the ones from redis-ui). I noticed a few components using hardcoded values, which is why I left it as-is for now. If you could clarify or point me in the right direction, that would be helpful.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since redis-ui uses styled components, all these values are in the theme used for styled components.
You can obtain the theme via a hook:

import { useTheme } from '@redis-ui/styles'

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also each styled component gets a theme prop, that is the same as the result of useTheme

See /redisinsight/ui/src/components/base/display/loader/Loader.tsx for some example usage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I applied changes regarding this point.

export const StyledDisabledBar = styled.div`
padding: 2px 0;
/* Design color: #f4f5f6 */
background: var(--comboBoxBadgeBgColor);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this defined?

Copy link
Collaborator Author

@pawelangelow pawelangelow Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can find them in redisinsight/ui/src/styles/themes, specifically within darkTheme and lightTheme.
Not sure if this is the best source to pull from - if you have a better suggestion, feel free to share!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I changed it to get the values from the redis-ui theme.

StyledTitle,
} from './SelectionBox.styles'

export interface BoxSelectionOption<T extends string = string>
Copy link
Collaborator

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?

Copy link
Collaborator Author

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 support text as well. So I'm exporting the type for the consumers of this component.

Copy link
Collaborator

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
image
image

valkirilov
valkirilov previously approved these changes Jul 11, 2025
@pawelangelow pawelangelow changed the base branch from fe/feature/RI-7039-replace-eui to feature/RI-6855/vector-search July 11, 2025 09:11
valkirilov
valkirilov previously approved these changes Jul 11, 2025
valkirilov
valkirilov previously approved these changes Jul 11, 2025
Copy link
Collaborator

@pd-redis pd-redis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants