Skip to content
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

feat: add search box and title above model list #5987

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

chenyu-01
Copy link

@chenyu-01 chenyu-01 commented Dec 27, 2024

πŸ’» ε˜ζ›΄η±»εž‹ | Change Type

  • feat
  • fix
  • refactor
  • perf
  • style
  • test
  • docs
  • ci
  • chore
  • build

πŸ”€ ε˜ζ›΄θ―΄ζ˜Ž | Description of Change

Can now search llm models when selecting them

πŸ“ θ‘₯充俑息 | Additional Information

image

Summary by CodeRabbit

  • New Features

    • Introduced a searchable interface within the Selector component, allowing users to filter items dynamically.
    • Added new UI components for selector functionality, including a search input and titles.
  • Bug Fixes

    • Updated styles for the list component to improve visual structure and responsiveness.
  • Localization

    • Added new localized strings for search functionality and model selection in both Chinese and English, including "搜紒", "选择", "ζ²‘ζœ‰η»“ζžœ", "Search", "Select", and "No Results".

Copy link

vercel bot commented Dec 27, 2024

@chenyu-01 is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

Walkthrough

The pull request introduces enhancements to the Selector component, adding search functionality and improving the styling of UI elements. Changes include the addition of new state variables and functions for managing search input and filtered results in the component logic. The styling updates in the SCSS file create a more structured layout for the selector interface. Localization files are updated to include new entries for search-related text in both Chinese and English, ensuring the feature is accessible to a wider audience.

Changes

File Change Summary
app/components/ui-lib.module.scss - Modified .list border radius
- Added new classes for .selector-bar, .selector-title, .selector-search-container, and .selector-search-input
- Reduced max height of .list within .selector-content
app/components/ui-lib.tsx - Added searchText and filteredItems state variables
- Implemented onSearch function for filtering items
- Updated rendering to display filteredItems
- Added search input field
app/locales/cn.ts - Added localized strings for Search, SelectorTitle, and NoResults
app/locales/en.ts - Added English strings for Search, SelectorTitle, and NoResults

Sequence Diagram

sequenceDiagram
    participant User
    participant SearchInput
    participant Selector
    participant ItemList

    User->>SearchInput: Type search text
    SearchInput->>Selector: Trigger onSearch
    Selector->>Selector: Filter items
    Selector->>ItemList: Update displayed items
    ItemList-->>User: Show filtered results
Loading

Poem

🐰 A Rabbit's Search Delight πŸ”
With whiskers twitching, I seek and scan,
Through lists that dance at my command,
A search so swift, a filter so bright,
Revealing treasures, pure and light!

hop hop πŸ₯•


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❀️ Share
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
app/components/ui-lib.tsx (3)

510-523: Consider adding a debounce or memoization for the search logic.
Repeatedly filtering large lists on every input event may impact performance. A debounce approach or memoizing could enhance efficiency for larger data sets.


527-541: Include accessibility attributes on the search input.
Applying appropriate labels or aria attributes on the search input (e.g., aria-label="Search" or associating a <label>) can improve accessibility and assist screen readers.


543-582: Leverage a consistent styling or standardized component for the selected indicator.
Changing the inline styles for the selected indicator to a dedicated SCSS class helps ensure visual consistency and maintainability.

πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 0c3d446 and 055ac64.

πŸ“’ Files selected for processing (4)
  • app/components/ui-lib.module.scss (2 hunks)
  • app/components/ui-lib.tsx (1 hunks)
  • app/locales/cn.ts (1 hunks)
  • app/locales/en.ts (1 hunks)
πŸ”‡ Additional comments (5)
app/locales/cn.ts (1)

761-763: Localized strings look good.
Thank you for covering the edge case with "ζ²‘ζœ‰η»“ζžœ" to handle empty search results.

app/locales/en.ts (1)

767-769: Clear and concise localization updates.
This ensures a consistent user experience for English-speaking users when no results match their search.

app/components/ui-lib.module.scss (3)

81-81: Revising the border radius only on the bottom corners.
Aligning the .list with the new .selector-bar top radius is logical, but ensure the change doesn’t conflict with other places where .list styling is reused.


316-341: New search bar styles are clear and well-organized.
Using distinct class names for .selector-bar, .selector-title, and .selector-search-input avoids conflicts with other UI elements.


346-346: Lowering max-height from 90vh to 50vh.
This will constrain the visible area of the list for larger screen sizes. Verify that it doesn’t negatively impact usability for scenarios with extensive item lists.

