Skip to content

Download tool#6411

Merged
pablonoel merged 45 commits into
datacommonsorg:masterfrom
pablonoel:download-tool
Jul 17, 2026
Merged

Download tool#6411
pablonoel merged 45 commits into
datacommonsorg:masterfrom
pablonoel:download-tool

Conversation

@pablonoel

@pablonoel pablonoel commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This PR address the Download Tool refactor, it includes fixing the Facet selector and streamline the interface.

  • Complete download page.tsx refactor
  • Move state elements into contex.tsx ( as per maps / scatter tools use )
  • Add Theme / App wrapper
  • Remove Date
  • Fix Facet selector
  • Refactor URL/Path handling
  • Remove Preview button, implement auto-preview
localhost_8080_tools_download(Laptop XS) (2) localhost_8080_tools_download(Laptop XS) (1) localhost_8080_tools_download(Laptop XS)

Things to consider:

  • Download tool uses its own EnclosedPlacesSelector and FacetSelector, we should consider that to be shared among the rest of the tools.
  • There might be space for further refactor of the loadStateFromURL and some other elements
  • There is no current change on the html/styles structure, that will be implemented separately

- Separate the UI Logic
- Add page (app) provider with theme
- Move state elements into contex.tsx ( as per maps / scatter tools use )
- Remove data range, defaulting to DATE_ALL, updating the validation/url params.
- Update facet fetching
- Add pill examples
- Remove info_places references an info
- Refactor stat_var_chooser access
- Add download to shared vis tool components
- Add redirects to allow pill link construction
- Refactor dowload flash template
- Removes preview button, content reloads when a varStat is selected
- Refactor messages and filters logics
- Fix url based loader for pills
- Reset content when options are emptied
@pablonoel
pablonoel requested a review from nick-nlb June 25, 2026 19:52
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the summary. You can try again by commenting /gemini summary.

@pablonoel

Copy link
Copy Markdown
Contributor Author

@nick-nlb ready for review, let me know if you need more context.

@nick-nlb nick-nlb 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.

Thank you Pablo for all of this!

There are some inline comments, but I'll put a couple of behavioral notes here.

Mismatch of responsive breakpoints.

  • View in a wide desktop view
  • Select a location (say “United States”)
  • Select a breakdown (say “State”)
  • You will see “Pick a statistical variable in the left pane” as well as the statistical variable explorer on the left.
  • Slowly shrink the viewport
  • At a certain point, we flip into mobile/tablet, where the lefthand explorer disappears.
  • At this point, the message correctly switches to “Pick a statistical variable using the “select variable” button above.”
  • However, the button does not appear.
  • Shrink the viewport further, and the button will appear.

