diff --git a/src/components/file-tree.tsx b/src/components/file-tree.tsx index 248f267..7a9c6b7 100644 --- a/src/components/file-tree.tsx +++ b/src/components/file-tree.tsx @@ -5,17 +5,21 @@ import { Folder, FolderOpen, FolderTree, + GitPullRequest, + House, MonitorCog, ScrollText, SlidersHorizontal, SwatchBook, } from "lucide-react"; import { FileIcon } from "react-files-icons"; +import { GitHostIcon } from "@/components/git-host-icon"; import { type ChangeKind, type FileNode, useFileTree, } from "@/lib/file-tree-context"; +import type { GitHost } from "@/lib/git-host/types"; import { cn } from "@/lib/utils"; interface FileTreeProps { @@ -28,9 +32,14 @@ interface FileTreeProps { viewedFiles?: ReadonlySet; onToggleViewed?: (path: string) => void; onFileClick?: (node: FileNode) => void; + onDirectoryClick?: (node: FileNode) => boolean | undefined; + showUnviewedIndicator?: boolean; } const SETTINGS_PATH_PREFIX = "__settings__/"; +const HOME_PATH = "__home__"; +const PR_PATH_PREFIX = "pr:"; +const REPO_PATH_PREFIX = "repo:"; function kindColor(kind: ChangeKind) { switch (kind) { @@ -57,6 +66,24 @@ function isSettingsPath(path: string) { return path.startsWith(SETTINGS_PATH_PREFIX); } +function isHomePath(path: string) { + return path === HOME_PATH; +} + +function isPullRequestPath(path: string) { + return path.startsWith(PR_PATH_PREFIX); +} + +function isRepositoryPath(path: string) { + return path.startsWith(REPO_PATH_PREFIX); +} + +function hostFromTreePath(path: string): GitHost | null { + const [, host] = path.split(":"); + if (host === "github" || host === "bitbucket") return host; + return null; +} + function settingsIcon(path: string) { if (!isSettingsPath(path)) return null; const tab = path.slice(SETTINGS_PATH_PREFIX.length); @@ -78,6 +105,8 @@ export function FileTree({ viewedFiles, onToggleViewed, onFileClick, + onDirectoryClick, + showUnviewedIndicator = true, }: FileTreeProps) { const tree = useFileTree(); const resolvedKinds = kinds ?? tree.kinds; @@ -99,6 +128,12 @@ export function FileTree({ return queryMatch && allowedMatch; } const children = tree.children(node.path); + const host = hostFromTreePath(node.path); + if (host && children.length === 0) { + if (!normalizedQuery) return true; + const hostSearch = `${node.name} ${node.path}`.toLowerCase(); + return hostSearch.includes(normalizedQuery); + } return children.some(matchesNode); }; @@ -121,6 +156,8 @@ export function FileTree({ viewedFiles={viewedFiles} onToggleViewed={onToggleViewed} onFileClick={onFileClick} + onDirectoryClick={onDirectoryClick} + showUnviewedIndicator={showUnviewedIndicator} /> ); } @@ -134,6 +171,7 @@ export function FileTree({ active={active} viewed={viewedFiles?.has(node.path)} onFileClick={onFileClick} + showUnviewedIndicator={showUnviewedIndicator} /> ); })} @@ -152,6 +190,8 @@ function DirectoryNode({ viewedFiles, onToggleViewed, onFileClick, + onDirectoryClick, + showUnviewedIndicator, }: { node: FileNode; level: number; @@ -163,6 +203,8 @@ function DirectoryNode({ viewedFiles?: ReadonlySet; onToggleViewed?: (path: string) => void; onFileClick?: (node: FileNode) => void; + onDirectoryClick?: (node: FileNode) => boolean | undefined; + showUnviewedIndicator: boolean; }) { const tree = useFileTree(); const compactEnabled = tree.compactSingleChildDirectories; @@ -183,6 +225,16 @@ function DirectoryNode({ const expanded = tree.isExpanded(displayNode.path); const kind = kinds.get(displayNode.path); const displayName = nameParts.join("/"); + const host = hostFromTreePath(displayNode.path); + const isActive = activeFile === displayNode.path; + const isRepositoryNode = isRepositoryPath(displayNode.path); + const pullRequestCount = isRepositoryNode + ? tree + .children(displayNode.path) + .filter( + (child) => child.type === "file" && isPullRequestPath(child.path), + ).length + : 0; return (
@@ -191,10 +243,17 @@ function DirectoryNode({ className={cn( "group w-full min-w-0 flex items-center gap-3 py-1 text-left", "hover:bg-accent active:bg-accent/80 transition-colors cursor-pointer", - "text-muted-foreground", + isActive + ? "bg-accent text-accent-foreground" + : "text-muted-foreground", )} style={{ paddingLeft: `${4 + level * treeIndentSize}px` }} - onClick={() => tree.toggle(displayNode.path)} + onClick={() => { + tree.setActiveFile(displayNode.path); + const handled = onDirectoryClick?.(displayNode); + if (handled) return; + tree.toggle(displayNode.path); + }} aria-expanded={expanded} > - {expanded ? ( + {isRepositoryNode ? ( + + {pullRequestCount} + + ) : host ? ( + + ) : expanded ? ( ) : ( @@ -238,6 +303,8 @@ function DirectoryNode({ viewedFiles={viewedFiles} onToggleViewed={onToggleViewed} onFileClick={onFileClick} + onDirectoryClick={onDirectoryClick} + showUnviewedIndicator={showUnviewedIndicator} />
)} @@ -253,6 +320,7 @@ function FileNodeRow({ active, viewed, onFileClick, + showUnviewedIndicator, }: { node: FileNode; level: number; @@ -261,11 +329,14 @@ function FileNodeRow({ active?: string; viewed?: boolean; onFileClick?: (node: FileNode) => void; + showUnviewedIndicator: boolean; }) { const tree = useFileTree(); const kind = node.type === "summary" ? undefined : kinds.get(node.path); const nodeSettingsIcon = node.type === "file" ? settingsIcon(node.path) : null; + const isHomeNode = isHomePath(node.path); + const isPullRequestNode = isPullRequestPath(node.path); const isSettingsNode = node.type === "file" && isSettingsPath(node.path); const isActive = node.path === active; @@ -285,9 +356,17 @@ function FileNodeRow({ > {node.type === "summary" ? ( - + isHomeNode ? ( + + ) : ( + + ) ) : nodeSettingsIcon ? ( nodeSettingsIcon + ) : isHomeNode ? ( + + ) : isPullRequestNode ? ( + ) : ( )} @@ -296,12 +375,16 @@ function FileNodeRow({ {node.name} - {node.type !== "summary" && !isSettingsNode && !viewed && ( - - )} + {showUnviewedIndicator && + node.type !== "summary" && + !isSettingsNode && + !isHomeNode && + !viewed && ( + + )} ); } diff --git a/src/components/git-host-icon.tsx b/src/components/git-host-icon.tsx new file mode 100644 index 0000000..45e5697 --- /dev/null +++ b/src/components/git-host-icon.tsx @@ -0,0 +1,62 @@ +import type { GitHost } from "@/lib/git-host/types"; +import { cn } from "@/lib/utils"; + +export function GitHostIcon({ + host, + className, +}: { + host: GitHost; + className?: string; +}) { + if (host === "github") { + return ( + + ); + } + + return ( + + ); +} diff --git a/src/components/pull-request-review-page.tsx b/src/components/pull-request-review-page.tsx index f5b8425..643ea2a 100644 --- a/src/components/pull-request-review-page.tsx +++ b/src/components/pull-request-review-page.tsx @@ -17,10 +17,9 @@ import { Copy, Eye, EyeOff, - FolderGit, FolderMinus, FolderPlus, - GitPullRequest, + House, Loader2, MessageSquare, Minus, @@ -1010,6 +1009,21 @@ export function PullRequestReviewPage({ }, [diffByPath, selectedFilePath]); const isSummarySelected = activeFile === PR_SUMMARY_PATH; + useEffect(() => { + if (showSettingsPanel || viewMode !== "single") return; + if (!prData) return; + if (isSummarySelected) return; + if (selectedFileDiff) return; + setActiveFile(PR_SUMMARY_PATH); + }, [ + isSummarySelected, + prData, + selectedFileDiff, + setActiveFile, + showSettingsPanel, + viewMode, + ]); + const comments = prData?.comments ?? []; const threads = useMemo(() => buildThreads(comments), [comments]); const unresolvedThreads = threads.filter( @@ -1715,10 +1729,125 @@ export function PullRequestReviewPage({ if (prQuery.isLoading) { return ( -
-
- - Loading pull request... +
+ + +
+
+ {treeCollapsed ? ( + + ) : null} + + Loading pull request... + +
+
+
+
+ + Loading pull request... +
+
+
); @@ -1787,6 +1916,16 @@ export function PullRequestReviewPage({ className="h-11 px-2 border-b border-border flex items-center gap-2 text-[11px] text-muted-foreground" data-component="top-sidebar" > + - - +
-
+
{(["bitbucket", "github"] as GitHost[]).map((host) => ( ))} @@ -313,6 +336,7 @@ function AppLayout() { select: (state) => state.location.pathname, }); const isGithubPullPath = /^\/[^/]+\/[^/]+\/pull\/[^/]+/.test(pathname); + const isSettingsPath = pathname === "/settings" || pathname === "/settings/"; if (pathname.startsWith("/oauth/callback")) { return ; @@ -322,7 +346,7 @@ function AppLayout() { return null; } - if (!isAuthenticated && !isGithubPullPath) { + if (!isAuthenticated && !isGithubPullPath && !isSettingsPath) { return ; } diff --git a/src/routes/index.tsx b/src/routes/index.tsx index ebb9c78..30cc9e7 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -3,8 +3,8 @@ import { createFileRoute, useNavigate } from "@tanstack/react-router"; import { AlertCircle, ExternalLink, - FolderGit, GitPullRequest, + House, Loader2, RefreshCw, Settings2, @@ -12,6 +12,12 @@ import { import { useEffect, useMemo, useState } from "react"; import { FileTree } from "@/components/file-tree"; import { RepositorySelector } from "@/components/repository-selector"; +import { + getSettingsTreeItems, + SettingsPanel, + settingsPathForTab, + settingsTabFromPath, +} from "@/components/settings-menu"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { type FileNode, useFileTree } from "@/lib/file-tree-context"; @@ -28,9 +34,10 @@ import { usePrContext } from "@/lib/pr-context"; import { cn } from "@/lib/utils"; const HOSTS: GitHost[] = ["bitbucket", "github"]; +const HOST_PATH_PREFIX = "host:"; +const WORKSPACE_PATH_PREFIX = "workspace:"; -type LandingMode = "pull-requests" | "repositories" | "hosts"; -type LandingSearch = { mode?: LandingMode }; +type DiffPanel = "pull-requests" | "repositories"; type PullRequestTreeMeta = { host: GitHost; workspace: string; @@ -38,49 +45,42 @@ type PullRequestTreeMeta = { pullRequestId: string; }; +function normalizeWorkspaceLabel(workspace: string, hostDomain: string) { + const normalized = workspace + .trim() + .replace(/^https?:\/\//i, "") + .replace(/\/+$/, ""); + const hostVariants = new Set([ + hostDomain.toLowerCase(), + `www.${hostDomain.toLowerCase()}`, + ]); + const segments = normalized + .split("/") + .map((segment) => segment.trim()) + .filter(Boolean); + while (segments.length > 0 && hostVariants.has(segments[0].toLowerCase())) { + segments.shift(); + } + return segments.join("/"); +} + +function hostFromLandingTreePath(path: string): GitHost | null { + if ( + !path.startsWith(HOST_PATH_PREFIX) && + !path.startsWith(WORKSPACE_PATH_PREFIX) + ) { + return null; + } + const [, host] = path.split(":"); + return host === "bitbucket" || host === "github" ? host : null; +} + export const Route = createFileRoute("/")({ - validateSearch: (search: Record): LandingSearch => ({ - mode: - search.mode === "pull-requests" || - search.mode === "repositories" || - search.mode === "hosts" - ? search.mode - : undefined, - }), component: LandingPage, }); -function HostTree({ - activeHost, - onSelect, -}: { - activeHost: GitHost; - onSelect: (host: GitHost) => void; -}) { - return ( -
- {HOSTS.map((host) => ( - - ))} -
- ); -} - function HostAuthPanel({ host }: { host: GitHost }) { - const { authByHost, login } = usePrContext(); + const { authByHost, login, logout } = usePrContext(); const [email, setEmail] = useState(""); const [apiToken, setApiToken] = useState(""); const [githubToken, setGithubToken] = useState(""); @@ -95,6 +95,15 @@ function HostAuthPanel({ host }: { host: GitHost }) {
{getHostLabel(host)} is connected.
+
); } @@ -222,12 +231,14 @@ function buildPullRequestTree( const root: FileNode[] = []; for (const host of HOSTS) { + const hostDomain = host === "github" ? "github.com" : "bitbucket.org"; const hostNode: FileNode = { - name: getHostLabel(host), + name: hostDomain, path: `host:${host}`, type: "directory", children: [], }; + const workspaceNodes = new Map(); for (const repo of reposByHost[host]) { const key = `${host}:${repo.fullName}`; @@ -249,9 +260,27 @@ function buildPullRequestTree( if (!repoMatches && filteredPrs.length === 0) continue; + const workspaceLabel = normalizeWorkspaceLabel( + repo.workspace, + hostDomain, + ); + + const workspacePath = `workspace:${host}:${repo.workspace}`; + let workspaceNode = workspaceNodes.get(workspacePath); + if (!workspaceNode) { + workspaceNode = { + name: workspaceLabel || repo.workspace, + path: workspacePath, + type: "directory", + children: [], + }; + workspaceNodes.set(workspacePath, workspaceNode); + hostNode.children?.push(workspaceNode); + } + const repoPath = `repo:${host}:${repo.workspace}:${repo.repo}`; const repoNode: FileNode = { - name: repo.fullName, + name: repo.repo, path: repoPath, type: "directory", children: filteredPrs.map((pr) => { @@ -270,22 +299,25 @@ function buildPullRequestTree( }), }; - hostNode.children?.push(repoNode); + workspaceNode.children?.push(repoNode); } - if (hostNode.children && hostNode.children.length > 0) { - root.push(hostNode); - } + root.push(hostNode); } return { root, pullRequestMeta }; } -function LandingPage() { - const search = Route.useSearch(); +export function LandingPage({ + initialHost, + initialDiffPanel = "pull-requests", +}: { + initialHost?: GitHost; + initialDiffPanel?: DiffPanel; +} = {}) { const navigate = useNavigate(); const queryClient = useQueryClient(); - const tree = useFileTree(); + const { setTree, setKinds, activeFile, setActiveFile } = useFileTree(); const { authByHost, activeHost, @@ -297,8 +329,25 @@ function LandingPage() { logout, } = usePrContext(); - const mode = search.mode ?? "pull-requests"; + const [showSettingsPanel, setShowSettingsPanel] = useState(false); + const [diffPanel, setDiffPanel] = useState(initialDiffPanel); + const showRepositoryPanel = diffPanel === "repositories"; const [searchQuery, setSearchQuery] = useState(""); + const settingsTreeItems = useMemo(() => getSettingsTreeItems(), []); + const settingsPathSet = useMemo( + () => new Set(settingsTreeItems.map((item) => item.path)), + [settingsTreeItems], + ); + + useEffect(() => { + setDiffPanel(initialDiffPanel); + }, [initialDiffPanel]); + + useEffect(() => { + if (!initialHost) return; + setActiveHost(initialHost); + setDiffPanel("repositories"); + }, [initialHost, setActiveHost]); const authenticatedHosts = useMemo( () => HOSTS.filter((host) => authByHost[host]), @@ -343,16 +392,57 @@ function LandingPage() { ); useEffect(() => { - if (mode !== "pull-requests") return; - tree.setTree(pullRequestTree.root); - tree.setKinds(new Map()); + if (showSettingsPanel) { + const settingsNodes: FileNode[] = settingsTreeItems.map((item) => ({ + name: item.name, + path: item.path, + type: "file", + })); + setTree(settingsNodes); + setKinds(new Map()); + return; + } + setTree(pullRequestTree.root); + setKinds(new Map()); if ( - !tree.activeFile || - !pullRequestTree.pullRequestMeta.has(tree.activeFile) + !activeFile || + (!activeFile.startsWith(HOST_PATH_PREFIX) && + !pullRequestTree.pullRequestMeta.has(activeFile)) ) { - tree.setActiveFile(undefined); + setActiveFile(undefined); + } + }, [ + activeFile, + pullRequestTree, + setKinds, + setTree, + setActiveFile, + settingsTreeItems, + showSettingsPanel, + ]); + + useEffect(() => { + if (!showSettingsPanel) return; + const firstSettingsPath = settingsTreeItems[0]?.path; + if (!firstSettingsPath) return; + if (!activeFile || !settingsPathSet.has(activeFile)) { + setActiveFile(firstSettingsPath); } - }, [mode, pullRequestTree, tree]); + }, [ + activeFile, + setActiveFile, + settingsPathSet, + settingsTreeItems, + showSettingsPanel, + ]); + + useEffect(() => { + if (showSettingsPanel) return; + if (diffPanel !== "repositories") return; + const hostPath = `${HOST_PATH_PREFIX}${activeHost}`; + if (activeFile === hostPath) return; + setActiveFile(hostPath); + }, [activeFile, activeHost, diffPanel, setActiveFile, showSettingsPanel]); const selectedRepoCount = reposByHost.bitbucket.length + reposByHost.github.length; @@ -369,42 +459,31 @@ function LandingPage() { > -
@@ -412,61 +491,82 @@ function LandingPage() { data-component="search-sidebar" className="h-10 pl-2 pr-2 border-b border-border flex items-center gap-2" > - {mode === "pull-requests" ? ( - setSearchQuery(event.target.value)} - /> - ) : ( - - Select host - - )} + setSearchQuery(event.target.value)} + />
-
- {mode === "pull-requests" ? ( - pullRequestTree.root.length === 0 ? ( -
- No repositories or pull requests match. -
- ) : ( - { - const meta = pullRequestTree.pullRequestMeta.get(node.path); - if (!meta) return; - setActiveHost(meta.host); - if (meta.host === "github") { +
+ {!showSettingsPanel && pullRequestTree.root.length === 0 ? ( +
+ No repositories or pull requests match. +
+ ) : ( + { + if (showSettingsPanel && settingsPathSet.has(node.path)) { + setActiveFile(node.path); + return; + } + if (node.path.startsWith(HOST_PATH_PREFIX)) { + const host = node.path.slice(HOST_PATH_PREFIX.length); + if (host === "bitbucket" || host === "github") { + setShowSettingsPanel(false); + setActiveHost(host); + setDiffPanel("repositories"); navigate({ - to: "/$workspace/$repo/pull/$pullRequestId", - params: { - workspace: meta.workspace, - repo: meta.repo, - pullRequestId: meta.pullRequestId, - }, + to: "/$host", + params: { host }, }); - return; } + return; + } + const meta = pullRequestTree.pullRequestMeta.get(node.path); + if (!meta) return; + setActiveHost(meta.host); + if (meta.host === "github") { navigate({ - to: "/$workspace/$repo/pull-requests/$pullRequestId", + to: "/$workspace/$repo/pull/$pullRequestId", params: { workspace: meta.workspace, repo: meta.repo, pullRequestId: meta.pullRequestId, }, }); - }} - /> - ) - ) : ( - + return; + } + navigate({ + to: "/$workspace/$repo/pull-requests/$pullRequestId", + params: { + workspace: meta.workspace, + repo: meta.repo, + pullRequestId: meta.pullRequestId, + }, + }); + }} + onDirectoryClick={(node) => { + const host = hostFromLandingTreePath(node.path); + if (!host) return; + setShowSettingsPanel(false); + setActiveHost(host); + setDiffPanel("repositories"); + navigate({ + to: "/$host", + params: { host }, + }); + return true; + }} + /> )}
@@ -477,11 +577,11 @@ function LandingPage() { className="h-11 border-b border-border bg-card px-3 flex items-center gap-2 text-[12px]" > - {mode === "pull-requests" - ? "Open Pull Requests" - : mode === "repositories" + {showSettingsPanel + ? "Settings" + : showRepositoryPanel ? "Repository Selection" - : "Host Settings"} + : "Open Pull Requests"} {selectedRepoCount} selected repos @@ -497,7 +597,7 @@ function LandingPage() { Refresh - {mode !== "hosts" ? ( + {!showSettingsPanel ? ( -
+ )} ) : selectedRepoCount === 0 ? (
- + No repositories selected.
+ +
+ +
+ setSearchQuery(event.target.value)} + /> +
+ +
+ { + if (settingsPathSet.has(node.path)) { + setActiveFile(node.path); + } + }} + /> +
+ + +
+
+ Settings +
+ +
+
+ { + setActiveFile(settingsPathForTab(tab)); + }} + /> +
+
+
+ + ); +}