Copy link

vercel bot commented Dec 28, 2024

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
nextchat βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Dec 28, 2024 1:40pm

@Leizhenpeng
Copy link
Member

Leizhenpeng commented Dec 28, 2024

I found some issues below that you can fix.

  • The animation in the model list had some issues the first time it appeared. The timing was off compared to the list above, creating a noticeable disconnect.
  • The model size changes drastically when I type in the input box. This needs optimization.

@chenyu-01

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
app/components/ui-lib.tsx (2)

510-523: Enhance search functionality and optimize state updates

A few suggestions to improve the search implementation:

  1. Include subtitle in the search to improve findability
  2. Remove unnecessary spread operators
  3. Consider debouncing the search for better performance with large lists
 function onSearch(text: string) {
   setSearchText(text);
   if (text === "") {
-    setFilteredItems([...props.items]);
+    setFilteredItems(props.items);
     return;
   }
-  // filter by items title
+  // filter by title and subtitle
   const newItems = props.items.filter((item) =>
-    item.title.toLowerCase().includes(text.toLowerCase()),
+    item.title.toLowerCase().includes(text.toLowerCase()) ||
+    (item.subTitle?.toLowerCase()?.includes(text.toLowerCase()) ?? false)
   );
-  setFilteredItems([...newItems]);
+  setFilteredItems(newItems);
 }

566-577: Move inline styles to CSS module

Extract the selection indicator styles to the CSS module for better maintainability and consistency with the codebase's styling approach.

+// In ui-lib.module.scss
+.selector-item-indicator {
+  height: 10px;
+  width: 10px;
+  background-color: var(--primary);
+  border-radius: 10px;
+}

-<div
-  style={{
-    height: 10,
-    width: 10,
-    backgroundColor: "var(--primary)",
-    borderRadius: 10,
-  }}
-></div>
+<div className={styles["selector-item-indicator"]} />
-<></>
+{null}
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 055ac64 and 96ede7d.

πŸ“’ Files selected for processing (2)
  • app/components/ui-lib.module.scss (2 hunks)
  • app/components/ui-lib.tsx (1 hunks)
πŸ”‡ Additional comments (1)
app/components/ui-lib.module.scss (1)

81-81: LGTM! Border radius adjustment aligns with new design

The border-radius change correctly implements the visual connection between the search bar and list.

