diff --git a/src/main/ipc/linear.ts b/src/main/ipc/linear.ts index 96de78c74..f08a49653 100644 --- a/src/main/ipc/linear.ts +++ b/src/main/ipc/linear.ts @@ -10,6 +10,7 @@ import { addIssueComment, getIssueComments } from '../linear/issues' +import { listProjects } from '../linear/projects' import { listTeams, getTeamStates, getTeamLabels, getTeamMembers } from '../linear/teams' import type { LinearListFilter } from '../linear/issues' import type { LinearIssueUpdate, LinearWorkspaceSelection } from '../../shared/types' @@ -90,7 +91,14 @@ export function registerLinearHandlers(): void { 'linear:createIssue', async ( _event, - args: { teamId: string; title: string; description?: string; workspaceId?: string } + args: { + teamId: string + title: string + description?: string + workspaceId?: string + parentIssueId?: string + projectId?: string | null + } ) => { if (typeof args?.teamId !== 'string' || !args.teamId.trim()) { return { ok: false, error: 'Team ID is required' } @@ -102,7 +110,11 @@ export function registerLinearHandlers(): void { args.teamId.trim(), args.title.trim(), args.description?.trim() || undefined, - normalizeWorkspaceId(args.workspaceId) + normalizeWorkspaceId(args.workspaceId), + { + parentId: typeof args.parentIssueId === 'string' ? args.parentIssueId.trim() : undefined, + projectId: typeof args.projectId === 'string' ? args.projectId.trim() : null + } ) } ) @@ -142,6 +154,13 @@ export function registerLinearHandlers(): void { ) { return { ok: false, error: 'Label IDs must be an array of strings' } } + if ( + u.projectId !== undefined && + u.projectId !== null && + (typeof u.projectId !== 'string' || !u.projectId.trim()) + ) { + return { ok: false, error: 'Invalid project ID' } + } return updateIssue(args.id.trim(), args.updates, normalizeWorkspaceId(args.workspaceId)) } ) @@ -180,6 +199,17 @@ export function registerLinearHandlers(): void { } ) + ipcMain.handle( + 'linear:listProjects', + async ( + _event, + args?: { query?: string; limit?: number; workspaceId?: LinearWorkspaceSelection } + ) => { + const limit = Math.min(Math.max(1, args?.limit ?? 20), 50) + return listProjects(args?.query, limit, normalizeWorkspaceSelection(args?.workspaceId)) + } + ) + ipcMain.handle( 'linear:teamStates', async (_event, args: { teamId: string; workspaceId?: string }) => { diff --git a/src/main/linear/issues.ts b/src/main/linear/issues.ts index e24bc12b9..4bade32ba 100644 --- a/src/main/linear/issues.ts +++ b/src/main/linear/issues.ts @@ -143,9 +143,10 @@ const VIEWER_CREATED_ISSUES_QUERY = ` async function mapIssueForWorkspace( entry: LinearClientForWorkspace, - issue: Parameters[0] + issue: Parameters[0], + options?: Parameters[1] ): Promise { - const mapped = await mapLinearIssue(issue) + const mapped = await mapLinearIssue(issue, options) return { ...mapped, workspaceId: entry.workspace.id, @@ -215,7 +216,10 @@ export async function getIssue( await acquire() try { const issue = await entry.client.issue(id) - return await mapIssueForWorkspace(entry, issue) + return await mapIssueForWorkspace(entry, issue, { + includeChildren: true, + includeProject: true + }) } catch (error) { if (isAuthError(error)) { clearToken(entry.workspace.id) @@ -358,9 +362,11 @@ export async function createIssue( teamId: string, title: string, description?: string, - workspaceId?: string | null + workspaceId?: string | null, + options?: { parentId?: string; projectId?: string | null } ): Promise< - { ok: true; id: string; identifier: string; url: string } | { ok: false; error: string } + | { ok: true; id: string; identifier: string; title: string; url: string } + | { ok: false; error: string } > { const entry = getClients(workspaceId)[0] if (!entry) { @@ -372,7 +378,9 @@ export async function createIssue( const result = await entry.client.createIssue({ teamId, title, - ...(description ? { description } : {}) + ...(description ? { description } : {}), + ...(options?.parentId ? { parentId: options.parentId } : {}), + ...(options?.projectId ? { projectId: options.projectId } : {}) }) if (!result.success) { return { ok: false, error: 'Linear create failed' } @@ -381,7 +389,13 @@ export async function createIssue( if (!issue) { return { ok: false, error: 'Issue was created but could not be retrieved' } } - return { ok: true, id: issue.id, identifier: issue.identifier, url: issue.url } + return { + ok: true, + id: issue.id, + identifier: issue.identifier, + title: issue.title, + url: issue.url + } } catch (error) { if (isAuthError(error)) { clearToken(entry.workspace.id) @@ -428,6 +442,9 @@ export async function updateIssue( if (resolvedLabelIds !== undefined) { payload.labelIds = resolvedLabelIds } + if (updates.projectId !== undefined) { + payload.projectId = updates.projectId + } const result = await entry.client.updateIssue(id, payload) if (!result.success) { diff --git a/src/main/linear/mappers.ts b/src/main/linear/mappers.ts index 9a273edd8..638d9a19f 100644 --- a/src/main/linear/mappers.ts +++ b/src/main/linear/mappers.ts @@ -1,13 +1,35 @@ import type { Issue, IssueSearchResult } from '@linear/sdk' -import type { LinearIssue } from '../../shared/types' +import type { LinearIssue, LinearIssueChildSummary } from '../../shared/types' + +type IssueWithChildren = Issue & { + children: Issue['children'] +} + +type MapLinearIssueOptions = { + includeChildren?: boolean + includeProject?: boolean +} + +function mapLinearIssueChild(issue: Issue): LinearIssueChildSummary { + return { + id: issue.id, + identifier: issue.identifier, + title: issue.title, + url: issue.url + } +} // Why: the @linear/sdk uses lazy-loading for related entities โ€” state, team, // and assignee are fetched on property access and return promises. This mapper // awaits them all so callers receive a plain serializable object safe for IPC // transfer. Labels use the labels() method on Issue but IssueSearchResult only // has labelIds (string UUIDs), so we conditionally resolve label names. -export async function mapLinearIssue(issue: Issue | IssueSearchResult): Promise { +export async function mapLinearIssue( + issue: Issue | IssueSearchResult, + options: MapLinearIssueOptions = {} +): Promise { const [state, team, assignee] = await Promise.all([issue.state, issue.team, issue.assignee]) + const project = options.includeProject ? await issue.project : undefined // Why: IssueSearchResult does not expose the labels() relation method โ€” only // the raw labelIds array. For Issue instances we resolve actual label names; @@ -27,6 +49,16 @@ export async function mapLinearIssue(issue: Issue | IssueSearchResult): Promise< labelIds = issue.labelIds as string[] } + let subIssues: LinearIssueChildSummary[] | undefined + if (options.includeChildren && 'children' in issue && typeof issue.children === 'function') { + try { + const childrenConnection = await (issue as IssueWithChildren).children({ first: 25 }) + subIssues = childrenConnection.nodes.map(mapLinearIssueChild) + } catch { + // Swallow โ€” child issues are secondary display data and creation still works without them. + } + } + return { id: issue.id, identifier: issue.identifier, @@ -43,6 +75,15 @@ export async function mapLinearIssue(issue: Issue | IssueSearchResult): Promise< name: team?.name ?? '', key: team?.key ?? '' }, + project: project + ? { + id: project.id, + name: project.name, + url: project.url ?? undefined, + color: project.color ?? undefined + } + : undefined, + subIssues, labels: labelNames, labelIds, assignee: assignee diff --git a/src/main/linear/projects.ts b/src/main/linear/projects.ts new file mode 100644 index 000000000..142895e84 --- /dev/null +++ b/src/main/linear/projects.ts @@ -0,0 +1,52 @@ +import type { Project, ProjectSearchResult } from '@linear/sdk' +import type { LinearProjectSummary, LinearWorkspaceSelection } from '../../shared/types' +import { acquire, clearToken, getClients, isAuthError, release } from './client' + +function mapLinearProject(project: Project | ProjectSearchResult): LinearProjectSummary { + return { + id: project.id, + name: project.name, + url: project.url ?? undefined, + color: project.color ?? undefined + } +} + +export async function listProjects( + query: string | undefined, + limit = 20, + workspaceId?: LinearWorkspaceSelection | null +): Promise { + const trimmed = query?.trim() + if (!trimmed) { + return [] + } + + const entries = getClients(workspaceId) + if (entries.length === 0) { + return [] + } + + const results = await Promise.all( + entries.map(async (entry) => { + await acquire() + try { + const connection = await entry.client.searchProjects(trimmed, { first: limit }) + return connection.nodes.map(mapLinearProject) + } catch (error) { + if (isAuthError(error)) { + clearToken(entry.workspace.id) + if (workspaceId !== 'all') { + throw error + } + } else { + console.warn('[linear] listProjects failed:', error) + } + return [] + } finally { + release() + } + }) + ) + + return results.flat().slice(0, limit) +} diff --git a/src/main/runtime/orca-runtime.ts b/src/main/runtime/orca-runtime.ts index c197143cb..9e3f642b1 100644 --- a/src/main/runtime/orca-runtime.ts +++ b/src/main/runtime/orca-runtime.ts @@ -150,6 +150,7 @@ import { updateIssue as updateLinearIssue, type LinearListFilter } from '../linear/issues' +import { listProjects as listLinearProjects } from '../linear/projects' import { getTeamLabels as getLinearTeamLabels, getTeamMembers as getLinearTeamMembers, @@ -8391,9 +8392,14 @@ export class OrcaRuntimeService { teamId: string, title: string, description?: string, - workspaceId?: string + workspaceId?: string, + parentIssueId?: string, + projectId?: string | null ): ReturnType { - return createLinearIssue(teamId, title, description, workspaceId) + return createLinearIssue(teamId, title, description, workspaceId, { + parentId: parentIssueId, + projectId + }) } linearGetIssue(id: string, workspaceId?: string): ReturnType { @@ -8427,6 +8433,14 @@ export class OrcaRuntimeService { return listLinearTeams(workspaceId) } + linearListProjects( + query?: string, + limit = 20, + workspaceId?: LinearWorkspaceSelection + ): ReturnType { + return listLinearProjects(query, Math.min(Math.max(1, limit), 50), workspaceId) + } + linearTeamStates(teamId: string, workspaceId?: string): ReturnType { return getLinearTeamStates(teamId, workspaceId) } diff --git a/src/main/runtime/rpc/methods/linear.test.ts b/src/main/runtime/rpc/methods/linear.test.ts index 85ec802fc..3f0a905cb 100644 --- a/src/main/runtime/rpc/methods/linear.test.ts +++ b/src/main/runtime/rpc/methods/linear.test.ts @@ -71,7 +71,22 @@ describe('linear RPC methods', () => { makeRequest('linear.updateIssue', { id: 'issue-3', workspaceId: 'workspace-1', - updates: { stateId: 'state-1', assigneeId: null, priority: 2, labelIds: ['label-1'] } + updates: { + stateId: 'state-1', + assigneeId: null, + priority: 2, + labelIds: ['label-1'], + projectId: 'project-1' + } + }) + ) + await dispatcher.dispatch( + makeRequest('linear.createIssue', { + parentIssueId: 'issue-3', + teamId: 'team-1', + title: 'Child task', + workspaceId: 'workspace-1', + projectId: 'project-1' }) ) await dispatcher.dispatch( @@ -92,7 +107,17 @@ describe('linear RPC methods', () => { 'team-1', 'Fix bug', 'Details', - 'workspace-1' + 'workspace-1', + undefined, + undefined + ) + expect(runtime.linearCreateIssue).toHaveBeenCalledWith( + 'team-1', + 'Child task', + undefined, + 'workspace-1', + 'issue-3', + 'project-1' ) expect(runtime.linearUpdateIssue).toHaveBeenCalledWith( 'issue-3', @@ -100,7 +125,8 @@ describe('linear RPC methods', () => { stateId: 'state-1', assigneeId: null, priority: 2, - labelIds: ['label-1'] + labelIds: ['label-1'], + projectId: 'project-1' }, 'workspace-1' ) @@ -116,6 +142,7 @@ describe('linear RPC methods', () => { const runtime = { getRuntimeId: () => 'test-runtime', linearListTeams: vi.fn().mockResolvedValue([{ id: 'team-1' }]), + linearListProjects: vi.fn().mockResolvedValue([{ id: 'project-1' }]), linearTeamStates: vi.fn().mockResolvedValue([{ id: 'state-1' }]), linearTeamLabels: vi.fn().mockResolvedValue([{ id: 'label-1' }]), linearTeamMembers: vi.fn().mockResolvedValue([{ id: 'member-1' }]) @@ -123,6 +150,7 @@ describe('linear RPC methods', () => { const dispatcher = new RpcDispatcher({ runtime, methods: LINEAR_METHODS }) await dispatcher.dispatch(makeRequest('linear.listTeams', { workspaceId: 'all' })) + await dispatcher.dispatch(makeRequest('linear.listProjects', { query: 'roadmap', limit: 5 })) await dispatcher.dispatch( makeRequest('linear.teamStates', { teamId: 'team-1', workspaceId: 'workspace-1' }) ) @@ -134,6 +162,7 @@ describe('linear RPC methods', () => { ) expect(runtime.linearListTeams).toHaveBeenCalledWith('all') + expect(runtime.linearListProjects).toHaveBeenCalledWith('roadmap', 5, undefined) expect(runtime.linearTeamStates).toHaveBeenCalledWith('team-1', 'workspace-1') expect(runtime.linearTeamLabels).toHaveBeenCalledWith('team-1', 'workspace-1') expect(runtime.linearTeamMembers).toHaveBeenCalledWith('team-1', 'workspace-1') diff --git a/src/main/runtime/rpc/methods/linear.ts b/src/main/runtime/rpc/methods/linear.ts index 71c10ab3d..d9e4c0588 100644 --- a/src/main/runtime/rpc/methods/linear.ts +++ b/src/main/runtime/rpc/methods/linear.ts @@ -36,7 +36,9 @@ const CreateIssue = z.object({ teamId: requiredString('Team ID is required'), title: requiredString('Title is required'), description: OptionalString, - workspaceId: OptionalString + workspaceId: OptionalString, + parentIssueId: OptionalString, + projectId: z.union([z.string(), z.null()]).optional() }) const IssueId = z.object({ @@ -50,6 +52,14 @@ const IssueComment = z.object({ workspaceId: OptionalString }) +const ListProjects = z + .object({ + query: OptionalString, + limit: OptionalFiniteNumber, + workspaceId: OptionalString + }) + .optional() + const TeamId = z.object({ teamId: requiredString('Team ID is required'), workspaceId: OptionalString @@ -63,7 +73,8 @@ const IssueUpdate = z.object({ title: OptionalString, assigneeId: z.union([z.string(), z.null()]).optional(), priority: z.number().int().min(0).max(4).optional(), - labelIds: z.array(z.string()).optional() + labelIds: z.array(z.string()).optional(), + projectId: z.union([z.string(), z.null()]).optional() }) }) @@ -113,7 +124,9 @@ export const LINEAR_METHODS: RpcMethod[] = [ params.teamId.trim(), params.title.trim(), params.description?.trim() || undefined, - params.workspaceId + params.workspaceId, + params.parentIssueId, + params.projectId ) }), defineMethod({ @@ -148,6 +161,12 @@ export const LINEAR_METHODS: RpcMethod[] = [ params: WorkspaceSelection, handler: async (params, { runtime }) => runtime.linearListTeams(params?.workspaceId) }), + defineMethod({ + name: 'linear.listProjects', + params: ListProjects, + handler: async (params, { runtime }) => + runtime.linearListProjects(params?.query, params?.limit, params?.workspaceId) + }), defineMethod({ name: 'linear.teamStates', params: TeamId, diff --git a/src/preload/api-types.ts b/src/preload/api-types.ts index 10e555860..c74761e25 100644 --- a/src/preload/api-types.ts +++ b/src/preload/api-types.ts @@ -64,6 +64,7 @@ import type { LinearWorkflowState, LinearLabel, LinearMember, + LinearProjectSummary, LinearTeam, MarkdownDocument, FloatingTerminalCwdRequest, @@ -1061,8 +1062,11 @@ export type PreloadApi = { title: string description?: string workspaceId?: string + parentIssueId?: string + projectId?: string | null }) => Promise< - { ok: true; id: string; identifier: string; url: string } | { ok: false; error: string } + | { ok: true; id: string; identifier: string; title: string; url: string } + | { ok: false; error: string } > getIssue: (args: { id: string; workspaceId?: string }) => Promise updateIssue: (args: { @@ -1077,6 +1081,11 @@ export type PreloadApi = { }) => Promise<{ ok: true; id: string } | { ok: false; error: string }> issueComments: (args: { issueId: string; workspaceId?: string }) => Promise listTeams: (args?: { workspaceId?: LinearWorkspaceSelection }) => Promise + listProjects: (args?: { + query?: string + limit?: number + workspaceId?: LinearWorkspaceSelection + }) => Promise teamStates: (args: { teamId: string; workspaceId?: string }) => Promise teamLabels: (args: { teamId: string; workspaceId?: string }) => Promise teamMembers: (args: { teamId: string; workspaceId?: string }) => Promise diff --git a/src/preload/index.ts b/src/preload/index.ts index 384678139..9b243c3d7 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -1057,8 +1057,11 @@ const api = { title: string description?: string workspaceId?: string + parentIssueId?: string + projectId?: string | null }): Promise< - { ok: true; id: string; identifier: string; url: string } | { ok: false; error: string } + | { ok: true; id: string; identifier: string; title: string; url: string } + | { ok: false; error: string } > => ipcRenderer.invoke('linear:createIssue', args), getIssue: (args: { id: string; workspaceId?: string }): Promise => @@ -1084,6 +1087,12 @@ const api = { listTeams: (args?: { workspaceId?: string }): Promise => ipcRenderer.invoke('linear:listTeams', args), + listProjects: (args?: { + query?: string + limit?: number + workspaceId?: string + }): Promise => ipcRenderer.invoke('linear:listProjects', args), + teamStates: (args: { teamId: string; workspaceId?: string }): Promise => ipcRenderer.invoke('linear:teamStates', args), diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 422dd9538..fb274ed3e 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -75,6 +75,7 @@ import { setRuntimeGraphSyncEnabled } from './runtime/sync-runtime-graph' import { useGlobalFileDrop } from './hooks/useGlobalFileDrop' +import { useRadixBodyPointerEventsRecovery } from './hooks/useRadixBodyPointerEventsRecovery' import { registerUpdaterBeforeUnloadBypass } from './lib/updater-beforeunload' import { buildWorkspaceSessionPayload, @@ -219,6 +220,7 @@ function applyRemoteWorkspacePatchStatus( function App(): React.JSX.Element { useUnreadDockBadge() + useRadixBodyPointerEventsRecovery() const [floatingTerminalOpen, setFloatingTerminalOpen] = useState(false) // Why: Zustand actions are referentially stable, but each individual diff --git a/src/renderer/src/assets/main.css b/src/renderer/src/assets/main.css index 0659d0d1a..467c14d5e 100644 --- a/src/renderer/src/assets/main.css +++ b/src/renderer/src/assets/main.css @@ -218,11 +218,11 @@ list-style: none; } - button:not(:disabled) { + :where(button:not(:disabled)) { cursor: pointer; } - button:disabled { + :where(button:disabled) { cursor: default; } } diff --git a/src/renderer/src/components/LinearIssueWorkspace.tsx b/src/renderer/src/components/LinearIssueWorkspace.tsx index 373c87082..984020e2b 100644 --- a/src/renderer/src/components/LinearIssueWorkspace.tsx +++ b/src/renderer/src/components/LinearIssueWorkspace.tsx @@ -1,16 +1,25 @@ +/* eslint-disable max-lines -- Why: the Linear issue page co-locates the + full-page layout with its hydration/comment state so the selected issue + surface stays coherent with the existing Linear drawer behavior. */ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { ArrowRight, + Check, + ChevronDown, + ChevronRight, Clipboard, - ExternalLink, + FolderKanban, GitBranch, + Link, LoaderCircle, + Plus, RefreshCw, X } from 'lucide-react' import { toast } from 'sonner' import { VisuallyHidden } from 'radix-ui' +import { LinearIcon } from '@/components/icons/LinearIcon' import CommentMarkdown from '@/components/sidebar/CommentMarkdown' import { initLinearIssueEditState, @@ -20,6 +29,7 @@ import { type LinearLocalComment } from '@/components/LinearItemDrawer' import { Button } from '@/components/ui/button' +import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover' import { Sheet, SheetContent, SheetDescription, SheetTitle } from '@/components/ui/sheet' import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' import { createBrowserUuid } from '@/lib/browser-uuid' @@ -29,8 +39,19 @@ import { buildLinearIssuePrompt, formatLinearIssueRelativeTime } from '@/components/linear-issue-workspace-text' -import { linearGetIssue, linearIssueComments } from '@/runtime/runtime-linear-client' -import type { LinearComment, LinearIssue } from '../../../shared/types' +import { + linearCreateSubIssue, + linearGetIssue, + linearIssueComments, + linearListProjects, + linearUpdateIssue +} from '@/runtime/runtime-linear-client' +import type { + LinearComment, + LinearIssue, + LinearIssueChildSummary, + LinearProjectSummary +} from '../../../shared/types' type LinearIssueWorkspaceProps = { issue: LinearIssue | null @@ -47,6 +68,277 @@ async function copyTextToClipboard(text: string, label: string): Promise { } } +function LinearIssueAvatar({ + avatarUrl, + name, + className = 'size-6' +}: { + avatarUrl?: string + name?: string + className?: string +}): React.JSX.Element { + if (avatarUrl) { + return {name + } + + const initial = name?.trim().charAt(0).toUpperCase() || '?' + return ( + + ) +} + +function LinearIssueSubIssueButton({ issue }: { issue: LinearIssue }): React.JSX.Element { + const settings = useAppStore((s) => s.settings) + const [open, setOpen] = useState(false) + const [title, setTitle] = useState('') + const [subIssues, setSubIssues] = useState(issue.subIssues ?? []) + const [submitting, setSubmitting] = useState(false) + + useEffect(() => { + setSubIssues(issue.subIssues ?? []) + }, [issue.id, issue.subIssues]) + + const handleCreate = useCallback(async () => { + const trimmed = title.trim() + if (!trimmed) { + return + } + setSubmitting(true) + try { + const result = await linearCreateSubIssue(settings, { + parentIssueId: issue.id, + teamId: issue.team.id, + title: trimmed, + workspaceId: issue.workspaceId, + projectId: issue.project?.id ?? null + }) + if (result.ok) { + const child = { + id: result.id, + identifier: result.identifier, + title: result.title || trimmed, + url: result.url + } + setSubIssues((prev) => + prev.some((subIssue) => subIssue.id === child.id) ? prev : [...prev, child] + ) + toast.success(`Created ${result.identifier}`) + setTitle('') + setOpen(false) + } else { + toast.error(result.error) + } + } catch (error) { + toast.error(error instanceof Error ? error.message : 'Failed to create sub-issue') + } finally { + setSubmitting(false) + } + }, [issue.id, issue.project?.id, issue.team.id, issue.workspaceId, settings, title]) + + return ( +
+ {subIssues.length > 0 ? ( +
+ {subIssues.map((subIssue) => ( + + ))} +
+ ) : null} + + + + + + +
+ setTitle(event.target.value)} + onKeyDown={(event) => { + if (event.key === 'Enter') { + event.preventDefault() + void handleCreate() + } + }} + placeholder="Sub-issue title" + className="h-9 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus-visible:ring-1 focus-visible:ring-ring" + /> +
+ +
+
+
+
+
+ ) +} + +function LinearIssueSidebarProjectCard({ + issue, + onProjectChanged +}: { + issue: LinearIssue + onProjectChanged: (project: LinearProjectSummary) => void +}): React.JSX.Element { + const settings = useAppStore((s) => s.settings) + const patchLinearIssue = useAppStore((s) => s.patchLinearIssue) + const [open, setOpen] = useState(false) + const [query, setQuery] = useState('') + const [projects, setProjects] = useState([]) + const [loading, setLoading] = useState(false) + const [savingProjectId, setSavingProjectId] = useState(null) + + useEffect(() => { + if (!open) { + return + } + let cancelled = false + const timeout = window.setTimeout(() => { + setLoading(true) + void linearListProjects(settings, query, 20, issue.workspaceId) + .then((result) => { + if (!cancelled) { + setProjects(result) + } + }) + .catch((error) => { + if (!cancelled) { + toast.error(error instanceof Error ? error.message : 'Failed to load projects') + } + }) + .finally(() => { + if (!cancelled) { + setLoading(false) + } + }) + }, 150) + return () => { + cancelled = true + window.clearTimeout(timeout) + } + }, [issue.workspaceId, open, query, settings]) + + const handleSelectProject = useCallback( + async (project: LinearProjectSummary) => { + setSavingProjectId(project.id) + try { + const result = await linearUpdateIssue( + settings, + issue.id, + { projectId: project.id }, + issue.workspaceId + ) + if (result.ok) { + onProjectChanged(project) + patchLinearIssue(issue.id, { project }) + toast.success('Project updated') + setOpen(false) + } else { + toast.error(result.error) + } + } catch (error) { + toast.error(error instanceof Error ? error.message : 'Failed to update project') + } finally { + setSavingProjectId(null) + } + }, + [issue.id, issue.workspaceId, onProjectChanged, patchLinearIssue, settings] + ) + + return ( +
+
+ Project + +
+ + + + + +
+ setQuery(event.target.value)} + placeholder="Search projects" + className="h-8 w-full rounded-md border border-input bg-background px-2 text-sm outline-none focus-visible:ring-1 focus-visible:ring-ring" + /> +
+ {loading ? ( +
+ + Loading projects +
+ ) : projects.length > 0 ? ( + projects.map((project) => ( + + )) + ) : ( +
+ {query.trim() ? 'No projects found.' : 'Search for a project to add.'} +
+ )} +
+
+
+
+
+ ) +} + export default function LinearIssueWorkspace({ issue, onUse, @@ -60,11 +352,13 @@ export default function LinearIssueWorkspace({ const [commentsError, setCommentsError] = useState(null) const [editState, setEditState] = useState(null) const requestIdRef = useRef(0) + const hydratedIssueKeyRef = useRef(null) const hasEditedRef = useRef(false) const optimisticCommentsRef = useRef([]) const handleEditStateChange = useCallback((patch: Partial) => { hasEditedRef.current = true + setFullIssue((prev) => (prev ? { ...prev, ...patch } : prev)) setEditState((prev) => (prev ? { ...prev, ...patch } : prev)) }, []) @@ -102,6 +396,7 @@ export default function LinearIssueWorkspace({ useEffect(() => { if (!issue) { + hydratedIssueKeyRef.current = null setFullIssue(null) setIssueLoading(false) setComments([]) @@ -112,6 +407,12 @@ export default function LinearIssueWorkspace({ return } + const issueKey = `${settings?.activeRuntimeEnvironmentId ?? 'local'}:${issue.workspaceId ?? 'selected'}:${issue.id}` + if (hydratedIssueKeyRef.current === issueKey) { + return + } + hydratedIssueKeyRef.current = issueKey + requestIdRef.current += 1 const requestId = requestIdRef.current hasEditedRef.current = false @@ -131,7 +432,21 @@ export default function LinearIssueWorkspace({ } if (issueResult) { const fetched = issueResult as LinearIssue - setFullIssue(fetched) + setFullIssue((prev) => { + if (!hasEditedRef.current || !prev) { + return fetched + } + // Why: late hydration can carry pre-edit field data; keep the + // optimistic fields while accepting fresh non-field detail data. + return { + ...fetched, + state: prev.state, + priority: prev.priority, + assignee: prev.assignee, + labelIds: prev.labelIds, + labels: prev.labels + } + }) if (!hasEditedRef.current) { setEditState(initLinearIssueEditState(fetched)) } @@ -162,16 +477,15 @@ export default function LinearIssueWorkspace({ setComments((prev) => [...prev, newComment]) }, []) + const handleProjectChanged = useCallback((project: LinearProjectSummary) => { + setFullIssue((prev) => (prev ? { ...prev, project } : prev)) + }, []) + const actionItems = useMemo(() => { if (!displayed) { return [] } return [ - { - label: 'Open in Linear', - icon: ExternalLink, - action: () => window.api.shell.openUrl(displayed.url) - }, { label: 'Copy URL', icon: Clipboard, @@ -201,7 +515,7 @@ export default function LinearIssueWorkspace({ { event.preventDefault() }} @@ -217,34 +531,73 @@ export default function LinearIssueWorkspace({ {displayed ? (
-
-
-
-
- {displayed.identifier} - {displayed.workspaceName ? {displayed.workspaceName} : null} - {displayed.team.name} - {formatLinearIssueRelativeTime(displayed.updatedAt)} - {issueLoading ? : null} -
-

- {displayed.title} -

-
- +
+
+ + + {displayed.workspaceName ?? 'Linear'} + + + Issues + + {displayed.identifier} + + {displayed.title} + + {issueLoading ? : null} +
+
+ 2 / 17 + + + + + + Copy URL + + + + + + + + Copy identifier + + + + + + + + Start workspace + +
-
+ - {editState ? ( - - ) : null} +
+
+
+

+ {displayed.title} +

-
-
-
-
- - - {displayed.state.name} - - - {displayed.assignee?.displayName ?? 'Unassigned'} - -
- {displayed.description?.trim() ? ( - - ) : ( -

No description provided.

- )} -
+
+ {displayed.description?.trim() ? ( + + ) : ( +

+ No description provided. +

+ )} +
-
-
-
- Comments - {comments.length > 0 ? ( - {comments.length} - ) : null} + + +
+
+

Activity

+
+ +
+ +
+ + + {displayed.assignee?.displayName ?? 'Someone'} updated the issue ยท{' '} + {formatLinearIssueRelativeTime(displayed.updatedAt)} + +
+ {commentsError ? ( - - ) : null} -
- - {commentsError ? ( -
- {commentsError} -
- ) : commentsLoading && comments.length === 0 ? ( -
- -
- ) : comments.length === 0 ? ( -

No comments yet.

- ) : ( -
- {comments.map((comment) => ( -
+ {commentsError} + +
+ ) : null} + + {commentsLoading && comments.length === 0 ? ( +
+ +
+ ) : comments.length > 0 ? ( +
+ {comments.map((comment) => ( +
+ -
-
- ))} +
+
+ + {comment.user?.displayName ?? 'Unknown'} + + + {formatLinearIssueRelativeTime(comment.createdAt)} + +
+
+ +
+
+ + ))} +
+ ) : null} + + +
+
+ +
- -
- -
) : null} diff --git a/src/renderer/src/components/LinearItemDrawer.tsx b/src/renderer/src/components/LinearItemDrawer.tsx index 4977e09c7..461025a70 100644 --- a/src/renderer/src/components/LinearItemDrawer.tsx +++ b/src/renderer/src/components/LinearItemDrawer.tsx @@ -1,6 +1,17 @@ /* eslint-disable max-lines -- Why: the Linear drawer co-locates read-only preview, edit controls, and comment input so the full issue surface stays in one file. */ import React, { useCallback, useEffect, useRef, useState } from 'react' -import { ArrowRight, ExternalLink, LoaderCircle, Send, X } from 'lucide-react' +import { + AlertTriangle, + ArrowRight, + ChevronDown, + Circle, + ExternalLink, + LoaderCircle, + Send, + Tag, + UserRound, + X +} from 'lucide-react' import { toast } from 'sonner' import { Button } from '@/components/ui/button' @@ -18,6 +29,10 @@ import { useTeamMembers, useImmediateMutation } from '@/hooks/useIssueMetadata' +import { + getLinearStateMarkerStyle, + getLinearStatePillStyle +} from '@/components/linear-state-pill-style' import type { LinearIssue, LinearComment } from '../../../shared/types' import { linearAddIssueComment, @@ -44,6 +59,29 @@ const PRIORITY_LABELS: Record = { 4: 'Low' } +const LINEAR_EDIT_CHIP_CLASS = + 'inline-flex h-6 min-w-0 max-w-[14rem] cursor-pointer items-center gap-1.5 rounded-full border border-border/70 bg-background/70 px-2.5 text-[11px] font-medium leading-none text-muted-foreground shadow-xs transition-[background-color,border-color,color,box-shadow] hover:border-border hover:bg-accent hover:text-accent-foreground hover:[--linear-state-pill-current-background:var(--linear-state-pill-hover-background)] hover:[--linear-state-pill-current-border:var(--linear-state-pill-hover-border)] hover:[--linear-state-pill-current-foreground:var(--linear-state-pill-hover-foreground)] focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-80' + +const LINEAR_EDIT_MENU_ITEM_CLASS = + 'flex w-full cursor-pointer items-center rounded-sm px-2 py-1.5 text-[12px] hover:bg-accent' + +const LINEAR_EDIT_MENU_ITEM_WITH_ICON_CLASS = + 'flex w-full cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-[12px] hover:bg-accent' + +function LinearEditChipAdornment({ + loading, + pending +}: { + loading?: boolean + pending?: boolean +}): React.JSX.Element { + if (loading || pending) { + return + } + + return +} + function formatRelativeTime(input: string): string { const date = new Date(input) if (Number.isNaN(date.getTime())) { @@ -63,16 +101,6 @@ function formatRelativeTime(input: string): string { return formatter.format(diffDays, 'day') } -// Why: derive pill border/background/text from the actual Linear state color -// so the pill always matches the colored dot, regardless of state type. -function statePillStyle(color: string): React.CSSProperties { - return { - borderColor: `color-mix(in srgb, ${color} 30%, transparent)`, - backgroundColor: `color-mix(in srgb, ${color} 10%, transparent)`, - color - } -} - type LinearItemDrawerProps = { issue: LinearIssue | null onUse: (issue: LinearIssue) => void @@ -91,12 +119,14 @@ type EditSectionProps = { issue: LinearIssue editState: LinearEditState onEditStateChange: (patch: Partial) => void + layout?: 'chips' | 'properties' } export function LinearIssueEditSection({ issue, editState, - onEditStateChange + onEditStateChange, + layout = 'chips' }: EditSectionProps): React.JSX.Element { const [labelPopoverOpen, setLabelPopoverOpen] = useState(false) const patchLinearIssue = useAppStore((s) => s.patchLinearIssue) @@ -246,6 +276,16 @@ export function LinearIssueEditSection({ const currentStateId = states.data.find( (s) => s.name === localState.name && s.type === localState.type )?.id + const statePending = isPending('state') + const priorityPending = isPending('priority') + const assigneePending = isPending('assignee') + const labelsPending = isPending('labels') + const labelSummary = + localLabels.length === 0 + ? '+ Label' + : localLabels.length === 1 + ? localLabels[0] + : `${localLabels[0]} +${localLabels.length - 1}` const checkIcon = ( @@ -259,6 +299,263 @@ export function LinearIssueEditSection({ ) + if (layout === 'properties') { + const propertyRowClass = + 'flex min-h-9 w-full cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-foreground transition hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-80' + const propertyIconClass = 'size-4 shrink-0 text-muted-foreground' + + return ( +
+
+
+ Properties + +
+
+ + + + + + {states.error ? ( +
+ {states.error} +
+ ) : states.loading ? ( +
+ + Loading states +
+ ) : states.data.length > 0 ? ( +
+ {states.data.map((s) => ( + + ))} +
+ ) : ( +
+ No states found +
+ )} +
+
+ + + + + + + {[0, 1, 2, 3, 4].map((p) => ( + + ))} + + + + + + + + +
+ + {members.error ? ( +
+ {members.error} +
+ ) : members.loading ? ( +
+ + Loading members +
+ ) : ( + members.data.map((m) => ( + + )) + )} +
+
+
+ + +
+
+ +
+
+ Labels + +
+
+ + + + + + {labels.error ? ( +
+ {labels.error} +
+ ) : labels.loading ? ( +
+ + Loading labels +
+ ) : labels.data.length > 0 ? ( +
+ {labels.data.map((label) => ( + + ))} +
+ ) : ( +
+ No labels found +
+ )} +
+
+
+
+
+ ) + } + return (
{/* Status */} @@ -266,38 +563,52 @@ export function LinearIssueEditSection({ -
- {states.data.map((s) => ( - - ))} -
+ {states.error ? ( +
{states.error}
+ ) : states.loading ? ( +
+ + Loading states +
+ ) : states.data.length > 0 ? ( +
+ {states.data.map((s) => ( + + ))} +
+ ) : ( +
+ No states found +
+ )}
@@ -306,11 +617,14 @@ export function LinearIssueEditSection({ @@ -319,10 +633,7 @@ export function LinearIssueEditSection({ key={p} type="button" onClick={() => handlePriorityChange(String(p))} - className={cn( - 'flex w-full items-center rounded-sm px-2 py-1.5 text-[12px] hover:bg-accent', - localPriority === p && 'bg-accent/50' - )} + className={cn(LINEAR_EDIT_MENU_ITEM_CLASS, localPriority === p && 'bg-accent/50')} > {PRIORITY_LABELS[p]} @@ -335,17 +646,14 @@ export function LinearIssueEditSection({ @@ -353,26 +661,34 @@ export function LinearIssueEditSection({ - {members.data.map((m) => ( - - ))} + {members.error ? ( +
+ {members.error} +
+ ) : members.loading ? ( +
+ + Loading members +
+ ) : ( + members.data.map((m) => ( + + )) + )}
@@ -382,37 +698,31 @@ export function LinearIssueEditSection({ {labels.error ? (
{labels.error}
- ) : ( + ) : labels.loading ? ( +
+ + Loading labels +
+ ) : labels.data.length > 0 ? (
{labels.data.map((label) => (
+ ) : ( +
+ No labels found +
)}
@@ -444,11 +758,13 @@ export type LinearLocalComment = { id: string; body: string; createdAt: string } export function LinearIssueCommentFooter({ issueId, workspaceId, - onCommentAdded + onCommentAdded, + variant = 'compact' }: { issueId: string workspaceId?: string | null onCommentAdded: (comment: LinearLocalComment) => void + variant?: 'compact' | 'linear-page' }): React.JSX.Element { const settings = useAppStore((s) => s.settings) const [body, setBody] = useState('') @@ -501,6 +817,42 @@ export function LinearIssueCommentFooter({ [handleSubmit] ) + if (variant === 'linear-page') { + return ( +
+