From 2757926d2ca2910cafdf5ff14ea1e84834fea86e Mon Sep 17 00:00:00 2001 From: Bil0000 <62337003+Bil0000@users.noreply.github.com> Date: Sat, 21 Nov 2026 01:41:49 +0100 Subject: [PATCH 1/3] feat(issues): a project can list issues from several Linear teams A binding keeps its default team and gains additionalScopes. The server reads each team as its own scope, so listing, cursors, writability and link resolution work per team. Settings on web and mobile pick several teams; unchecking all unbinds. Agents file in the first team picked, and a key such as OPS-12 reads its own team. --- ...ettingsSourceControlDetailRouteScreens.tsx | 2 +- .../components/IssueTrackerSection.tsx | 31 ++++++++----- apps/mobile/src/i18n/translations/de.json | 2 +- apps/mobile/src/i18n/translations/en.json | 2 +- apps/mobile/src/i18n/translations/es.json | 2 +- apps/mobile/src/i18n/translations/fr.json | 2 +- apps/mobile/src/i18n/translations/ja.json | 2 +- apps/mobile/src/i18n/translations/ko.json | 2 +- apps/mobile/src/i18n/translations/pt-BR.json | 2 +- apps/mobile/src/i18n/translations/ru.json | 2 +- apps/mobile/src/i18n/translations/sv.json | 2 +- apps/mobile/src/i18n/translations/zh.json | 2 +- apps/server/src/issue/IssueService.test.ts | 38 +++++++++++++--- apps/server/src/issue/IssueService.ts | 31 ++++++++----- .../src/mcp/toolkits/issues/handlers.ts | 5 ++- .../src/persistence/IssueTrackerBindings.ts | 43 +++++++++++++------ apps/server/src/persistence/Migrations.ts | 2 + .../103_IssueTrackerAdditionalScopes.test.ts | 34 +++++++++++++++ .../103_IssueTrackerAdditionalScopes.ts | 9 ++++ .../reconcileV2PreviewMigration.test.ts | 2 + .../settings/IssueTrackerSettings.tsx | 37 ++++++++-------- apps/web/src/i18n/translations/de.json | 3 +- apps/web/src/i18n/translations/en.json | 3 +- apps/web/src/i18n/translations/es.json | 3 +- apps/web/src/i18n/translations/fr.json | 3 +- apps/web/src/i18n/translations/ja.json | 3 +- apps/web/src/i18n/translations/ko.json | 3 +- apps/web/src/i18n/translations/pt-BR.json | 3 +- apps/web/src/i18n/translations/ru.json | 3 +- apps/web/src/i18n/translations/sv.json | 3 +- apps/web/src/i18n/translations/zh.json | 3 +- docs/user/source-control.md | 7 ++- .../client-runtime/src/issueLinks.test.ts | 10 ++++- packages/client-runtime/src/issueLinks.ts | 9 ++-- .../client-runtime/src/state/issueTrackers.ts | 21 +++++++++ packages/contracts/src/issue.ts | 15 ++++++- 36 files changed, 246 insertions(+), 100 deletions(-) create mode 100644 apps/server/src/persistence/Migrations/103_IssueTrackerAdditionalScopes.test.ts create mode 100644 apps/server/src/persistence/Migrations/103_IssueTrackerAdditionalScopes.ts diff --git a/apps/mobile/src/features/settings/SettingsSourceControlDetailRouteScreens.tsx b/apps/mobile/src/features/settings/SettingsSourceControlDetailRouteScreens.tsx index 7c7f0e21db37..d786f8c106be 100644 --- a/apps/mobile/src/features/settings/SettingsSourceControlDetailRouteScreens.tsx +++ b/apps/mobile/src/features/settings/SettingsSourceControlDetailRouteScreens.tsx @@ -196,7 +196,7 @@ export function SettingsIssueTrackerRouteScreen({ diff --git a/apps/mobile/src/features/settings/components/IssueTrackerSection.tsx b/apps/mobile/src/features/settings/components/IssueTrackerSection.tsx index 7e655b18ff03..377f5ba92b6f 100644 --- a/apps/mobile/src/features/settings/components/IssueTrackerSection.tsx +++ b/apps/mobile/src/features/settings/components/IssueTrackerSection.tsx @@ -1,4 +1,8 @@ -import { issueTrackerSummary } from "@t3tools/client-runtime/state/issue-trackers"; +import { + boundIssueTrackerScopes, + issueTrackerBindingFor, + issueTrackerSummary, +} from "@t3tools/client-runtime/state/issue-trackers"; import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; import type { EnvironmentId, @@ -219,22 +223,27 @@ export function IssueTrackerProjectRows(props: { }); const projects = useProjects().filter((project) => project.environmentId === environmentId); const [binding, setBinding] = useState(null); - const change = async (projectId: ProjectId, scope: string) => { + const change = async (projectId: ProjectId, scopes: ReadonlyArray) => { if (props.disabled || binding !== null) return; setBinding(projectId); await bind({ environmentId, input: { projectId, - binding: scope === UNBOUND ? null : { tracker: tracker.tracker, scope }, + binding: issueTrackerBindingFor(tracker.tracker, props.bindings[projectId], scopes), }, }); setBinding(null); }; return projects.map((project) => { - const bound = props.bindings[project.id]; // A project bound to another tracker keeps that binding; this row shows it unbound. - const value = bound?.tracker === tracker.tracker ? bound.scope : UNBOUND; + const value = boundIssueTrackerScopes(tracker.tracker, props.bindings[project.id]); + const toggle = (key: string) => + key === UNBOUND + ? [] + : value.includes(key) + ? value.filter((scope) => scope !== key) + : [...value, key]; const locked = props.disabled || binding !== null; return ( ({ id: scope.key, title: `${scope.name} (${scope.key})`, - state: scope.key === value ? ("on" as const) : ("off" as const), + state: value.includes(scope.key) ? ("on" as const) : ("off" as const), attributes: { disabled: locked }, })), ]} - onPressAction={({ nativeEvent }) => void change(project.id, nativeEvent.event)} + onPressAction={({ nativeEvent }) => void change(project.id, toggle(nativeEvent.event))} > scope.key === value)?.name ?? value) + : value + .map((key) => tracker.scopes.find((scope) => scope.key === key)?.name ?? key) + .join(", ") } disabled={locked} /> diff --git a/apps/mobile/src/i18n/translations/de.json b/apps/mobile/src/i18n/translations/de.json index 37470078895b..9d795be3c5a1 100644 --- a/apps/mobile/src/i18n/translations/de.json +++ b/apps/mobile/src/i18n/translations/de.json @@ -3699,7 +3699,7 @@ "b725843fd45b74aa": "Anmeldedaten", "b239ba3ce2899a3e": "Oder verwende deine eigenen Anmeldedaten", "f0e6397ab4de588e": "Token", - "15ad0159a826b290": "Wähle das {scope} in {tracker}, dessen Issues jedes Projekt neben denen seines eigenen Repositorys auflistet.", + "295392927d5c8a84": "Wähle für jedes Projekt ein oder mehrere {scope}s in {tracker}. Ihre Issues erscheinen neben denen des Repositorys, und Agenten legen neue Issues im ersten an.", "ce2136b36f87b655": "Verbinde diese Umgebung, um ihre Einstellungen zu ändern.", "a90a441fd0e08de7": "Diese Umgebung", "32fb83554cfd85b4": "Transkriptionsmodelle", diff --git a/apps/mobile/src/i18n/translations/en.json b/apps/mobile/src/i18n/translations/en.json index f89c5bddb7eb..c321e1042521 100644 --- a/apps/mobile/src/i18n/translations/en.json +++ b/apps/mobile/src/i18n/translations/en.json @@ -3700,7 +3700,7 @@ "b725843fd45b74aa": "Credentials", "b239ba3ce2899a3e": "Or use your own credentials", "f0e6397ab4de588e": "Token", - "15ad0159a826b290": "Pick the {tracker} {scope} whose issues each project lists beside its repository's own.", + "295392927d5c8a84": "Pick one or more {tracker} {scope}s for each project. Their issues list beside the repository's own, and agents file new issues in the first one.", "ce2136b36f87b655": "Connect this environment to change its settings.", "a90a441fd0e08de7": "This environment", "32fb83554cfd85b4": "Transcription models", diff --git a/apps/mobile/src/i18n/translations/es.json b/apps/mobile/src/i18n/translations/es.json index a0df74614dfd..e10144d55806 100644 --- a/apps/mobile/src/i18n/translations/es.json +++ b/apps/mobile/src/i18n/translations/es.json @@ -3694,7 +3694,7 @@ "b725843fd45b74aa": "Credenciales", "b239ba3ce2899a3e": "O usa tus propias credenciales", "f0e6397ab4de588e": "Token", - "15ad0159a826b290": "Elige el {scope} de {tracker} cuyas issues lista cada proyecto junto a las de su propio repositorio.", + "295392927d5c8a84": "Elige uno o más {scope}s de {tracker} para cada proyecto. Sus issues aparecen junto a las del repositorio, y los agentes crean issues nuevas en el primero.", "ce2136b36f87b655": "Conecta este entorno para cambiar sus ajustes.", "a90a441fd0e08de7": "Este entorno", "32fb83554cfd85b4": "Modelos de transcripción", diff --git a/apps/mobile/src/i18n/translations/fr.json b/apps/mobile/src/i18n/translations/fr.json index 9e9d733338af..be5691cea753 100644 --- a/apps/mobile/src/i18n/translations/fr.json +++ b/apps/mobile/src/i18n/translations/fr.json @@ -3694,7 +3694,7 @@ "b725843fd45b74aa": "Identifiants", "b239ba3ce2899a3e": "Ou utilisez vos propres identifiants", "f0e6397ab4de588e": "Jeton", - "15ad0159a826b290": "Choisissez le {scope} {tracker} dont chaque projet liste les tickets à côté de ceux de son propre dépôt.", + "295392927d5c8a84": "Choisissez un ou plusieurs {scope}s {tracker} pour chaque projet. Leurs tickets s'affichent à côté de ceux du dépôt, et les agents créent les nouveaux tickets dans le premier.", "ce2136b36f87b655": "Connectez cet environnement pour modifier ses paramètres.", "a90a441fd0e08de7": "Cet environnement", "32fb83554cfd85b4": "Modèles de transcription", diff --git a/apps/mobile/src/i18n/translations/ja.json b/apps/mobile/src/i18n/translations/ja.json index f8c3f391742a..dd785cf87322 100644 --- a/apps/mobile/src/i18n/translations/ja.json +++ b/apps/mobile/src/i18n/translations/ja.json @@ -3691,7 +3691,7 @@ "b725843fd45b74aa": "資格情報", "b239ba3ce2899a3e": "または自分の資格情報を使用", "f0e6397ab4de588e": "トークン", - "15ad0159a826b290": "各プロジェクトがリポジトリ自身の Issue と並べて一覧表示する {tracker} の {scope} を選択します。", + "295392927d5c8a84": "各プロジェクトに {tracker} の {scope} を1つ以上選択します。その Issue はリポジトリ自身の Issue と並べて表示され、エージェントは最初の {scope} に新しい Issue を作成します。", "ce2136b36f87b655": "設定を変更するには、この環境に接続してください。", "a90a441fd0e08de7": "この環境", "32fb83554cfd85b4": "文字起こしモデル", diff --git a/apps/mobile/src/i18n/translations/ko.json b/apps/mobile/src/i18n/translations/ko.json index 368b459f45b5..62a3ef6e7305 100644 --- a/apps/mobile/src/i18n/translations/ko.json +++ b/apps/mobile/src/i18n/translations/ko.json @@ -3695,7 +3695,7 @@ "b725843fd45b74aa": "자격 증명", "b239ba3ce2899a3e": "또는 내 자격 증명 사용", "f0e6397ab4de588e": "토큰", - "15ad0159a826b290": "각 프로젝트가 저장소 자체 이슈와 함께 표시할 이슈의 {tracker} {scope}을(를) 선택하세요.", + "295392927d5c8a84": "각 프로젝트에 {tracker} {scope}을(를) 하나 이상 선택하세요. 해당 이슈는 저장소 자체 이슈와 함께 표시되며, 에이전트는 첫 번째 {scope}에 새 이슈를 만듭니다.", "ce2136b36f87b655": "설정을 변경하려면 이 환경에 연결하세요.", "a90a441fd0e08de7": "이 환경", "32fb83554cfd85b4": "받아쓰기 모델", diff --git a/apps/mobile/src/i18n/translations/pt-BR.json b/apps/mobile/src/i18n/translations/pt-BR.json index 7529fe513885..83aca49ebbfb 100644 --- a/apps/mobile/src/i18n/translations/pt-BR.json +++ b/apps/mobile/src/i18n/translations/pt-BR.json @@ -3694,7 +3694,7 @@ "b725843fd45b74aa": "Credenciais", "b239ba3ce2899a3e": "Ou use suas próprias credenciais", "f0e6397ab4de588e": "Token", - "15ad0159a826b290": "Escolha o {scope} do {tracker} cujas issues cada projeto lista ao lado das do próprio repositório.", + "295392927d5c8a84": "Escolha um ou mais {scope}s do {tracker} para cada projeto. As issues deles aparecem ao lado das do repositório, e os agentes criam novas issues no primeiro.", "ce2136b36f87b655": "Conecte este ambiente para alterar as configurações dele.", "a90a441fd0e08de7": "Este ambiente", "32fb83554cfd85b4": "Modelos de transcrição", diff --git a/apps/mobile/src/i18n/translations/ru.json b/apps/mobile/src/i18n/translations/ru.json index 976f53ecf6de..abde7ed8b011 100644 --- a/apps/mobile/src/i18n/translations/ru.json +++ b/apps/mobile/src/i18n/translations/ru.json @@ -3748,7 +3748,7 @@ "b725843fd45b74aa": "Учётные данные", "b239ba3ce2899a3e": "Или используйте свои учётные данные", "f0e6397ab4de588e": "Токен", - "15ad0159a826b290": "Выберите {scope} в {tracker}, issue которого каждый проект показывает рядом с issue своего репозитория.", + "295392927d5c8a84": "Выберите один или несколько {scope} в {tracker} для каждого проекта. Их issue показываются рядом с issue репозитория, а агенты создают новые issue в первом.", "ce2136b36f87b655": "Подключите это окружение, чтобы изменить его настройки.", "a90a441fd0e08de7": "Это окружение", "32fb83554cfd85b4": "Модели расшифровки", diff --git a/apps/mobile/src/i18n/translations/sv.json b/apps/mobile/src/i18n/translations/sv.json index 45a259d11d34..6f9e300adfb4 100644 --- a/apps/mobile/src/i18n/translations/sv.json +++ b/apps/mobile/src/i18n/translations/sv.json @@ -3700,7 +3700,7 @@ "b725843fd45b74aa": "Autentiseringsuppgifter", "b239ba3ce2899a3e": "Eller använd dina egna autentiseringsuppgifter", "f0e6397ab4de588e": "Token", - "15ad0159a826b290": "Välj den {scope} i {tracker} vars ärenden varje projekt listar bredvid repots egna.", + "295392927d5c8a84": "Välj en eller flera {scope} i {tracker} för varje projekt. Deras ärenden listas bredvid repots egna, och agenter skapar nya ärenden i den första.", "ce2136b36f87b655": "Anslut den här miljön för att ändra dess inställningar.", "a90a441fd0e08de7": "Den här miljön", "32fb83554cfd85b4": "Transkriberingsmodeller", diff --git a/apps/mobile/src/i18n/translations/zh.json b/apps/mobile/src/i18n/translations/zh.json index 860ff98a0f10..76c6d0b5a448 100644 --- a/apps/mobile/src/i18n/translations/zh.json +++ b/apps/mobile/src/i18n/translations/zh.json @@ -3696,7 +3696,7 @@ "b725843fd45b74aa": "凭据", "b239ba3ce2899a3e": "或使用你自己的凭据", "f0e6397ab4de588e": "token", - "15ad0159a826b290": "选择 {tracker} {scope},每个项目会在其仓库自身的 issue 旁列出它的 issue。", + "295392927d5c8a84": "为每个项目选择一个或多个 {tracker} {scope}。它们的 issue 会列在仓库自身的 issue 旁,智能体会在第一个中创建新 issue。", "ce2136b36f87b655": "连接此环境以更改其设置。", "a90a441fd0e08de7": "此环境", "32fb83554cfd85b4": "转写模型", diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index 1251729b5bba..231559e9eb4d 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -598,14 +598,17 @@ describe("IssueService with a standalone tracker", () => { }), ); - it.effect("lists a bound project's standalone scope beside its git host and serves both", () => + it.effect("lists a bound project's standalone scopes beside its git host and serves them", () => Effect.gen(function* () { const listed: string[] = []; const record = (tracker: IssueTrackerKind): Partial => ({ listIssues: (input) => Effect.sync(() => { listed.push(`${tracker} ${input.host} ${input.scope}`); - return { items: [issue(tracker === LINEAR ? "ENG-1" : "1")], nextCursor: null }; + return { + items: [issue(tracker === LINEAR ? `${input.scope}-1` : "1")], + nextCursor: null, + }; }), }); const projects = [project({ id: "web", repository: "acme/web" }), project({ id: "notes" })]; @@ -613,7 +616,9 @@ describe("IssueService with a standalone tracker", () => { const bound = yield* makeService({ projects: [...projects, project({ id: "api", repository: "acme/api" })], trackers, - bindings: { ["web" as ProjectId]: { tracker: LINEAR, scope: "ENG" } }, + bindings: { + ["web" as ProjectId]: { tracker: LINEAR, scope: "ENG", additionalScopes: ["OPS"] }, + }, }); const result = yield* bound.list({ state: "open" }); @@ -621,17 +626,23 @@ describe("IssueService with a standalone tracker", () => { "github github.com acme/api", "github github.com acme/web", "linear linear.app ENG", + "linear linear.app OPS", ]); expect(result.entries.map((entry) => [entry.tracker, entry.scope, entry.key]).sort()).toEqual( [ ["github", "acme/api", "1"], ["github", "acme/web", "1"], ["linear", "ENG", "ENG-1"], + ["linear", "OPS", "OPS-1"], ], ); - expect(result.trackers.map((tracker) => [tracker.tracker, tracker.host]).sort()).toEqual([ - ["github", "github.com"], - ["linear", "linear.app"], + expect( + result.trackers + .map((tracker) => [tracker.tracker, tracker.host, tracker.projectCount]) + .sort(), + ).toEqual([ + ["github", "github.com", 2], + ["linear", "linear.app", 1], ]); expect(result.scopes).toContainEqual({ projectId: "web", @@ -642,9 +653,14 @@ describe("IssueService with a standalone tracker", () => { // Narrowed to one project, both of its trackers are still read. listed.length = 0; const selected = yield* bound.list({ state: "open", projectId: "web" as ProjectId }); - expect(listed.sort()).toEqual(["github github.com acme/web", "linear linear.app ENG"]); + expect(listed.sort()).toEqual([ + "github github.com acme/web", + "linear linear.app ENG", + "linear linear.app OPS", + ]); expect(selected.entries.map((entry) => [entry.projectId, entry.scope]).sort()).toEqual([ ["web", "ENG"], + ["web", "OPS"], ["web", "acme/web"], ]); listed.length = 0; @@ -658,6 +674,14 @@ describe("IssueService with a standalone tracker", () => { key: "ENG-1", }; expect(yield* bound.detail(linearRef)).toMatchObject({ host: "linear.app", writable: true }); + expect(yield* bound.detail({ ...linearRef, scope: "OPS", key: "OPS-1" })).toMatchObject({ + writable: true, + }); + expect(yield* bound.detail({ ...linearRef, scope: "QA", key: "QA-1" })).toMatchObject({ + writable: false, + }); + expect((yield* bound.projectScope("web" as ProjectId)).scope).toBe("ENG"); + expect((yield* bound.projectScope("web" as ProjectId, "ops-12")).scope).toBe("OPS"); expect( yield* bound.detail({ projectId: "web" as ProjectId, diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 56712954a49c..a4483e222492 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -29,6 +29,7 @@ import { type IssueTemplateList, type IssueTrackerSummary, type IssueTrackerProjectBinding, + issueTrackerBindingScopes, type IssueUpdateInput, type OrchestrationProjectShell, type ProjectId, @@ -157,9 +158,10 @@ export class IssueService extends Context.Service< readonly update: (input: IssueUpdateInput) => Effect.Effect; readonly setState: (input: IssueSetStateInput) => Effect.Effect; readonly react: (input: IssueReactionInput) => Effect.Effect; - /** The tracker and container a project's own issues live in. */ + /** The tracker and container a project's own issues live in, or the one `key` names. */ readonly projectScope: ( projectId: ProjectId, + key?: string, ) => Effect.Effect; /** * Resolve through a matching project, preferring `preferredProjectId`; other scopes are read-only. @@ -186,11 +188,18 @@ const make = Effect.gen(function* () { const repositoryIdentities = yield* RepositoryIdentityResolver.RepositoryIdentityResolver; const bindings = yield* IssueTrackerBindings.IssueTrackerBindingsRepository; - const resolveStandaloneBinding = (binding: IssueTrackerProjectBinding | undefined) => { - if (binding === undefined) return null; + const resolveStandaloneBindings = ( + binding: IssueTrackerProjectBinding | undefined, + ): ReadonlyArray => { + if (binding === undefined) return []; const api = registry.get(binding.tracker); - if (api === null || !isStandaloneIssueTracker(api)) return null; - return { tracker: binding.tracker, host: api.standalone.host, scope: binding.scope }; + if (api === null || !isStandaloneIssueTracker(api)) return []; + const host = api.standalone.host; + return issueTrackerBindingScopes(binding).map((scope) => ({ + tracker: binding.tracker, + host, + scope, + })); }; /** @@ -206,9 +215,8 @@ const make = Effect.gen(function* () { : repositoryIdentities.resolve(project.workspaceRoot) ).pipe( Effect.map((repositoryIdentity) => { - const standalone = resolveStandaloneBinding(binding); const gitHost = resolveGitHostBindings({ ...project, repositoryIdentity }); - return standalone === null ? gitHost : [standalone, ...gitHost]; + return [...resolveStandaloneBindings(binding), ...gitHost]; }), ); @@ -428,7 +436,7 @@ const make = Effect.gen(function* () { if (page._tag === "Failure") { if (cursor !== undefined) nextCursors[key] = cursor; recordFailure(project, page.failure); - // A fork reads two repositories, so its failure names the one that failed. + // A fork or a multi-team binding reads several scopes; the failure names its own. const forked = supported.some( (other) => other.project.id === project.project.id && other.scope !== project.scope, ); @@ -670,9 +678,12 @@ const make = Effect.gen(function* () { const projectScope: IssueService["Service"]["projectScope"] = Effect.fn( "IssueService.projectScope", - )(function* (projectId) { + )(function* (projectId, key) { const { supported } = yield* listProjects({ projectId }); - const [own] = supported; + const prefix = key?.toLowerCase(); + const own = + supported.find((candidate) => prefix?.startsWith(`${candidate.scope.toLowerCase()}-`)) ?? + supported[0]; if (own === undefined) { return yield* new IssueUnavailableError({ reason: "tracker-unsupported" }); } diff --git a/apps/server/src/mcp/toolkits/issues/handlers.ts b/apps/server/src/mcp/toolkits/issues/handlers.ts index 1b4235ec7565..6b835ffb564f 100644 --- a/apps/server/src/mcp/toolkits/issues/handlers.ts +++ b/apps/server/src/mcp/toolkits/issues/handlers.ts @@ -90,13 +90,14 @@ const make = Effect.gen(function* () { /** Where a key-only reference is read: the named project's tracker, or the caller's thread's. */ const requireProjectScope = Effect.fn("IssuesToolkit.requireProjectScope")(function* ( requested: ProjectId | undefined, + key?: string, ) { // A named project skips the caller's thread, so the capability is checked here too. yield* McpInvocationContext.requireMcpCapability("issues"); const projectId = requested ?? (yield* callerThread())?.projectId; if (projectId === undefined) return yield* new IssueProjectRequiredError(); return yield* issues - .projectScope(projectId) + .projectScope(projectId, key) .pipe(Effect.mapError(() => new IssueProjectNotFoundError({ projectId }))); }); @@ -115,7 +116,7 @@ const make = Effect.gen(function* () { return { ...resolved, url: input.url } satisfies ResolvedTarget; } if (input.key === undefined) return yield* new IssueTargetIncompleteError(); - const scope = yield* requireProjectScope(input.projectId); + const scope = yield* requireProjectScope(input.projectId, input.key); return { ...scope, key: input.key, diff --git a/apps/server/src/persistence/IssueTrackerBindings.ts b/apps/server/src/persistence/IssueTrackerBindings.ts index f5e5f62d8192..fbb0a398900d 100644 --- a/apps/server/src/persistence/IssueTrackerBindings.ts +++ b/apps/server/src/persistence/IssueTrackerBindings.ts @@ -16,11 +16,12 @@ const BindingRow = Schema.Struct({ projectId: ProjectId, tracker: IssueTrackerKind, scope: Schema.String, + additionalScopes: Schema.fromJsonString(Schema.Array(Schema.String)), }); /** - * Which standalone issue tracker scope each project reads beside its git host's own issues. A - * project is bound to one scope at most, and only while it has a row. + * Which standalone issue tracker scopes each project reads beside its git host's own issues. A + * project is bound to one tracker at most, and only while it has a row. */ export class IssueTrackerBindingsRepository extends Context.Service< IssueTrackerBindingsRepository, @@ -43,6 +44,8 @@ export class IssueTrackerBindingsRepository extends Context.Service< } >()("t3/persistence/IssueTrackerBindings/IssueTrackerBindingsRepository") {} +const encodeAdditionalScopes = Schema.encodeEffect(BindingRow.fields.additionalScopes); + function toSqlOrDecodeError(sqlOperation: string, decodeOperation: string) { return (cause: unknown): IssueTrackerBindingsRepositoryError => Schema.isSchemaError(cause) @@ -58,7 +61,8 @@ const make = Effect.gen(function* () { Result: BindingRow, execute: () => sql` - SELECT project_id AS "projectId", tracker AS "tracker", scope AS "scope" + SELECT project_id AS "projectId", tracker AS "tracker", scope AS "scope", + additional_scopes AS "additionalScopes" FROM issue_tracker_bindings `, }); @@ -68,25 +72,38 @@ const make = Effect.gen(function* () { Effect.map( (rows) => new Map( - rows.map((row) => [row.projectId, { tracker: row.tracker, scope: row.scope }] as const), + rows.map( + ({ projectId, additionalScopes, ...binding }) => + [ + projectId, + additionalScopes.length === 0 ? binding : { ...binding, additionalScopes }, + ] as const, + ), ), ), Effect.mapError(toSqlOrDecodeError("listIssueTrackerBindings", "IssueTrackerBinding")), ), set: Effect.fn("IssueTrackerBindingsRepository.set")( function* (input) { - yield* input.binding === null - ? sql`DELETE FROM issue_tracker_bindings WHERE project_id = ${input.projectId}` - : sql` - INSERT INTO issue_tracker_bindings (project_id, tracker, scope, updated_at) - VALUES (${input.projectId}, ${input.binding.tracker}, ${input.binding.scope}, ${input.updatedAt}) + if (input.binding === null) { + yield* sql`DELETE FROM issue_tracker_bindings WHERE project_id = ${input.projectId}`; + return; + } + const additionalScopes = yield* encodeAdditionalScopes( + input.binding.additionalScopes ?? [], + ); + yield* sql` + INSERT INTO issue_tracker_bindings (project_id, tracker, scope, additional_scopes, updated_at) + VALUES ( + ${input.projectId}, ${input.binding.tracker}, ${input.binding.scope}, + ${additionalScopes}, ${input.updatedAt} + ) ON CONFLICT (project_id) - DO UPDATE SET tracker = excluded.tracker, scope = excluded.scope, updated_at = excluded.updated_at + DO UPDATE SET tracker = excluded.tracker, scope = excluded.scope, + additional_scopes = excluded.additional_scopes, updated_at = excluded.updated_at `; }, - Effect.mapError( - (cause) => new PersistenceSqlError({ operation: "setIssueTrackerBinding", cause }), - ), + Effect.mapError(toSqlOrDecodeError("setIssueTrackerBinding", "IssueTrackerBinding")), ), removeTracker: Effect.fn("IssueTrackerBindingsRepository.removeTracker")( function* (tracker) { diff --git a/apps/server/src/persistence/Migrations.ts b/apps/server/src/persistence/Migrations.ts index 6f0b74e02960..39d13521240e 100644 --- a/apps/server/src/persistence/Migrations.ts +++ b/apps/server/src/persistence/Migrations.ts @@ -110,6 +110,7 @@ import Migration0099 from "./Migrations/099_BackgroundRecoveryIndexes.ts"; import Migration0100 from "./Migrations/100_TurnStartReadIndexes.ts"; import Migration0101 from "./Migrations/101_DelegatedTaskReadIndexes.ts"; import Migration0102 from "./Migrations/102_ThreadItemCounts.ts"; +import Migration0103 from "./Migrations/103_IssueTrackerAdditionalScopes.ts"; const migrationEntries = [ [1, "OrchestrationEvents", Migration0001], @@ -215,6 +216,7 @@ const migrationEntries = [ [100, "TurnStartReadIndexes", Migration0100], [101, "DelegatedTaskReadIndexes", Migration0101], [102, "ThreadItemCounts", Migration0102], + [103, "IssueTrackerAdditionalScopes", Migration0103], ] as const; export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const); diff --git a/apps/server/src/persistence/Migrations/103_IssueTrackerAdditionalScopes.test.ts b/apps/server/src/persistence/Migrations/103_IssueTrackerAdditionalScopes.test.ts new file mode 100644 index 000000000000..3ea190f41d2e --- /dev/null +++ b/apps/server/src/persistence/Migrations/103_IssueTrackerAdditionalScopes.test.ts @@ -0,0 +1,34 @@ +import { assert, it } from "@effect/vitest"; +import { IssueTrackerKind, ProjectId } from "@t3tools/contracts"; +import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient"; +import * as Effect from "effect/Effect"; +import * as SqlClient from "effect/sql/SqlClient"; + +import * as IssueTrackerBindings from "../IssueTrackerBindings.ts"; +import { runMigrations } from "../Migrations.ts"; + +it.layer(NodeSqliteClient.layer({ filename: ":memory:" }))( + "103_IssueTrackerAdditionalScopes", + (it) => { + it.effect("keeps a one-team binding and saves and replaces extra teams", () => + Effect.gen(function* () { + const sql = yield* SqlClient.SqlClient; + yield* runMigrations({ toMigrationInclusive: 102 }); + yield* sql`INSERT INTO issue_tracker_bindings VALUES ('web', 'linear', 'ENG', '2026-11-21')`; + yield* runMigrations(); + const bindings = yield* IssueTrackerBindings.IssueTrackerBindingsRepository.pipe( + Effect.provide(IssueTrackerBindings.layer), + ); + const projectId = ProjectId.make("web"); + const binding = { tracker: IssueTrackerKind.make("linear"), scope: "ENG" }; + const read = () => bindings.list.pipe(Effect.map((all) => all.get(projectId))); + assert.deepStrictEqual(yield* read(), binding); + const multi = { ...binding, additionalScopes: ["OPS", "DOCS"] }; + yield* bindings.set({ projectId, binding: multi, updatedAt: "2026-11-21" }); + assert.deepStrictEqual(yield* read(), multi); + yield* bindings.set({ projectId, binding, updatedAt: "2026-11-21" }); + assert.deepStrictEqual(yield* read(), binding); + }), + ); + }, +); diff --git a/apps/server/src/persistence/Migrations/103_IssueTrackerAdditionalScopes.ts b/apps/server/src/persistence/Migrations/103_IssueTrackerAdditionalScopes.ts new file mode 100644 index 000000000000..aa4656e52d29 --- /dev/null +++ b/apps/server/src/persistence/Migrations/103_IssueTrackerAdditionalScopes.ts @@ -0,0 +1,9 @@ +import * as Effect from "effect/Effect"; +import * as SqlClient from "effect/sql/SqlClient"; + +export default Effect.gen(function* () { + const sql = yield* SqlClient.SqlClient; + yield* sql` + ALTER TABLE issue_tracker_bindings ADD COLUMN additional_scopes TEXT NOT NULL DEFAULT '[]' + `; +}); diff --git a/apps/server/src/persistence/reconcileV2PreviewMigration.test.ts b/apps/server/src/persistence/reconcileV2PreviewMigration.test.ts index 1703789b6b47..07e921d5032e 100644 --- a/apps/server/src/persistence/reconcileV2PreviewMigration.test.ts +++ b/apps/server/src/persistence/reconcileV2PreviewMigration.test.ts @@ -82,6 +82,7 @@ describe("V2 preview upgrade", () => { [100, "TurnStartReadIndexes"], [101, "DelegatedTaskReadIndexes"], [102, "ThreadItemCounts"], + [103, "IssueTrackerAdditionalScopes"], ]); assert.deepStrictEqual(yield* runMigrations(), []); assert.deepStrictEqual(yield* sql`SELECT * FROM orchestration_v2_legacy_imports`, imports); @@ -207,6 +208,7 @@ describe("V2 preview upgrade", () => { [100, "TurnStartReadIndexes"], [101, "DelegatedTaskReadIndexes"], [102, "ThreadItemCounts"], + [103, "IssueTrackerAdditionalScopes"], ]); }).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))), ); diff --git a/apps/web/src/components/settings/IssueTrackerSettings.tsx b/apps/web/src/components/settings/IssueTrackerSettings.tsx index a397a84439f7..7a8e0a5283d6 100644 --- a/apps/web/src/components/settings/IssueTrackerSettings.tsx +++ b/apps/web/src/components/settings/IssueTrackerSettings.tsx @@ -1,5 +1,9 @@ import { useAtomValue } from "@effect/atom-react"; -import { issueTrackerSummary } from "@t3tools/client-runtime/state/issue-trackers"; +import { + boundIssueTrackerScopes, + issueTrackerBindingFor, + issueTrackerSummary, +} from "@t3tools/client-runtime/state/issue-trackers"; import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; import { T, useGT, useMessages } from "gt-react"; import { ChevronDownIcon, ExternalLinkIcon, XIcon } from "lucide-react"; @@ -34,11 +38,9 @@ const TRACKER_ICONS: Partial> = { linear: LinearIcon, }; -const UNBOUND = ""; - /** * Standalone issue trackers for one environment: connect each with a credential, and bind the - * environment's projects to one of the tracker's scopes so their issues list beside the git + * environment's projects to the tracker's scopes so their issues list beside the git * host's. Generic over the trackers the server reports; nothing here names Linear but its icon. */ export function IssueTrackerSettings({ environmentId }: { readonly environmentId: EnvironmentId }) { @@ -254,13 +256,13 @@ function ProjectBindings({ const [pending, setPending] = useState(null); if (projects.length === 0 || tracker.scopes.length === 0) return null; - const change = async (projectId: ProjectId, scope: string) => { + const change = async (projectId: ProjectId, scopes: ReadonlyArray) => { setPending(projectId); await bind({ environmentId, input: { projectId, - binding: scope === UNBOUND ? null : { tracker: tracker.tracker, scope }, + binding: issueTrackerBindingFor(tracker.tracker, bindings[projectId], scopes), }, }); setPending(null); @@ -271,25 +273,23 @@ function ProjectBindings({ {projects.map((project) => { - const bound = bindings[project.id]; // A project bound to another tracker keeps that binding; this picker shows it unbound. - const value = bound?.tracker === tracker.tracker ? bound.scope : UNBOUND; + const value = boundIssueTrackerScopes(tracker.tracker, bindings[project.id]); return ( { - if (next !== null) void change(project.id, next); - }} + onValueChange={(next) => void change(project.id, next)} > - {value === UNBOUND + {value.length === 0 ? gt("Not bound") - : (tracker.scopes.find((scope) => scope.key === value)?.name ?? value)} + : value + .map( + (key) => tracker.scopes.find((scope) => scope.key === key)?.name ?? key, + ) + .join(", ")} - - Not bound - {tracker.scopes.map((scope) => ( {scope.name} ({scope.key}) diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json index b9fa296bc143..a60714773567 100644 --- a/apps/web/src/i18n/translations/de.json +++ b/apps/web/src/i18n/translations/de.json @@ -8649,13 +8649,12 @@ "58e0e226493150e7": "Issue-Tracker konnten nicht geladen werden", "77cfcbde543df32d": "Details zu {tracker} ein-/ausblenden", "0083f65885c60156": "{tracker} trennen", - "15ad0159a826b290": "Wähle das {scope} in {tracker}, dessen Issues jedes Projekt neben denen seines eigenen Repositorys auflistet.", + "295392927d5c8a84": "Wähle für jedes Projekt ein oder mehrere {scope}s in {tracker}. Ihre Issues erscheinen neben denen des Repositorys, und Agenten legen neue Issues im ersten an.", "19c2d5e81ff8f89a": "{tracker} {scope} für {project}", "68e061510b765772": "Nicht zugeordnet", "a2d95d39d3398bda": "Anmeldedaten abgelehnt", "9eae463720500113": "Auf dem Server gespeichert.", "b6e27ab2537ef874": "Erstellen", - "e63611bd62fad8d8": "Nicht zugeordnet", "13ef526271b0f5d4": "Alle Bedingungen löschen", "d1938a629f039515": "Bedingung entfernen", "84a605b241ce65b7": "Gruppe und ihre Bedingungen entfernen", diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json index 76f76ae85bc8..233ae1b17d5a 100644 --- a/apps/web/src/i18n/translations/en.json +++ b/apps/web/src/i18n/translations/en.json @@ -8657,13 +8657,12 @@ "58e0e226493150e7": "Could not load issue trackers", "77cfcbde543df32d": "Toggle {tracker} details", "0083f65885c60156": "Disconnect {tracker}", - "15ad0159a826b290": "Pick the {tracker} {scope} whose issues each project lists beside its repository's own.", + "295392927d5c8a84": "Pick one or more {tracker} {scope}s for each project. Their issues list beside the repository's own, and agents file new issues in the first one.", "19c2d5e81ff8f89a": "{tracker} {scope} for {project}", "68e061510b765772": "Not bound", "a2d95d39d3398bda": "Credential rejected", "9eae463720500113": "Stored on the server.", "b6e27ab2537ef874": "Create one", - "e63611bd62fad8d8": "Not bound", "13ef526271b0f5d4": "Clear all conditions", "d1938a629f039515": "Remove condition", "84a605b241ce65b7": "Remove group and its conditions", diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json index d281df5925c3..1e85dbfdd21a 100644 --- a/apps/web/src/i18n/translations/es.json +++ b/apps/web/src/i18n/translations/es.json @@ -8647,13 +8647,12 @@ "58e0e226493150e7": "No se pudieron cargar los gestores de issues", "77cfcbde543df32d": "Mostrar u ocultar detalles de {tracker}", "0083f65885c60156": "Desconectar {tracker}", - "15ad0159a826b290": "Elige el {scope} de {tracker} cuyas issues lista cada proyecto junto a las de su propio repositorio.", + "295392927d5c8a84": "Elige uno o más {scope}s de {tracker} para cada proyecto. Sus issues aparecen junto a las del repositorio, y los agentes crean issues nuevas en el primero.", "19c2d5e81ff8f89a": "{scope} de {tracker} para {project}", "68e061510b765772": "Sin vincular", "a2d95d39d3398bda": "Credencial rechazada", "9eae463720500113": "Guardado en el servidor.", "b6e27ab2537ef874": "Crear uno", - "e63611bd62fad8d8": "Sin vincular", "13ef526271b0f5d4": "Borrar todas las condiciones", "d1938a629f039515": "Quitar condición", "84a605b241ce65b7": "Quitar grupo y sus condiciones", diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json index 90b389da3be8..936df90e37e3 100644 --- a/apps/web/src/i18n/translations/fr.json +++ b/apps/web/src/i18n/translations/fr.json @@ -8648,13 +8648,12 @@ "58e0e226493150e7": "Impossible de charger les gestionnaires de tickets", "77cfcbde543df32d": "Afficher ou masquer les détails de {tracker}", "0083f65885c60156": "Déconnecter {tracker}", - "15ad0159a826b290": "Choisissez le {scope} {tracker} dont chaque projet liste les tickets à côté de ceux de son propre dépôt.", + "295392927d5c8a84": "Choisissez un ou plusieurs {scope}s {tracker} pour chaque projet. Leurs tickets s'affichent à côté de ceux du dépôt, et les agents créent les nouveaux tickets dans le premier.", "19c2d5e81ff8f89a": "{scope} {tracker} pour {project}", "68e061510b765772": "Non lié", "a2d95d39d3398bda": "Identifiant refusé", "9eae463720500113": "Stocké sur le serveur.", "b6e27ab2537ef874": "En créer un", - "e63611bd62fad8d8": "Non lié", "13ef526271b0f5d4": "Effacer toutes les conditions", "d1938a629f039515": "Supprimer la condition", "84a605b241ce65b7": "Supprimer le groupe et ses conditions", diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json index e4b9041bebd9..170ecd9e212c 100644 --- a/apps/web/src/i18n/translations/ja.json +++ b/apps/web/src/i18n/translations/ja.json @@ -8605,13 +8605,12 @@ "58e0e226493150e7": "Issue トラッカーを読み込めませんでした", "77cfcbde543df32d": "{tracker} の詳細を切り替え", "0083f65885c60156": "{tracker} を切断", - "15ad0159a826b290": "各プロジェクトがリポジトリ自身の Issue と並べて一覧表示する {tracker} の {scope} を選択します。", + "295392927d5c8a84": "各プロジェクトに {tracker} の {scope} を1つ以上選択します。その Issue はリポジトリ自身の Issue と並べて表示され、エージェントは最初の {scope} に新しい Issue を作成します。", "19c2d5e81ff8f89a": "{project} の {tracker} {scope}", "68e061510b765772": "未バインド", "a2d95d39d3398bda": "資格情報が拒否されました", "9eae463720500113": "サーバーに保存されています。", "b6e27ab2537ef874": "作成する", - "e63611bd62fad8d8": "未バインド", "13ef526271b0f5d4": "すべての条件をクリア", "d1938a629f039515": "条件を削除", "84a605b241ce65b7": "グループとその条件を削除", diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json index 3094c42aee61..cb41dfe54463 100644 --- a/apps/web/src/i18n/translations/ko.json +++ b/apps/web/src/i18n/translations/ko.json @@ -8608,13 +8608,12 @@ "58e0e226493150e7": "이슈 트래커를 불러올 수 없습니다", "77cfcbde543df32d": "{tracker} 세부 정보 전환", "0083f65885c60156": "{tracker} 연결 끊기", - "15ad0159a826b290": "각 프로젝트가 저장소 자체 이슈와 함께 표시할 이슈의 {tracker} {scope}을(를) 선택하세요.", + "295392927d5c8a84": "각 프로젝트에 {tracker} {scope}을(를) 하나 이상 선택하세요. 해당 이슈는 저장소 자체 이슈와 함께 표시되며, 에이전트는 첫 번째 {scope}에 새 이슈를 만듭니다.", "19c2d5e81ff8f89a": "{project}의 {tracker} {scope}", "68e061510b765772": "바인딩되지 않음", "a2d95d39d3398bda": "자격 증명 거부됨", "9eae463720500113": "서버에 저장됩니다.", "b6e27ab2537ef874": "새로 만들기", - "e63611bd62fad8d8": "바인딩되지 않음", "13ef526271b0f5d4": "모든 조건 지우기", "d1938a629f039515": "조건 제거", "84a605b241ce65b7": "그룹과 조건 제거", diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json index 5db3d9957809..1903a5251d86 100644 --- a/apps/web/src/i18n/translations/pt-BR.json +++ b/apps/web/src/i18n/translations/pt-BR.json @@ -8647,13 +8647,12 @@ "58e0e226493150e7": "Não foi possível carregar os rastreadores de issues", "77cfcbde543df32d": "Mostrar ou ocultar detalhes de {tracker}", "0083f65885c60156": "Desconectar {tracker}", - "15ad0159a826b290": "Escolha o {scope} do {tracker} cujas issues cada projeto lista ao lado das do próprio repositório.", + "295392927d5c8a84": "Escolha um ou mais {scope}s do {tracker} para cada projeto. As issues deles aparecem ao lado das do repositório, e os agentes criam novas issues no primeiro.", "19c2d5e81ff8f89a": "{scope} do {tracker} para {project}", "68e061510b765772": "Não vinculado", "a2d95d39d3398bda": "Credencial recusada", "9eae463720500113": "Armazenado no servidor.", "b6e27ab2537ef874": "Criar um", - "e63611bd62fad8d8": "Não vinculado", "13ef526271b0f5d4": "Limpar todas as condições", "d1938a629f039515": "Remover condição", "84a605b241ce65b7": "Remover grupo e as condições dele", diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json index 67313be38d93..fd655a0e3dca 100644 --- a/apps/web/src/i18n/translations/ru.json +++ b/apps/web/src/i18n/translations/ru.json @@ -8649,13 +8649,12 @@ "58e0e226493150e7": "Не удалось загрузить issue-трекеры", "77cfcbde543df32d": "Показать или скрыть подробности {tracker}", "0083f65885c60156": "Отключить {tracker}", - "15ad0159a826b290": "Выберите {scope} в {tracker}, issue которого каждый проект показывает рядом с issue своего репозитория.", + "295392927d5c8a84": "Выберите один или несколько {scope} в {tracker} для каждого проекта. Их issue показываются рядом с issue репозитория, а агенты создают новые issue в первом.", "19c2d5e81ff8f89a": "{tracker} {scope} для {project}", "68e061510b765772": "Не привязано", "a2d95d39d3398bda": "Учётные данные отклонены", "9eae463720500113": "Хранится на сервере.", "b6e27ab2537ef874": "Создать", - "e63611bd62fad8d8": "Не привязано", "13ef526271b0f5d4": "Очистить все условия", "d1938a629f039515": "Удалить условие", "84a605b241ce65b7": "Удалить группу и её условия", diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json index d47161cbd787..51aab1b3dd67 100644 --- a/apps/web/src/i18n/translations/sv.json +++ b/apps/web/src/i18n/translations/sv.json @@ -8655,13 +8655,12 @@ "58e0e226493150e7": "Kunde inte läsa in ärendehanterare", "77cfcbde543df32d": "Visa/dölj detaljer för {tracker}", "0083f65885c60156": "Koppla från {tracker}", - "15ad0159a826b290": "Välj den {scope} i {tracker} vars ärenden varje projekt listar bredvid repots egna.", + "295392927d5c8a84": "Välj en eller flera {scope} i {tracker} för varje projekt. Deras ärenden listas bredvid repots egna, och agenter skapar nya ärenden i den första.", "19c2d5e81ff8f89a": "{scope} i {tracker} för {project}", "68e061510b765772": "Inte kopplad", "a2d95d39d3398bda": "Autentiseringsuppgiften avvisades", "9eae463720500113": "Lagras på servern.", "b6e27ab2537ef874": "Skapa en", - "e63611bd62fad8d8": "Inte kopplad", "13ef526271b0f5d4": "Rensa alla villkor", "d1938a629f039515": "Ta bort villkor", "84a605b241ce65b7": "Ta bort gruppen och dess villkor", diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json index 9cfaafd041c4..6f4cc0523213 100644 --- a/apps/web/src/i18n/translations/zh.json +++ b/apps/web/src/i18n/translations/zh.json @@ -8665,13 +8665,12 @@ "58e0e226493150e7": "无法加载 issue 跟踪器", "77cfcbde543df32d": "切换 {tracker} 详情", "0083f65885c60156": "断开 {tracker} 连接", - "15ad0159a826b290": "选择 {tracker} {scope},每个项目会在其仓库自身的 issue 旁列出它的 issue。", + "295392927d5c8a84": "为每个项目选择一个或多个 {tracker} {scope}。它们的 issue 会列在仓库自身的 issue 旁,智能体会在第一个中创建新 issue。", "19c2d5e81ff8f89a": "{project} 的 {tracker} {scope}", "68e061510b765772": "未绑定", "a2d95d39d3398bda": "凭据被拒绝", "9eae463720500113": "存储在服务器上。", "b6e27ab2537ef874": "创建一个", - "e63611bd62fad8d8": "未绑定", "13ef526271b0f5d4": "清除所有条件", "d1938a629f039515": "移除条件", "84a605b241ce65b7": "移除条件组及其条件", diff --git a/docs/user/source-control.md b/docs/user/source-control.md index 1bd54659eb5a..7ff64cd24b44 100644 --- a/docs/user/source-control.md +++ b/docs/user/source-control.md @@ -375,8 +375,11 @@ The search box asks the tracker itself where it can search. Press **Load more** The **Views** menu saves and restores a search, filter, and sort setup, as it does for pull requests. -To list a Linear team's issues beside a project's, connect Linear with an API key under -Settings → Source control & issues, then choose the team for that project there. +To list Linear issues beside a project's, connect Linear with an API key under +Settings → Source control & issues, then pick one or more teams for that project there. Pick +another team at any time to add it; uncheck every team to unbind the project. Each team's +issues appear in the Linear group of the issue list, sorted with the rest by last update, and +each can be loaded further on its own. Agents file new issues in the first team picked. Select an issue to open it beside the list: description, comments, state changes, linked pull requests, labels, assignees, and reactions. Linked pull requests open in the same panel. You can diff --git a/packages/client-runtime/src/issueLinks.test.ts b/packages/client-runtime/src/issueLinks.test.ts index ff9fabfc8964..66909fad1f05 100644 --- a/packages/client-runtime/src/issueLinks.test.ts +++ b/packages/client-runtime/src/issueLinks.test.ts @@ -97,7 +97,11 @@ describe("resolveIssueLinkTarget", () => { ], bindings: { [ProjectId.make("p1")]: { tracker: IssueTrackerKind.make("linear"), scope: "API" }, - [ProjectId.make("p2")]: { tracker: IssueTrackerKind.make("linear"), scope: "WEB" }, + [ProjectId.make("p2")]: { + tracker: IssueTrackerKind.make("linear"), + scope: "WEB", + additionalScopes: ["DOCS"], + }, }, }; const resolve = (url: string) => resolveIssueLinkTarget({ url, projects, trackers }); @@ -108,6 +112,10 @@ describe("resolveIssueLinkTarget", () => { scope: "WEB", key: "WEB-17", }); + expect(resolve("https://linear.app/acme/issue/DOCS-4")?.ref).toMatchObject({ + projectId: "p2", + scope: "DOCS", + }); expect(resolve("https://linear.app/acme/issue/OPS-3")?.ref).toMatchObject({ projectId: "p1", scope: "OPS", diff --git a/packages/client-runtime/src/issueLinks.ts b/packages/client-runtime/src/issueLinks.ts index 311d7e998262..0b442d18c92b 100644 --- a/packages/client-runtime/src/issueLinks.ts +++ b/packages/client-runtime/src/issueLinks.ts @@ -1,5 +1,6 @@ import { IssueTrackerKind, + issueTrackerBindingScopes, type IssueRef, type IssueTrackerConnectionList, } from "@t3tools/contracts"; @@ -93,9 +94,9 @@ function resolveStandaloneIssueLink( const preferFirst = (candidates: typeof onTracker) => candidates.find((candidate) => candidate.project.id === preferredProjectId) ?? candidates[0]; const scope = link.scope.toLowerCase(); - const own = preferFirst( - onTracker.filter((candidate) => candidate.binding.scope.toLowerCase() === scope), - ); + const boundScope = (candidate: (typeof onTracker)[number]) => + issueTrackerBindingScopes(candidate.binding).find((key) => key.toLowerCase() === scope); + const own = preferFirst(onTracker.filter((candidate) => boundScope(candidate) !== undefined)); const lender = own ?? preferFirst(onTracker); if (lender === undefined) return null; return { @@ -104,7 +105,7 @@ function resolveStandaloneIssueLink( projectId: lender.project.id, tracker: lender.binding.tracker, host: link.host, - scope: own === undefined ? link.scope : lender.binding.scope, + scope: (own && boundScope(own)) ?? link.scope, key: link.key, }, }; diff --git a/packages/client-runtime/src/state/issueTrackers.ts b/packages/client-runtime/src/state/issueTrackers.ts index 045f283f310e..d8e1e6f7f0b7 100644 --- a/packages/client-runtime/src/state/issueTrackers.ts +++ b/packages/client-runtime/src/state/issueTrackers.ts @@ -1,7 +1,10 @@ import { WS_METHODS, + issueTrackerBindingScopes, type IssueTrackerConnection, type IssueTrackerConnectionList, + type IssueTrackerKind, + type IssueTrackerProjectBinding, } from "@t3tools/contracts"; import * as Effect from "effect/Effect"; import { Atom } from "effect/reactivity"; @@ -115,3 +118,21 @@ export function issueTrackerSummary( ), ); } + +export function boundIssueTrackerScopes( + tracker: IssueTrackerKind, + binding: IssueTrackerProjectBinding | undefined, +): ReadonlyArray { + return binding?.tracker === tracker ? issueTrackerBindingScopes(binding) : []; +} + +export function issueTrackerBindingFor( + tracker: IssueTrackerKind, + binding: IssueTrackerProjectBinding | undefined, + scopes: ReadonlyArray, +): IssueTrackerProjectBinding | null { + const kept = boundIssueTrackerScopes(tracker, binding).filter((key) => scopes.includes(key)); + const [scope, ...additionalScopes] = [...kept, ...scopes.filter((key) => !kept.includes(key))]; + if (scope === undefined) return null; + return additionalScopes.length === 0 ? { tracker, scope } : { tracker, scope, additionalScopes }; +} diff --git a/packages/contracts/src/issue.ts b/packages/contracts/src/issue.ts index b17911da295e..38c091e1b95d 100644 --- a/packages/contracts/src/issue.ts +++ b/packages/contracts/src/issue.ts @@ -572,13 +572,24 @@ export const StandaloneIssueTrackerDescriptor = Schema.Struct({ }); export type StandaloneIssueTrackerDescriptor = typeof StandaloneIssueTrackerDescriptor.Type; -/** Which standalone tracker scope a project's issues come from, beside its git host's own. */ +/** + * Which standalone tracker scopes a project's issues come from, beside its git host's own. + * `scope` is where agents file new issues; `additionalScopes` are listed and written too. + */ export const IssueTrackerProjectBinding = Schema.Struct({ tracker: IssueTrackerKind, scope: TrimmedNonEmptyString, + additionalScopes: Schema.optionalKey( + Schema.Array(TrimmedNonEmptyString).check(Schema.isMaxLength(50)), + ), }); export type IssueTrackerProjectBinding = typeof IssueTrackerProjectBinding.Type; +export const issueTrackerBindingScopes = (binding: IssueTrackerProjectBinding) => [ + binding.scope, + ...(binding.additionalScopes ?? []), +]; + /** One container the connected account can read, offered when a project is bound. */ export const IssueTrackerScope = Schema.Struct({ key: TrimmedNonEmptyString, @@ -606,7 +617,7 @@ export type IssueTrackerConnection = typeof IssueTrackerConnection.Type; export const IssueTrackerConnectionList = Schema.Struct({ trackers: Schema.Array(IssueTrackerConnection), - /** Which standalone tracker scope each bound project reads; a project absent here reads none. */ + /** Which standalone tracker scopes each bound project reads; a project absent here reads none. */ bindings: Schema.Record(ProjectId, IssueTrackerProjectBinding), }); export type IssueTrackerConnectionList = typeof IssueTrackerConnectionList.Type; From db48bcedc1b4ecd58ebba1464e53ac59de103d09 Mon Sep 17 00:00:00 2001 From: Bil0000 <62337003+Bil0000@users.noreply.github.com> Date: Sat, 21 Nov 2026 02:57:31 +0100 Subject: [PATCH 2/3] fix(issues): team pickers keep each pick until the server shows it A pick locks the project pickers until its save and the refresh after it finish, so a fast second pick or a save from another client is not lost. Teams Linear no longer lists stay removable, pickers still show when only a binding remains, the team cap is shared with the schema, and web options show checkboxes. --- ...ettingsSourceControlDetailRouteScreens.tsx | 9 ++- .../components/IssueTrackerSection.tsx | 39 ++++++----- .../settings/IssueTrackerSettings.tsx | 66 ++++++++++++++----- .../src/state/issueTrackers.test.ts | 36 ++++++++++ .../client-runtime/src/state/issueTrackers.ts | 33 +++++++++- packages/contracts/src/issue.ts | 6 +- 6 files changed, 152 insertions(+), 37 deletions(-) create mode 100644 packages/client-runtime/src/state/issueTrackers.test.ts diff --git a/apps/mobile/src/features/settings/SettingsSourceControlDetailRouteScreens.tsx b/apps/mobile/src/features/settings/SettingsSourceControlDetailRouteScreens.tsx index d786f8c106be..f368dcca2dfc 100644 --- a/apps/mobile/src/features/settings/SettingsSourceControlDetailRouteScreens.tsx +++ b/apps/mobile/src/features/settings/SettingsSourceControlDetailRouteScreens.tsx @@ -1,6 +1,9 @@ import { useAtomValue } from "@effect/atom-react"; import type { StaticScreenProps } from "@react-navigation/native"; -import { issueTrackerSummary } from "@t3tools/client-runtime/state/issue-trackers"; +import { + hasIssueTrackerTeams, + issueTrackerSummary, +} from "@t3tools/client-runtime/state/issue-trackers"; import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients"; import { AuthSettingsWriteScope, @@ -192,7 +195,7 @@ export function SettingsIssueTrackerRouteScreen({ disabled={disabled} /> - {usable && tracker.scopes.length > 0 ? ( + {usable && hasIssueTrackerTeams(tracker, query.data?.bindings ?? {}) ? ( diff --git a/apps/mobile/src/features/settings/components/IssueTrackerSection.tsx b/apps/mobile/src/features/settings/components/IssueTrackerSection.tsx index 377f5ba92b6f..cc914adae5d7 100644 --- a/apps/mobile/src/features/settings/components/IssueTrackerSection.tsx +++ b/apps/mobile/src/features/settings/components/IssueTrackerSection.tsx @@ -1,7 +1,9 @@ import { boundIssueTrackerScopes, issueTrackerBindingFor, + issueTrackerScopeOptions, issueTrackerSummary, + type IssueTrackerPick, } from "@t3tools/client-runtime/state/issue-trackers"; import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; import type { @@ -214,6 +216,8 @@ export function IssueTrackerProjectRows(props: { readonly environmentId: EnvironmentId; readonly tracker: IssueTrackerConnection; readonly bindings: IssueTrackerConnectionList["bindings"]; + readonly refreshing: boolean; + readonly refreshFailed: boolean; readonly disabled: boolean; }) { const gt = useGT(); @@ -222,29 +226,34 @@ export function IssueTrackerProjectRows(props: { label: `bind project to ${tracker.displayName}`, }); const projects = useProjects().filter((project) => project.environmentId === environmentId); - const [binding, setBinding] = useState(null); + const [pick, setPick] = useState(null); + const [saving, setSaving] = useState(false); + if (pick !== null && !saving && !props.refreshing && !props.refreshFailed) setPick(null); + const busy = saving || (pick !== null && props.refreshing); + const bound = (projectId: ProjectId) => + pick?.projectId === projectId + ? pick.scopes + : boundIssueTrackerScopes(tracker.tracker, props.bindings[projectId]); const change = async (projectId: ProjectId, scopes: ReadonlyArray) => { - if (props.disabled || binding !== null) return; - setBinding(projectId); - await bind({ - environmentId, - input: { - projectId, - binding: issueTrackerBindingFor(tracker.tracker, props.bindings[projectId], scopes), - }, - }); - setBinding(null); + if (props.disabled || busy) return; + const binding = issueTrackerBindingFor(tracker.tracker, bound(projectId), scopes); + setSaving(true); + setPick({ projectId, scopes: boundIssueTrackerScopes(tracker.tracker, binding ?? undefined) }); + const result = await bind({ environmentId, input: { projectId, binding } }); + if (result._tag !== "Success") setPick(null); + setSaving(false); }; return projects.map((project) => { // A project bound to another tracker keeps that binding; this row shows it unbound. - const value = boundIssueTrackerScopes(tracker.tracker, props.bindings[project.id]); + const value = bound(project.id); + const options = issueTrackerScopeOptions(tracker, value); const toggle = (key: string) => key === UNBOUND ? [] : value.includes(key) ? value.filter((scope) => scope !== key) : [...value, key]; - const locked = props.disabled || binding !== null; + const locked = props.disabled || busy; return ( ({ + ...options.map((scope) => ({ id: scope.key, title: `${scope.name} (${scope.key})`, state: value.includes(scope.key) ? ("on" as const) : ("off" as const), - attributes: { disabled: locked }, + attributes: { disabled: locked || !scope.addable }, })), ]} onPressAction={({ nativeEvent }) => void change(project.id, toggle(nativeEvent.event))} diff --git a/apps/web/src/components/settings/IssueTrackerSettings.tsx b/apps/web/src/components/settings/IssueTrackerSettings.tsx index 7a8e0a5283d6..1ae3821bf4d7 100644 --- a/apps/web/src/components/settings/IssueTrackerSettings.tsx +++ b/apps/web/src/components/settings/IssueTrackerSettings.tsx @@ -2,7 +2,10 @@ import { useAtomValue } from "@effect/atom-react"; import { boundIssueTrackerScopes, issueTrackerBindingFor, + issueTrackerScopeOptions, issueTrackerSummary, + hasIssueTrackerTeams, + type IssueTrackerPick, } from "@t3tools/client-runtime/state/issue-trackers"; import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; import { T, useGT, useMessages } from "gt-react"; @@ -23,6 +26,7 @@ import { LinearIcon } from "../Icons"; import { cn } from "~/lib/utils"; import { Badge } from "../ui/badge"; +import { CheckboxMark } from "../ui/checkbox"; import { Button, InlineButton } from "../ui/button"; import { Collapsible, CollapsibleContent } from "../ui/collapsible"; import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select"; @@ -86,6 +90,8 @@ export function IssueTrackerSettings({ environmentId }: { readonly environmentId environmentId={environmentId} tracker={tracker} bindings={query.data?.bindings ?? {}} + refreshing={query.isPending} + refreshFailed={query.error !== null} /> ))} @@ -96,10 +102,14 @@ function TrackerRow({ environmentId, tracker, bindings, + refreshing, + refreshFailed, }: { readonly environmentId: EnvironmentId; readonly tracker: IssueTrackerConnection; readonly bindings: IssueTrackerConnectionList["bindings"]; + readonly refreshing: boolean; + readonly refreshFailed: boolean; }) { const gt = useGT(); const messages = useMessages(); @@ -168,7 +178,8 @@ function TrackerRow({ - + {/* Kept mounted so a pick awaiting its refresh stays locked when the panel is reopened. */} + {/* Locked while saving, so an edit made mid-request is not overwritten by the saved value. */}
@@ -228,6 +239,8 @@ function TrackerRow({ environmentId={environmentId} tracker={tracker} bindings={bindings} + refreshing={refreshing} + refreshFailed={refreshFailed} /> ) : null}
@@ -243,29 +256,38 @@ function ProjectBindings({ environmentId, tracker, bindings, + refreshing, + refreshFailed, }: { readonly environmentId: EnvironmentId; readonly tracker: IssueTrackerConnection; readonly bindings: IssueTrackerConnectionList["bindings"]; + readonly refreshing: boolean; + readonly refreshFailed: boolean; }) { const gt = useGT(); const projects = useProjects().filter((project) => project.environmentId === environmentId); const bind = useAtomCommand(issueTrackerEnvironment.bindProject, { label: `bind project to ${tracker.displayName}`, }); - const [pending, setPending] = useState(null); - if (projects.length === 0 || tracker.scopes.length === 0) return null; + const [pick, setPick] = useState(null); + const [saving, setSaving] = useState(false); + if (pick !== null && !saving && !refreshing && !refreshFailed) setPick(null); + const busy = saving || (pick !== null && refreshing); + const bound = (projectId: ProjectId) => + pick?.projectId === projectId + ? pick.scopes + : boundIssueTrackerScopes(tracker.tracker, bindings[projectId]); + if (projects.length === 0 || !hasIssueTrackerTeams(tracker, bindings)) return null; const change = async (projectId: ProjectId, scopes: ReadonlyArray) => { - setPending(projectId); - await bind({ - environmentId, - input: { - projectId, - binding: issueTrackerBindingFor(tracker.tracker, bindings[projectId], scopes), - }, - }); - setPending(null); + if (busy) return; + const binding = issueTrackerBindingFor(tracker.tracker, bound(projectId), scopes); + setSaving(true); + setPick({ projectId, scopes: boundIssueTrackerScopes(tracker.tracker, binding ?? undefined) }); + const result = await bind({ environmentId, input: { projectId, binding } }); + if (result._tag !== "Success") setPick(null); + setSaving(false); }; return ( @@ -279,7 +301,8 @@ function ProjectBindings({ /> {projects.map((project) => { // A project bound to another tracker keeps that binding; this picker shows it unbound. - const value = boundIssueTrackerScopes(tracker.tracker, bindings[project.id]); + const value = bound(project.id); + const options = issueTrackerScopeOptions(tracker, value); return ( void change(project.id, next)} > - {tracker.scopes.map((scope) => ( - - {scope.name} ({scope.key}) + {options.map((scope) => ( + + + + {scope.name} ({scope.key}) + ))} diff --git a/packages/client-runtime/src/state/issueTrackers.test.ts b/packages/client-runtime/src/state/issueTrackers.test.ts new file mode 100644 index 000000000000..32d459bf79ed --- /dev/null +++ b/packages/client-runtime/src/state/issueTrackers.test.ts @@ -0,0 +1,36 @@ +import { IssueTrackerKind, MAX_ISSUE_TRACKER_ADDITIONAL_SCOPES } from "@t3tools/contracts"; +import { describe, expect, it } from "vite-plus/test"; + +import { issueTrackerScopeOptions } from "./issueTrackers.ts"; + +describe("issueTrackerScopeOptions", () => { + it("offers no new team once the binding is full, and keeps bound ones removable", () => { + const tracker = { + tracker: IssueTrackerKind.make("linear"), + displayName: "Linear", + host: "linear.app", + scopeNoun: "team", + credential: { label: "Personal API key", helpUrl: null }, + connected: true, + account: "demo", + detail: null, + scopes: [ + { key: "ENG", name: "Engineering" }, + { key: "OPS", name: "Operations" }, + ], + }; + const full = [ + "ENG", + ...Array.from({ length: MAX_ISSUE_TRACKER_ADDITIONAL_SCOPES }, (_, i) => `T${i}`), + ]; + const options = issueTrackerScopeOptions(tracker, full); + expect(options.find((scope) => scope.key === "OPS")?.addable).toBe(false); + expect(options.find((scope) => scope.key === "ENG")?.addable).toBe(true); + expect(options.find((scope) => scope.key === "T0")).toEqual({ + key: "T0", + name: "T0", + addable: true, + }); + expect(issueTrackerScopeOptions(tracker, ["ENG"]).every((scope) => scope.addable)).toBe(true); + }); +}); diff --git a/packages/client-runtime/src/state/issueTrackers.ts b/packages/client-runtime/src/state/issueTrackers.ts index d8e1e6f7f0b7..f3232b64d0e4 100644 --- a/packages/client-runtime/src/state/issueTrackers.ts +++ b/packages/client-runtime/src/state/issueTrackers.ts @@ -1,10 +1,12 @@ import { + MAX_ISSUE_TRACKER_ADDITIONAL_SCOPES, WS_METHODS, issueTrackerBindingScopes, type IssueTrackerConnection, type IssueTrackerConnectionList, type IssueTrackerKind, type IssueTrackerProjectBinding, + type ProjectId, } from "@t3tools/contracts"; import * as Effect from "effect/Effect"; import { Atom } from "effect/reactivity"; @@ -128,11 +130,38 @@ export function boundIssueTrackerScopes( export function issueTrackerBindingFor( tracker: IssueTrackerKind, - binding: IssueTrackerProjectBinding | undefined, + current: ReadonlyArray, scopes: ReadonlyArray, ): IssueTrackerProjectBinding | null { - const kept = boundIssueTrackerScopes(tracker, binding).filter((key) => scopes.includes(key)); + const kept = current.filter((key) => scopes.includes(key)); const [scope, ...additionalScopes] = [...kept, ...scopes.filter((key) => !kept.includes(key))]; if (scope === undefined) return null; return additionalScopes.length === 0 ? { tracker, scope } : { tracker, scope, additionalScopes }; } + +export interface IssueTrackerPick { + readonly projectId: ProjectId; + readonly scopes: ReadonlyArray; +} + +export function issueTrackerScopeOptions( + tracker: IssueTrackerConnection, + bound: ReadonlyArray, +): ReadonlyArray<{ readonly key: string; readonly name: string; readonly addable: boolean }> { + const offered = new Set(tracker.scopes.map((scope) => scope.key)); + const full = bound.length > MAX_ISSUE_TRACKER_ADDITIONAL_SCOPES; + return [ + ...tracker.scopes, + ...bound.filter((key) => !offered.has(key)).map((key) => ({ key, name: key })), + ].map((scope) => ({ ...scope, addable: !full || bound.includes(scope.key) })); +} + +export function hasIssueTrackerTeams( + tracker: IssueTrackerConnection, + bindings: IssueTrackerConnectionList["bindings"], +): boolean { + return ( + tracker.scopes.length > 0 || + Object.values(bindings).some((binding) => binding.tracker === tracker.tracker) + ); +} diff --git a/packages/contracts/src/issue.ts b/packages/contracts/src/issue.ts index 38c091e1b95d..78b0cbb04b85 100644 --- a/packages/contracts/src/issue.ts +++ b/packages/contracts/src/issue.ts @@ -572,6 +572,8 @@ export const StandaloneIssueTrackerDescriptor = Schema.Struct({ }); export type StandaloneIssueTrackerDescriptor = typeof StandaloneIssueTrackerDescriptor.Type; +export const MAX_ISSUE_TRACKER_ADDITIONAL_SCOPES = 250; + /** * Which standalone tracker scopes a project's issues come from, beside its git host's own. * `scope` is where agents file new issues; `additionalScopes` are listed and written too. @@ -580,7 +582,9 @@ export const IssueTrackerProjectBinding = Schema.Struct({ tracker: IssueTrackerKind, scope: TrimmedNonEmptyString, additionalScopes: Schema.optionalKey( - Schema.Array(TrimmedNonEmptyString).check(Schema.isMaxLength(50)), + Schema.Array(TrimmedNonEmptyString).check( + Schema.isMaxLength(MAX_ISSUE_TRACKER_ADDITIONAL_SCOPES), + ), ), }); export type IssueTrackerProjectBinding = typeof IssueTrackerProjectBinding.Type; From 62260beec7af1849aeebf1addc71de71d7af1700 Mon Sep 17 00:00:00 2001 From: Bil0000 <62337003+Bil0000@users.noreply.github.com> Date: Sat, 21 Nov 2026 03:23:22 +0100 Subject: [PATCH 3/3] fix(issues): each project keeps its own pending team pick A failed refresh no longer lets an edit to one project drop the unconfirmed teams of another. --- .../components/IssueTrackerSection.tsx | 20 ++++++++++--------- .../settings/IssueTrackerSettings.tsx | 20 ++++++++++--------- .../client-runtime/src/state/issueTrackers.ts | 6 ------ 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/apps/mobile/src/features/settings/components/IssueTrackerSection.tsx b/apps/mobile/src/features/settings/components/IssueTrackerSection.tsx index cc914adae5d7..285a9e801ab6 100644 --- a/apps/mobile/src/features/settings/components/IssueTrackerSection.tsx +++ b/apps/mobile/src/features/settings/components/IssueTrackerSection.tsx @@ -3,7 +3,6 @@ import { issueTrackerBindingFor, issueTrackerScopeOptions, issueTrackerSummary, - type IssueTrackerPick, } from "@t3tools/client-runtime/state/issue-trackers"; import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; import type { @@ -226,21 +225,24 @@ export function IssueTrackerProjectRows(props: { label: `bind project to ${tracker.displayName}`, }); const projects = useProjects().filter((project) => project.environmentId === environmentId); - const [pick, setPick] = useState(null); + const [picks, setPicks] = useState>>>({}); const [saving, setSaving] = useState(false); - if (pick !== null && !saving && !props.refreshing && !props.refreshFailed) setPick(null); - const busy = saving || (pick !== null && props.refreshing); + const held = Object.values(picks).some((scopes) => scopes !== undefined); + if (held && !saving && !props.refreshing && !props.refreshFailed) setPicks({}); + const busy = saving || (held && props.refreshing); const bound = (projectId: ProjectId) => - pick?.projectId === projectId - ? pick.scopes - : boundIssueTrackerScopes(tracker.tracker, props.bindings[projectId]); + picks[projectId] ?? boundIssueTrackerScopes(tracker.tracker, props.bindings[projectId]); const change = async (projectId: ProjectId, scopes: ReadonlyArray) => { if (props.disabled || busy) return; const binding = issueTrackerBindingFor(tracker.tracker, bound(projectId), scopes); + const before = picks[projectId]; setSaving(true); - setPick({ projectId, scopes: boundIssueTrackerScopes(tracker.tracker, binding ?? undefined) }); + setPicks((current) => ({ + ...current, + [projectId]: boundIssueTrackerScopes(tracker.tracker, binding ?? undefined), + })); const result = await bind({ environmentId, input: { projectId, binding } }); - if (result._tag !== "Success") setPick(null); + if (result._tag !== "Success") setPicks((current) => ({ ...current, [projectId]: before })); setSaving(false); }; return projects.map((project) => { diff --git a/apps/web/src/components/settings/IssueTrackerSettings.tsx b/apps/web/src/components/settings/IssueTrackerSettings.tsx index 1ae3821bf4d7..1bf3e2466f83 100644 --- a/apps/web/src/components/settings/IssueTrackerSettings.tsx +++ b/apps/web/src/components/settings/IssueTrackerSettings.tsx @@ -5,7 +5,6 @@ import { issueTrackerScopeOptions, issueTrackerSummary, hasIssueTrackerTeams, - type IssueTrackerPick, } from "@t3tools/client-runtime/state/issue-trackers"; import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; import { T, useGT, useMessages } from "gt-react"; @@ -270,23 +269,26 @@ function ProjectBindings({ const bind = useAtomCommand(issueTrackerEnvironment.bindProject, { label: `bind project to ${tracker.displayName}`, }); - const [pick, setPick] = useState(null); + const [picks, setPicks] = useState>>>({}); const [saving, setSaving] = useState(false); - if (pick !== null && !saving && !refreshing && !refreshFailed) setPick(null); - const busy = saving || (pick !== null && refreshing); + const held = Object.values(picks).some((scopes) => scopes !== undefined); + if (held && !saving && !refreshing && !refreshFailed) setPicks({}); + const busy = saving || (held && refreshing); const bound = (projectId: ProjectId) => - pick?.projectId === projectId - ? pick.scopes - : boundIssueTrackerScopes(tracker.tracker, bindings[projectId]); + picks[projectId] ?? boundIssueTrackerScopes(tracker.tracker, bindings[projectId]); if (projects.length === 0 || !hasIssueTrackerTeams(tracker, bindings)) return null; const change = async (projectId: ProjectId, scopes: ReadonlyArray) => { if (busy) return; const binding = issueTrackerBindingFor(tracker.tracker, bound(projectId), scopes); + const before = picks[projectId]; setSaving(true); - setPick({ projectId, scopes: boundIssueTrackerScopes(tracker.tracker, binding ?? undefined) }); + setPicks((current) => ({ + ...current, + [projectId]: boundIssueTrackerScopes(tracker.tracker, binding ?? undefined), + })); const result = await bind({ environmentId, input: { projectId, binding } }); - if (result._tag !== "Success") setPick(null); + if (result._tag !== "Success") setPicks((current) => ({ ...current, [projectId]: before })); setSaving(false); }; diff --git a/packages/client-runtime/src/state/issueTrackers.ts b/packages/client-runtime/src/state/issueTrackers.ts index f3232b64d0e4..a4bb5187f840 100644 --- a/packages/client-runtime/src/state/issueTrackers.ts +++ b/packages/client-runtime/src/state/issueTrackers.ts @@ -6,7 +6,6 @@ import { type IssueTrackerConnectionList, type IssueTrackerKind, type IssueTrackerProjectBinding, - type ProjectId, } from "@t3tools/contracts"; import * as Effect from "effect/Effect"; import { Atom } from "effect/reactivity"; @@ -139,11 +138,6 @@ export function issueTrackerBindingFor( return additionalScopes.length === 0 ? { tracker, scope } : { tracker, scope, additionalScopes }; } -export interface IssueTrackerPick { - readonly projectId: ProjectId; - readonly scopes: ReadonlyArray; -} - export function issueTrackerScopeOptions( tracker: IssueTrackerConnection, bound: ReadonlyArray,