mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-24 05:02:20 +08:00
feat(task-changes): 文件列表单行展示,增删行数右对齐,添加可拖拽分隔条
Made-with: Cursor
This commit is contained in:
1 parent
b11f86df07
commit
de76cc449b
1 file changed
+63
-81
@@ -1,8 +1,8 @@
|
||||
import { useState } from "react"
|
||||
import type { RepoFileChange, TaskWebSocketManager } from "./ws-manager"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia } from "@/components/ui/empty"
|
||||
import { Item, ItemContent, ItemDescription, ItemGroup, ItemTitle } from "@/components/ui/item"
|
||||
import { Item, ItemContent, ItemGroup, ItemTitle } from "@/components/ui/item"
|
||||
import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@/components/ui/resizable"
|
||||
import { IconCloudOff, IconFileDiff, IconLoader, IconReport } from "@tabler/icons-react"
|
||||
import { parseDiff, Diff, Hunk } from "react-diff-view"
|
||||
import "react-diff-view/style/index.css"
|
||||
@@ -15,23 +15,6 @@ interface TaskChangesPanelProps {
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
function getStatusLabel(status?: string): string {
|
||||
switch (status) {
|
||||
case "A":
|
||||
return "新增"
|
||||
case "D":
|
||||
return "删除"
|
||||
case "M":
|
||||
return "修改"
|
||||
case "R":
|
||||
return "重命名"
|
||||
case "RM":
|
||||
return "删除"
|
||||
default:
|
||||
return "变更"
|
||||
}
|
||||
}
|
||||
|
||||
export function TaskChangesPanel({ fileChanges, fileChangesMap, taskManager, disabled }: TaskChangesPanelProps) {
|
||||
const sortedPaths = [...fileChanges].sort((a, b) => a.localeCompare(b))
|
||||
const [selectedFile, setSelectedFile] = useState<string | null>(null)
|
||||
@@ -86,7 +69,7 @@ export function TaskChangesPanel({ fileChanges, fileChangesMap, taskManager, dis
|
||||
}
|
||||
if (diffFiles.length > 0 && diffFiles.some((file) => file.hunks?.length)) {
|
||||
return (
|
||||
<div className="h-full overflow-auto p-2" style={{ "--diff-font-family": "var(--font-google-sans-code)" } as React.CSSProperties}>
|
||||
<div className="h-full overflow-auto" style={{ "--diff-font-family": "var(--font-google-sans-code)" } as React.CSSProperties}>
|
||||
<style>{`
|
||||
.task-changes-diff .diff-line td:nth-child(2) {
|
||||
border-left: 1px var(--border) solid;
|
||||
@@ -110,69 +93,68 @@ export function TaskChangesPanel({ fileChanges, fileChangesMap, taskManager, dis
|
||||
)
|
||||
}
|
||||
|
||||
const fileListContent = (
|
||||
<div className={cn("flex-1 min-h-0", sortedPaths.length === 0 ? "flex flex-col" : "overflow-y-auto")}>
|
||||
{sortedPaths.length === 0 ? (
|
||||
<Empty className="border border-dashed w-full flex-1 min-h-0">
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant="icon">
|
||||
<IconFileDiff className="size-6" />
|
||||
</EmptyMedia>
|
||||
<EmptyDescription>暂无文件变更</EmptyDescription>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
) : (
|
||||
<ItemGroup className="gap-2">
|
||||
{sortedPaths.map((path) => {
|
||||
const change = fileChangesMap.get(path)
|
||||
const additions = change?.additions ?? 0
|
||||
const deletions = change?.deletions ?? 0
|
||||
const isSelected = selectedFile === path
|
||||
return (
|
||||
<Item variant="outline" size="sm" key={path} className={cn("group hover:border-primary/50", isSelected && "border-primary bg-primary/5")}>
|
||||
<ItemContent className="flex flex-row items-center justify-between gap-2">
|
||||
<ItemTitle
|
||||
className={cn(
|
||||
"truncate font-mono text-xs cursor-pointer transition-colors hover:text-primary min-w-0 flex-1",
|
||||
isSelected && "text-primary"
|
||||
)}
|
||||
onClick={() => handlePathClick(path)}
|
||||
>
|
||||
{path}
|
||||
</ItemTitle>
|
||||
<div className="flex items-center gap-1 shrink-0 tabular-nums text-xs">
|
||||
{additions > 0 && (
|
||||
<span className="text-green-700 dark:text-green-400">+{additions}</span>
|
||||
)}
|
||||
{deletions > 0 && (
|
||||
<span className="text-red-700 dark:text-red-400">-{deletions}</span>
|
||||
)}
|
||||
</div>
|
||||
</ItemContent>
|
||||
</Item>
|
||||
)
|
||||
})}
|
||||
</ItemGroup>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full min-h-0">
|
||||
<div className={cn("min-h-0 flex flex-col overflow-hidden", selectedFile ? "h-1/2 border-b" : "flex-1")}>
|
||||
<div className="text-sm font-medium text-foreground mb-3 shrink-0">文件变更</div>
|
||||
<div className={cn("flex-1 min-h-0", sortedPaths.length === 0 ? "flex flex-col" : "overflow-y-auto")}>
|
||||
{sortedPaths.length === 0 ? (
|
||||
<Empty className="border border-dashed w-full flex-1 min-h-0">
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant="icon">
|
||||
<IconFileDiff className="size-6" />
|
||||
</EmptyMedia>
|
||||
<EmptyDescription>暂无文件变更</EmptyDescription>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
) : (
|
||||
<ItemGroup className="gap-2">
|
||||
{sortedPaths.map((path) => {
|
||||
const change = fileChangesMap.get(path)
|
||||
const status = getStatusLabel(change?.status)
|
||||
const additions = change?.additions ?? 0
|
||||
const deletions = change?.deletions ?? 0
|
||||
const isSelected = selectedFile === path
|
||||
return (
|
||||
<Item variant="outline" size="sm" key={path} className={cn("group hover:border-primary/50", isSelected && "border-primary bg-primary/5")}>
|
||||
<ItemContent>
|
||||
<ItemTitle
|
||||
className={cn(
|
||||
"truncate font-mono text-xs cursor-pointer transition-colors hover:text-primary",
|
||||
isSelected && "text-primary"
|
||||
)}
|
||||
onClick={() => handlePathClick(path)}
|
||||
>
|
||||
{path}
|
||||
</ItemTitle>
|
||||
<ItemDescription className="flex items-center justify-between gap-2">
|
||||
<Badge variant="outline" className="text-xs font-normal">
|
||||
{status}
|
||||
</Badge>
|
||||
<div className="flex items-center gap-1 shrink-0">
|
||||
{additions > 0 && (
|
||||
<Badge variant="outline" className="text-xs font-normal tabular-nums text-green-700 dark:text-green-400">
|
||||
增加 {additions} 行
|
||||
</Badge>
|
||||
)}
|
||||
{deletions > 0 && (
|
||||
<Badge variant="outline" className="text-xs font-normal tabular-nums text-red-700 dark:text-red-400">
|
||||
删除 {deletions} 行
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</ItemDescription>
|
||||
</ItemContent>
|
||||
</Item>
|
||||
)
|
||||
})}
|
||||
</ItemGroup>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{selectedFile && (
|
||||
<div className="h-1/2 min-h-0 flex flex-col overflow-hidden">
|
||||
{renderDiffContent()}
|
||||
</div>
|
||||
<div className="text-sm font-medium text-foreground mb-3 shrink-0">文件变更</div>
|
||||
{selectedFile ? (
|
||||
<ResizablePanelGroup direction="vertical" className="flex-1 min-h-0 gap-4">
|
||||
<ResizablePanel defaultSize={40} minSize={20} className="min-h-0 flex flex-col overflow-hidden">
|
||||
{fileListContent}
|
||||
</ResizablePanel>
|
||||
<ResizableHandle withHandle className="shrink-0" />
|
||||
<ResizablePanel defaultSize={60} minSize={30} className="min-h-0 flex flex-col overflow-hidden">
|
||||
{renderDiffContent()}
|
||||
</ResizablePanel>
|
||||
</ResizablePanelGroup>
|
||||
) : (
|
||||
<div className="flex-1 min-h-0 flex flex-col overflow-hidden">{fileListContent}</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user