Skip to content

frontend: LogViewer: Add copy to clipboard action - #6813

Open
Priyanshu-rgbb wants to merge 1 commit into
kubernetes-sigs:mainfrom
Priyanshu-rgbb:frontend-logviewer-copy-clipboard-clean
Open

frontend: LogViewer: Add copy to clipboard action#6813
Priyanshu-rgbb wants to merge 1 commit into
kubernetes-sigs:mainfrom
Priyanshu-rgbb:frontend-logviewer-copy-clipboard-clean

Conversation

@Priyanshu-rgbb

@Priyanshu-rgbb Priyanshu-rgbb commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds a Copy to Clipboard action to the LogViewer, allowing users to copy log output directly instead of downloading it first. It also updates the affected Storybook snapshots, reduces snapshot flakiness caused by xterm-generated output, and regenerates the frontend i18n files for the new user-facing strings.


Related Issue

No related issue. This is a small, self-contained improvement.


Changes

  • Added a copyLogs handler that copies the current log output using navigator.clipboard.writeText.
  • Added a new Copy to Clipboard ActionButton next to the existing Download button.
  • Displays a success snackbar when the copy succeeds and an error snackbar if it fails.
  • Added unit tests in LogViewer.test.tsx covering both the success and failure paths.
  • Updated the affected PodLogs.* storyshots since they render LogViewer and now include the new action.
  • Normalized unstable xterm-generated DOM and style output in src/storybook.test.tsx to reduce Storybook snapshot flakiness.
  • Updated the affected common/Terminal.* storyshots to match the normalized snapshot output.
  • Regenerated the frontend i18n locale files so the new LogViewer strings are included in the translation output.

Steps to Test

  1. Open the logs for any pod.
  2. Click the Copy to Clipboard button next to Download.
  3. Confirm a "Logs copied to clipboard" success message appears.
  4. Paste the clipboard contents into a text editor and verify they match the logs shown in the viewer.

Screenshots

Not applicable — this adds a single action button next to the existing Download button.


Notes for the Reviewer

  • This follows the existing useSnackbar pattern already used elsewhere in the codebase.
  • No new dependencies were added. The implementation uses the browser's native Clipboard API.
  • The xterm snapshot normalization is limited to the Storybook test helper and is intended only to remove unstable DOM/style differences that were causing snapshot churn.
  • Validation performed:
    • npx vitest run src/components/common/LogViewer.test.tsx --reporter=verbose
    • npm run lint -- src/components/common/LogViewer.test.tsx src/components/common/LogViewer.tsx
    • npx vitest run src/components/common/LogViewer.test.tsx
    • npx vitest run src/storybook.test.tsx -t "Pod/PodLogViewer" -u --reporter=dot
    • npx vitest run src/storybook.test.tsx -t "common/Terminal" -u --reporter=dot
    • npx vitest run src/storybook.test.tsx --reporter=dot
    • make frontend-i18n
  • The PodLogs.* and common/Terminal.* storyshot updates are expected. They reflect the new LogViewer action and the normalized xterm snapshot output.

Summary by CodeRabbit

  • New Features
    • Added a “Copy to clipboard” action to log viewers and pod logs.
    • Added success and error notifications when copying logs.
    • Added localized copy-related messages across supported languages.
  • Tests
    • Added coverage for successful and failed clipboard operations.
  • Documentation
    • Added a Storybook example showcasing log copying.
  • Chores
    • Updated terminal visual references for consistent rendering.

@kubernetes-prow
kubernetes-prow Bot requested review from gambtho and skoeva August 2, 2026 08:49
@kubernetes-prow kubernetes-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 2, 2026
@Priyanshu-rgbb
Priyanshu-rgbb force-pushed the frontend-logviewer-copy-clipboard-clean branch 2 times, most recently from 8d879e2 to 2b7d4ca Compare August 2, 2026 12:50
@skoeva skoeva added the frontend Issues related to the frontend label Aug 3, 2026
@skoeva skoeva added this to the v0.45.0 milestone Aug 3, 2026
@skoeva

