Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add component for downloading the static report #1312

Merged
merged 3 commits into from
Aug 29, 2023

Conversation

ibolton336
Copy link
Member

@ibolton336 ibolton336 commented Aug 24, 2023

  • Adds a download button to handle downloading the analysis report with custom headers driven by props passed in
  • Uses the Fetch API to allow setting custom headers. Converts the received data to a blob & then creates an object URL from that blob. Then we can use that URL with a temporary anchor <a> element to trigger the download with a localized loading state.
  • This approach allows us to bin any custom headers we were adding in the proxy and just use the fetch api to set the custom headers.

image

@codecov
Copy link

codecov bot commented Aug 24, 2023

Codecov Report

Patch coverage has no change and project coverage change: +0.02% 🎉

Comparison is base (3c4d31e) 43.04% compared to head (ba8beec) 43.07%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1312      +/-   ##
==========================================
+ Coverage   43.04%   43.07%   +0.02%     
==========================================
  Files         145      145              
  Lines        4330     4325       -5     
  Branches      999      998       -1     
==========================================
- Hits         1864     1863       -1     
+ Misses       2454     2450       -4     
  Partials       12       12              
Flag Coverage Δ
client 43.07% <ø> (+0.02%) ⬆️
server ∅ <ø> (∅)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
client/src/app/api/rest.ts 55.29% <ø> (+0.51%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ibolton336 ibolton336 changed the title Add component for downloading the static report ✨ Add component for downloading the static report Aug 24, 2023
@ibolton336 ibolton336 force-pushed the add-download-button branch 3 times, most recently from 12027e0 to 86b3404 Compare August 24, 2023 21:17
@ibolton336 ibolton336 marked this pull request as ready for review August 24, 2023 21:19
@ibolton336 ibolton336 force-pushed the add-download-button branch 2 times, most recently from c87c7c0 to bb4ca97 Compare August 25, 2023 17:22
Copy link
Collaborator

@mturley mturley left a comment

Choose a reason for hiding this comment

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

Looking good, and I'm fine with merging as-is, but I wonder if it's worth trying this tweak

Comment on lines 50 to 56
const a = document.createElement("a");
a.style.display = "none";
a.href = url;
a.download = `analysis-${application.name}.` + mimeType;

document.body.appendChild(a);
a.click();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh wow, this is very clever but I'm surprised it's necessary. I think we've used the file-saver library in the past to achieve the same thing, but tbh this might be more elegant.

I wonder if you even need to do the fetch in JS... could we just have the href of this anchor element be the URL we're fetching and let the click event do all the work? If that works that would mean the browser handles the whole download and can show progress natively instead of having it appear as a delayed instant-download.

@ibolton336 ibolton336 force-pushed the add-download-button branch 2 times, most recently from 590c394 to b50ce0a Compare August 29, 2023 15:00
Signed-off-by: ibolton336 <ibolton@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants