Skip to content

Commit

Permalink
Moving forward
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Feb 1, 2017
1 parent 874ad1e commit c8a00e6
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,8 @@ export function runQuery(formData, datasourceType) {
});
};
}

export const RESET_FIELDS = 'RESET_FIELDS';
export function resetFields(datasourceType) {
return { type: RESET_FIELDS };
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import ChartContainer from './ChartContainer';
import ControlPanelsContainer from './ControlPanelsContainer';
import SaveModal from './SaveModal';
import QueryAndSaveBtns from '../../explore/components/QueryAndSaveBtns';
import { autoQueryFields } from '../stores/fields';
import { getExploreUrl } from '../exploreUtils';

const propTypes = {
Expand All @@ -30,15 +29,16 @@ class ExploreViewContainer extends React.Component {
componentDidMount() {
window.addEventListener('resize', this.handleResize.bind(this));
this.runQuery();
this.props.actions.resetFields();
this.props.actions.fetchDatasources();
}

componentWillReceiveProps(nextProps) {
const refreshChart = Object.keys(nextProps.fields).some((field) => (
nextProps.fields[field].value !== this.props.fields[field].value
&& autoQueryFields.indexOf(field) !== -1)
);
if (refreshChart) {
// Reset fields and run a query if the datasource or viz_type has changed
if (
nextProps.fields.datasource.value !== this.props.fields.datasource.value ||
nextProps.fields.viz_type.value !== this.props.fields.viz_type.value) {
this.props.actions.resetFields();
this.onQuery();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export default class SelectField extends React.PureComponent {
}
render() {
// Tab, comma or Enter will trigger a new option created for FreeFormSelect
console.log(this.props.name, this.props.value);
const selectProps = {
multi: this.props.multi,
name: `select-${this.props.name}`,
Expand Down
3 changes: 0 additions & 3 deletions superset/assets/javascripts/explorev2/exploreUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ export function getFilters(form_data, datasource_type) {

export function getParamObject(form_data, datasource_type, saveNewSlice) {
const data = {
// V2 tag temporarily for updating url
// Todo: remove after launch
V2: true,
datasource_id: form_data.datasource,
datasource_type,
};
Expand Down
28 changes: 8 additions & 20 deletions superset/assets/javascripts/explorev2/reducers/exploreReducer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint camelcase: 0 */
import { defaultFormData } from '../stores/store';
import { getFieldsState, getFormDataFromFields } from '../stores/store';
import * as actions from '../actions/exploreActions';
import { now } from '../../modules/dates';

Expand Down Expand Up @@ -59,28 +59,12 @@ export const exploreReducer = function (state, action) {
{ saveModalAlert: `fetching dashboards failed for ${action.userId}` });
},
[actions.SET_FIELD_VALUE]() {
let newFormData = Object.assign({}, state.form_data);
if (action.fieldName === 'datasource') {
newFormData = defaultFormData(state.form_data.viz_type, action.datasource_type);
newFormData.datasource_name = action.label;
newFormData.slice_id = state.form_data.slice_id;
newFormData.slice_name = state.form_data.slice_name;
newFormData.viz_type = state.form_data.viz_type;
}
newFormData[action.fieldName] = action.value;

const fields = Object.assign({}, state.fields);
const field = fields[action.fieldName];
const field = Object.assign({}, fields[action.fieldName]);
field.value = action.value;
field.validationErrors = action.validationErrors;
return Object.assign(
{},
state,
{
fields,
viz: Object.assign({}, state.viz, { form_data: newFormData }),
}
);
fields[action.fieldName] = field;
return Object.assign({}, state, { fields });
},
[actions.CHART_UPDATE_SUCCEEDED]() {
return Object.assign(
Expand Down Expand Up @@ -133,6 +117,10 @@ export const exploreReducer = function (state, action) {
[actions.REMOVE_SAVE_MODAL_ALERT]() {
return Object.assign({}, state, { saveModalAlert: null });
},
[actions.RESET_FIELDS]() {
const fields = getFieldsState(state, getFormDataFromFields(state.fields));
return Object.assign({}, state, { fields });
},
};
if (action.type in actionHandlers) {
return actionHandlers[action.type]();
Expand Down
29 changes: 0 additions & 29 deletions superset/assets/javascripts/explorev2/stores/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -1144,32 +1144,3 @@ export const fields = {
},
};
export default fields;

// Control Panel fields that re-render chart without need for 'Query button'
export const autoQueryFields = [
'datasource',
'viz_type',
'bar_stacked',
'show_markers',
'show_bar_value',
'order_bars',
'show_controls',
'reduce_x_ticks',
'include_series',
'pie_label_type',
'show_brush',
'include_search',
'show_bubbles',
'show_legend',
'x_axis_showminmax',
'rich_tooltip',
'y_axis_zero',
'y_log_scale',
'x_log_scale',
'donut',
'labels_outside',
'contribution',
'size',
'row_limit',
'max_bubble_size',
];
25 changes: 23 additions & 2 deletions superset/assets/javascripts/explorev2/stores/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,30 @@ import { sectionsToRender } from './visTypes';
import fields from './fields';
import visTypes, { fieldNames } from './visTypes';

export function getFieldsState(state, form_data, datasourceType = 'table') {
export function getFormDataFromFields(fields) {
const formData = {};
Object.keys(fields).forEach(fieldName => {
formData[fieldName] = fields[fieldName].value;
});
return formData;
}

export function getFieldsState(state, form_data) {
/*
* Gets a new fields object to put in the state. The fields object
* is similar to the configuration field with only the fields
* related to the current viz_type, materializes mapStateToProps functions,
* adds value keys coming from form_data passed here. This can't be an action creator
* just yet because it's used in both the explore and dashboard views.
* */

// Getting a list of active field names for the current viz
const fieldNames = [];
sectionsToRender(form_data.viz_type, datasourceType).forEach(section => section.fieldSetRows.forEach(fsr => fsr.forEach(f => fieldNames.push(f))));
sectionsToRender(form_data.viz_type, state.datasource.type).forEach(
section => section.fieldSetRows.forEach(
fsr => fsr.forEach(
f => fieldNames.push(f))));

const viz = visTypes[form_data.viz_type];
const fieldOverrides = viz.fieldOverrides || {};
const fieldsState = {};
Expand Down

0 comments on commit c8a00e6

Please sign in to comment.