Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented May 30, 2025

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
Comes from: #4019
Signed-off-by: Eric Wheeler [email protected]<!--
Thank you for contributing to Roo Code!

Before submitting your PR, please ensure:

Related GitHub Issue

Closes: #

Description

Test Procedure

Type of Change

  • 🐛 Bug Fix: Non-breaking change that fixes an issue.
  • New Feature: Non-breaking change that adds functionality.
  • 💥 Breaking Change: Fix or feature that would cause existing functionality to not work as expected.
  • ♻️ Refactor: Code change that neither fixes a bug nor adds a feature.
  • 💅 Style: Changes that do not affect the meaning of the code (white-space, formatting, etc.).
  • 📚 Documentation: Updates to documentation files.
  • ⚙️ Build/CI: Changes to the build process or CI configuration.
  • 🧹 Chore: Other changes that don't modify src or test files.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Code Quality:
    • My code adheres to the project's style guidelines.
    • There are no new linting errors or warnings (npm run lint).
    • All debug code (e.g., console.log) has been removed.
  • Testing:
    • New and/or updated tests have been added to cover my changes.
    • All tests pass locally (npm test).
    • The application builds successfully with my changes.
  • Branch Hygiene: My branch is up-to-date (rebased) with the main branch.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Changeset: A changeset has been created using npm run changeset if this PR includes user-facing changes or dependency updates.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Documentation Updates

Additional Notes

Get in Touch

Eric Wheeler and others added 5 commits May 26, 2025 20:11
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: RooCodeInc#4018
Signed-off-by: Eric Wheeler <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
@daniel-lxs daniel-lxs requested review from cte and mrubens as code owners May 30, 2025 21:25
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. UI/UX UI/UX related or focused labels May 30, 2025
overflowWrap: "anywhere",
}}
data-testid={isCompact ? undefined : "task-content"}
{...(isCompact ? {} : { dangerouslySetInnerHTML: { __html: item.task } })}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that item.task is sanitized before using dangerouslySetInnerHTML to prevent potential XSS vulnerabilities.

Suggested change
{...(isCompact ? {} : { dangerouslySetInnerHTML: { __html: item.task } })}>
{...(isCompact ? {} : { dangerouslySetInnerHTML: { __html: sanitizeHtml(item.task) } })}>

@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap May 30, 2025
@hannesrudolph
Copy link
Collaborator

image
LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 2, 2025
@mrubens mrubens merged commit 0ad6be7 into RooCodeInc:main Jun 2, 2025
11 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jun 2, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Jun 2, 2025
@KJ7LNW
Copy link
Contributor

KJ7LNW commented Jun 2, 2025

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer PR - Needs Review size:XL This PR changes 500-999 lines, ignoring generated files. UI/UX UI/UX related or focused

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

refactor: HistoryPreview and HistoryView components have lots of duplicated code between variants

4 participants