skoeva commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

I think the implementation could be shared with the other copy to clipboard buttons in the code

@Priyanshu-rgbb

Copy link
Copy Markdown
Contributor Author

@skoeva Good catch, thanks. I'll look through the existing copy-to-clipboard implementations in the codebase and pull this into a shared hook or utility instead of duplicating the logic here. I'll push an update once that's done.

@illume illume added kind/feature Categorizes issue or PR as related to a new feature. testing labels Aug 5, 2026
@illume
illume requested a lite review from Copilot August 5, 2026 07:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new useSnackbar dependency can break the LogViewer Storybook stories unless they are wrapped in a SnackbarProvider, and the current snapshot normalization approach is overly destructive.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR enhances the frontend LogViewer by adding a “Copy to clipboard” action (with snackbar feedback), and updates Storybook snapshot testing to reduce churn from xterm’s dynamically generated output while regenerating i18n locale keys for the new user-facing strings.

Changes:

  • Added a clipboard-copy action and snackbar notifications to LogViewer.
  • Added unit tests for copy success/failure behavior.
  • Reduced Storybook snapshot flakiness by normalizing xterm-generated output and updated affected snapshots + regenerated i18n locale files.
File summaries
File Description
frontend/src/components/common/LogViewer.tsx Adds copyLogs handler, snackbar notifications, and a new ActionButton for copying logs.
frontend/src/components/common/LogViewer.test.tsx New unit tests covering clipboard copy success and failure paths.
frontend/src/components/common/LogViewer.stories.tsx Adds a new story variant that renders LogViewer with the copy action present.
frontend/src/storybook.test.tsx Normalizes xterm-generated output during Storybook snapshot runs to reduce flakiness.
frontend/src/components/common/snapshots/Terminal.TerminalNoDialog.stories.storyshot Updates snapshot output to reflect normalized xterm styles.
frontend/src/components/common/snapshots/Terminal.TerminalDisconnected.stories.storyshot Updates snapshot output to reflect normalized xterm styles.
frontend/src/components/common/snapshots/Terminal.TerminalConnectionFailed.stories.storyshot Updates snapshot output to reflect normalized xterm styles.
frontend/src/i18n/locales/ar/translation.json Adds new LogViewer clipboard-related strings to the locale output.
frontend/src/i18n/locales/bn/translation.json Adds new LogViewer clipboard-related strings to the locale output.
frontend/src/i18n/locales/de/translation.json Adds new LogViewer clipboard-related strings to the locale output.
frontend/src/i18n/locales/en/translation.json Adds new LogViewer clipboard-related strings to the locale output.
frontend/src/i18n/locales/es/translation.json Adds new LogViewer clipboard-related strings to the locale output.
frontend/src/i18n/locales/fr/translation.json Adds new LogViewer clipboard-related strings to the locale output.
frontend/src/i18n/locales/he/translation.json Adds new LogViewer clipboard-related strings to the locale output.
frontend/src/i18n/locales/hi/translation.json Adds new LogViewer clipboard-related strings to the locale output.
frontend/src/i18n/locales/it/translation.json Adds new LogViewer clipboard-related strings to the locale output.
frontend/src/i18n/locales/ja/translation.json Adds new LogViewer clipboard-related strings to the locale output.
frontend/src/i18n/locales/ko/translation.json Adds new LogViewer clipboard-related strings to the locale output.
frontend/src/i18n/locales/pt/translation.json Adds new LogViewer clipboard-related strings to the locale output.
frontend/src/i18n/locales/ru/translation.json Adds new LogViewer clipboard-related strings to the locale output.
frontend/src/i18n/locales/ta/translation.json Adds new LogViewer clipboard-related strings to the locale output.
frontend/src/i18n/locales/ur/translation.json Adds new LogViewer clipboard-related strings to the locale output.
frontend/src/i18n/locales/zh/translation.json Adds new LogViewer clipboard-related strings to the locale output.
frontend/src/i18n/locales/zh-tw/translation.json Adds new LogViewer clipboard-related strings to the locale output.
Review details
  • Files reviewed: 37/37 changed files
  • Comments generated: 2
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread frontend/src/components/common/LogViewer.stories.tsx
Comment thread frontend/src/storybook.test.tsx

