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

fix(explore): Restore missing dataset states #22693

Merged
merged 5 commits into from
Jan 13, 2023

Conversation

codyml
Copy link
Member

@codyml codyml commented Jan 11, 2023

SUMMARY

This PR fixes Explore's dataset control so it correctly displays the intended UI when the chart's dataset doesn't exist or Explore has been opened without a specified chart or dataset.

Prior to moving Explore into the SPA, DatasourceControl (the dataset picker in the upper left) would check for a dataset ID of null to determine if the current chart's dataset existed. As part of moving Explore into the SPA, the initial Explore state in Redux was set to this object, which has the dataset ID set to 0. When a user opens Explore for a chart whose dataset does not exist, or when Explore is opened without a specified chart (this happens for new charts) and also without a dataset specified (this should only happen by accident), the initial Explore state's dataset object is not overwritten. Because DatasourceControl is checking for an ID of null, it doesn't correctly identify these cases as empty dataset situations, and shows options that should only be present in situations when there is a dataset and don't work correctly when no dataset is present.

This PR:

  • Makes Explore check for a dataset ID of 0, so the empty dataset alerts that were already present in code appear again
  • Hides the "Edit Dataset" and "View in SQL Lab" menu items, which don't work without a dataset
  • Makes the "missing dataset" text translated and a little more human-readable
  • Adds tests

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Chart with missing dataset, before:
localhost_9000_explore__slice_id=152 (1)

Chart with missing dataset, after:
localhost_9000_explore__slice_id=152 (2)

No chart with no dataset specified (e.g. from visiting /explore with no query string), before:
localhost_9000_explore_

No chart with no dataset specified, after:
localhost_9000_explore_ (1)

TESTING INSTRUCTIONS

  • Create and save a chart based on a dataset, then delete that dataset. Open that chart again and confirm that the correct message (dataset was deleted) appears under DatasourceControl and that the only menu option in the DatasourceControl three-dots menu is "Swap dataset".
  • Check that swapping the dataset via button or via menu item makes the message disappear and allows for chart editing/saving.
  • Visit /explore and confirm that the correct message (missing URL params) appears under DatasourceControl and that the only menu option in the DatasourceControl three-dots menu is "Swap dataset".
  • Check that swapping the dataset via menu item makes the message disappear and allows for chart editing/saving.
  • Check that creating charts from the Add Chart page works the same as before.
  • Check that editing existing charts with existing datasets works the same as before.
  • Check that creating charts from a SQL Lab query works the same, before and after saving the dataset.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codecov
Copy link

codecov bot commented Jan 11, 2023

Codecov Report

Merging #22693 (3e6d31a) into master (c0aeb2a) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master   #22693      +/-   ##
==========================================
- Coverage   67.10%   67.08%   -0.02%     
==========================================
  Files        1869     1869              
  Lines       71580    71551      -29     
  Branches     7806     7822      +16     
==========================================
- Hits        48031    48001      -30     
- Misses      21521    21523       +2     
+ Partials     2028     2027       -1     
Flag Coverage Δ
javascript 53.92% <100.00%> (-0.04%) ⬇️

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

Impacted Files Coverage Δ
...re/components/controls/DatasourceControl/index.jsx 91.50% <100.00%> (+6.60%) ⬆️
...rontend/src/components/DeprecatedSelect/styles.tsx 52.83% <0.00%> (-28.31%) ⬇️
...nents/DeprecatedSelect/WindowedSelect/windowed.tsx 54.54% <0.00%> (-18.19%) ⬇️
...c/components/DeprecatedSelect/DeprecatedSelect.tsx 41.33% <0.00%> (-12.00%) ⬇️
...rontend/src/SqlLab/components/QueryTable/index.tsx 66.66% <0.00%> (-3.51%) ⬇️
...et-frontend/src/components/TableView/TableView.tsx 80.70% <0.00%> (-1.76%) ⬇️
...perset-frontend/src/views/components/RightMenu.tsx 77.48% <0.00%> (-0.75%) ⬇️
superset-frontend/src/types/bootstrapTypes.ts 100.00% <0.00%> (ø)
...et-frontend/src/explore/controlPanels/sections.tsx 100.00% <0.00%> (ø)
...rontend/src/filters/components/Range/buildQuery.ts 0.00% <0.00%> (ø)
... and 41 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -267,11 +267,12 @@ class DatasourceControl extends React.PureComponent {
showSaveDatasetModal,
} = this.state;
const { datasource, onChange, theme } = this.props;
const isMissingDatasource = datasource?.id == null;
const isMissingDatasource = !datasource || datasource.id === 0;
Copy link
Member

Choose a reason for hiding this comment

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

Would this also work?

Suggested change
const isMissingDatasource = !datasource || datasource.id === 0;
const isMissingDatasource = !!datasource?.id

Copy link
Member Author

Choose a reason for hiding this comment

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

That's cleaner, thanks! This now also covers the original null case in case it's still used somewhere I couldn't find, which is probably good.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually sorry, !!datasource?.id doesn't work but !datasource?.id works. Is that what you meant?

Copy link
Member

Choose a reason for hiding this comment

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

yeah, that's it. 👍

@codyml
Copy link
Member Author

codyml commented Jan 13, 2023

@eschutho thanks, feel free to merge!

@rusackas rusackas merged commit f5c404f into apache:master Jan 13, 2023
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 and removed 🚢 2.1.3 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/M 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants