Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(settings): edit and remove the repository the dialog was opened for (#11500)
pseudoyu0f5f0e0b538a
diff --git a/packages/views/settings/components/repositories-section.test.tsx b/packages/views/settings/components/repositories-section.test.tsxindex aa21ef8d97..fcb65100ea 100644--- a/packages/views/settings/components/repositories-section.test.tsx+++ b/packages/views/settings/components/repositories-section.test.tsx@@ -239,6 +239,75 @@ describe("RepositoriesSection", () => {});});+ describe("when the list changes while a dialog is open", () => {+ const api = { url: "https://github.com/acme/api", description: "API" };+ const web = { url: "https://github.com/acme/web", description: "Web" };+ const docs = { url: "https://github.com/acme/docs", description: "Docs" };++ async function openRowAction(user: ReturnType<typeof userEvent.setup>, url: string, action: string) {+ await user.click(screen.getByRole("button", { name: `Actions for ${url}` }));+ await user.click(await screen.findByRole("menuitem", { name: action }));+ }++ function replaceRepos(rerender: (ui: ReactNode) => void, repos: typeof workspaceRef.current.repos) {+ workspaceRef.current = { ...workspaceRef.current, repos };+ rerender(<RepositoriesSection connection={connection} />);+ }++ async function saveDescription(user: ReturnType<typeof userEvent.setup>, text: string) {+ const dialog = screen.getByRole("dialog", { name: "Edit repository" });+ const description = within(dialog).getByRole("textbox", { name: "Description" });+ await user.clear(description);+ await user.type(description, text);+ await user.click(within(dialog).getByRole("button", { name: "Save" }));+ }++ beforeEach(() => {+ workspaceRef.current = { ...workspaceRef.current, repos: [api, web, docs] };+ });++ it("edits the repository the dialog was opened for", async () => {+ const user = userEvent.setup();+ const { rerender } = render(<RepositoriesSection connection={connection} />, { wrapper: Wrapper });+ await openRowAction(user, web.url, "Edit");+ replaceRepos(rerender, [web, docs]);+ await saveDescription(user, "Web app");++ await waitFor(() =>+ expect(mockUpdateWorkspace).toHaveBeenCalledWith("workspace-1", {+ repos: [{ url: web.url, description: "Web app" }, docs],+ }),+ );+ });++ it("saves an edit to a repository that was removed meanwhile", async () => {+ const user = userEvent.setup();+ const { rerender } = render(<RepositoriesSection connection={connection} />, { wrapper: Wrapper });+ await openRowAction(user, web.url, "Edit");+ replaceRepos(rerender, [api, docs]);+ await saveDescription(user, "Web app");++ await waitFor(() =>+ expect(mockUpdateWorkspace).toHaveBeenCalledWith("workspace-1", {+ repos: [api, docs, { url: web.url, description: "Web app" }],+ }),+ );+ });++ it("removes the repository the confirmation was opened for", async () => {+ const user = userEvent.setup();+ const { rerender } = render(<RepositoriesSection connection={connection} />, { wrapper: Wrapper });+ await openRowAction(user, web.url, "Delete repository");+ const dialog = await screen.findByRole("alertdialog");+ replaceRepos(rerender, [web, docs]);+ await user.click(within(dialog).getByRole("button", { name: "Delete repository" }));++ await waitFor(() =>+ expect(mockUpdateWorkspace).toHaveBeenCalledWith("workspace-1", { repos: [docs] }),+ );+ });+ });+it("hides every write affordance from members", () => {roleRef.current = "member";render(<RepositoriesSection connection={connection} />, { wrapper: Wrapper });diff --git a/packages/views/settings/components/repositories-section.tsx b/packages/views/settings/components/repositories-section.tsxindex de523bee59..14df5c2da1 100644--- a/packages/views/settings/components/repositories-section.tsx+++ b/packages/views/settings/components/repositories-section.tsx@@ -121,8 +121,11 @@ export function repositoryIdentity(rawURL: string): string | null {}interface RepositoryDraft {- /** Index being edited, or null when adding. */- index: number | null;+ /**+ * Stored URL of the repository being edited, or null when adding. The server+ * keeps URLs unique; a row index goes stale when the list changes elsewhere.+ */+ editingURL: string | null;url: string;description: string;}@@ -144,7 +147,7 @@ export function RepositoriesSection({ connection }: { connection: ReturnType<typconst [draft, setDraft] = useState<RepositoryDraft | null>(null);const [saving, setSaving] = useState(false);- const [pendingRemovalIndex, setPendingRemovalIndex] = useState<number | null>(null);+ const [pendingRemovalURL, setPendingRemovalURL] = useState<string | null>(null);const {connecting: connectingGitHub,connect: connectGitHub,@@ -369,8 +372,8 @@ export function RepositoriesSection({ connection }: { connection: ReturnType<typconst draftDuplicate =!!draftIdentity &&repositories.some(- (repository, index) =>- index !== draft?.index &&+ (repository) =>+ repository.url !== draft?.editingURL &&repositoryIdentity(repository.url) === draftIdentity,);@@ -380,20 +383,19 @@ export function RepositoriesSection({ connection }: { connection: ReturnType<typurl: draft.url.trim(),...(draft.description.trim() ? { description: draft.description.trim() } : {}),};- const next =- draft.index === null- ? [...repositories, entry]- : repositories.map((repository, index) =>- index === draft.index ? entry : repository,- );+ const next = repositories.some((repository) => repository.url === draft.editingURL)+ ? repositories.map((repository) =>+ repository.url === draft.editingURL ? entry : repository,+ )+ : [...repositories, entry];if (await persist(next)) setDraft(null);};- const removeRepository = async (index: number) => {+ const removeRepository = async (url: string) => {const ok = await persist(- repositories.filter((_, repoIndex) => repoIndex !== index),+ repositories.filter((repository) => repository.url !== url),);- if (ok) setPendingRemovalIndex(null);+ if (ok) setPendingRemovalURL(null);};const openGitHubPicker = () => {@@ -486,7 +488,7 @@ export function RepositoriesSection({ connection }: { connection: ReturnType<typ</>) : null}<DropdownMenuItem- onClick={() => setDraft({ index: null, url: "", description: "" })}+ onClick={() => setDraft({ editingURL: null, url: "", description: "" })}><Pencil />{t(($) => $.repositories.add_manually)}@@ -553,7 +555,7 @@ export function RepositoriesSection({ connection }: { connection: ReturnType<typ<DropdownMenuItemonClick={() =>setDraft({- index,+ editingURL: repository.url,url: repository.url,description: repository.description ?? "",})@@ -564,7 +566,7 @@ export function RepositoriesSection({ connection }: { connection: ReturnType<typ</DropdownMenuItem><DropdownMenuItemvariant="destructive"- onClick={() => setPendingRemovalIndex(index)}+ onClick={() => setPendingRemovalURL(repository.url)}><Trash2 />{t(($) => $.repositories.delete_confirm_action)}@@ -587,7 +589,7 @@ export function RepositoriesSection({ connection }: { connection: ReturnType<typ<DialogContent className="sm:max-w-lg"><DialogHeader><DialogTitle>- {draft?.index === null+ {draft?.editingURL === null? t(($) => $.repositories.add_title): t(($) => $.repositories.edit_title)}</DialogTitle>@@ -842,9 +844,9 @@ export function RepositoriesSection({ connection }: { connection: ReturnType<typ</Dialog><AlertDialog- open={pendingRemovalIndex !== null}+ open={pendingRemovalURL !== null}onOpenChange={(open) => {- if (!open && !saving) setPendingRemovalIndex(null);+ if (!open && !saving) setPendingRemovalURL(null);}}><AlertDialogContent>@@ -864,8 +866,8 @@ export function RepositoriesSection({ connection }: { connection: ReturnType<typvariant="destructive"disabled={saving}onClick={() => {- if (pendingRemovalIndex !== null) {- void removeRepository(pendingRemovalIndex);+ if (pendingRemovalURL !== null) {+ void removeRepository(pendingRemovalURL);}}}>