diff --git a/apps/server/src/environment/ServerEnvironment.ts b/apps/server/src/environment/ServerEnvironment.ts index 0f3a88f5c0d94..1760623071efb 100644 --- a/apps/server/src/environment/ServerEnvironment.ts +++ b/apps/server/src/environment/ServerEnvironment.ts @@ -227,6 +227,7 @@ export const make = Effect.gen(function* () { fileAttachments: { maxUploadBytes: PROVIDER_SEND_TURN_MAX_FILE_BYTES }, pullRequests: true, pullRequestChecks: true, + issues: true, linkedThreadRefreshes: true, sideChats: true, vcsBranchStatus: true, diff --git a/apps/web/src/closedViewStore.ts b/apps/web/src/closedViewStore.ts index b5db7bd741bef..2578922db3d11 100644 --- a/apps/web/src/closedViewStore.ts +++ b/apps/web/src/closedViewStore.ts @@ -95,6 +95,16 @@ const isClosedViewEntry = (entry: unknown): entry is ClosedViewEntry => { (surface.host === undefined || typeof surface.host === "string") && (surface.url === undefined || typeof surface.url === "string") ); + case "issue": + return ( + typeof surface.projectId === "string" && + typeof surface.tracker === "string" && + typeof surface.scope === "string" && + typeof surface.key === "string" && + (surface.environmentId === undefined || typeof surface.environmentId === "string") && + (surface.host === undefined || typeof surface.host === "string") && + (surface.url === undefined || typeof surface.url === "string") + ); default: return false; } diff --git a/apps/web/src/components/CommandPalette.tsx b/apps/web/src/components/CommandPalette.tsx index d84e7b5b2bc84..b3c332dd96924 100644 --- a/apps/web/src/components/CommandPalette.tsx +++ b/apps/web/src/components/CommandPalette.tsx @@ -278,6 +278,8 @@ import { pickableProjectGroups } from "@t3tools/client-runtime/state/project-gro import { buildSidebarProjectPickerEntries } from "../sidebarProjectGrouping"; import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons"; import { readPullRequestListPreferences } from "~/components/pullRequest/pullRequestListPreferences"; +import { readIssueListPreferences } from "~/components/issue/issueListPreferences"; +import { IssueGlyph } from "~/components/issue/issuePresentation"; import { useThreadRouteTarget } from "../hooks/useThreadRouteTarget"; import { threadRecentUse } from "@t3tools/shared/paletteSearch"; @@ -1654,6 +1656,23 @@ function OpenCommandPaletteDialog(props: { }); } + if ( + environments.some( + (environment) => environment.serverConfig?.environment.capabilities.issues === true, + ) + ) { + actionItems.push({ + kind: "action", + value: "action:issues", + searchTerms: ["issues", "issue", "bugs", "tracker", "github", "triage"], + title: "Open issues", + icon: , + run: async () => { + await navigate({ to: "/issues", search: readIssueListPreferences() }); + }, + }); + } + actionItems.push({ kind: "action", value: "action:use-in-another-app", diff --git a/apps/web/src/components/ReopenClosedViewShortcut.tsx b/apps/web/src/components/ReopenClosedViewShortcut.tsx index dfb68fe27e80a..3895f272d20f5 100644 --- a/apps/web/src/components/ReopenClosedViewShortcut.tsx +++ b/apps/web/src/components/ReopenClosedViewShortcut.tsx @@ -23,6 +23,7 @@ import { reopenClosedView, } from "../reopenClosedView"; import { + ISSUES_PANEL_REF, PULL_REQUESTS_PANEL_REF, selectActiveRightPanel, selectSelectedRightPanelSurface, @@ -42,6 +43,7 @@ import { resolveThreadRouteTarget, } from "../threadRoutes"; import { toastManager } from "./ui/toast"; +import { readIssueListPreferences } from "./issue/issueListPreferences"; const PREVIEW_FORWARDED_COMMANDS = [ "workspace.focusNext", @@ -58,6 +60,8 @@ const PREVIEW_FORWARDED_COMMANDS = [ const isGlobalPullRequests = (ref: ScopedThreadRef) => scopedThreadKey(ref) === scopedThreadKey(PULL_REQUESTS_PANEL_REF); +const isGlobalIssues = (ref: ScopedThreadRef) => + scopedThreadKey(ref) === scopedThreadKey(ISSUES_PANEL_REF); export function ReopenClosedViewShortcut() { const navigate = useNavigate(); @@ -91,7 +95,7 @@ export function ReopenClosedViewShortcut() { const { drop, restore } = planNextReopen(useClosedViewStore.getState().entries, (entry) => { const ref = entry.threadRef; const panel = selectThreadRightPanelState(panelsByThread, ref); - if (isGlobalPullRequests(ref)) { + if (isGlobalPullRequests(ref) || isGlobalIssues(ref)) { return { environmentKnown: true, catalogReady: true, @@ -119,7 +123,8 @@ export function ReopenClosedViewShortcut() { const ref = restore.threadRef; const globalPullRequests = isGlobalPullRequests(ref); - const thread = globalPullRequests ? null : readThreadShell(ref); + const globalIssues = isGlobalIssues(ref); + const thread = globalPullRequests || globalIssues ? null : readThreadShell(ref); const owner = thread ?? drafts.getDraftThreadByRef(ref); const project = owner ? readProject(scopeProjectRef(ref.environmentId, owner.projectId)) : null; if (!(await reopenClosedView(restore, { openPreview, workspaceAvailable: project !== null }))) { @@ -136,6 +141,8 @@ export function ReopenClosedViewShortcut() { to: "/pull-requests", search: (previous) => pullRequestsSearchForRestore(previous, selected), }); + } else if (globalIssues) { + await navigate({ to: "/issues", search: readIssueListPreferences() }); } else { const draftId = thread === null ? drafts.getDraftIdByRef(ref) : null; if (draftId !== null) diff --git a/apps/web/src/components/RightPanelTabs.tsx b/apps/web/src/components/RightPanelTabs.tsx index 7976616286735..5e18356f4830d 100644 --- a/apps/web/src/components/RightPanelTabs.tsx +++ b/apps/web/src/components/RightPanelTabs.tsx @@ -17,6 +17,7 @@ import { import type { ContextMenuItem, EnvironmentId, + IssueTrackerKind, PreviewSessionSnapshot, ProjectId, PullRequestState, @@ -36,6 +37,7 @@ import { restrictToFirstScrollableAncestor, restrictToHorizontalAxis } from "@dn import { horizontalListSortingStrategy, SortableContext, useSortable } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; import { + CircleDotIcon, Smartphone, ChevronDown, ChevronLeft, @@ -64,6 +66,8 @@ import { isElectron } from "~/env"; import type { DesktopPreviewOverlay } from "~/previewStateStore"; import type { RightPanelSurface } from "~/rightPanelStore"; import { cn } from "~/lib/utils"; +import { issueStatePresentation } from "~/components/issue/issuePresentation"; +import { issueEnvironment } from "~/state/issues"; import { resolveShortcutCommand, type ShortcutMatchContext } from "~/keybindings"; import { readLocalApi } from "~/localApi"; import { useStableCallback } from "~/hooks/useStableCallback"; @@ -592,6 +596,9 @@ function surfaceTitle( return `#${surface.number}`; case "pull-requests": return "Pull requests"; + case "issue": + // A git host numbers its issues; a tracker with keys of its own, such as Linear, names them. + return /^\d+$/.test(surface.key) ? `#${surface.key}` : surface.key; case "device": return surface.title ?? surface.target?.name ?? "Device"; case "side-chat": @@ -684,6 +691,8 @@ function SurfaceIcon({ ); case "pull-requests": return ; + case "issue": + return ; case "side-chat": return ; case "device": @@ -756,6 +765,41 @@ export function resolvePullRequestTabLink( return newest; } +/** The issue's own state mark, from the detail its panel already reads; a plain dot until then. */ +function IssueSurfaceIcon({ + surface, + environmentId, +}: { + surface: Extract; + environmentId: EnvironmentId | null; +}) { + const resolvedEnvironmentId = + (surface.environmentId as EnvironmentId | undefined) ?? environmentId; + const detail = useEnvironmentQuery( + resolvedEnvironmentId === null + ? null + : issueEnvironment.detail({ + environmentId: resolvedEnvironmentId, + input: { + projectId: surface.projectId as ProjectId, + tracker: surface.tracker as IssueTrackerKind, + ...(surface.host ? { host: surface.host } : {}), + scope: surface.scope, + key: surface.key, + }, + }), + ).data; + if (detail === null) return ; + const presentation = issueStatePresentation(detail.state); + return ( + + ); +} + function PullRequestSurfaceIcon({ surface, environmentId, diff --git a/apps/web/src/components/issue/IssueCommentComposer.tsx b/apps/web/src/components/issue/IssueCommentComposer.tsx new file mode 100644 index 0000000000000..6383f25b15b95 --- /dev/null +++ b/apps/web/src/components/issue/IssueCommentComposer.tsx @@ -0,0 +1,110 @@ +import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; +import type { EnvironmentId, IssueRef } from "@t3tools/contracts"; +import { ArrowUpIcon } from "lucide-react"; +import { useRef, useState } from "react"; + +import { TextFieldSpeechControls, useTextFieldSpeech } from "~/speech/useTextFieldSpeech"; +import { issueEnvironment } from "~/state/issues"; +import { useAtomCommand } from "~/state/use-atom-command"; + +import { ComposerSurface } from "../chat/ComposerSurface"; +import { readableFailure } from "../pullRequest/pullRequestDetail.logic"; +import { Spinner } from "../ui/spinner"; +import { toastManager } from "../ui/toast"; + +/** The thread composer's card, floating over the issue's timeline, with a comment as its message. */ +export function IssueCommentComposer({ + environmentId, + reference, + blocked, +}: { + environmentId: EnvironmentId; + reference: IssueRef; + /** Why the viewer cannot comment here; null when they can. */ + blocked: string | null; +}) { + const [body, setBody] = useState(""); + const [submitting, setSubmitting] = useState(false); + const textareaRef = useRef(null); + const comment = useAtomCommand(issueEnvironment.comment, { reportFailure: false }); + const locked = blocked !== null || submitting; + const speech = useTextFieldSpeech({ + environmentId, + projectId: reference.projectId, + ownerKey: JSON.stringify(["issue-comment", environmentId, reference]), + text: body, + textareaRef, + onTextChange: setBody, + disabled: locked, + }); + + const submit = async (text: string) => { + if (text.trim().length === 0 || locked) return; + setSubmitting(true); + const result = await comment({ environmentId, input: { ...reference, body: text } }); + setSubmitting(false); + if (result._tag === "Failure") { + toastManager.add({ + type: "error", + title: "The comment could not be posted", + description: readableFailure(squashAtomCommandFailure(result), "The tracker refused it."), + }); + return; + } + setBody(""); + }; + const submitAfterDictation = () => speech.submitAfterDictation((text) => void submit(text)); + const submitDisabled = + speech.preparing || (body.trim().length === 0 && !speech.blocksSubmission) || locked; + + return ( +
+ + +
{ + event.preventDefault(); + submitAfterDictation(); + }} + > +