Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(ui): add repository search to resource pickers (#3126)
Michael Wong3e1066a638f4
diff --git a/packages/views/locales/en/modals.json b/packages/views/locales/en/modals.jsonindex c2dbc46084..efc7f8d19b 100644--- a/packages/views/locales/en/modals.json+++ b/packages/views/locales/en/modals.json@@ -105,6 +105,8 @@"repos_pill_count_other": "{{count}} repos","repos_heading": "Attach GitHub repos to this project","repos_empty": "No workspace-level repos yet. Paste a URL below to attach one ad-hoc.",+ "repos_search_placeholder": "Search repositories...",+ "repos_search_empty": "No repositories match your search.","repos_url_placeholder": "https://github.com/owner/repo or [email protected]:owner/repo.git","repos_add": "Add","repos_selected": "Selected"diff --git a/packages/views/locales/en/projects.json b/packages/views/locales/en/projects.jsonindex bb5d119d3b..524ece9bdd 100644--- a/packages/views/locales/en/projects.json+++ b/packages/views/locales/en/projects.json@@ -71,6 +71,8 @@"empty": "No resources attached.","add_button": "Add resource","popover_title": "Attach a GitHub repo",+ "repos_search_placeholder": "Search repositories...",+ "repos_search_empty": "No repositories match your search.","attached_badge": "attached","remove_tooltip": "Remove","url_placeholder": "https://github.com/owner/repo or [email protected]:owner/repo.git",diff --git a/packages/views/locales/zh-Hans/modals.json b/packages/views/locales/zh-Hans/modals.jsonindex a50b26dbca..57a91ce431 100644--- a/packages/views/locales/zh-Hans/modals.json+++ b/packages/views/locales/zh-Hans/modals.json@@ -105,6 +105,8 @@"repos_pill_count_other": "{{count}} 个仓库","repos_heading": "为此项目关联 GitHub 仓库","repos_empty": "还没有工作区级别的仓库。可以在下方粘贴 URL 临时关联一个。",+ "repos_search_placeholder": "搜索仓库...",+ "repos_search_empty": "没有匹配的仓库。","repos_url_placeholder": "https://github.com/owner/repo 或 [email protected]:owner/repo.git","repos_add": "添加","repos_selected": "已选"diff --git a/packages/views/locales/zh-Hans/projects.json b/packages/views/locales/zh-Hans/projects.jsonindex 5790b429d1..44d905bd96 100644--- a/packages/views/locales/zh-Hans/projects.json+++ b/packages/views/locales/zh-Hans/projects.json@@ -71,6 +71,8 @@"empty": "还没有关联资源。","add_button": "添加资源","popover_title": "关联 GitHub 仓库",+ "repos_search_placeholder": "搜索仓库...",+ "repos_search_empty": "没有匹配的仓库。","attached_badge": "已关联","remove_tooltip": "移除","url_placeholder": "https://github.com/owner/repo 或 [email protected]:owner/repo.git",diff --git a/packages/views/modals/create-project.test.tsx b/packages/views/modals/create-project.test.tsxindex bbe5cae485..9f3004facb 100644--- a/packages/views/modals/create-project.test.tsx+++ b/packages/views/modals/create-project.test.tsx@@ -1,9 +1,13 @@import React from "react";import { describe, expect, it, vi } from "vitest";import { render, screen } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { renderWithI18n } from "../test/i18n";const longRepoUrl ="https://github.com/multica-ai/a-very-long-repository-name-that-needs-a-tooltip";+const apiRepoUrl = "https://github.com/multica-ai/api";+const webRepoUrl = "https://github.com/multica-ai/web";vi.mock("@tanstack/react-query", () => ({useQuery: () => ({ data: [] }),@@ -39,7 +43,7 @@ vi.mock("@multica/core/paths", () => ({id: "workspace-1",name: "Test Workspace",slug: "test-workspace",- repos: [{ url: longRepoUrl }],+ repos: [{ url: longRepoUrl }, { url: apiRepoUrl }, { url: webRepoUrl }],}),useWorkspacePaths: () => ({projectDetail: (id: string) => `/test-workspace/projects/${id}`,@@ -165,4 +169,29 @@ describe("CreateProjectModal", () => {expect(screen.getByTitle(longRepoUrl)).toHaveTextContent(longRepoUrl);expect(screen.getByRole("tooltip", { name: longRepoUrl })).toBeInTheDocument();});++ it("filters workspace repositories by search text", async () => {+ const user = userEvent.setup();++ renderWithI18n(<CreateProjectModal onClose={vi.fn()} />);++ const repoSearchInput = screen.getByRole("textbox", { name: "Search repositories..." });++ await user.type(repoSearchInput, "api");++ expect(+ screen.getByRole("button", { name: (name) => name.includes(apiRepoUrl) }),+ ).toBeInTheDocument();+ expect(+ screen.queryByRole("button", { name: (name) => name.includes(webRepoUrl) }),+ ).not.toBeInTheDocument();+ expect(+ screen.queryByRole("button", { name: (name) => name.includes(longRepoUrl) }),+ ).not.toBeInTheDocument();++ await user.clear(repoSearchInput);+ await user.type(repoSearchInput, "no-match");++ expect(screen.getByText("No repositories match your search.")).toBeInTheDocument();+ });});diff --git a/packages/views/modals/create-project.tsx b/packages/views/modals/create-project.tsxindex 43e3a1886c..d783956f92 100644--- a/packages/views/modals/create-project.tsx+++ b/packages/views/modals/create-project.tsx@@ -1,7 +1,7 @@"use client";import { useState, useRef } from "react";-import { ChevronRight, Maximize2, Minimize2, X as XIcon, UserMinus } from "lucide-react";+import { ChevronRight, Maximize2, Minimize2, Search, X as XIcon, UserMinus } from "lucide-react";/*** GitHub mark — lucide-react v1 dropped brand icons, so we inline the@@ -136,8 +136,13 @@ export function CreateProjectModal({ onClose }: { onClose: () => void }) {// persisted until handleSubmit fires the createProjectResource calls.const [selectedRepos, setSelectedRepos] = useState<string[]>([]);const [repoPopoverOpen, setRepoPopoverOpen] = useState(false);+ const [repoSearch, setRepoSearch] = useState("");const [customRepoUrl, setCustomRepoUrl] = useState("");const workspaceRepos = workspace?.repos ?? [];+ const repoQuery = repoSearch.trim().toLowerCase();+ const filteredWorkspaceRepos = workspaceRepos.filter((repo) =>+ repo.url.toLowerCase().includes(repoQuery),+ );// Sync field changes to draft storeconst updateTitle = (v: string) => { setTitle(v); setDraft({ title: v }); };@@ -451,7 +456,13 @@ export function CreateProjectModal({ onClose }: { onClose: () => void }) {</PopoverContent></Popover>- <Popover open={repoPopoverOpen} onOpenChange={setRepoPopoverOpen}>+ <Popover+ open={repoPopoverOpen}+ onOpenChange={(v) => {+ setRepoPopoverOpen(v);+ if (!v) setRepoSearch("");+ }}+ ><PopoverTriggerrender={<PillButton>@@ -469,31 +480,49 @@ export function CreateProjectModal({ onClose }: { onClose: () => void }) {{t(($) => $.create_project.repos_heading)}</div>{workspaceRepos.length > 0 ? (- <div className="space-y-1 max-h-48 overflow-y-auto">- {workspaceRepos.map((repo) => {- const checked = selectedRepos.includes(repo.url);- return (- <button- type="button"- key={repo.url}- onClick={() => toggleRepo(repo.url)}- className={cn(- "flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs hover:bg-accent transition-colors",- checked && "bg-accent",- )}- >- <input- type="checkbox"- checked={checked}- readOnly- className="size-3.5"- />- <GithubIcon className="size-3.5" />- <RepoUrlText url={repo.url} />- </button>- );- })}- </div>+ <>+ <div className="relative">+ <Search className="pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground" />+ <input+ type="text"+ value={repoSearch}+ onChange={(e) => setRepoSearch(e.target.value)}+ aria-label={t(($) => $.create_project.repos_search_placeholder)}+ placeholder={t(($) => $.create_project.repos_search_placeholder)}+ className="h-8 w-full rounded-md border bg-transparent pl-7 pr-2 text-xs outline-none placeholder:text-muted-foreground focus-visible:ring-1 focus-visible:ring-ring"+ />+ </div>+ <div className="max-h-48 space-y-1 overflow-y-auto">+ {filteredWorkspaceRepos.length === 0 && repoQuery && (+ <p className="py-2 text-center text-xs text-muted-foreground">+ {t(($) => $.create_project.repos_search_empty)}+ </p>+ )}+ {filteredWorkspaceRepos.map((repo) => {+ const checked = selectedRepos.includes(repo.url);+ return (+ <button+ type="button"+ key={repo.url}+ onClick={() => toggleRepo(repo.url)}+ className={cn(+ "flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs hover:bg-accent transition-colors",+ checked && "bg-accent",+ )}+ >+ <input+ type="checkbox"+ checked={checked}+ readOnly+ className="size-3.5"+ />+ <GithubIcon className="size-3.5" />+ <RepoUrlText url={repo.url} />+ </button>+ );+ })}+ </div>+ </>) : (<p className="text-xs text-muted-foreground">{t(($) => $.create_project.repos_empty)}diff --git a/packages/views/projects/components/project-resources-section.tsx b/packages/views/projects/components/project-resources-section.tsxindex 8e9f29544c..6b8e986c4c 100644--- a/packages/views/projects/components/project-resources-section.tsx+++ b/packages/views/projects/components/project-resources-section.tsx@@ -2,7 +2,7 @@import { useState } from "react";import { useQuery } from "@tanstack/react-query";-import { ChevronRight, FolderGit, Plus, Trash2 } from "lucide-react";+import { ChevronRight, FolderGit, Plus, Search, Trash2 } from "lucide-react";import { toast } from "sonner";import {projectResourcesOptions,@@ -39,6 +39,7 @@ export function ProjectResourcesSection({ projectId }: { projectId: string }) {const workspace = useCurrentWorkspace();const [open, setOpen] = useState(true);const [addOpen, setAddOpen] = useState(false);+ const [repoSearch, setRepoSearch] = useState("");const { data: resources = [] } = useQuery(projectResourcesOptions(wsId, projectId),@@ -52,6 +53,10 @@ export function ProjectResourcesSection({ projectId }: { projectId: string }) {.map((r) => (r.resource_ref as GithubRepoResourceRef).url),);+ const repoQuery = repoSearch.trim().toLowerCase();+ const filteredRepos =+ workspace?.repos?.filter((repo) => repo.url.toLowerCase().includes(repoQuery)) ?? [];+const handleAttach = async (url: string) => {try {await createResource.mutateAsync({@@ -96,14 +101,24 @@ export function ProjectResourcesSection({ projectId }: { projectId: string }) {{t(($) => $.resources.empty)}</p>)}- {resources.map((resource) => (- <ResourceRow- key={resource.id}- resource={resource}- onRemove={() => handleRemove(resource)}- />- ))}- <Popover open={addOpen} onOpenChange={setAddOpen}>+ {resources.length > 0 && (+ <div className="max-h-64 space-y-1.5 overflow-y-auto pr-1">+ {resources.map((resource) => (+ <ResourceRow+ key={resource.id}+ resource={resource}+ onRemove={() => handleRemove(resource)}+ />+ ))}+ </div>+ )}+ <Popover+ open={addOpen}+ onOpenChange={(v) => {+ setAddOpen(v);+ if (!v) setRepoSearch("");+ }}+ ><PopoverTriggerrender={<Button@@ -121,43 +136,61 @@ export function ProjectResourcesSection({ projectId }: { projectId: string }) {{t(($) => $.resources.popover_title)}</div>{workspace?.repos && workspace.repos.length > 0 && (- <div className="space-y-1 max-h-48 overflow-y-auto">- {workspace.repos.map((repo) => {- const isAttached = attachedUrls.has(repo.url);- const isDisabled = isAttached || createResource.isPending;- return (- // Use aria-disabled instead of the native `disabled` attribute so- // hover events still reach the tooltip trigger on attached rows- // (browsers suppress pointer events on disabled form controls).- <button- key={repo.url}- type="button"- aria-disabled={isDisabled}- onClick={async () => {- if (isDisabled) return;- await handleAttach(repo.url);- setAddOpen(false);- }}- className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs text-left hover:bg-accent transition-colors aria-disabled:opacity-50 aria-disabled:cursor-not-allowed aria-disabled:hover:bg-transparent"- >- <FolderGit className="size-3.5" />- <Tooltip>- <TooltipTrigger- render={- <span className="truncate flex-1">{repo.url}</span>- }- />- <TooltipContent side="top">{repo.url}</TooltipContent>- </Tooltip>- {isAttached && (- <span className="text-[10px] text-muted-foreground">- {t(($) => $.resources.attached_badge)}- </span>- )}- </button>- );- })}- </div>+ <>+ <div className="relative">+ <Search className="pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground" />+ <input+ type="text"+ value={repoSearch}+ onChange={(e) => setRepoSearch(e.target.value)}+ aria-label={t(($) => $.resources.repos_search_placeholder)}+ placeholder={t(($) => $.resources.repos_search_placeholder)}+ className="h-8 w-full rounded-md border bg-transparent pl-7 pr-2 text-xs outline-none placeholder:text-muted-foreground focus-visible:ring-1 focus-visible:ring-ring"+ />+ </div>+ <div className="max-h-48 space-y-1 overflow-y-auto">+ {filteredRepos.length === 0 && repoQuery && (+ <p className="py-2 text-center text-xs text-muted-foreground">+ {t(($) => $.resources.repos_search_empty)}+ </p>+ )}+ {filteredRepos.map((repo) => {+ const isAttached = attachedUrls.has(repo.url);+ const isDisabled = isAttached || createResource.isPending;+ return (+ // Use aria-disabled instead of the native `disabled` attribute so+ // hover events still reach the tooltip trigger on attached rows+ // (browsers suppress pointer events on disabled form controls).+ <button+ key={repo.url}+ type="button"+ aria-disabled={isDisabled}+ onClick={async () => {+ if (isDisabled) return;+ await handleAttach(repo.url);+ setAddOpen(false);+ }}+ className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs text-left hover:bg-accent transition-colors aria-disabled:opacity-50 aria-disabled:cursor-not-allowed aria-disabled:hover:bg-transparent"+ >+ <FolderGit className="size-3.5" />+ <Tooltip>+ <TooltipTrigger+ render={+ <span className="truncate flex-1">{repo.url}</span>+ }+ />+ <TooltipContent side="top">{repo.url}</TooltipContent>+ </Tooltip>+ {isAttached && (+ <span className="text-[10px] text-muted-foreground">+ {t(($) => $.resources.attached_badge)}+ </span>+ )}+ </button>+ );+ })}+ </div>+ </>)}<CustomRepoFormonSubmit={async (url) => {