diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index 5a5d9753c36d8..f42a1aea6f563 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -424,6 +424,14 @@ describe("IssueService", () => { }), ]); + // Narrowing to one host still names every tracker, so the client can switch between them. + const narrowed = yield* service.list({ state: "open", host: "github.com" }); + expect(narrowed.entries.every((entry) => entry.host === "github.com")).toBe(true); + expect(narrowed.trackers.map((tracker) => tracker.host)).toEqual([ + "github.com", + "gitlab.com", + ]); + // A continuation only reads the scopes it names. listed.length = 0; const failed = yield* service.list({ diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 7da9674d1cdd4..2832ab04d15bb 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -312,12 +312,16 @@ const make = Effect.gen(function* () { ); const list: IssueService["Service"]["list"] = Effect.fn("IssueService.list")(function* (input) { - const { supported, unimplemented } = yield* listProjects(input); + // Trackers name every host so a client narrowed to one can switch to another; only the + // narrowed host's scopes are read. + const { supported, unimplemented } = yield* listProjects({ projectId: input.projectId }); + const host = input.host?.trim().toLowerCase(); const limit = input.limit ?? DEFAULT_LIST_LIMIT; // Worktrees of one repository are separate projects, and every repository of an Azure // DevOps project shares its work items; read each scope once. const scopes = new Map(); for (const project of supported) { + if (host !== undefined && project.host !== host) continue; const key = listCursorKey(project.host, project.scope); if (!scopes.has(key)) scopes.set(key, project); } diff --git a/apps/web/src/components/issue/IssuesPage.tsx b/apps/web/src/components/issue/IssuesPage.tsx index c3c340ce40021..94a1d4e905f91 100644 --- a/apps/web/src/components/issue/IssuesPage.tsx +++ b/apps/web/src/components/issue/IssuesPage.tsx @@ -137,9 +137,16 @@ function getShortcutContext() { }; } -function hostOptionsFor(groups: ReturnType, chosen: string | undefined) { +function hostOptionsFor(trackers: ReadonlyArray, chosen: string | undefined) { const hosts = new Map(); - for (const group of groups) hosts.set(group.tracker.host, group.tracker); + const ordered = [...trackers].sort((a, b) => + issueTrackerKey(a).localeCompare(issueTrackerKey(b)), + ); + for (const tracker of ordered) { + const existing = hosts.get(tracker.host); + if (existing === undefined || (!existing.configured && tracker.configured)) + hosts.set(tracker.host, tracker); + } return [ { value: "", label: "All", Icon: Plug2Icon }, // A remembered host no project is on any more stays listed, so the filter can be taken off. @@ -220,10 +227,31 @@ export function IssuesPage() { // Rows grouped per tracker account, so a tracker that cannot be read says so where its rows // would be, and each tracker's rows carry on from their own cursors. - const groups = groupIssues(held, debouncedQuery, projects, search.order ?? "updated"); - const filterScopes = issueFilterScopes(held, projects); + // The server names every tracker so the menu can switch hosts, but reads only the chosen one. + const chosenHost = search.host?.toLowerCase(); + const shown = chosenHost + ? new Map( + [...held].map(([environmentId, page]) => [ + environmentId, + { + ...page, + answer: { + ...page.answer, + trackers: page.answer.trackers.filter( + (tracker) => tracker.host.toLowerCase() === chosenHost, + ), + }, + }, + ]), + ) + : held; + const groups = groupIssues(shown, debouncedQuery, projects, search.order ?? "updated"); + const filterScopes = issueFilterScopes(shown, projects); - const hostOptions = hostOptionsFor(groups, search.host); + const hostOptions = hostOptionsFor( + [...held.values()].flatMap((page) => page.answer.trackers), + search.host, + ); const updateSearch = (patch: { [Key in keyof IssuesSearch]?: IssuesSearch[Key] | undefined }) => { const merged = { ...search, ...patch };