Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/web/src/components/RightPanelTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import type { DesktopPreviewOverlay } from "~/previewStateStore";
import { linkedThreadTitle } from "~/linkedThreadSurface";
import type { RightPanelSurface } from "~/rightPanelStore";
import { cn } from "~/lib/utils";
import { type FilePathCopyKind, filePathCopyLabel } from "~/fileContextMenu";
import type { FilePathCopyKind } from "~/fileContextMenu";
import { issueStatePresentation } from "~/components/issue/issuePresentation";
import { issueEnvironment } from "~/state/issues";
import { resolveShortcutCommand, type ShortcutMatchContext } from "~/keybindings";
Expand Down Expand Up @@ -1353,9 +1353,9 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
if (surface.kind === "file" && surface.attachment === undefined) {
// A host file's only path is the full one.
if (!isAbsolutePath(surface.relativePath)) {
items.push({ id: "copy-relative-path", label: filePathCopyLabel("relative") });
items.push({ id: "copy-relative-path", label: gt("Copy relative path") });
}
items.push({ id: "copy-full-path", label: filePathCopyLabel("full") });
items.push({ id: "copy-full-path", label: gt("Copy full path") });
}
const menuPreviewTabId = previewTabIdOf(surface, props.previewSessions);
const menuOverlay = menuPreviewTabId ? (props.desktopByTabId[menuPreviewTabId] ?? null) : null;
Expand Down
20 changes: 14 additions & 6 deletions apps/web/src/components/chat/MessagesTimeline.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ import {
deriveFinalResponseRunIdsKey,
workEntryReadOutput,
} from "./MessagesTimeline.logic";
import { deriveTimelineMinimapItems } from "./MessagesTimeline.minimap";
import {
computeTimelineMinimapState,
EMPTY_TIMELINE_MINIMAP_STATE,
} from "./MessagesTimeline.minimap";
import { workEntryIconName } from "./TimelineWorkEntryRow.logic";

