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

chore: Restructure explore redux state #20448

Merged
merged 11 commits into from
Jun 24, 2022

Conversation

kgabryje
Copy link
Member

@kgabryje kgabryje commented Jun 21, 2022

SUMMARY

This PR restructures Explore redux state, so that it's more consistent with redux state of Dashboard view. This is a prerequisite for upcoming Explore SPA project - we need the redux states to be consistent so that we can smoothly navigate between dashboards and charts.

Now the following structure is used:

{
  user: User;
  common: {
    flash_messages: string[];
    conf: JsonObject;
  };
  charts: { [key: number]: ChartState };
  datasources: { [key: string]: Dataset };
  explore: {
    can_add: boolean;
    can_download: boolean;
    can_overwrite: boolean;
    isDatasourceMetaLoading: boolean;
    isStarred: boolean;
    triggerRender: boolean;
    // duplicate datasource in exploreState - it's needed by getControlsState
    datasource: Dataset,
    controls: ControlStateMapping;
    form_data: JsonObject;
    slice: Slice;
    controlsTransferred: string[],
    standalone: boolean;
    force: boolean;
  }
}

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

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

@kgabryje
Copy link
Member Author

CC @eric-briscoe since you were interested in this project 🙂

@codecov
Copy link

codecov bot commented Jun 21, 2022

Codecov Report

Merging #20448 (76e0b46) into master (44f0b51) will increase coverage by 0.01%.
The diff coverage is 64.44%.

@@            Coverage Diff             @@
##           master   #20448      +/-   ##
==========================================
+ Coverage   66.75%   66.76%   +0.01%     
==========================================
  Files        1740     1744       +4     
  Lines       65172    65172              
  Branches     6900     6901       +1     
==========================================
+ Hits        43505    43514       +9     
+ Misses      19918    19908      -10     
- Partials     1749     1750       +1     
Flag Coverage Δ
javascript 51.83% <64.44%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
...d/packages/superset-ui-chart-controls/src/types.ts 100.00% <ø> (ø)
...perset-frontend/src/addSlice/AddSliceContainer.tsx 65.85% <ø> (ø)
superset-frontend/src/dashboard/actions/hydrate.js 2.04% <ø> (ø)
...frontend/src/dashboard/components/Header/index.jsx 59.39% <ø> (ø)
...rontend/src/dashboard/containers/DashboardPage.tsx 5.31% <ø> (ø)
...set-frontend/src/dashboard/util/permissionUtils.ts 90.00% <ø> (ø)
...rset-frontend/src/explore/components/SaveModal.tsx 66.19% <ø> (ø)
...re/components/controls/DatasourceControl/index.jsx 74.73% <0.00%> (ø)
...et-frontend/src/explore/reducers/exploreReducer.js 40.67% <0.00%> (+5.89%) ⬆️
...t-frontend/src/explore/reducers/getInitialState.ts 0.00% <0.00%> (ø)
... and 19 more

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 44f0b51...76e0b46. Read the comment docs.

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @kgabryje! I left some first-pass comments.

superset-frontend/src/explore/reducers/index.js Outdated Show resolved Hide resolved
superset-frontend/src/utils/findPermission.test.ts Outdated Show resolved Hide resolved
superset-frontend/src/utils/getDatasourceUid.test.ts Outdated Show resolved Hide resolved
superset-frontend/src/utils/getDatasourceUid.test.ts Outdated Show resolved Hide resolved
@kgabryje
Copy link
Member Author

Thanks for comments Michael, they all make sense to me. Will fix

Comment on lines 40 to 44
export function getChartKey(explore) {
const { slice } = explore;
return slice ? slice.slice_id : 0;
const { slice, form_data } = explore;
return slice?.slice_id ?? form_data?.slice_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.

no blocking suggestion, define a constant for the unsaved chart, default value is 0, and this function might be splited into getChartKeyFromSlice and getChartKeyFromFromData.

Copy link
Member Author

Choose a reason for hiding this comment

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

+1 for creating a constant for default slice id, but is there a use case for splitting this function in 2?

superset-frontend/src/utils/getDatasourceUid.ts Outdated Show resolved Hide resolved
} from '../actions/datasourcesActions';

export default function datasourcesReducer(
datasources: { [key: string]: Dataset },
Copy link
Member

Choose a reason for hiding this comment

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

This type will probably change in the future to include other datasource types.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I change it now? Or just add a todo when those new datasource types are introduced?

Copy link
Member

Choose a reason for hiding this comment

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

Either way would work. Using the intersection type may cause some typescript errors because you'll need to resolve the difference in the schema of the datasources, which is something that we're working on now in a feature branch. It may be easiest to leave it as a todo, honestly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a todo

@jinghua-qa
Copy link
Member

/testenv up

@github-actions
Copy link
Contributor

@jinghua-qa Ephemeral environment spinning up at http://54.70.20.159:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

}

export function changeDatasource(newDatasource: Dataset) {
return function (dispatch: Dispatch, getState: () => any) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we confirm the exact type of getState return here?

Copy link
Member Author

@kgabryje kgabryje Jun 23, 2022

Choose a reason for hiding this comment

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

Good point... which resulted in finding a bug. I thought that getState returns the state of reducer, but it actually returns global redux state.
Added a unit test for that

@jinghua-qa
Copy link
Member

Explore regression is tested in ephemeral env , did not find major issue related to this PR, LGTM

@kgabryje
Copy link
Member Author

/testenv up

@github-actions
Copy link
Contributor

@kgabryje Ephemeral environment spinning up at http://34.221.129.165:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

datasource_type: explore.datasource.type,
datasourceId: explore.datasource_id,
datasource,
datasource_type: datasource.type,
Copy link
Member

Choose a reason for hiding this comment

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

I think this might be a good time to make also the property names consistent, some of them are camel case, some others use hyphens currently

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 call. I'll fix it in a follow up PR

@kgabryje
Copy link
Member Author

/testenv up

@github-actions
Copy link
Contributor

@kgabryje Ephemeral environment spinning up at http://34.223.225.190:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@stephenLYZ stephenLYZ left a comment

Choose a reason for hiding this comment

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

Nice Work!

@kgabryje kgabryje merged commit c7f1c7d into apache:master Jun 24, 2022
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

akshatsri pushed a commit to charan1314/superset that referenced this pull request Jul 19, 2022
* chore: Restructure explore redux state

* fixes

* fix tests

* add new tests

* Fix type

* Address comments

* Fix bug

* Fix import

* Add new test

* Move unsaved chart id to a constant

* Add todo
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.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-io size/XL 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants