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

Created store and reducers #1108

Merged

Conversation

vera-liu
Copy link
Contributor

@vera-liu vera-liu commented Sep 14, 2016

  • Four objects in store: TimeFilter, GroupBy, Sql and Filter
  • For the four object-stores above, action can be fired once the query button is pressed
  • For the stores that are not contained in objects (datasourceId, vizType, columns, ordering, etc.) the actions will be fired once the field is changed, for instance, the user could see updated visualization once he selects a different viz_type without clicking the query button.

col: null,
};

export const initialState = {
Copy link
Contributor

Choose a reason for hiding this comment

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

i think initialState should go in the store

Copy link
Contributor Author

@vera-liu vera-liu Sep 14, 2016

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

i mean put initial state in a file called store.js

then rather than importing initial state from ./reducers.js, import from store.js

the way you are creating the store looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it!

@ascott
Copy link
Contributor

ascott commented Sep 14, 2016

this is looking really good!

i think now would be a good time to add tests for the reducers and actions.
there are some examples here: http://redux.js.org/docs/recipes/WritingTests.html#action-creators

this is a good example of logging your state to test in browser, to make sure your actions are returning the new state correctly: http://redux.js.org/docs/basics/Store.html#dispatching-actions

filters: [defaultFilter],
};

function addToArr(state, arrKey, obj) {
Copy link
Member

@mistercrunch mistercrunch Sep 15, 2016

Choose a reason for hiding this comment

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

All of these helper functions are copy-pasted from SqlLab/reducer.jsx, let's refactor them in some reducerUtils.jsx module. Copy-pasting code is bad because it then needs to be maintained in multiple places.

Copy link
Contributor

@ascott ascott Sep 20, 2016

Choose a reason for hiding this comment

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

yes, definitely great idea to share these utils. best place for them would be caravel/assets/javascripts/utils/, then all reducers can import from there.

reducerUtils.js

export function addToArr(state, arrKey, obj) {
  ...
}

export function someOtherUtil(state, arrKey, obj) {
  ...
}

import { addToArr, someOtherUtil } from '../utils/reducerUtils.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done:)

Copy link
Contributor

Choose a reason for hiding this comment

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

great! looks like you just need to push your new changes...

return { type: SET_SQL, sql };
}

export function addFilter(filter) {
Copy link
Member

Choose a reason for hiding this comment

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

After a bit of experience on Redux, I think passing objects to action creators isn't a great pattern because there's no place where the object structure is defined except for where it's being created. If it's being created in only one place in the codebase it isn't too bad, but if many places in the code need to create the object there's no central place for constructor-type logic.

After a bit of thinking I now think that action creator is the right place to act as a constructor. Meaning the action creator would detail which param the object has, and implement constructor logic if any.

@ascott , thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

i'm not sure i get what you are suggesting here... could you clarify?

@@ -112,6 +112,7 @@
"react-addons-test-utils": "^0.14.8",
"react-dom": "^0.14.8",
"style-loader": "^0.13.0",
"tape": "^4.6.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

we should remove this dependency since we will stick with mocha for testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done:)

@@ -0,0 +1,190 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

this file should be located in caravel/assets/spec/javascripts/explore/actions/ and be renamed to actions_spec.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done:)

@@ -0,0 +1,71 @@
export const SET_DATASOURCE = 'SET_DATASOURCE';
Copy link
Contributor

Choose a reason for hiding this comment

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

let's move this to caravel/assets/javascripts/explorev2/actions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done:)

@@ -0,0 +1,89 @@
import shortid from 'shortid';
Copy link
Contributor

Choose a reason for hiding this comment

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

let's move this to caravel/assets/javascripts/explorev2/reducers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done:)

@@ -0,0 +1,39 @@
import shortid from 'shortid';
Copy link
Contributor

Choose a reason for hiding this comment

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

let's move this to caravel/assets/javascripts/explorev2/stores

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done:)

import shortid from 'shortid';
import * as actions from '../../../../javascripts/explorev2/actions';
import { initialState } from '../../../../javascripts/explorev2/store';
import { exploreReducer } from '../../../../javascripts/explorev2/reducers';
Copy link
Contributor

Choose a reason for hiding this comment

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

the import name and file name should be the same according to our style guide: https://github.com/airbnb/javascript#naming--filename-matches-export

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done:)

@vera-liu vera-liu force-pushed the vliu_refactor_explore branch 2 times, most recently from 67a69e4 to b9648b9 Compare September 20, 2016 21:04
@@ -1,6 +1,7 @@
import shortid from 'shortid';
import * as actions from './actions';
import { now } from '../modules/dates';
import * as utils from '../../utils/reducerUtils';
Copy link
Contributor

@ascott ascott Sep 20, 2016

Choose a reason for hiding this comment

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

would be nice to use destructuring here: so you don't have to use utils.addToArr elsewhere.
const { addToArr, removeFromArr, alterInArr, alterInObject } from '../../utils/reducerUtils';

import { exploreReducer } from './reducers/exploreReducer';
import persistState from 'redux-localstorage';

let enhancer = compose(persistState());
Copy link
Contributor

Choose a reason for hiding this comment

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

i think i've seen this pattern in sql-lab too, would be great to add to redux utils.

/>,
<Provider store={store}>
<ExploreViewContainer
data={bootstrapData}
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any data from the server in bootstrapData that can be used to bootstrap the initial state? i think we get vizType and datasourceID

Copy link
Contributor

Choose a reason for hiding this comment

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

so above we probably want to do

const bootstrappedState = Object.assign(initialState, {
  datasourceId: bootstrapData.datasourceId,
  vizType: bootstrapData.vizType
});

