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

Export records from tables #1646

Open
wants to merge 16 commits into
base: john/20202-page-and-record-counts
Choose a base branch
from

Conversation

johnclary
Copy link
Member

@johnclary johnclary commented Jan 3, 2025

Associated issues

This PR adds a basic CSV export to the grid table. I decided to hold off on some more sophisticated functionality, which can be addressed via cityofaustin/atd-data-tech#20481. The main thing this export does not do versus the old VZE is allow exporting related records. That will require some bigger changes to the structure of the queryConfig and the queryBuilder.

See also some discussion here about the style of the pagination + record counts 👀

Screenshot 2025-01-06 at 2 11 23 PM Screenshot 2025-01-06 at 2 15 27 PM

Testing

URL to test: Local

Steps to test:

⚠️ In order to see this new functionality, you will need to hit the Reset filters button on each table to clear out the old query config from local storage.

These tables are now exportable:

  1. Try exporting each table. Verify that the suggested filename makes sense to you.
  2. Search and filter and export again.
  3. Open the CSVs in your favorite spreadsheet editor to verify that they look ok 👍

Ship list

  • Check migrations for any conflicts with latest migrations in main branch
  • Confirm Hasura role permissions for necessary access
  • Code reviewed
  • Product manager approved

@johnclary johnclary added the WIP Work in progress label Jan 3, 2025
// update the provided query with export settings
return produce(queryConfig, (newQueryConfig) => {
// reset limit and offset
newQueryConfig.limit = MAX_RECORD_EXPORT_LIMIT;
Copy link
Member Author

Choose a reason for hiding this comment

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

Hasura will accept a limit of null, but modifying this typing to accept null was a headache i didn't really want to deal with 🤷

Copy link
Member

@frankhereford frankhereford left a comment

Choose a reason for hiding this comment

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

I think this is shippable as-is, but I have a couple of suggestions I want to put forth. If you'll see what you think about them, I'm eager to put a ✅ on this.

This is looking good! Thank you John.

* Generate the CSV export filename
*/
const formatFileName = (exportFilename?: string) =>
`${exportFilename || "export"}-${formatDate(new Date().toISOString())}.csv`;
Copy link
Member

Choose a reason for hiding this comment

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

What would you think about including the time in addition to the date string in this default filename? Maybe <table_name>-20250108-1532.csv for something downloaded today, the 8th at 3:32PM local time?

I know this bleeds slightly outside of the scope of this work here, as it's contained in that utility formatter, but bringing in that change allows for a user more easily keep multiple files downloaded in a set straight. I'm thinking of the use-case of when someone wants to compare multiple sets of crashes in some BI software or something like that. Being able to open up your file browser and easily sort the files in the order in which they were downloaded is valuable.

I guess put another way -- the filename is the only tiny bit of metadata we get to attach to these CSVs, so let's take as much advantage of that as we can, and avoid the browser's behavior that yields stuff like this: some-name.csv, some-name (1).csv, some-name (2).csv.

Comment on lines +118 to +122
<Button
href={downloadUrl || "#"}
download={formatFileName(exportFilename)}
as="a"
>
Copy link
Member

Choose a reason for hiding this comment

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

Since the data is pulled together as shown by the spinner on the download button before it can be clicked, can we close this modal automatically once or very shortly after the download button is clicked by the user? I can't see any situation where a user needs to download the same data twice in rapid succession. In fact, I think we want to avoid making that easy to do.

The model closing will give the user some visual feedback that the operation has occurred, and as it is, I think this relies too much on the browser's gloss outside of the viewport to telegraph that activity to the user, if it does telegraph it at all.

If we can't close the modal because maybe we need to keep it mounted to preserve the URL held in the useState, can we do something like a check-mark that has some spinner-like motion, to indicate that something intended and/or positive has happened. If you look in our slack at the :checked: emoji .. one loop of that is what I'm trying to describe as a good indicator of this type of thing.

Copy link
Contributor

@mateoclarke mateoclarke left a comment

Choose a reason for hiding this comment

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

dl-pizza

{exportable && (
<Button
variant="outline-primary"
style={{ border: "none" }}
Copy link
Contributor

@mateoclarke mateoclarke Jan 9, 2025

Choose a reason for hiding this comment

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

This feels weird to me. To use the outline-primary variant but then override the outline/border entirely. I can see this being pretty fickle and inconsistent over time. So my question/recommendation is can we write a reusable CSS class that would be consistent to apply as an override and as a 1-liner?

Aside from that, why use style here when bootstrap has good utilities? It doesn't make a big difference but I'd use class="border-0" in this case. Inline style are bad is a dogma I've inherited. Not sure how well it serves us here.

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