mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
Restore enhanced source control features from PR #138
PR #145 accidentally reverted all source control enhancements from PR #138. This cherry-picks those changes back: discard changes functionality, commit detail view, commit file diffs, diff truncation, and UI improvements.
This commit is contained in:
1 parent
3461f86556
commit
a911a2f759
18 files changed
+1611
-203
No files matched your search
@@ -12,7 +12,11 @@ interface GitFlatFileListProps {
|
||||
onSelect: (path: string, staged: boolean) => void
|
||||
onStage?: (paths: string[]) => void
|
||||
onUnstage?: (paths: string[]) => void
|
||||
onDiscard?: (paths: string[], staged: boolean) => void
|
||||
selectedFile?: string
|
||||
readOnly?: boolean
|
||||
totalAdditions?: number
|
||||
totalDeletions?: number
|
||||
}
|
||||
|
||||
interface GroupedFiles {
|
||||
@@ -28,7 +32,11 @@ export function GitFlatFileList({
|
||||
onSelect,
|
||||
onStage,
|
||||
onUnstage,
|
||||
onDiscard,
|
||||
selectedFile,
|
||||
readOnly = false,
|
||||
totalAdditions,
|
||||
totalDeletions,
|
||||
}: GitFlatFileListProps) {
|
||||
const [collapsedGroups, setCollapsedGroups] = useState<Set<GitFileStatusType>>(new Set())
|
||||
|
||||
@@ -83,6 +91,13 @@ export function GitFlatFileList({
|
||||
}
|
||||
}
|
||||
|
||||
const handleDiscardAll = (e: React.MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
if (onDiscard) {
|
||||
onDiscard(filteredFiles.map(f => f.path), staged)
|
||||
}
|
||||
}
|
||||
|
||||
if (filteredFiles.length === 0) {
|
||||
return null
|
||||
}
|
||||
@@ -93,24 +108,44 @@ export function GitFlatFileList({
|
||||
<span className="text-xs font-medium text-muted-foreground uppercase tracking-wider">
|
||||
{staged ? 'Staged Changes' : 'Changes'} ({filteredFiles.length})
|
||||
</span>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 px-2 text-xs"
|
||||
onClick={staged ? handleUnstageAll : handleStageAll}
|
||||
>
|
||||
{staged ? (
|
||||
<>
|
||||
<Minus className="w-3 h-3 mr-1" />
|
||||
Unstage All
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Plus className="w-3 h-3 mr-1" />
|
||||
Stage All
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
{(totalAdditions !== undefined && totalAdditions > 0 || totalDeletions !== undefined && totalDeletions > 0) && (
|
||||
<div className="flex items-center gap-1 text-xs">
|
||||
{totalAdditions !== undefined && totalAdditions > 0 && <span className="text-green-500">+{totalAdditions}</span>}
|
||||
{totalDeletions !== undefined && totalDeletions > 0 && <span className="text-red-500">-{totalDeletions}</span>}
|
||||
</div>
|
||||
)}
|
||||
{!readOnly && (
|
||||
<div className="flex items-center gap-1">
|
||||
{onDiscard && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 px-2 text-xs text-rose-500 hover:text-rose-600"
|
||||
onClick={handleDiscardAll}
|
||||
>
|
||||
Discard All
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 px-2 text-xs"
|
||||
onClick={staged ? handleUnstageAll : handleStageAll}
|
||||
>
|
||||
{staged ? (
|
||||
<>
|
||||
<Minus className="w-3 h-3 mr-1" />
|
||||
Unstage All
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Plus className="w-3 h-3 mr-1" />
|
||||
Stage All
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{groupedFiles.map(({ status, files: groupFiles }) => {
|
||||
@@ -143,8 +178,9 @@ export function GitFlatFileList({
|
||||
file={file}
|
||||
isSelected={selectedFile === file.path}
|
||||
onSelect={onSelect}
|
||||
onStage={handleStageFile}
|
||||
onUnstage={handleUnstageFile}
|
||||
onStage={readOnly ? undefined : handleStageFile}
|
||||
onUnstage={readOnly ? undefined : handleUnstageFile}
|
||||
onDiscard={readOnly ? undefined : onDiscard ? ((path: string, staged: boolean) => onDiscard([path], staged)) : undefined}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user