describe("resolveAssistantMessageCopyState", () => {
Expand Down Expand Up @@ -2950,16 +2953,21 @@ describe("deriveMessagesTimelineRows", () => {

expect(finalIds(rows)).toEqual(["final-1", "final-3"]);
expect(
deriveTimelineMinimapItems(rows, "final-assistant").map((item) => ({
id: item.id,
primaryText: item.primaryText,
})),
computeTimelineMinimapState(rows, EMPTY_TIMELINE_MINIMAP_STATE).assistantItems.map(
(item) => ({
id: item.id,
primaryText: item.primaryText,
}),
),
).toEqual([
{ id: "final-1-entry", primaryText: "Done." },
{ id: "final-3-entry", primaryText: "Third answer." },
]);
expect(
deriveTimelineMinimapItems(rows, "user-turn").map((item) => [item.id, item.secondaryText]),
computeTimelineMinimapState(rows, EMPTY_TIMELINE_MINIMAP_STATE).userItems.map((item) => [
item.id,
item.secondaryText,
]),
).toEqual([
["user-1-entry", "Done."],
["user-2-entry", "Still working."],
Expand Down
28 changes: 13 additions & 15 deletions apps/web/src/components/chat/MessagesTimeline.minimap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import type { MessagesTimelineRow } from "./MessagesTimeline.logic";
import {
computeTimelineMinimapState,
deriveTimelineMinimapItems,
EMPTY_TIMELINE_MINIMAP_STATE,
resolveTimelineMinimapAnchorIndex,
resolveTimelineMinimapAriaLabel,
Expand Down Expand Up @@ -76,7 +75,7 @@ describe("resolveTimelineMinimapTooltipTranslate", () => {
});
});

describe("deriveTimelineMinimapItems", () => {
describe("computeTimelineMinimapState items", () => {
it("lists replies in order without gaps and flags messages from other agents", () => {
const rows = [
messageRow({ id: "user-1", role: "user", text: "user-1" }),
Expand All @@ -92,20 +91,17 @@ describe("deriveTimelineMinimapItems", () => {
];

expect(
deriveTimelineMinimapItems(rows, "final-assistant").map(({ id, timestamp }) => [
id,
timestamp,
]),
computeTimelineMinimapState(rows, EMPTY_TIMELINE_MINIMAP_STATE).assistantItems.map(
({ id, timestamp }) => [id, timestamp],
),
).toEqual([
["assistant-1", "updated:assistant-1"],
["assistant-3", "updated:assistant-3"],
]);
expect(
deriveTimelineMinimapItems(rows, "user-turn").map(({ id, fromAgent, timestamp }) => [
id,
fromAgent,
timestamp,
]),
computeTimelineMinimapState(rows, EMPTY_TIMELINE_MINIMAP_STATE).userItems.map(
({ id, fromAgent, timestamp }) => [id, fromAgent, timestamp],
),
).toEqual([
["user-1", false, "created:user-1"],
["user-2", false, "created:user-2"],
Expand All @@ -122,7 +118,9 @@ describe("deriveTimelineMinimapItems", () => {
}),
];

expect(deriveTimelineMinimapItems(rows, "user-turn")[0]?.primaryText).toBeNull();
expect(
computeTimelineMinimapState(rows, EMPTY_TIMELINE_MINIMAP_STATE).userItems[0]?.primaryText,
).toBeNull();
});

it("previews a quote and a context chip in the user's message as their text", () => {
Expand All @@ -146,9 +144,9 @@ describe("deriveTimelineMinimapItems", () => {
messageRow({ id: "user-1", role: "user", text: `${quote}\nWhere does ${file} cover this?` }),
];

expect(deriveTimelineMinimapItems(rows, "user-turn")[0]?.primaryText).toBe(
"The cache misses on a cold start. Where does README.md cover this?",
);
expect(
computeTimelineMinimapState(rows, EMPTY_TIMELINE_MINIMAP_STATE).userItems[0]?.primaryText,
).toBe("The cache misses on a cold start. Where does README.md cover this?");
});
});

Expand Down
10 changes: 0 additions & 10 deletions apps/web/src/components/chat/MessagesTimeline.minimap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import {
const TIMELINE_MINIMAP_ARIA_EXCERPT_MAX_LENGTH = 120;
export const TIMELINE_MINIMAP_PREVIEW_MAX_LENGTH = 240;

export type TimelineMinimapKind = "user-turn" | "final-assistant";

export interface TimelineMinimapItem {
readonly id: string;
readonly rowIndex: number;
Expand Down Expand Up @@ -240,14 +238,6 @@ export function computeTimelineMinimapState(
};
}

export function deriveTimelineMinimapItems(
rows: ReadonlyArray<MessagesTimelineRow>,
kind: TimelineMinimapKind,
): ReadonlyArray<TimelineMinimapItem> {
const state = computeTimelineMinimapState(rows, EMPTY_TIMELINE_MINIMAP_STATE);
return kind === "user-turn" ? state.userItems : state.assistantItems;
}

export function resolveTimelineMinimapTooltipTranslate(index: number, itemCount: number): string {
if (index === 0) {
return "0%";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/chat/useRightPanelActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export function useRightPanelActions(input: RightPanelActionsInput) {
if (activeWorkspaceRoot === undefined) {
toastManager.add({
type: "error",
title: "Failed to copy full path",
title: m(msg("Failed to copy full path")),
description: "The project root is not loaded yet.",
});
return;
Expand Down
74 changes: 30 additions & 44 deletions apps/web/src/components/linear/LinearIssueDetailPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ import type {
ScopedThreadRef,
} from "@t3tools/contracts";
import {
CheckIcon,
CopyIcon,
CornerLeftUpIcon,
ExternalLinkIcon,
GitBranchIcon,
LinkIcon,
SendIcon,
} from "lucide-react";
import { useAtomValue } from "@effect/atom-react";
import { useRef, useState, type ReactNode } from "react";
import { msg, useGT } from "gt-react";
import { useState, type ReactNode } from "react";

import { RefreshIcon } from "~/components/ui/refresh-icon";
import { cn } from "~/lib/utils";
Expand All @@ -33,11 +32,8 @@ import { formatRelativeTimeLabel } from "~/timestampFormat";
import { useRightPanelStore } from "../../rightPanelStore";
import ChatMarkdown from "../ChatMarkdown";
import { LinearIcon } from "../Icons";
import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";
import {
ANCHORED_COPY_TOAST_TIMEOUT_MS,
showAnchoredCopyErrorToast,
} from "../ui/anchoredCopyToast";
import { PullRequestCopyableCode } from "../pullRequest/PullRequestCopyableCode";
import { PullRequestLabelChip } from "../pullRequest/pullRequestPresentation";
import { Badge } from "../ui/badge";
import { Button } from "../ui/button";
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from "../ui/empty";
Expand All @@ -48,7 +44,6 @@ import { linearCommentDraftKey, useLinearCommentDraftStore } from "./linearComme
import { linearIssueUrl } from "./linearMarkdown.logic";
import {
formatLinearDueDate,
LinearLabelPill,
LinearPriorityIcon,
LinearStateIcon,
LinearUserAvatar,
Expand Down Expand Up @@ -255,41 +250,12 @@ function DetailRow({ label, children }: { label: string; children: ReactNode })
);
}

function CopyButton({ value, label }: { value: string; label: string }) {
const ref = useRef<HTMLButtonElement>(null);
const { copyToClipboard, isCopied } = useCopyToClipboard<void>({
onError: (error) => showAnchoredCopyErrorToast(ref, error),
timeout: ANCHORED_COPY_TOAST_TIMEOUT_MS,
});
return (
<Tooltip>
<TooltipTrigger
render={
<Button
ref={ref}
aria-label={label}
size="icon-micro"
variant="ghost-muted"
onClick={() => copyToClipboard(value, undefined)}
>
{isCopied ? (
<CheckIcon className="size-3 text-success" />
) : (
<CopyIcon className="size-3" />
)}
</Button>
}
/>
<TooltipPopup side="top">{label}</TooltipPopup>
</Tooltip>
);
}

/**
* Timestamps, the due date, and the branch name. Two label/value pairs per row once the panel
* is wide enough for them, one below the other before that.
*/
function IssueDetails({ issue }: { issue: LinearIssue }) {
const gt = useGT();
const due = issue.dueDate ? formatLinearDueDate(issue.dueDate) : null;
const settled = isEnded(issue.state);
return (
Expand Down Expand Up @@ -328,10 +294,25 @@ function IssueDetails({ issue }: { issue: LinearIssue }) {
{issue.branchName ? (
<div className="mt-2.5 flex min-w-0 items-center gap-1.5">
<GitBranchIcon aria-hidden className="size-3.5 shrink-0 text-muted-foreground" />
<code className="min-w-0 truncate font-mono text-2xs text-foreground/90">
{issue.branchName}
</code>
<CopyButton value={issue.branchName} label="Copy branch name" />
<PullRequestCopyableCode
key={issue.branchName}
value={issue.branchName}
target={{
target: "branch name",
unavailableMessage: msg("Clipboard API is unavailable while copying branch name."),
failureMessage: msg("Failed to copy branch name to the clipboard."),
}}
copyLabel={gt("Copy branch name")}
copiedLabel={gt("Branch name copied")}
onError={(error) =>
toastManager.add({
type: "error",
title: gt("Failed to copy"),
description: error.message,
})
}
className="font-mono text-2xs text-foreground/90"
/>
</div>
) : null}
</div>
Expand Down Expand Up @@ -701,7 +682,12 @@ export function LinearIssueDetailPanel({
{issue.labels.length > 0 ? (
<div className="mt-2 flex flex-wrap gap-1.5">
{issue.labels.map((label) => (
<LinearLabelPill key={label.name} label={label} />
<PullRequestLabelChip
key={label.name}
label={label}
size="default"
className="max-w-48"
/>
))}
</div>
) : null}
Expand Down
13 changes: 0 additions & 13 deletions apps/web/src/components/linear/linearPresentation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,6 @@ export function LinearStateBadge({
);
}

export function LinearLabelPill({ label }: { label: LinearIssue["labels"][number] }) {
return (
<span className="inline-flex h-6 items-center gap-1.5 rounded-full border border-border/60 px-2 text-xs text-foreground/90">
<span
aria-hidden
className="size-2 shrink-0 rounded-full"
style={{ backgroundColor: label.color }}
/>
<span className="truncate">{label.name}</span>
</span>
);
}

export function LinearUserAvatar({
user,
className,
Expand Down
16 changes: 7 additions & 9 deletions apps/web/src/fileContextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { toastManager } from "./components/ui/toast";
import { useAtomValue } from "@effect/atom-react";
import { msg, useMessages } from "gt-react";

import type { MessageResolver } from "./i18n/messages";
import { m, type MessageResolver } from "./i18n/messages";

export type FileContextMenuAction =
| "reveal-in-folder"
Expand Down Expand Up @@ -145,24 +145,20 @@ export function buildFileContextMenuItems(input: {
if (input.hasRelativePath) {
items.push({
id: "copy-relative-path",
label: filePathCopyLabel("relative"),
label: input.resolve(msg("Copy relative path")),
icon: "copy",
separatorBefore,
});
}
items.push({
id: "copy-full-path",
label: filePathCopyLabel("full"),
label: input.resolve(msg("Copy full path")),
icon: "copy",
separatorBefore: separatorBefore && !input.hasRelativePath,
});
return items;
}

export function filePathCopyLabel(kind: FilePathCopyKind): string {
return kind === "relative" ? "Copy relative path" : "Copy full path";
}

/** Copies a file path and reports the outcome with the same toasts everywhere. */
export async function copyFilePathToClipboard(
value: string,
Expand All @@ -175,12 +171,14 @@ export async function copyFilePathToClipboard(
if (!(await writeTextToClipboard(value, namedClipboardTarget(noun.toLowerCase()))))
failure = "The path is empty.";
} catch (error) {
failure = error instanceof Error ? error.message : "An error occurred.";
failure = error instanceof Error ? error.message : m(msg("An error occurred."));
}
if (failure !== null) {
toastManager.add({
type: "error",
title: `Failed to copy ${noun.toLowerCase()}`,
title: m(
kind === "relative" ? msg("Failed to copy relative path") : msg("Failed to copy full path"),
),
description: failure,
});
return;
Expand Down
Loading