.list {
max-height: 90vh;
max-height: 50vh;
Copy link
Contributor

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Improve list size handling to prevent jarring changes

The fixed 50vh height might cause abrupt size changes during typing. Consider a more flexible approach:

-  max-height: 50vh;
+  min-height: 30vh;
+  max-height: calc(90vh - 120px); /* Account for search bar and padding */
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
max-height: 50vh;
min-height: 30vh;
max-height: calc(90vh - 120px); /* Account for search bar and padding */

Comment on lines +536 to +542
<input
type="text"
className={styles["selector-search-input"]}
placeholder={Locale.UI.Search}
autoFocus
onInput={(e) => onSearch(e.currentTarget.value)}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Improve accessibility and event handling of search input

Add accessibility attributes and use onChange for better cross-browser compatibility.

 <input
   type="text"
   className={styles["selector-search-input"]}
   placeholder={Locale.UI.Search}
   autoFocus
-  onInput={(e) => onSearch(e.currentTarget.value)}
+  onChange={(e) => onSearch(e.target.value)}
+  aria-label={Locale.UI.Search}
+  role="searchbox"
 />
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<input
type="text"
className={styles["selector-search-input"]}
placeholder={Locale.UI.Search}
autoFocus
onInput={(e) => onSearch(e.currentTarget.value)}
/>
<input
type="text"
className={styles["selector-search-input"]}
placeholder={Locale.UI.Search}
autoFocus
onChange={(e) => onSearch(e.target.value)}
aria-label={Locale.UI.Search}
role="searchbox"
/>

@Leizhenpeng
Copy link
Member

Try setting a fixed height of select box~

@chenyu-01
Copy link
Author

Try setting a fixed height of select box~

PixPin_2024-12-30_15-55-55

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 6582376 and dee9c94.

πŸ“’ Files selected for processing (1)
  • app/components/ui-lib.module.scss (2 hunks)
πŸ”‡ Additional comments (1)
app/components/ui-lib.module.scss (1)

81-84: LGTM: Border radius adjustment aligns with new selector bar design

The border-radius modification correctly implements a seamless connection between the list and the new selector bar above it.

Comment on lines +344 to +346
animation: slide-in ease 0.3s;
width: 30rem;
height: 60vh;
Copy link
Contributor

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Improve responsive handling of selector dimensions

The fixed dimensions might cause layout issues on different screen sizes and during interactions. Consider:

 &-content {
   animation: slide-in ease 0.3s;
-  width: 30rem;
-  height: 60vh;
+  width: min(30rem, 90vw);  /* Responsive width */
+  max-height: 60vh;         /* Use max-height instead of fixed height */
+  min-height: 300px;        /* Prevent too small height */
+
+  @media screen and (max-width: 480px) {
+    width: 95vw;            /* Fuller width on mobile */
+    max-height: 70vh;       /* More vertical space on mobile */
+  }

This change will:

  • Prevent content overflow on smaller screens
  • Reduce size changes during typing
  • Improve mobile experience
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
animation: slide-in ease 0.3s;
width: 30rem;
height: 60vh;
animation: slide-in ease 0.3s;
width: min(30rem, 90vw); /* Responsive width */
max-height: 60vh; /* Use max-height instead of fixed height */
min-height: 300px; /* Prevent too small height */
@media screen and (max-width: 480px) {
width: 95vw; /* Fuller width on mobile */
max-height: 70vh; /* More vertical space on mobile */
}

Comment on lines +316 to +341
.selector-bar {
background-color: var(--white);
border: solid var(--border-in-light);
border-top-left-radius: 10px;
border-top-right-radius: 10px;
min-height: 40px;
width: 100%;
}
.selector-title {
font-size: large;
font-weight: bold;
padding: 10px;
}
.selector-search-container {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px;
border-bottom: solid var(--border-in-light);
}
.selector-search-input {
padding: 5px;
margin-right: 5px;
flex-grow: 1;
max-width: none;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Enhance selector bar styling for better visual consistency

The selector bar implementation needs improvements for better visual consistency and user experience:

  1. Add consistent spacing and alignment:
 .selector-bar {
   background-color: var(--white);
   border: solid var(--border-in-light);
   border-top-left-radius: 10px;
   border-top-right-radius: 10px;
   min-height: 40px;
   width: 100%;
+  display: flex;
+  flex-direction: column;
 }

 .selector-title {
   font-size: large;
   font-weight: bold;
   padding: 10px;
+  padding-bottom: 5px;  /* Reduce spacing before search */
 }

 .selector-search-container {
   display: flex;
   align-items: center;
   justify-content: space-between;
   padding: 10px;
+  padding-top: 5px;  /* Balance with title padding */
   border-bottom: solid var(--border-in-light);
 }

 .selector-search-input {
   padding: 5px;
   margin-right: 5px;
   flex-grow: 1;
   max-width: none;
+  height: 30px;  /* Consistent height */
+  border: 1px solid var(--border-in-light);
+  border-radius: 6px;
+  outline: none;
+
+  &:focus {
+    border-color: var(--primary);
+  }
 }
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.selector-bar {
background-color: var(--white);
border: solid var(--border-in-light);
border-top-left-radius: 10px;
border-top-right-radius: 10px;
min-height: 40px;
width: 100%;
}
.selector-title {
font-size: large;
font-weight: bold;
padding: 10px;
}
.selector-search-container {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px;
border-bottom: solid var(--border-in-light);
}
.selector-search-input {
padding: 5px;
margin-right: 5px;
flex-grow: 1;
max-width: none;
}
.selector-bar {
background-color: var(--white);
border: solid var(--border-in-light);
border-top-left-radius: 10px;
border-top-right-radius: 10px;
min-height: 40px;
width: 100%;
display: flex;
flex-direction: column;
}
.selector-title {
font-size: large;
font-weight: bold;
padding: 10px;
padding-bottom: 5px; /* Reduce spacing before search */
}
.selector-search-container {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px;
padding-top: 5px; /* Balance with title padding */
border-bottom: solid var(--border-in-light);
}
.selector-search-input {
padding: 5px;
margin-right: 5px;
flex-grow: 1;
max-width: none;
height: 30px; /* Consistent height */
border: 1px solid var(--border-in-light);
border-radius: 6px;
outline: none;
&:focus {
border-color: var(--primary);
}
}

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

Successfully merging this pull request may close these issues.

2 participants