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: clear modal state after adding dataset #17044

Merged
merged 3 commits into from
Oct 10, 2021

Conversation

betodealmeida
Copy link
Member

SUMMARY

This PR fixes a bug where after adding a dataset the modal would not reset properly. For example, adding if a user added, database.schema.table, when they tried to add another dataset the model would be already populated with database, schema and table on the dropdowns.

While troubleshooting the problem I also cleaned up the code. <TableSelector> would take as props both a database object as well as a database ID. The logic was not correct so they were falling out of sync. I modified the component to take only a database object.

I also consolidated a database type that was used in slightly different ways — the only difference was that one had allow_multi_schema_metadata_fetch and the other didn't.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

modal.add.dataset.mov

TESTING INSTRUCTIONS

Add a dataset; add another. Modal should be empty when it loads.

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

@@ -176,13 +169,22 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
const [tableOptions, setTableOptions] = useState<TableOption[]>([]);

useEffect(() => {
if (currentDbId && currentSchema) {
// reset selections
if (database === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

could this ever be null? Do you want to check a more generic falsy value iow?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I'll check for any falsy values.

@@ -61,15 +64,11 @@ const DatasetModal: FunctionComponent<DatasetModalProps> = ({
);

useEffect(() => {
setDisableSave(isNil(datasourceId) || isEmpty(currentTableName));
}, [currentTableName, datasourceId]);
setDisableSave(isNil(currentDatabase) || isEmpty(currentTableName));
Copy link
Member

Choose a reason for hiding this comment

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

should this be isEmpty(currentDatabase)?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can get rid of lodash here, let me do it.

const onSave = () => {
const data = {
database: datasourceId,
database: currentDatabase?.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.

what does setting the default to 0 do in this case, rather than undefined or null?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me clean this up... here currentDatabase will always be defined, otherwise you can't save.

Copy link
Member

@eschutho eschutho left a comment

Choose a reason for hiding this comment

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

looks great.. just a few small questions.

@codecov
Copy link

codecov bot commented Oct 9, 2021

Codecov Report

Merging #17044 (0844add) into master (2c8e06e) will decrease coverage by 0.01%.
The diff coverage is 48.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17044      +/-   ##
==========================================
- Coverage   76.92%   76.91%   -0.02%     
==========================================
  Files        1031     1031              
  Lines       55157    55176      +19     
  Branches     7501     7503       +2     
==========================================
+ Hits        42430    42437       +7     
- Misses      12475    12487      +12     
  Partials      252      252              
Flag Coverage Δ
javascript 70.85% <48.00%> (-0.03%) ⬇️

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

Impacted Files Coverage Δ
...nd/src/views/CRUD/data/dataset/AddDatasetModal.tsx 54.54% <33.33%> (-8.32%) ⬇️
...et-frontend/src/components/TableSelector/index.tsx 74.52% <66.66%> (-3.03%) ⬇️
...frontend/src/components/DatabaseSelector/index.tsx 95.12% <100.00%> (+0.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2c8e06e...0844add. Read the comment docs.

@betodealmeida betodealmeida merged commit 16a1df7 into apache:master Oct 10, 2021
@sadpandajoe
Copy link
Contributor

🏷️ 2021.40

sadpandajoe pushed a commit to preset-io/superset that referenced this pull request Oct 11, 2021
* fix: clear modal state after adding dataset

* Fix test

* Small fixes

(cherry picked from commit 16a1df7)
@eschutho eschutho added the v1.4 label Oct 26, 2021
eschutho pushed a commit to preset-io/superset that referenced this pull request Oct 27, 2021
* fix: clear modal state after adding dataset

* Fix test

* Small fixes

(cherry picked from commit 16a1df7)
opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
* fix: clear modal state after adding dataset

* Fix test

* Small fixes
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 28, 2021
* fix: clear modal state after adding dataset

* Fix test

* Small fixes
@mistercrunch mistercrunch added 🍒 1.4.0 🍒 1.4.1 🍒 1.4.2 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.5.0 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 preset:2021.40 size/L v1.4 🍒 1.4.0 🍒 1.4.1 🍒 1.4.2 🚢 1.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants