|
| 1 | +# Apply Diff UI/UX Improvements |
| 2 | + |
| 3 | +This document describes the improved UI/UX components for the apply diff functionality in Roo Code. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The new apply diff UI provides a comprehensive interface for reviewing and applying batch file changes with enhanced visual feedback, granular control, and better error handling. |
| 8 | + |
| 9 | +## Components |
| 10 | + |
| 11 | +### 1. BatchDiffView |
| 12 | + |
| 13 | +The main component that displays all files with pending changes in an organized, hierarchical view. |
| 14 | + |
| 15 | +**Features:** |
| 16 | + |
| 17 | +- **Directory Grouping**: Files are automatically grouped by their directory paths |
| 18 | +- **Individual Selection**: Each file has a checkbox for granular control |
| 19 | +- **Batch Actions**: "Select All/Deselect All" for quick batch operations |
| 20 | +- **Status Indicators**: Visual icons showing success (✓), error (⚠), or partial status |
| 21 | +- **Change Summary**: Shows total files, selected files, and change counts |
| 22 | +- **Expandable Details**: Click to expand and see individual diff previews |
| 23 | + |
| 24 | +**Usage:** |
| 25 | + |
| 26 | +```tsx |
| 27 | +import { BatchDiffView } from './components/chat/BatchDiffView' |
| 28 | + |
| 29 | +<BatchDiffView |
| 30 | + files={[ |
| 31 | + { |
| 32 | + path: 'src/components/Button.tsx', |
| 33 | + diffs: [...], |
| 34 | + selected: true, |
| 35 | + expanded: false |
| 36 | + } |
| 37 | + ]} |
| 38 | + onApprove={(approvedFiles) => {...}} |
| 39 | + onReject={() => {...}} |
| 40 | + ts={timestamp} |
| 41 | +/> |
| 42 | +``` |
| 43 | + |
| 44 | +### 2. BatchDiffPreview |
| 45 | + |
| 46 | +A sophisticated diff preview component that displays changes in a side-by-side view. |
| 47 | + |
| 48 | +**Features:** |
| 49 | + |
| 50 | +- **Split View**: Shows original (search) and modified (replace) content side by side |
| 51 | +- **Syntax Highlighting**: Language-aware code highlighting using the existing CodeBlock component |
| 52 | +- **Multi-Change Navigation**: Navigate between multiple changes with arrow buttons or dots |
| 53 | +- **Copy Functionality**: Copy all changes in diff format |
| 54 | +- **Line Information**: Shows affected line numbers |
| 55 | +- **Responsive Design**: Adjustable height with scroll support |
| 56 | + |
| 57 | +**Usage:** |
| 58 | + |
| 59 | +```tsx |
| 60 | +import { BatchDiffPreview } from './components/chat/BatchDiffPreview' |
| 61 | + |
| 62 | +<BatchDiffPreview |
| 63 | + filePath="src/utils/helpers.ts" |
| 64 | + changes={[ |
| 65 | + { |
| 66 | + searchText: "function foo() {", |
| 67 | + replaceText: "export function foo(): void {", |
| 68 | + startLine: 10 |
| 69 | + } |
| 70 | + ]} |
| 71 | + expanded={true} |
| 72 | + onToggleExpand={() => {...}} |
| 73 | +/> |
| 74 | +``` |
| 75 | + |
| 76 | +### 3. ApplyDiffView |
| 77 | + |
| 78 | +The container component that orchestrates the entire diff approval workflow. |
| 79 | + |
| 80 | +**Features:** |
| 81 | + |
| 82 | +- **Processing Status**: Real-time updates during diff application |
| 83 | +- **Error Handling**: Clear visual feedback for failures |
| 84 | +- **Preview Panel**: Optional side panel for detailed diff preview |
| 85 | +- **Quick Preview Buttons**: Fast access to preview first 5 files |
| 86 | +- **WebSocket Integration**: Listens for status updates from backend |
| 87 | + |
| 88 | +**Usage:** |
| 89 | + |
| 90 | +```tsx |
| 91 | +import { ApplyDiffView } from './components/chat/ApplyDiffView' |
| 92 | + |
| 93 | +<ApplyDiffView |
| 94 | + taskId="task-123" |
| 95 | + files={diffFiles} |
| 96 | + onComplete={() => {...}} |
| 97 | + ts={timestamp} |
| 98 | +/> |
| 99 | +``` |
| 100 | + |
| 101 | +### 4. ApplyDiffTool |
| 102 | + |
| 103 | +Integration component that bridges the existing tool format with the new UI components. |
| 104 | + |
| 105 | +**Features:** |
| 106 | + |
| 107 | +- **Format Conversion**: Handles both batch and legacy single-file formats |
| 108 | +- **Diff Parsing**: Extracts search/replace content from diff strings |
| 109 | +- **Backward Compatibility**: Works with existing tool data structures |
| 110 | + |
| 111 | +## UI/UX Improvements |
| 112 | + |
| 113 | +### Visual Organization |
| 114 | + |
| 115 | +- Files grouped by directory for better mental model |
| 116 | +- Clear visual hierarchy with indentation and borders |
| 117 | +- Consistent use of VSCode theme colors |
| 118 | + |
| 119 | +### User Control |
| 120 | + |
| 121 | +- Granular file selection with batch operations |
| 122 | +- Preview before applying changes |
| 123 | +- Clear approve/reject actions |
| 124 | + |
| 125 | +### Feedback |
| 126 | + |
| 127 | +- Real-time status updates |
| 128 | +- Progress indicators during processing |
| 129 | +- Success/error states with appropriate icons |
| 130 | +- Descriptive error messages |
| 131 | + |
| 132 | +### Performance |
| 133 | + |
| 134 | +- Lazy loading of diff previews |
| 135 | +- Efficient rendering with React memoization |
| 136 | +- Minimal re-renders during status updates |
| 137 | + |
| 138 | +## Integration Guide |
| 139 | + |
| 140 | +To integrate these components into the existing chat view: |
| 141 | + |
| 142 | +1. Import the ApplyDiffTool component: |
| 143 | + |
| 144 | +```tsx |
| 145 | +import { ApplyDiffTool } from "./components/chat/tools/ApplyDiffTool" |
| 146 | +``` |
| 147 | + |
| 148 | +2. Use it in the tool rendering logic: |
| 149 | + |
| 150 | +```tsx |
| 151 | +case "appliedDiff": |
| 152 | + return <ApplyDiffTool tool={tool} onComplete={handleComplete} /> |
| 153 | +``` |
| 154 | + |
| 155 | +3. Handle the approval response in the backend: |
| 156 | + |
| 157 | +```typescript |
| 158 | +// Listen for objectResponse with action: "applyDiff" |
| 159 | +if (askResponse === "objectResponse") { |
| 160 | + const data = JSON.parse(text) |
| 161 | + if (data.action === "applyDiff") { |
| 162 | + // Process approved files |
| 163 | + const approvedFiles = data.approvedFiles |
| 164 | + // Apply diffs only to approved files |
| 165 | + } |
| 166 | +} |
| 167 | +``` |
| 168 | + |
| 169 | +## Accessibility |
| 170 | + |
| 171 | +- Keyboard navigation support |
| 172 | +- ARIA labels for interactive elements |
| 173 | +- Focus management for modal-like interactions |
| 174 | +- Screen reader friendly status messages |
| 175 | + |
| 176 | +## Future Enhancements |
| 177 | + |
| 178 | +1. **Inline Diff Mode**: Option to view diffs inline instead of side-by-side |
| 179 | +2. **Syntax Error Detection**: Pre-validate changes for syntax errors |
| 180 | +3. **Undo/Redo**: Allow reverting applied changes |
| 181 | +4. **Diff Statistics**: Show lines added/removed counts |
| 182 | +5. **Search & Filter**: Find specific changes across files |
| 183 | +6. **Conflict Resolution**: Handle merge conflicts intelligently |
| 184 | + |
| 185 | +## Testing |
| 186 | + |
| 187 | +Comprehensive test coverage is provided in: |
| 188 | + |
| 189 | +- `BatchDiffView.test.tsx` - Unit tests for the main view component |
| 190 | +- Integration tests can be added to verify the full workflow |
| 191 | + |
| 192 | +Run tests with: |
| 193 | + |
| 194 | +```bash |
| 195 | +npm test -- BatchDiffView |
| 196 | +``` |
0 commit comments