const store = createStore(exploreReducer, bootstrappedState, enhancer);

@vera-liu
Copy link
Contributor Author

Made modifications based on all of the comments, the python tests are failing, is it expected and safe to merge? @ascott

@ascott
Copy link
Contributor

ascott commented Sep 21, 2016

yeah, this is safe to merge since we are just merging to airbnb:alanna-explore-v2-main and not to master. for some reason it seems tests fail on PR's that are not to master. @mistercrunch @bkyryliuk do u have any ideas on this?

in the mean time @vera-liu let's merge!

@vera-liu vera-liu merged commit dcfb604 into apache:alanna-explore-v2-main Sep 21, 2016
import { connect, Provider } from 'react-redux';

import { initialState, sqlLabReducer } from './reducers';
import persistState from 'redux-localstorage';
import { enhancer } from '../../utils/common';
Copy link
Contributor

Choose a reason for hiding this comment

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

i wonder if this should go in a reduxUtils.js file rather than just common utils...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry merged in too early ;( I'll fix this in my next refactor_explore PR

Copy link
Contributor

Choose a reason for hiding this comment

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

np, just a thought for another PR 👌

vera-liu added a commit to vera-liu/caravel that referenced this pull request Sep 27, 2016
* Created store and reducers

* Added spec

* Modifications based on comments
vera-liu added a commit that referenced this pull request Sep 29, 2016
…1205)

* create structure for new forked explore view (#1099)

* create structure for new forked explore view

* update component name

* add bootstrap data pattern

* remove console.log

* Associate version to entry files (#1060)

* Associate version to entry files

* Modified path joins for configs

* Made changes based on comments

* Created store and reducers (#1108)

* Created store and reducers

* Added spec

* Modifications based on comments

* Explore control panel components: Chart control, Time filter, SQL,
GroupBy and Filters

* Modifications based on comments
ascott pushed a commit that referenced this pull request Oct 4, 2016
* Explore control panel - Chart control, TimeFilter, GroupBy, Filters (#1205)

* create structure for new forked explore view (#1099)

* create structure for new forked explore view

* update component name

* add bootstrap data pattern

* remove console.log

* Associate version to entry files (#1060)

* Associate version to entry files

* Modified path joins for configs

* Made changes based on comments

* Created store and reducers (#1108)

* Created store and reducers

* Added spec

* Modifications based on comments

* Explore control panel components: Chart control, Time filter, SQL,
GroupBy and Filters

* Modifications based on comments

* accommodate old and new explore urls

* move bootstrap data up in scope

* fix code climate issues

* fix long lines

* fix syntax error
vera-liu added a commit to vera-liu/caravel that referenced this pull request Oct 4, 2016
…pache#1205)

* create structure for new forked explore view (apache#1099)

* create structure for new forked explore view

* update component name

* add bootstrap data pattern

* remove console.log

* Associate version to entry files (apache#1060)

* Associate version to entry files

* Modified path joins for configs

* Made changes based on comments

* Created store and reducers (apache#1108)

* Created store and reducers

* Added spec

* Modifications based on comments

* Explore control panel components: Chart control, Time filter, SQL,
GroupBy and Filters

* Modifications based on comments
vera-liu added a commit that referenced this pull request Oct 4, 2016
* Explore control panel - Chart control, TimeFilter, GroupBy, Filters (#1205)

* create structure for new forked explore view (#1099)

* create structure for new forked explore view

* update component name

* add bootstrap data pattern

* remove console.log

* Associate version to entry files (#1060)

* Associate version to entry files

* Modified path joins for configs

* Made changes based on comments

* Created store and reducers (#1108)

* Created store and reducers

* Added spec

* Modifications based on comments

* Explore control panel components: Chart control, Time filter, SQL,
GroupBy and Filters

* Modifications based on comments

* Added access check + Druid in endpoint

* pull grains to constants

* Switch explore.html to old version
vera-liu added a commit to vera-liu/caravel that referenced this pull request Oct 4, 2016
…pache#1205)

* create structure for new forked explore view (apache#1099)

* create structure for new forked explore view

* update component name

* add bootstrap data pattern

* remove console.log

* Associate version to entry files (apache#1060)

* Associate version to entry files

* Modified path joins for configs

* Made changes based on comments

* Created store and reducers (apache#1108)

* Created store and reducers

* Added spec

* Modifications based on comments

* Explore control panel components: Chart control, Time filter, SQL,
GroupBy and Filters

* Modifications based on comments
ascott pushed a commit that referenced this pull request Oct 6, 2016
* create structure for new forked explore view (#1099)

* create structure for new forked explore view

* update component name

* add bootstrap data pattern

* remove console.log

* Created store and reducers (#1108)

* Created store and reducers

* Added spec

* Modifications based on comments

* do use bootstrap data for now

* don't deal with bootstrap data for now

* use victory as a base

* import fake line data, add fake panels, make chart fixed

* add fetch support

* get slice data from json endpoint

* render chart with slicejson

* update chart and label demo

* remove fetch config

* remove dummy control panels

* should be a func

* make TimeSeriesLineChart

* add a comment

* inner height for height

* don't need fetch yet

* trailing comma breaks in package json

* pass in viz data from props

* add style sheet

* set height on explore container

* add legend

* make chart responsive to window resize

* can't use head_css in template bc overrides head_css in basic

* fix linting

* break labelItem into own SFC, make legend SFC

* add propTypes and fix linter
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this pull request Nov 17, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this pull request Nov 24, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this pull request Nov 25, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this pull request Nov 26, 2021
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.5.0 labels Feb 19, 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 🚢 1.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants