Skip to content

Add href to download iso button#3114

Merged
openshift-merge-bot[bot] merged 1 commit intoopenshift-assisted:masterfrom
rawagner:link_href
Aug 13, 2025
Merged

Add href to download iso button#3114
openshift-merge-bot[bot] merged 1 commit intoopenshift-assisted:masterfrom
rawagner:link_href

Conversation

@rawagner
Copy link
Member

@rawagner rawagner commented Aug 13, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of file downloads in chatbot messages, preventing unintended navigation and handling errors more gracefully.
  • Refactor

    • Updated the download action to use standard link semantics for better accessibility and keyboard/navigation support while preserving existing behavior.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 13, 2025
@openshift-ci
Copy link

openshift-ci bot commented Aug 13, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@coderabbitai
Copy link

coderabbitai bot commented Aug 13, 2025

Walkthrough

Updated BotMessage download button to render as an anchor with href, adjusted onClick to receive the event, prevent default navigation, and invoke saveAs(url) within try/catch with error logging.

Changes

Cohort / File(s) Summary of Changes
ChatBot UI
libs/chatbot/lib/components/ChatBot/BotMessage.tsx
Button now uses anchor semantics (component="a", href). onClick updated to accept event, call preventDefault, and execute saveAs(url) within try/catch with error logging. No exported/public API signature changes.

Sequence Diagram(s)

sequenceDiagram
  actor User
  participant AnchorButton as Button (anchor)
  participant Handler as onClick Handler
  participant FileSaver as saveAs
  participant Console as Logger

  User->>AnchorButton: Click
  AnchorButton->>Handler: onClick(e)
  Handler->>Handler: e.preventDefault()
  Handler->>FileSaver: saveAs(url)
  alt Error
    Handler->>Console: console.error(err)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~6 minutes

Poem

A hop, a click, a link so bright,
I tapped my paw—prevented flight.
Wrapped in try, I save the stash,
If bits misbehave—log the crash.
Carrot-keen, I ship with glee,
Anchored buttons, bug-free spree! 🥕✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 13, 2025
@rawagner rawagner marked this pull request as ready for review August 13, 2025 08:14
@openshift-ci openshift-ci bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Aug 13, 2025
@openshift-ci openshift-ci bot requested review from celdrake and jgyselov August 13, 2025 08:14
@rawagner
Copy link
Member Author

/cherry-pick releases/v0.1-chatbot

@openshift-cherrypick-robot
Copy link
Contributor

@rawagner: once the present PR merges, I will cherry-pick it on top of releases/v0.1-chatbot in a new PR and assign it to you.

Details

In response to this:

/cherry-pick releases/v0.1-chatbot

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 13, 2025
@openshift-ci
Copy link

openshift-ci bot commented Aug 13, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ammont82, rawagner

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

The pull request process is described 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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
libs/chatbot/lib/components/ChatBot/BotMessage.tsx (1)

121-129: Allow modifier-clicks and add a download fallback

To preserve Ctrl/Cmd-Click (and other modifier-assisted navigation) while still handling plain clicks and providing a fallback if saveAs fails, update the onClick in
libs/chatbot/lib/components/ChatBot/BotMessage.tsx (around line 124):

                           onClick={(e) => {
-                            e.preventDefault();
-                            try {
-                              saveAs(url);
-                            } catch (error) {
-                              // eslint-disable-next-line
-                              console.error('Download failed: ', error);
-                            }
+                            // Let modifier-clicks (e.g. Ctrl/Cmd+Click) open in a new tab
+                            if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
+                              return;
+                            }
+                            e.preventDefault();
+                            try {
+                              saveAs(url);
+                            } catch (error) {
+                              // eslint-disable-next-line
+                              console.error('Download failed:', error);
+                              // Fallback: open the file URL so the browser can download it
+                              void window.open(url, '_blank', 'noopener,noreferrer');
+                            }
                           }}
  • Targets the existing <Button component="a" href={url}>… with the download icon
  • Preserves default navigation on modifier-clicks
  • Falls back to window.open when saveAs throws
🧹 Nitpick comments (1)
libs/chatbot/lib/components/ChatBot/BotMessage.tsx (1)

131-133: Optional: add the download attribute to hint browsers to download.

For same-origin URLs, adding download can improve native download behavior and filename handling. Browsers ignore it for cross-origin URLs, so it’s safe but optional.

-                          component="a"
-                          href={url}
+                          component="a"
+                          href={url}
+                          download
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86daafa and 5126e9a.

📒 Files selected for processing (1)
  • libs/chatbot/lib/components/ChatBot/BotMessage.tsx (2 hunks)
🔇 Additional comments (1)
libs/chatbot/lib/components/ChatBot/BotMessage.tsx (1)

131-133: Good change: anchor + href improves semantics and UX.

Rendering the Button as an anchor with href aligns with link semantics, enables context-menu actions (e.g., “Copy link”, “Open in new tab”), and meets the PR objective.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
libs/chatbot/lib/components/ChatBot/BotMessage.tsx (1)

121-129: Preserve native link behavior; only prevent default on unmodified left-clicks and provide a robust fallback

Preventing default on every click breaks expected UX (open-in-new-tab via Ctrl/Cmd-click, middle-click, keyboard modifiers). Restrict preventDefault to simple primary-button clicks without modifiers. Also, provide a filename to saveAs and a safe fallback if saveAs fails.

Apply this diff:

-                          onClick={(e) => {
-                            e.preventDefault();
-                            try {
-                              saveAs(url);
-                            } catch (error) {
-                              // eslint-disable-next-line
-                              console.error('Download failed: ', error);
-                            }
-                          }}
+                          onClick={(e) => {
+                            // Only intercept simple left-clicks without modifiers.
+                            if (
+                              e.button !== 0 ||
+                              e.altKey ||
+                              e.ctrlKey ||
+                              e.metaKey ||
+                              e.shiftKey
+                            ) {
+                              return; // allow native browser handling
+                            }
+                            e.preventDefault();
+                            try {
+                              // Provide a best-effort filename derived from the URL.
+                              const name = (() => {
+                                try {
+                                  const u = new URL(url, window.location.href);
+                                  return u.pathname.split('/').pop() || undefined;
+                                } catch {
+                                  return undefined;
+                                }
+                              })();
+                              saveAs(url, name);
+                            } catch (error) {
+                              // eslint-disable-next-line no-console
+                              console.error('Download failed: ', error);
+                              // Fallback: open the link if it's safe.
+                              if (typeof isSafeUrl === 'function' && isSafeUrl(url)) {
+                                window.open(url, '_blank', 'noopener,noreferrer');
+                              }
+                            }
+                          }}

Add the helper referenced above (outside of this block, e.g., near the top or within the component scope):

function isSafeUrl(href: string): boolean {
  try {
    const proto = new URL(href, window.location.origin).protocol;
    return proto === 'https:' || proto === 'http:' || proto === 'blob:';
  } catch {
    return false;
  }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86daafa and 5126e9a.

📒 Files selected for processing (1)
  • libs/chatbot/lib/components/ChatBot/BotMessage.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: tests
  • GitHub Check: translation-files
  • GitHub Check: circular-deps
  • GitHub Check: unit-tests
  • GitHub Check: format
  • GitHub Check: lint

@openshift-merge-bot openshift-merge-bot bot merged commit 28f715e into openshift-assisted:master Aug 13, 2025
18 checks passed
@openshift-cherrypick-robot
Copy link
Contributor

@rawagner: new pull request created: #3115

Details

In response to this:

/cherry-pick releases/v0.1-chatbot

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants