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
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions app/components/ui-lib.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@

.list {
border: var(--border-in-light);
border-radius: 10px;
border-radius: 0 0 10px 10px;
box-shadow: var(--card-shadow);
margin-bottom: 20px;
animation: slide-in ease 0.3s;

background: var(--white);
}

Expand Down Expand Up @@ -313,11 +313,38 @@
.selector-item-disabled {
opacity: 0.6;
}
.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;
}
Comment on lines +316 to +341
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);
}
}


&-content {
min-width: 300px;
animation: slide-in ease 0.3s;
width: 30rem;
.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 */

overflow-x: hidden;
overflow-y: auto;

Expand All @@ -336,4 +363,3 @@
}
}
}

109 changes: 74 additions & 35 deletions app/components/ui-lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -507,44 +507,83 @@ export function Selector<T>(props: {
props.onClose?.();
}
};

const [searchText, setSearchText] = useState("");
const [filteredItems, setFilteredItems] = useState([...props.items]);
function onSearch(text: string) {
setSearchText(text);
if (text === "") {
setFilteredItems([...props.items]);
return;
}
// filter by items title
const newItems = props.items.filter((item) =>
item.title.toLowerCase().includes(text.toLowerCase()),
);
setFilteredItems([...newItems]);
}
return (
<div className={styles["selector"]} onClick={() => props.onClose?.()}>
<div className={styles["selector-content"]}>
<div
className={styles["selector-content"]}
onClick={(e) => e.stopPropagation()}
>
{/* title and search box */}
<div className={styles["selector-bar"]}>
<div className={styles["selector-title"]}>
{Locale.UI.SelectorTitle}
</div>
<div className={styles["selector-search-container"]}>
<input
type="text"
className={styles["selector-search-input"]}
placeholder={Locale.UI.Search}
autoFocus
onInput={(e) => onSearch(e.currentTarget.value)}
/>
Comment on lines +536 to +542
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"
/>

</div>
</div>
{/* list content */}
<List>
{props.items.map((item, i) => {
const selected = selectedValues.includes(item.value);
return (
<ListItem
className={clsx(styles["selector-item"], {
[styles["selector-item-disabled"]]: item.disable,
})}
key={i}
title={item.title}
subTitle={item.subTitle}
onClick={(e) => {
if (item.disable) {
e.stopPropagation();
} else {
handleSelection(e, item.value);
}
}}
>
{selected ? (
<div
style={{
height: 10,
width: 10,
backgroundColor: "var(--primary)",
borderRadius: 10,
}}
></div>
) : (
<></>
)}
</ListItem>
);
})}
{filteredItems.length ? (
filteredItems.map((item, i) => {
const selected = selectedValues.includes(item.value);
return (
<ListItem
className={clsx(styles["selector-item"], {
[styles["selector-item-disabled"]]: item.disable,
})}
key={i}
title={item.title}
subTitle={item.subTitle}
onClick={(e) => {
if (item.disable) {
e.stopPropagation();
} else {
handleSelection(e, item.value);
}
}}
>
{selected ? (
<div
style={{
height: 10,
width: 10,
backgroundColor: "var(--primary)",
borderRadius: 10,
}}
></div>
) : (
<></>
)}
</ListItem>
);
})
) : (
<ListItem
title={Locale.UI.NoResults}
className={styles["selector-item"]}
></ListItem>
)}
</List>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions app/locales/cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,9 @@ const cn = {
Import: "导入",
Sync: "同步",
Config: "配置",
Search: "搜索",
SelectorTitle: "选择model",
NoResults: "没有结果",
},
Exporter: {
Description: {
Expand Down
3 changes: 3 additions & 0 deletions app/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,9 @@ const en: LocaleType = {
Import: "Import",
Sync: "Sync",
Config: "Config",
Search: "Search",
SelectorTitle: "Choose Model",
NoResults: "No Results",
},
Exporter: {
Description: {
Expand Down