-
Notifications
You must be signed in to change notification settings - Fork 14k
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
Vliu link form data explore v2 #1540
Conversation
x: null, | ||
y: null, | ||
size: null, | ||
url: 'https: //www.youtube.com/embed/JkI5rg_VcQ4', |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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',
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aac450f
to
2263027
Compare
Done:
|
@@ -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 }; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
bbe80d6
to
6187382
Compare
6187382
to
8bfbd72
Compare
const setFormInViz = function (state, action) { | ||
const newFormData = Object.assign({}, state); | ||
newFormData[action.key] = action.value; | ||
const setFormInViz = function (oldFd, action) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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.?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
abd8476
to
4424e56
Compare
Added tests in latest commit :) @ascott |
4424e56
to
94db0af
Compare
import { exploreReducer } from '../../../javascripts/explorev2/reducers/exploreReducer'; | ||
|
||
describe('reducers', () => { | ||
it('set form data according to given value', () => { |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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')
LGTM! 👍 🚢 |
0f581ff
to
1c56923
Compare
Done:
Todo:
needs-review @ascott