Skip to content

Commit 4c725c4

Browse files
committed
feat(web): add search to the project settings list
1 parent 02f4ce5 commit 4c725c4

1 file changed

Lines changed: 61 additions & 2 deletions

File tree

‎apps/web/src/components/settings/ProjectSettingsPanel.tsx‎

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ import { resolveEnvModeLabel } from "../BranchToolbar.logic";
2323
import { createModelSelection } from "@t3tools/shared/model";
2424
import { useLocation, useNavigate } from "@tanstack/react-router";
2525
import * as Cause from "effect/Cause";
26-
import { CopyIcon, FolderIcon, PlusIcon, ServerIcon, SettingsIcon, Trash2Icon } from "lucide-react";
26+
import {
27+
CopyIcon,
28+
FolderIcon,
29+
PlusIcon,
30+
SearchIcon,
31+
ServerIcon,
32+
SettingsIcon,
33+
Trash2Icon,
34+
} from "lucide-react";
2735
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2836

2937
import { useComposerDraftStore } from "../../composerDraftStore";
@@ -78,6 +86,7 @@ import {
7886
} from "../projectScriptEditor";
7987
import { Button } from "../ui/button";
8088
import { Input } from "../ui/input";
89+
import { InputGroup, InputGroupAddon, InputGroupInput } from "../ui/input-group";
8190
import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
8291
import { stackedThreadToast, toastManager } from "../ui/toast";
8392
import {
@@ -131,6 +140,22 @@ export function ProjectSettingsPanel({
131140
const groups = useSettingsProjectGroups();
132141
const navigate = useNavigate();
133142
const currentHash = useLocation({ select: (location) => location.hash });
143+
const [searchQuery, setSearchQuery] = useState("");
144+
const normalizedQuery = searchQuery.trim().toLowerCase();
145+
// Match checkout titles and paths too, so a group is findable by any of
146+
// the names it goes by, not just the grouped display name.
147+
const visibleGroups = useMemo(() => {
148+
if (!normalizedQuery) return groups;
149+
return groups.filter(
150+
(group) =>
151+
group.displayName.toLowerCase().includes(normalizedQuery) ||
152+
group.memberProjects.some(
153+
(member) =>
154+
member.title.toLowerCase().includes(normalizedQuery) ||
155+
member.workspaceRoot.toLowerCase().includes(normalizedQuery),
156+
),
157+
);
158+
}, [groups, normalizedQuery]);
134159

135160
// The index route auto-selects the first project so /settings/projects is
136161
// never a dead end. Hash is preserved for settings-search jumps.
@@ -206,7 +231,37 @@ export function ProjectSettingsPanel({
206231
aria-label="Projects"
207232
className="w-60 shrink-0 space-y-0.5 overflow-y-auto border-e border-border/40 p-3 pt-10 max-sm:hidden sm:pt-12"
208233
>
209-
{groups.map((group) => {
234+
{groups.length > 0 ? (
235+
<InputGroup variant="ghost" className="mb-1 h-8 rounded-md">
236+
<InputGroupAddon>
237+
<SearchIcon className="size-4 text-muted-foreground" />
238+
</InputGroupAddon>
239+
<InputGroupInput
240+
type="search"
241+
size="sm"
242+
value={searchQuery}
243+
aria-label="Search projects"
244+
placeholder="Search projects"
245+
spellCheck={false}
246+
onChange={(event) => setSearchQuery(event.target.value)}
247+
onKeyDown={(event) => {
248+
// Only intercept Escape while filtering, so an empty field
249+
// still lets the global shortcut close the settings page.
250+
if (event.key === "Escape" && searchQuery.length > 0) {
251+
event.preventDefault();
252+
event.stopPropagation();
253+
setSearchQuery("");
254+
return;
255+
}
256+
if (event.key === "Enter") {
257+
const first = visibleGroups[0];
258+
if (first) selectProject(first.projectKey);
259+
}
260+
}}
261+
/>
262+
</InputGroup>
263+
) : null}
264+
{visibleGroups.map((group) => {
210265
const isActive = group.projectKey === selected?.projectKey;
211266
return (
212267
<button
@@ -236,6 +291,10 @@ export function ProjectSettingsPanel({
236291
})}
237292
{groups.length === 0 ? (
238293
<p className="px-2 py-4 text-sm text-muted-foreground">No projects yet.</p>
294+
) : visibleGroups.length === 0 ? (
295+
<p role="status" className="px-2 py-4 text-sm text-muted-foreground">
296+
No matching projects.
297+
</p>
239298
) : null}
240299
</nav>
241300
{selected ? (

0 commit comments

Comments
 (0)