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

EES-5734 copy download charts #5674

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open

Conversation

rianski
Copy link
Collaborator

@rianski rianski commented Mar 10, 2025

Changes made:

Added the ability to export chart as PNG or copy charts to clipboard

download chart snip

Copy link
Collaborator

@mmyoungman mmyoungman left a comment

Choose a reason for hiding this comment

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

Thanks to Guy for help with the review

}
};

if (isOpen) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need something so that people can close this by pressing the escape key?

}, [isOpen]);

return (
<div className={styles.exportDropdown}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the prototype, the Export button was here:
image

Realise this is a pain to change, so just checking this new position has been run past Cam/Marv?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've had a chat with Cam and we've agreed it's better where it is now although I'm going to move it to the right of the container to make it more visible. Worth mentioning the export stuff wouldn't work where the designs are as the tabs component is shared and used throughout the site for other tabs etc. You'd just keep losing the reference to the chart when you change tabs then the export buttons won't work

}, [isOpen]);

return (
<div className={styles.exportDropdown}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add some vertical padding for the ButtonText below?

<ButtonText onClick={handleDivDownload}>
Download chart as PNG image
</ButtonText>
<br />
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we change the menu CSS rather than use BRs here?

const handleDivDownload = useCallback(async () => {
const jpeg = await getDivJpeg();
if (jpeg) {
downloadFile(jpeg, 'Chart.png');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to provide more context for the file name? Although maybe this is acceptable with Cam for now - I guess the downside here is if someone downloads multiple charts it could be confusing for a user, but unsure how often that would happen - maybe a potential future piece of work than something to do now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yer I was thinking that but just decided to work off the AC, will have a word with Cam on it as I'm not really sure what value we'd use for it

@@ -115,17 +116,21 @@ const ChartBuilderTabSection = ({
[onTableUpdate, query, releaseVersionId],
);

const exportRef = useRef(null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

So I think this ref is being used by html2canvas to indicate what should be rendered?

I was wondering if there was any way to make it clearer what this ref is being used for - not suggesting a change here as I'm not sure there is a clear way without adding a comment, and then you'd need to leave the same comment in other places ChartBuilder/ChartRenderer are used.

const handleDivDownload = useCallback(async () => {
const jpeg = await getDivJpeg();
if (jpeg) {
downloadFile(jpeg, 'Chart.png');
Copy link
Collaborator

Choose a reason for hiding this comment

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

The file seem to be saving as a jpeg, not a png. Assuming there isn't any hard requirement on the image type, I'd rename the extension, variable names, and any link text to JPEG. Or maybe the mime type in useGenerateImage can be changed to image/png.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it actually always saves as a PNG so I'm not even sure why the library had it named that way. Will rename it so it's obvious

Copy link
Collaborator

Choose a reason for hiding this comment

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

I checked the type of the images I downloaded locally and they were jpegs

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

mm strange the ones I have have PNG as image type - thanks for the heads up I'll look into it

}, [isOpen]);

return (
<div className={styles.exportDropdown}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just checking that this includes everything we need for accessibility generally? Might be worth someone who knows these things looking it over

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@mmyoungman just looking at the gov style guide and not really sure what we usually do for toast alerts/messages, just wondering if you've encountered any that can be re-used here?

@Guy-HiveIT
Copy link

I looked through this with Mark but since then a couple of things have jumped out:

  1. The popover menu needs some accessibility improvements, at least:
  • being able to close it with 'Esc'
  • various aria- markup being added such as aria-expanded on the toggle button
  • focus handling such as returning focus to the toggle when it is closed

Depending on the required browser support we could look to use the popover api? This would at least handle some of the above for us such as light dismiss, focus handling.
This would also remove the need for the ref and 'mousedown' listeners for closing on outside click.

  1. I think we need some loading and success / failure states adding to the UI and code. At the minute there is no indication the chart has been copied to clipboard, and downloading can take a short while, so could be made more obvious when it's happening and has happened or failed. Not sure if that needs more discussion with design.

Obviously I'm new to the project so if the above not relevant feel free to ignore!

@rianski
Copy link
Collaborator Author

rianski commented Mar 11, 2025

I looked through this with Mark but since then a couple of things have jumped out:

  1. The popover menu needs some accessibility improvements, at least:
  • being able to close it with 'Esc'
  • various aria- markup being added such as aria-expanded on the toggle button
  • focus handling such as returning focus to the toggle when it is closed

Depending on the required browser support we could look to use the popover api? This would at least handle some of the above for us such as light dismiss, focus handling. This would also remove the need for the ref and 'mousedown' listeners for closing on outside click.

  1. I think we need some loading and success / failure states adding to the UI and code. At the minute there is no indication the chart has been copied to clipboard, and downloading can take a short while, so could be made more obvious when it's happening and has happened or failed. Not sure if that needs more discussion with design.

Obviously I'm new to the project so if the above not relevant feel free to ignore!

@rianski rianski closed this Mar 11, 2025
@rianski rianski reopened this Mar 11, 2025
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.

3 participants