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

Vliu link form data explore v2 #1540

Merged
merged 9 commits into from
Nov 8, 2016

Conversation

vera-liu
Copy link
Contributor

@vera-liu vera-liu commented Nov 3, 2016

Done:

  • Changed defaultFormData and defaultViz in store to match structure sent from bootstrap_data
  • Added onChange function to push data from form components to store
  • Changed some variable names from camel to snake case matching state variables in ChartContainer and ControlPanelContainer

Todo:

  • pass down state needed for Field components from ControlPanelContainer
  • datasource/viz_type should be apart from form_data and reset all form data once they are changed
  • add query and save button, hit right url when query button clicked

needs-review @ascott

x: null,
y: null,
size: null,
url: 'https: //www.youtube.com/embed/JkI5rg_VcQ4',
Copy link

@ascott ascott Nov 4, 2016

Choose a reason for hiding this comment

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

i think this was just an example url, we should make this null

@@ -21,21 +26,41 @@ const defaultProps = {
validators: null,
};

export default class FieldSet extends React.Component {
export class FieldSet extends React.Component {
onChange(value) {
Copy link

Choose a reason for hiding this comment

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

we could move this onChange method to ControlPanelsContainer and pass that in as a prop so we don't have to connect to stores/bind actions in this component too.

x_axis_format: 'smart_date',
y_axis_format: '.3s',
markup_type: 'markdown',
rotation: 'random',
Copy link

@ascott ascott Nov 4, 2016

Choose a reason for hiding this comment

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

all of these defaults should live with the other field data. there is an object called fields which contains the data each field needs to render.

  rotation: {
    type: 'SelectField',
    label: 'Rotation',
    choices: formatSelectOptions(['random', 'flat', 'square']),
    default: 'random',
    description: 'Rotation to apply to words in the cloud',
  },

Copy link

Choose a reason for hiding this comment

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

@vera-liu vera-liu force-pushed the vliu_link_form_data_explore_v2 branch from aac450f to 2263027 Compare November 4, 2016 18:27
@vera-liu
Copy link
Contributor Author

vera-liu commented Nov 4, 2016

Done:

  • Moved onChange to ChartContainer
  • get defaultFormData from fields in store.js

@ascott

@@ -48,18 +48,14 @@ export function setFilterColumnOpts(filterColumnOpts) {
}

export function resetFormData() {
// Clear all form data when switching datasource
// Clear all form data when switching datasource or viz_type
return { type: RESET_FORM_DATA };
Copy link

Choose a reason for hiding this comment

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

i'm curious why we need to reset form data when switching a datasource? the way i would see this working is when a datasource changes, it should trigger a fetch of datasource meta data which, once returned will update state with the new meta data. the meta data should include select options and any defaults needed.

Copy link
Contributor Author

@vera-liu vera-liu Nov 7, 2016

Choose a reason for hiding this comment

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

When user switches datasource we would reset both choices and already selected values in all forms. I'm thinking about separating out actions for onChange of datasource/viz_type in another PR, and dispatch resetFormData and resetChoices from there. Some form_data will be set to default values ,some will be blank, e.g. metrics/columns

Copy link

Choose a reason for hiding this comment

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

right, so wouldn't the data that is returned from fetching the datasource meta data be set on the state, in effect 'resetting' the form data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right..yeah it makes sense to keep form_data used for visualization unchanged (such as show_bar_value) and only reset form_data such as columns/groupby. So I guess this is only needed for switching viz_type then? for instance when we switch from dist_bar to table, form_data such as show_control will be reset to default value false.

Copy link

Choose a reason for hiding this comment

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

when a viz type changes, then the state will be updated which will trigger a rerender of the control panel sections. https://github.com/airbnb/caravel/blob/master/caravel/assets/javascripts/explorev2/components/ControlPanelsContainer.jsx#L29

the sections and fields that get rendered are dynamic depending on the viz type.

so what i am getting at is that the field defaults should be stored in the field definitions, and we shouldn't need to reset the whole form at any point, react will take care of triggering the rerender and will render the appropriate fields/default when a new viz type is updated.

return newFormData;
};

const setVizInState = function (state, action) {
const setVizInState = function (oldViz, action) {
switch (action.type) {
case actions.SET_FORM_DATA:
Copy link

Choose a reason for hiding this comment

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

it looks like this only gets called SET_FORM_DATA action handler. curious why we need a switch statement to check the action type...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for if we will have actions for setting other attributes in viz object, such as json_endpoint, query and standalone_endpoint

Copy link

Choose a reason for hiding this comment

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

i think we will want other action handlers rather than switch statements here.

@vera-liu vera-liu force-pushed the vliu_link_form_data_explore_v2 branch from bbe80d6 to 6187382 Compare November 8, 2016 00:39
@vera-liu vera-liu force-pushed the vliu_link_form_data_explore_v2 branch from 6187382 to 8bfbd72 Compare November 8, 2016 00:40
const setFormInViz = function (state, action) {
const newFormData = Object.assign({}, state);
newFormData[action.key] = action.value;
const setFormInViz = function (oldFd, action) {
Copy link

Choose a reason for hiding this comment

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

seems like this should be called toggleCheckboxValue?

i think every method in the reducer should take state and action as args as a general pattern.

Copy link
Contributor Author

@vera-liu vera-liu Nov 8, 2016

Choose a reason for hiding this comment

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

we also use this function for Select and TextField, for checkbox action.value is undefined while for other fields they are directly set to action.value. I'll add a comment to make this clear

default:
return state;
}
const setVizInState = function (oldViz, action) {
Copy link

Choose a reason for hiding this comment

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

i think we should be setting state any time any field is changed, and not just one handler for updating the whole form at once. so we should replace this a function that can set the value for a given field name.

state,
{ viz: setVizInState(state.viz, action) }
);
const newViz = Object.assign({}, state.viz);
Copy link

Choose a reason for hiding this comment

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

i think we could simplify this to

const newState = Object.assign({}, state);
newState.viz.form_data[action.key] = 
  action.value ? action.value : (!state.viz.form_data[action.key]);
return newState;

};
const newState = exploreReducer(testState, actions.removeFilter(filter1));
expect(newState.filters).to.deep.equal([filter2]);
it('set form data', () => {
Copy link

Choose a reason for hiding this comment

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

could we add tests to test for each field type, checkbox, select, text, etc.?

Copy link

Choose a reason for hiding this comment

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

or at least for checkboxes since it's toggling the value....

}
}

onChange(name, value) {
this.props.actions.setFormData(name, value);
Copy link

Choose a reason for hiding this comment

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

i might call this setFieldValue for clarity since it's just updating a single field.

@vera-liu vera-liu force-pushed the vliu_link_form_data_explore_v2 branch 2 times, most recently from abd8476 to 4424e56 Compare November 8, 2016 04:21
@vera-liu
Copy link
Contributor Author

vera-liu commented Nov 8, 2016

Added tests in latest commit :) @ascott

@vera-liu vera-liu force-pushed the vliu_link_form_data_explore_v2 branch from 4424e56 to 94db0af Compare November 8, 2016 16:48
import { exploreReducer } from '../../../javascripts/explorev2/reducers/exploreReducer';

describe('reducers', () => {
it('set form data according to given value', () => {
Copy link

@ascott ascott Nov 8, 2016

Choose a reason for hiding this comment

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

i wonder if this would be more clear as:
it('sets correct field value given a key and value')

const newState = exploreReducer(initialState, actions.setFieldValue('x_axis_label', 'x'));
expect(newState.viz.form_data.x_axis_label).to.equal('x');
});
it('flip value in state when action.key is not defined', () => {
Copy link

Choose a reason for hiding this comment

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

would this be more clear as:
it('toggles a boolean field value given only a key')

@ascott
Copy link

ascott commented Nov 8, 2016

LGTM! 👍 🚢

@vera-liu vera-liu force-pushed the vliu_link_form_data_explore_v2 branch from 0f581ff to 1c56923 Compare November 8, 2016 18:04
@vera-liu vera-liu merged commit bb6ab11 into apache:master Nov 8, 2016
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.13.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 🚢 0.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants