Roo-Code/webview-ui
Daniel 0ad6be7e6e
Unify history item UI with TaskItem and TaskItemHeader (#4151)
* refactor: Unify history item UI with TaskItem and TaskItemHeader

Introduces `TaskItem.tsx` and `TaskItemHeader.tsx` to centralize and
standardize the rendering of history entries. `TaskItem` handles the
overall structure for "compact" (Preview) and "full" (HistoryView)
variants. `TaskItemHeader` consolidates all metadata (timestamp, tokens,
cost, cache, file size) into a single, consistent line above the task
content, enhancing visual clarity and reducing UI clutter.

This refactor significantly simplifies `HistoryPreview.tsx` and
`HistoryView.tsx`. Approximately 314 lines of previous rendering logic
were removed from these components and replaced by 242 lines in the new,
focused, and reusable `TaskItem` and `TaskItemHeader` components,
resulting in a net reduction and improved maintainability.

Most importantly, rendering logic happens in one place.

Key UI Changes:
- Metadata (timestamp, tokens, cost, cache, file size) now displayed
  inline on a single header row in both variants.
- Removed explicit "Tokens:" and "API Cost:" labels for a cleaner look.
- Action buttons (Copy, Export, Delete) in the full view are now
  aligned with the metadata header.
- File size is displayed in the header for the "full" variant only.
- Workspace information is no longer displayed in the "compact" preview.

Component Changes:
- Created `webview-ui/src/components/history/TaskItem.tsx` (125 lines)
- Created `webview-ui/src/components/history/TaskItemHeader.tsx` (117 lines)
- Modified `webview-ui/src/components/history/HistoryPreview.tsx` (-65 lines, +3 lines)
- Modified `webview-ui/src/components/history/HistoryView.tsx` (-249 lines, +3 lines)
- Uses `HistoryItem` type for standardized data handling.

Fixes: #4018
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>

* test: fix TaskItem and HistoryView test failures after refactor

Fixes test failures that occurred after the major refactoring that introduced
the shared TaskItem component. The original implementation was correct but
the tests needed updates to match the new component structure.

- Add data-testid attributes to TaskItemHeader for reliable test selection
- Update TaskItem.test.tsx assertions to use new test IDs for tokens/cache
- Fix Checkbox import path in TaskItem.tsx (ui/checkbox vs ui)
- Add missing mocks for lucide-react and Checkbox in HistoryView.test.tsx
- Update HistoryView test assertions to use correct selectors
- Ensure all 19 history component tests pass successfully

The refactoring reduced code duplication by ~250+ lines while maintaining
functionality, and these test fixes ensure the quality gates remain intact.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>

* ui: move token and cost info from header to dedicated footer

Create a new TaskItemFooter component that displays token and cost information
with different styles for compact and full views. Move the CopyButton and
ExportButton from header to footer in full view. Adjust file size display
positioning in the header for better visual alignment.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>

* test: update history component tests to match implementation

Update data-testid attributes in HistoryView and TaskItem tests to match the
actual implementation in TaskItemFooter component. The tests were looking for
generic "tokens-in" and "tokens-out" attributes, but the implementation uses
variant-specific attributes like "tokens-in-footer-full".

Also added mocks for CopyButton and ExportButton components to resolve
"Element type is invalid" errors during test rendering.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>

* Move cache information from header to footer to be consistent with cost/token data

* Fix ESLint warnings: remove unused imports and variables

---------

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
Co-authored-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-06-01 23:14:20 -04:00
..
.storybook Additional @shadcn/ui components 2025-02-14 23:41:39 -08:00
audio feat: move play audio to webview to ensure cross-platform (#3659) 2025-05-20 01:15:05 -04:00
public Remove CRA cruft 2025-01-30 14:38:41 -08:00
src Unify history item UI with TaskItem and TaskItemHeader (#4151) 2025-06-01 23:14:20 -04:00
.gitignore PR cleanup 2025-03-12 11:23:06 -04:00
components.json Remove lucide 2025-01-30 14:47:59 -08:00
eslint.config.mjs Preserve model settings when selecting a specific OpenRouter provider (#3915) 2025-05-23 23:22:41 -07:00
index.html Fix linter warning + run prettier on everything (#3581) 2025-05-13 15:16:24 -07:00
jest.config.cjs feat(read_file): enhance file reading capabilities with multi-file support and improved parameter handling (#2886) 2025-05-30 17:09:42 -04:00
package.json fix(deps): update dependency lucide-react to ^0.511.0 (#4182) 2025-05-31 16:04:43 -04:00
tsconfig.json Add a new @roo-code/types package and use it everywhere (#3912) 2025-05-26 12:06:45 -07:00
vite.config.ts Add a new @roo-code/types package and use it everywhere (#3912) 2025-05-26 12:06:45 -07:00