From 6a9be249f50a73b3da68732fdc0b6a9f2009a90b Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Tue, 26 May 2026 20:07:03 -0700 Subject: [PATCH] feat: add external task filter links (#2871) --- src/main/linear/teams.ts | 8 +- src/renderer/src/components/TaskPage.tsx | 149 +++++++++++++++--- .../src/components/ui/team-multi-combobox.tsx | 11 +- src/renderer/src/lib/github-links.test.ts | 15 ++ src/renderer/src/lib/github-links.ts | 7 + src/shared/linear-links.test.ts | 23 +++ src/shared/linear-links.ts | 26 +++ src/shared/types.ts | 1 + 8 files changed, 213 insertions(+), 27 deletions(-) create mode 100644 src/shared/linear-links.test.ts create mode 100644 src/shared/linear-links.ts diff --git a/src/main/linear/teams.ts b/src/main/linear/teams.ts index 4e0c7b012..73913dec7 100644 --- a/src/main/linear/teams.ts +++ b/src/main/linear/teams.ts @@ -5,6 +5,7 @@ import type { LinearMember, LinearWorkspaceSelection } from '../../shared/types' +import { buildLinearTeamUrl } from '../../shared/linear-links' import { acquire, release, getClients, isAuthError, clearToken } from './client' export async function listTeams( @@ -25,7 +26,12 @@ export async function listTeams( workspaceId: entry.workspace.id, workspaceName: entry.workspace.organizationName, name: t.name, - key: t.key + key: t.key, + url: + buildLinearTeamUrl({ + organizationUrlKey: entry.workspace.organizationUrlKey, + teamKey: t.key + }) ?? undefined })) } catch (error) { if (isAuthError(error)) { diff --git a/src/renderer/src/components/TaskPage.tsx b/src/renderer/src/components/TaskPage.tsx index 8ac129ee3..623d08356 100644 --- a/src/renderer/src/components/TaskPage.tsx +++ b/src/renderer/src/components/TaskPage.tsx @@ -88,8 +88,12 @@ import { getLinearStatePillStyle } from '@/components/linear-state-pill-style' import { parseTaskQuery, stripRepoQualifiers, withQualifier } from '../../../shared/task-query' +import { + buildLinearTeamUrl, + getLinearOrganizationUrlKeyFromIssueUrl +} from '../../../shared/linear-links' import PRFilterDropdowns, { type PRFilterChange } from '@/components/github/PRFilterDropdowns' -import { parseGitHubIssueOrPRLink } from '@/lib/github-links' +import { buildGitHubRepoUrl, parseGitHubIssueOrPRLink } from '@/lib/github-links' import { useRepoAssigneesBySlug } from '@/hooks/useGitHubSlugMetadata' import GitHubItemDialog, { type ItemDialogTab } from '@/components/GitHubItemDialog' import PullRequestPage from '@/components/PullRequestPage' @@ -2832,7 +2836,12 @@ export default function TaskPage(): React.JSX.Element { workspaceId: issue.workspaceId, workspaceName: issue.workspaceName, name: issue.team.name, - key: issue.team.key + key: issue.team.key, + url: + buildLinearTeamUrl({ + organizationUrlKey: getLinearOrganizationUrlKeyFromIssueUrl(issue.url), + teamKey: issue.team.key + }) ?? undefined }) } return teams.sort((a, b) => a.name.localeCompare(b.name)) @@ -2840,7 +2849,21 @@ export default function TaskPage(): React.JSX.Element { // Why: the full Linear team fetch is async and can temporarily be empty. // Keep the selector usable from issue metadata until the complete list lands. - const linearTeamOptions = availableTeams.length > 0 ? availableTeams : linearIssueTeams + const linearTeamOptions = useMemo(() => { + if (availableTeams.length === 0) { + return linearIssueTeams + } + const issueTeamById = new Map(linearIssueTeams.map((team) => [team.id, team])) + return availableTeams.map((team) => { + if (team.url) { + return team + } + return { + ...team, + url: issueTeamById.get(team.id)?.url + } + }) + }, [availableTeams, linearIssueTeams]) // Why: team IDs belong to one Linear workspace. Switching workspaces while a // saved subset exists must not leave the task list filtered by stale team IDs. @@ -2862,6 +2885,14 @@ export default function TaskPage(): React.JSX.Element { return displayedLinearIssues.filter((issue) => linearTeamSelection.has(issue.team.id)) }, [displayedLinearIssues, linearTeamSelection]) + const selectedLinearTeamForExternalLink = useMemo(() => { + if (linearTeamSelection.size !== 1) { + return null + } + const [teamId] = linearTeamSelection + return linearTeamOptions.find((team) => team.id === teamId && team.url) ?? null + }, [linearTeamOptions, linearTeamSelection]) + const effectiveLinearDisplayProperties = useMemo(() => { const next = new Set(linearDisplayProperties) const groupedProperty = @@ -3073,6 +3104,20 @@ export default function TaskPage(): React.JSX.Element { const [linearConnectError, setLinearConnectError] = useState(null) const activeGithubTaskKind = getGitHubTaskKind(activeTaskPreset, appliedTaskSearch) + const selectedGitHubRepoExternalLink = useMemo(() => { + if (selectedRepos.length !== 1) { + return null + } + const [repo] = selectedRepos + const sourceState = perRepoSourceState.find((state) => state.repoId === repo.id) + const sources = sourceState?.sources + const slug = + activeGithubTaskKind === 'issues' + ? (sources?.issues ?? sources?.prs) + : (sources?.prs ?? sources?.issues) + const url = buildGitHubRepoUrl(slug) + return url ? { url, label: slug ? `${slug.owner}/${slug.repo}` : repo.displayName } : null + }, [activeGithubTaskKind, perRepoSourceState, selectedRepos]) // Why: defense-in-depth safety net applied to the current page's items. // The active tab scopes requests to issues or PRs, and this keeps stale @@ -4231,6 +4276,34 @@ export default function TaskPage(): React.JSX.Element { ) : null} + + + + + + {selectedLinearTeamForExternalLink + ? `Open ${selectedLinearTeamForExternalLink.name} in Linear` + : 'Select one team to open in Linear'} + +
- { - setRepoSelection(next) - void updateSettings({ defaultRepoSelection: [...next] }).catch(() => { - toast.error('Failed to save project selection.') - }) - }} - onSelectAll={() => { - const allIds = new Set(eligibleRepos.map((r) => r.id)) - setRepoSelection(allIds) - void updateSettings({ defaultRepoSelection: null }).catch(() => { - toast.error('Failed to save project selection.') - }) - }} - triggerClassName="h-8 w-auto max-w-[220px] rounded-md border border-border/50 bg-muted/50 px-2 text-xs font-medium shadow-sm transition hover:bg-muted/50 focus:ring-2 focus:ring-ring/20 focus:outline-none" - /> -
+ <> +
+ { + setRepoSelection(next) + void updateSettings({ defaultRepoSelection: [...next] }).catch(() => { + toast.error('Failed to save project selection.') + }) + }} + onSelectAll={() => { + const allIds = new Set(eligibleRepos.map((r) => r.id)) + setRepoSelection(allIds) + void updateSettings({ defaultRepoSelection: null }).catch(() => { + toast.error('Failed to save project selection.') + }) + }} + triggerClassName="h-8 w-auto max-w-[220px] rounded-md border border-border/50 bg-muted/50 px-2 text-xs font-medium shadow-sm transition hover:bg-muted/50 focus:ring-2 focus:ring-ring/20 focus:outline-none" + /> +
+ + + + + + {selectedGitHubRepoExternalLink + ? `Open ${selectedGitHubRepoExternalLink.label} in GitHub` + : 'Select one project to open in GitHub'} + + + )} ) : null} diff --git a/src/renderer/src/components/ui/team-multi-combobox.tsx b/src/renderer/src/components/ui/team-multi-combobox.tsx index f11acc826..9078b5287 100644 --- a/src/renderer/src/components/ui/team-multi-combobox.tsx +++ b/src/renderer/src/components/ui/team-multi-combobox.tsx @@ -110,7 +110,12 @@ export default function TeamMultiCombobox({ - +
- - {team.name} + + {team.name} {team.key} diff --git a/src/renderer/src/lib/github-links.test.ts b/src/renderer/src/lib/github-links.test.ts index f4e5c7705..8928674ed 100644 --- a/src/renderer/src/lib/github-links.test.ts +++ b/src/renderer/src/lib/github-links.test.ts @@ -1,10 +1,25 @@ import { describe, expect, it } from 'vitest' import { + buildGitHubRepoUrl, normalizeGitHubLinkQuery, parseGitHubIssueOrPRLink, parseGitHubIssueOrPRNumber } from './github-links' +describe('buildGitHubRepoUrl', () => { + it('builds a GitHub repository URL from an owner/repo slug', () => { + expect(buildGitHubRepoUrl({ owner: 'stablyai', repo: 'orca' })).toBe( + 'https://github.com/stablyai/orca' + ) + }) + + it('encodes path segments', () => { + expect(buildGitHubRepoUrl({ owner: 'stably ai', repo: 'orca/tools' })).toBe( + 'https://github.com/stably%20ai/orca%2Ftools' + ) + }) +}) + describe('parseGitHubIssueOrPRNumber', () => { it('parses plain issue numbers and GitHub pull request URLs', () => { expect(parseGitHubIssueOrPRNumber('42')).toBe(42) diff --git a/src/renderer/src/lib/github-links.ts b/src/renderer/src/lib/github-links.ts index b61fac8aa..cc379cc99 100644 --- a/src/renderer/src/lib/github-links.ts +++ b/src/renderer/src/lib/github-links.ts @@ -10,6 +10,13 @@ export type GitHubLinkQuery = { directNumber: number | null } +export function buildGitHubRepoUrl(slug: RepoSlug | null | undefined): string | null { + if (!slug?.owner || !slug.repo) { + return null + } + return `https://github.com/${encodeURIComponent(slug.owner)}/${encodeURIComponent(slug.repo)}` +} + function matchGitHubItemPath(url: URL): RegExpExecArray | null { return GH_ITEM_PATH_RE.exec(url.pathname.replace(/\/+$/, '')) } diff --git a/src/shared/linear-links.test.ts b/src/shared/linear-links.test.ts new file mode 100644 index 000000000..069f49a05 --- /dev/null +++ b/src/shared/linear-links.test.ts @@ -0,0 +1,23 @@ +import { describe, expect, it } from 'vitest' + +import { buildLinearTeamUrl, getLinearOrganizationUrlKeyFromIssueUrl } from './linear-links' + +describe('linear links', () => { + it('builds team URLs from workspace and team keys', () => { + expect(buildLinearTeamUrl({ organizationUrlKey: 'acme', teamKey: 'ENG' })).toBe( + 'https://linear.app/acme/team/ENG/all' + ) + }) + + it('encodes URL path segments', () => { + expect(buildLinearTeamUrl({ organizationUrlKey: 'acme inc', teamKey: 'A/B' })).toBe( + 'https://linear.app/acme%20inc/team/A%2FB/all' + ) + }) + + it('extracts the workspace URL key from Linear issue URLs', () => { + expect(getLinearOrganizationUrlKeyFromIssueUrl('https://linear.app/acme/issue/ENG-1')).toBe( + 'acme' + ) + }) +}) diff --git a/src/shared/linear-links.ts b/src/shared/linear-links.ts new file mode 100644 index 000000000..c9c6e882c --- /dev/null +++ b/src/shared/linear-links.ts @@ -0,0 +1,26 @@ +export function buildLinearTeamUrl(args: { + organizationUrlKey?: string | null + teamKey?: string | null +}): string | null { + const organizationUrlKey = args.organizationUrlKey?.trim() + const teamKey = args.teamKey?.trim() + if (!organizationUrlKey || !teamKey) { + return null + } + return `https://linear.app/${encodeURIComponent(organizationUrlKey)}/team/${encodeURIComponent(teamKey)}/all` +} + +export function getLinearOrganizationUrlKeyFromIssueUrl(issueUrl?: string | null): string | null { + if (!issueUrl) { + return null + } + try { + const parsed = new URL(issueUrl) + if (parsed.hostname !== 'linear.app') { + return null + } + return parsed.pathname.split('/').filter(Boolean)[0] ?? null + } catch { + return null + } +} diff --git a/src/shared/types.ts b/src/shared/types.ts index f29da05fd..37bee4746 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -1216,6 +1216,7 @@ export type LinearTeam = { workspaceName?: string name: string key: string + url?: string } // ─── Hooks (orca.yaml) ──────────────────────────────────────────────