Facet Selector State state correspond with selected stat vars [I've suggested a fix in the comments]

  • Select “United States”
  • Select “State”
  • Select Health: Medical Condition: Diabetes: Percentage…”
  • You will see two facets (these are correct).
  • Now select Total Population
  • We expect 15 facets now be available (but we only see the two).
  • Refresh the page - you will see fifteen.

Comment thread static/js/i18n/i18n_tool_messages.ts
Comment thread static/js/tools/download/context.ts Outdated
Comment thread static/js/tools/download/page.tsx Outdated
Comment thread static/js/tools/download/page.tsx Outdated
Comment thread static/js/tools/download/page.tsx Outdated
pablonoel and others added 9 commits June 26, 2026 13:31
Remove preview and validation state management from the download context since they are no longer used. This includes removing PreviewWrapper and ValidationWrapper interfaces, and their associated state from useInitialContext(). Also update loadStateFromURL to accept only the setOptions function instead of the entire context object, and destructure facet methods directly for cleaner code.
Remove the maximum 5 statistical variable constraint and the associated modal dialog. Update the download tool to support single stat var selection at a time, replacing the previous selection instead of accumulating multiple variables. Simplify stat_var_chooser component by removing unused modal UI and state management logic.
Move variables and facets display into the preview card section for better organization. This includes:
- Wrapping variables and facet selector in a Card inside the preview
- Updating button label to "Download CSV" for clarity
- Converting Preview component from Card to div (Card moved to parent)
- Adding error handling for URL parameter JSON parsing
- Converting window.onhashchange to useEffect for proper cleanup
Add @emotion/react usage and theming to the data download tool. Import css and useTheme, apply theme.spacing for layout, replace Card with FormBox using flexDirection, add a responsive "select variable" Button, and remove unused imports. Also update the Preview component to use emotion styles (max-width, overflow, padding/margin) and useTheme. Minor layout and styling cleanup for a more consistent, theme-aware UI.
Add a short introductory paragraph to the Data Download Tool page and refactor the preview area into a bordered card with separated header (facet selector) and content region for improved spacing and UX. Also adjust the Preview component's container to use flex column layout to better align child elements. Files changed: static/js/tools/download/page.tsx, static/js/tools/download/preview.tsx.
@nick-nlb
nick-nlb marked this pull request as ready for review July 2, 2026 16:37
@nick-nlb
nick-nlb self-requested a review July 2, 2026 17:31

@nick-nlb nick-nlb 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.

Thank you Pablo!

Have a look at the comments - and could we also update the description, screenshots to reflect the design changes since the PR was originally created?

Comment thread static/js/i18n/i18n_tool_messages.ts
Comment thread static/js/tools/download/page.tsx Outdated
Comment thread static/js/tools/download/page.tsx Outdated
@nick-nlb

nick-nlb commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

@pablonoel Some questions to consider:

  • Now that we are guaranteed tidy long because we only have a single stat var, should the Date, Value and Source columns have the stat var removed (it serves no disambiguating purpose). The stat var could instead be incorporated into the download name.
  • Should the button to download be converted to our current button component and style set?

pablonoel and others added 2 commits July 3, 2026 11:41
New PlaceTag componen as an outlined-pill variant for single-select place pickers.

Update place_search_bar.tsx to: import emotion css/jsx pragma, use PlaceTag when numPlacesLimit === 1, add removePlaceAndRefocus and focusInputOnUpdate to ensure the autocomplete input is refocused after removing the single selected place, and keep existing Chip behavior for multi-select.

Adjust styles in static/css/_search_place.scss to target #location-field.input-area-hidden #ac and prevent flex growth when hidden.
Update download tool UI and caching: change i18n messages for the download tool (title/subtitle/placeholder) and remove an old go-back message. In page.tsx, include selectedStatVars keys in facetListCacheKey so cache varies by chosen stat vars, replace hardcoded title/subtitle/placeholder with intl.formatMessage usages (and pass placeholder to the search component), and switch hashchange handling to addEventListener/removeEventListener for proper cleanup.

Co-Authored-By: Nicholas Blumberg <41446765+nick-nlb@users.noreply.github.com>
@pablonoel

Copy link
Copy Markdown
Contributor Author

@pablonoel Some questions to consider:

* Now that we are guaranteed tidy long because we only have a single stat var, should the Date, Value and Source columns have the stat var removed (it serves no disambiguating purpose). The stat var could instead be incorporated into the download name.

* Should the button to download be converted to our current button component and style set?

Yes to both, I can take care of the button.

To use current button component.
@pablonoel

Copy link
Copy Markdown
Contributor Author
localhost_8080_tools_download(Laptop SM) (1) localhost_8080_tools_download(Laptop SM) (2) localhost_8080_tools_download(Laptop SM) (3) localhost_8080_tools_download(Laptop SM) (4)

@nick-nlb
nick-nlb self-requested a review July 3, 2026 21:26

@nick-nlb nick-nlb 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.

Thank you for the updates!

One item left in the comments, as well as another item to still be addressed:
The removal of the stat var from the column names (Date:Median_Age_Person -> Date), and the move of the stat var name into the file download.

Comment thread static/js/tools/shared/vis_tools/vis_tool_instructions_box.tsx Outdated
pablonoel added 5 commits July 6, 2026 10:34
The download tool was reusing instruction messages from the map tool. This change adds dedicated instruction messages for the download tool's variable selection UI.
- Always display facet selector in download tool, showing appropriate message when no alternatives exist
- Add mode-specific message for download tool's single facet case
- Keep stat var widget open after selection regardless of place type changes
- Add styling for no-facet message text in download page
Introduce a legacy/old download tool frontend and wire a feature flag to toggle it. Added a new static/js/tools/old_download React implementation (page, preview, info, stat_var_chooser, mocks, tests and snapshot) and a webpack entry (old_download). Server changes: add DOWNLOAD_TOOL_FEATURE_FLAG constant, update /tools/download route to choose between new download UI or legacy info+old_download bundle, and update download.html template to render either UI and include download.js or old_download.js accordingly. Enabled download_tool flag in multiple feature-flag config files (local/dev/staging/custom/autopush).
Implements a new DOWNLOAD_TOOL_FEATURE_FLAG to conditionally enable the new download tool functionality. The FacetSelector now returns null when in download mode with the flag disabled, and PlaceSearchBar only uses single-select mode when the flag is enabled.

Refactor radio button type checking across multiple components to use a new isRadioButtonType() function that respects the feature flag. This allows the legacy download tool (multi-select via checkboxes) to coexist with the new download tool (single-select via radio buttons).
@pablonoel

Copy link
Copy Markdown
Contributor Author

Feature flag implementation is up, there is some extra logic that needed to be implemented on the stat_var_chooser in order to accommodate for both ways to coexist, other than that when the feature flag is inactive, things should look and work exactly as they where.

@nick-nlb nick-nlb 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.

Thank you for the updates!

In addition to inline comments:

Column headers

Now that the tool displays data in tidy long, we no longer need to have the stat var in the headers. I.e., Source:Median_Income_Person should just be Source. The same applies for Date and Value.

However, let's include the stat var in the download file name itself (now that it is "global" to the file that is downloaded).

Download button reactivity

When you click the download button, it takes a second before the download is indicated by the browser, and the button itself gives you no indication that the click was received and that something is happening.

We solved this in the download dialog by animating a temporary check icon in the button that provides feedback to the user. You can see this by going to the explore page, opening any chart and clicking Copy Values. What do you think of using this here? (open to ideas on this).

Comment thread server/config/feature_flag_configs/autopush.json Outdated
Comment thread server/routes/tools/html.py Outdated
Comment thread static/js/shared/facet_selector/facet_selector.tsx Outdated
Comment thread static/js/shared/types.ts Outdated
@pablonoel

Copy link
Copy Markdown
Contributor Author

Thank you for the updates!

In addition to inline comments:

Column headers

Now that the tool displays data in tidy long, we no longer need to have the stat var in the headers. I.e., Source:Median_Income_Person should just be Source. The same applies for Date and Value.

However, let's include the stat var in the download file name itself (now that it is "global" to the file that is downloaded).

Download button reactivity

When you click the download button, it takes a second before the download is indicated by the browser, and the button itself gives you no indication that the click was received and that something is happening.

We solved this in the download dialog by animating a temporary check icon in the button that provides feedback to the user. You can see this by going to the explore page, opening any chart and clicking Copy Values. What do you think of using this here? (open to ideas on this).

Yes! changed the headers and good idea to implement the download button, all is done in the next push

Rename the feature flag from 'download_tool' to 'use_new_download_tool' across all configs and code. Update CSV export to use simplified headers and include stat var DCIDs in filenames when the new download tool is enabled. Add download success feedback with icon transition. Reorganize isRadioButtonType function to stat_var_hierarchy util module.
@nick-nlb
nick-nlb self-requested a review July 17, 2026 00:23

@nick-nlb nick-nlb 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.

Thank you Pablo for all of this!

@pablonoel
pablonoel merged commit 859b662 into datacommonsorg:master Jul 17, 2026
18 checks passed
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