@illume illume left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the contribution.

There are some open Copilot review comments — could you take a look at them? Please mark each one as resolved once you've addressed it.

@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Priyanshu-rgbb
Once this PR has been reviewed and has the lgtm label, please ask for approval from ashu8912. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Priyanshu-rgbb
Priyanshu-rgbb force-pushed the frontend-logviewer-copy-clipboard-clean branch from 2b7d4ca to 7fbf478 Compare August 5, 2026 18:16
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

LogViewer now copies concatenated logs to the clipboard and reports success or failure with localized snackbars. Storybook stories, tests, translations, and snapshots were updated to cover the new action and normalize generated XTerm identifiers.

Changes

LogViewer clipboard workflow

Layer / File(s) Summary
Clipboard action and feedback
frontend/src/components/common/LogViewer.tsx, frontend/src/components/common/LogViewer.test.tsx
LogViewer copies all logs, shows localized snackbar feedback, and tests success and failure paths.
Storybook integration
frontend/src/components/common/LogViewer.stories.tsx
Stories use SnackbarProvider and include a copy-action example.
Localized clipboard messages
frontend/src/i18n/locales/*/translation.json
Locales add log-copy success and failure messages and organize the copy action label with log translations.
Snapshot normalization and updates
frontend/src/storybook.test.tsx, frontend/src/components/common/__snapshots__/*, frontend/src/components/pod/__snapshots__/*
Snapshot comparison normalizes generated XTerm identifiers. Terminal and pod log snapshots reflect the new copy action and normalized styles.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: gambtho, skoeva, illume

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding a copy-to-clipboard action to LogViewer.
Description check ✅ Passed The description covers the summary, changes, testing steps, screenshots, reviewer notes, and explains that no related issue exists.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@illume
illume requested a lite review from Copilot August 5, 2026 18:20

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
frontend/src/components/common/LogViewer.tsx (1)

96-106: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse the shared clipboard behavior.

copyLogs inlines clipboard writes with its own success/error snackbar, while frontend/src/components/common/Resource/CopyButton.tsx and other copy handlers use reusable copy wrappers. Move this handler into a shared clipboard utility/hook and call it from LogViewer and any other new copy action.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/components/common/LogViewer.tsx` around lines 96 - 106, Replace
the inline clipboard logic in copyLogs with the existing shared clipboard
utility or hook used by Resource/CopyButton and other copy handlers, including
its standard success and error behavior. Update LogViewer to invoke that shared
mechanism with the joined logs text, and use the same mechanism for any newly
added copy actions instead of duplicating navigator.clipboard and snackbar
handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@frontend/src/components/common/LogViewer.tsx`:
- Around line 96-106: Replace the inline clipboard logic in copyLogs with the
existing shared clipboard utility or hook used by Resource/CopyButton and other
copy handlers, including its standard success and error behavior. Update
LogViewer to invoke that shared mechanism with the joined logs text, and use the
same mechanism for any newly added copy actions instead of duplicating
navigator.clipboard and snackbar handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: aa899884-ecb5-4dc5-826f-02db70ffd8b2

📥 Commits

Reviewing files that changed from the base of the PR and between 867fa4d and 7fbf478.

📒 Files selected for processing (37)
  • frontend/src/components/common/LogViewer.stories.tsx
  • frontend/src/components/common/LogViewer.test.tsx
  • frontend/src/components/common/LogViewer.tsx
  • frontend/src/components/common/__snapshots__/Terminal.TerminalAttachEmptyFirstOutput.stories.storyshot
  • frontend/src/components/common/__snapshots__/Terminal.TerminalConnectedAndReady.stories.storyshot
  • frontend/src/components/common/__snapshots__/Terminal.TerminalConnectionFailed.stories.storyshot
  • frontend/src/components/common/__snapshots__/Terminal.TerminalDefaultNodeSelector.stories.storyshot
  • frontend/src/components/common/__snapshots__/Terminal.TerminalDisconnected.stories.storyshot
  • frontend/src/components/common/__snapshots__/Terminal.TerminalInitAndEphemeralContainers.stories.storyshot
  • frontend/src/components/common/__snapshots__/Terminal.TerminalNoDialog.stories.storyshot
  • frontend/src/components/common/__snapshots__/Terminal.TerminalShellNotFoundTryNext.stories.storyshot
  • frontend/src/components/common/__snapshots__/Terminal.TerminalWindowsNodeSelector.stories.storyshot
  • frontend/src/components/common/__snapshots__/Terminal.TerminalWindowsShellNotFound.stories.storyshot
  • frontend/src/components/common/__snapshots__/Terminal.TerminalWithCommandOutput.stories.storyshot
  • frontend/src/components/pod/__snapshots__/PodLogs.BigJsonLogs.stories.storyshot
  • frontend/src/components/pod/__snapshots__/PodLogs.FormattedJsonLogs.stories.storyshot
  • frontend/src/components/pod/__snapshots__/PodLogs.FormattingLogs.stories.storyshot
  • frontend/src/components/pod/__snapshots__/PodLogs.JsonLogs.stories.storyshot
  • frontend/src/components/pod/__snapshots__/PodLogs.PlainLogs.stories.storyshot
  • frontend/src/i18n/locales/ar/translation.json
  • frontend/src/i18n/locales/bn/translation.json
  • frontend/src/i18n/locales/de/translation.json
  • frontend/src/i18n/locales/en/translation.json
  • frontend/src/i18n/locales/es/translation.json
  • frontend/src/i18n/locales/fr/translation.json
  • frontend/src/i18n/locales/he/translation.json
  • frontend/src/i18n/locales/hi/translation.json
  • frontend/src/i18n/locales/it/translation.json
  • frontend/src/i18n/locales/ja/translation.json
  • frontend/src/i18n/locales/ko/translation.json
  • frontend/src/i18n/locales/pt/translation.json
  • frontend/src/i18n/locales/ru/translation.json
  • frontend/src/i18n/locales/ta/translation.json
  • frontend/src/i18n/locales/ur/translation.json
  • frontend/src/i18n/locales/zh-tw/translation.json
  • frontend/src/i18n/locales/zh/translation.json
  • frontend/src/storybook.test.tsx

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Ready to approve

The clipboard action, notifications, tests, snapshot normalization, and regenerated i18n outputs are consistent and self-contained with no issues found in the reviewed diffs.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details
  • Files reviewed: 21/37 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@Priyanshu-rgbb

Copy link
Copy Markdown
Contributor Author

🟢 Ready to approve
The clipboard action, notifications, tests, snapshot normalization, and regenerated i18n outputs are consistent and self-contained with no issues found in the reviewed diffs.

Hey @illume, this PR is ready for another look. Whenever you have a chance, I'd really appreciate a final review. Thanks!

@Priyanshu-rgbb

Copy link
Copy Markdown
Contributor Author

🟢 Ready to approve
The clipboard action, notifications, tests, snapshot normalization, and regenerated i18n outputs are consistent and self-contained with no issues found in the reviewed diffs.

Hey @skoeva @illume please have a final review for this PR .

@kubernetes-prow kubernetes-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 12, 2026
@Priyanshu-rgbb
Priyanshu-rgbb force-pushed the frontend-logviewer-copy-clipboard-clean branch from 7fbf478 to 0228f6d Compare August 12, 2026 16:41
@kubernetes-prow kubernetes-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 12, 2026

@unlikelyzero unlikelyzero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The feature itself is small and fine, but there's a CI blocker and a few things worth fixing before this merges.

The one that'll actually fail the build: frontend/src/i18n/locales/pt-br/translation.json wasn't regenerated. Every other locale got the two new keys and had "Copy to clipboard" relocated to sit after Download - pt-br has neither, it's still got "Copy to clipboard" at its old position. CI runs npm run i18n -- --fail-on-update, which fails the whole PR if regenerating produces any diff, and it will here.

Also worth flagging: this repo's contributing guide asks for atomic commits, and this one bundles two unrelated things - the copy-to-clipboard feature, and a fix to shared Storybook test infrastructure (the xterm snapshot normalization in storybook.test.tsx, which rewrites 10+ Terminal storyshots that have nothing to do with LogViewer). Splitting those into two commits would make each one reviewable and revertable on its own - the infra fix is genuinely useful and would probably land quickly by itself.

And there's a still-open request from an earlier review round: skoeva asked for this to share an implementation with the other copy-to-clipboard buttons in the codebase, and the author agreed to pull it into a shared hook - that never happened. There are now five separate navigator.clipboard.writeText call sites (CopyButton.tsx, two in Resource.tsx, ErrorPage.tsx, and this one), each with different error handling - CopyButton.tsx doesn't even catch a rejection. A shared hook would fix that gap too, not just dedupe.

A few more inline.

Comment thread frontend/src/components/common/LogViewer.tsx Outdated
Comment thread frontend/src/components/common/LogViewer.tsx
Comment thread frontend/src/i18n/locales/en/translation.json
Comment thread frontend/src/storybook.test.tsx

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 21 out of 37 changed files in this pull request and generated 1 comment.

Comment thread frontend/src/i18n/locales/en/translation.json Outdated
@Priyanshu-rgbb
Priyanshu-rgbb force-pushed the frontend-logviewer-copy-clipboard-clean branch from cf0e3cd to 09a7809 Compare August 13, 2026 11:41
@Priyanshu-rgbb
Priyanshu-rgbb marked this pull request as draft August 13, 2026 11:55
@kubernetes-prow kubernetes-prow Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Aug 13, 2026
@Priyanshu-rgbb
Priyanshu-rgbb force-pushed the frontend-logviewer-copy-clipboard-clean branch from 09a7809 to de39cc4 Compare August 16, 2026 10:47
@kubernetes-prow kubernetes-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 16, 2026
@Priyanshu-rgbb
Priyanshu-rgbb marked this pull request as ready for review August 16, 2026 11:10
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 16, 2026
@kubernetes-prow
kubernetes-prow Bot requested a review from sniok August 16, 2026 11:10
@Priyanshu-rgbb

Copy link
Copy Markdown
Contributor Author

Hey @illume all the comments have been resolved , CI is green and the PR is ready for a final review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 22 out of 38 changed files in this pull request and generated no new comments.

Suppressed comments (2)

frontend/src/components/common/LogViewer.test.tsx:30

  • The terminal mock has no buffer, so all three tests take the fallback logs.join('') branch; the production path that reads xterm rows is never exercised. Please add a buffer-backed case covering ordinary output, a soft-wrapped line, and unused viewport rows so the copied text is verified against actual xterm semantics.
  Terminal: vi.fn().mockImplementation(() => ({

frontend/src/components/common/LogViewer.tsx:107

  • buffer.length includes unused viewport rows, so short logs are copied with many extra blank lines. It also represents soft-wrapped rows separately, and joining every row with \n inserts line breaks that were not in the log. Limit iteration to the cursor's last written row and merge rows marked isWrapped so pasted text matches the rendered log.
    const lines: string[] = [];
    for (let i = 0; i < buffer.length; i++) {
      lines.push(buffer.getLine(i)?.translateToString(true) ?? '');
    }
    return lines.join('\n');

@Priyanshu-rgbb

Copy link
Copy Markdown
Contributor Author

Copilot reviewed 22 out of 38 changed files in this pull request and generated no new comments.

@illume This PR is ready.

@kubernetes-prow kubernetes-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 17, 2026
@Priyanshu-rgbb
Priyanshu-rgbb force-pushed the frontend-logviewer-copy-clipboard-clean branch from de39cc4 to 70067b9 Compare August 17, 2026 12:03
@kubernetes-prow kubernetes-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. frontend Issues related to the frontend kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants