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
33 changes: 23 additions & 10 deletions apps/web/src/components/CommandPalette.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
readonly description?: string;
readonly timestamp?: string;
readonly icon: ReactNode;
/** Optional content rendered inline before the title text. */
readonly titleLeadingContent?: ReactNode;
/** Optional content rendered inline after the title text (before the timestamp). */
readonly titleTrailingContent?: ReactNode;
readonly shortcutCommand?: KeybindingCommand;
}

Expand Down Expand Up @@ -102,20 +106,24 @@
}));
}

export function buildThreadActionItems(input: {
threads: ReadonlyArray<
Pick<
SidebarThreadSummary,
"archivedAt" | "branch" | "createdAt" | "environmentId" | "id" | "projectId" | "title"
> & {
updatedAt?: string | undefined;
latestUserMessageAt?: string | null;
}
>;
export type BuildThreadActionItemsThread = Pick<
SidebarThreadSummary,
"archivedAt" | "branch" | "createdAt" | "environmentId" | "id" | "projectId" | "title"
> & {
updatedAt?: string | undefined;
latestUserMessageAt?: string | null;
};

export function buildThreadActionItems<TThread extends BuildThreadActionItemsThread>(input: {
threads: ReadonlyArray<TThread>;
activeThreadId?: Thread["id"];
projectTitleById: ReadonlyMap<Project["id"], string>;
sortOrder: SidebarThreadSortOrder;
icon: ReactNode;
/** Optional content rendered inline before the title text per-thread. */
renderLeadingContent?: (thread: TThread) => ReactNode;
/** Optional content rendered inline after the title text per-thread. */
renderTrailingContent?: (thread: TThread) => ReactNode;
runThread: (thread: Pick<SidebarThreadSummary, "environmentId" | "id">) => Promise<void>;
limit?: number;
}): CommandPaletteActionItem[] {
Expand All @@ -126,7 +134,7 @@
const visibleThreads =
input.limit === undefined ? sortedThreads : sortedThreads.slice(0, input.limit);

return visibleThreads.map((thread) => {

Check warning on line 137 in apps/web/src/components/CommandPalette.logic.ts

View workflow job for this annotation

GitHub Actions / Format, Lint, Typecheck, Test, Browser Test, Build

oxc(no-map-spread)

Spreading to modify object properties in `map` calls is inefficient
const projectTitle = input.projectTitleById.get(thread.projectId);
const descriptionParts: string[] = [];

Expand All @@ -140,6 +148,9 @@
descriptionParts.push("Current thread");
}

const leadingContent = input.renderLeadingContent?.(thread);
const trailingContent = input.renderTrailingContent?.(thread);

return {
kind: "action",
value: `thread:${thread.id}`,
Expand All @@ -150,6 +161,8 @@
thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt,
),
icon: input.icon,
...(leadingContent ? { titleLeadingContent: leadingContent } : {}),
...(trailingContent ? { titleTrailingContent: trailingContent } : {}),
run: async () => {
await input.runThread(thread);
},
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/components/CommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import {
import { resolveEnvironmentOptionLabel } from "./BranchToolbar.logic";
import { CommandPaletteResults } from "./CommandPaletteResults";
import { ProjectFavicon } from "./ProjectFavicon";
import { ThreadRowLeadingStatus, ThreadRowTrailingStatus } from "./ThreadStatusIndicators";
import { useServerKeybindings } from "../rpc/serverState";
import { resolveShortcutCommand } from "../keybindings";
import {
Expand Down Expand Up @@ -504,6 +505,8 @@ function OpenCommandPaletteDialog() {
projectTitleById,
sortOrder: settings.sidebarThreadSortOrder,
icon: <MessageSquareIcon className={ITEM_ICON_CLASS} />,
renderLeadingContent: (thread) => <ThreadRowLeadingStatus thread={thread} />,
renderTrailingContent: (thread) => <ThreadRowTrailingStatus thread={thread} />,
runThread: async (thread) => {
await navigate({
to: "/$environmentId/$threadId",
Expand Down
10 changes: 8 additions & 2 deletions apps/web/src/components/CommandPaletteResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,20 @@ function CommandPaletteResultRow(props: {
{props.item.icon}
{props.item.description ? (
<span className="flex min-w-0 flex-1 flex-col">
<span className="truncate text-sm text-foreground">{props.item.title}</span>
<span className="flex min-w-0 items-center gap-1.5 text-sm text-foreground">
{props.item.titleLeadingContent}
<span className="truncate">{props.item.title}</span>
{props.item.titleTrailingContent}
</span>
<span className="truncate text-muted-foreground/70 text-xs">
{props.item.description}
</span>
</span>
) : (
<span className="flex min-w-0 items-center gap-1.5 truncate text-sm text-foreground">
<span className="flex min-w-0 flex-1 items-center gap-1.5 text-sm text-foreground">
{props.item.titleLeadingContent}
<span className="truncate">{props.item.title}</span>
{props.item.titleTrailingContent}
</span>
)}
{props.item.timestamp ? (
Expand Down
114 changes: 6 additions & 108 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import {
TerminalIcon,
TriangleAlertIcon,
} from "lucide-react";
import {
prStatusIndicator,
resolveThreadPr,
terminalStatusFromRunningIds,
ThreadStatusLabel,
} from "./ThreadStatusIndicators";
import { ProjectFavicon } from "./ProjectFavicon";
import { autoAnimate } from "@formkit/auto-animate";
import React, { useCallback, useEffect, memo, useMemo, useRef, useState } from "react";
Expand Down Expand Up @@ -38,7 +44,6 @@ import {
type SidebarProjectGroupingMode,
type ThreadEnvMode,
ThreadId,
type GitStatusResult,
} from "@t3tools/contracts";
import {
parseScopedThreadKey,
Expand Down Expand Up @@ -264,113 +269,6 @@ function buildThreadJumpLabelMap(input: {
return mapping.size > 0 ? mapping : EMPTY_THREAD_JUMP_LABELS;
}

interface TerminalStatusIndicator {
label: "Terminal process running";
colorClass: string;
pulse: boolean;
}

interface PrStatusIndicator {
label: "PR open" | "PR closed" | "PR merged";
colorClass: string;
tooltip: string;
url: string;
}

type ThreadPr = GitStatusResult["pr"];

function ThreadStatusLabel({
status,
compact = false,
}: {
status: ThreadStatusPill;
compact?: boolean;
}) {
if (compact) {
return (
<span
title={status.label}
className={`inline-flex size-3.5 shrink-0 items-center justify-center ${status.colorClass}`}
>
<span
className={`size-[9px] rounded-full ${status.dotClass} ${
status.pulse ? "animate-pulse" : ""
}`}
/>
<span className="sr-only">{status.label}</span>
</span>
);
}

return (
<span
title={status.label}
className={`inline-flex items-center gap-1 text-[10px] ${status.colorClass}`}
>
<span
className={`h-1.5 w-1.5 rounded-full ${status.dotClass} ${
status.pulse ? "animate-pulse" : ""
}`}
/>
<span className="hidden md:inline">{status.label}</span>
</span>
);
}

function terminalStatusFromRunningIds(
runningTerminalIds: string[],
): TerminalStatusIndicator | null {
if (runningTerminalIds.length === 0) {
return null;
}
return {
label: "Terminal process running",
colorClass: "text-teal-600 dark:text-teal-300/90",
pulse: true,
};
}

function prStatusIndicator(pr: ThreadPr): PrStatusIndicator | null {
if (!pr) return null;

if (pr.state === "open") {
return {
label: "PR open",
colorClass: "text-emerald-600 dark:text-emerald-300/90",
tooltip: `#${pr.number} PR open: ${pr.title}`,
url: pr.url,
};
}
if (pr.state === "closed") {
return {
label: "PR closed",
colorClass: "text-zinc-500 dark:text-zinc-400/80",
tooltip: `#${pr.number} PR closed: ${pr.title}`,
url: pr.url,
};
}
if (pr.state === "merged") {
return {
label: "PR merged",
colorClass: "text-violet-600 dark:text-violet-300/90",
tooltip: `#${pr.number} PR merged: ${pr.title}`,
url: pr.url,
};
}
return null;
}

function resolveThreadPr(
threadBranch: string | null,
gitStatus: GitStatusResult | null,
): ThreadPr | null {
if (threadBranch === null || gitStatus === null || gitStatus.branch !== threadBranch) {
return null;
}

return gitStatus.pr ?? null;
}

interface SidebarThreadRowProps {
thread: SidebarThreadSummary;
projectCwd: string | null;
Expand Down
Loading
Loading