diff --git a/superset/assets/javascripts/explorev2/components/ExploreViewContainer.jsx b/superset/assets/javascripts/explorev2/components/ExploreViewContainer.jsx
index 0160d7681b3fc..e197c4d68040e 100644
--- a/superset/assets/javascripts/explorev2/components/ExploreViewContainer.jsx
+++ b/superset/assets/javascripts/explorev2/components/ExploreViewContainer.jsx
@@ -133,7 +133,6 @@ class ExploreViewContainer extends React.Component {
onHide={this.toggleModal.bind(this)}
actions={this.props.actions}
form_data={this.props.form_data}
- datasource_type={this.props.datasource_type}
/>
}
diff --git a/superset/assets/javascripts/explorev2/components/SaveModal.js b/superset/assets/javascripts/explorev2/components/SaveModal.js
index 30203fa80b9e2..cb21bceff279c 100644
--- a/superset/assets/javascripts/explorev2/components/SaveModal.js
+++ b/superset/assets/javascripts/explorev2/components/SaveModal.js
@@ -1,20 +1,20 @@
-/* eslint camel-case: 0 */
+/* eslint camelcase: 0 */
import React, { PropTypes } from 'react';
import $ from 'jquery';
import { Modal, Alert, Button, Radio } from 'react-bootstrap';
import Select from 'react-select';
import { connect } from 'react-redux';
-import { getParamObject } from '../exploreUtils';
const propTypes = {
can_edit: PropTypes.bool,
onHide: PropTypes.func.isRequired,
actions: PropTypes.object.isRequired,
form_data: PropTypes.object,
- datasource_type: PropTypes.string.isRequired,
user_id: PropTypes.string.isRequired,
dashboards: PropTypes.array.isRequired,
alert: PropTypes.string,
+ slice: PropTypes.object,
+ datasource: PropTypes.object,
};
class SaveModal extends React.Component {
@@ -58,13 +58,13 @@ class SaveModal extends React.Component {
saveOrOverwrite(gotodash) {
this.setState({ alert: null });
this.props.actions.removeSaveModalAlert();
- const params = getParamObject(
- this.props.form_data, this.props.datasource_type, this.state.action === 'saveas');
const sliceParams = {};
- params.datasource_name = this.props.form_data.datasource_name;
let sliceName = null;
sliceParams.action = this.state.action;
+ if (this.props.slice.slice_id) {
+ sliceParams.slice_id = this.props.slice.slice_id;
+ }
if (sliceParams.action === 'saveas') {
sliceName = this.state.newSliceName;
if (sliceName === '') {
@@ -73,7 +73,7 @@ class SaveModal extends React.Component {
}
sliceParams.slice_name = sliceName;
} else {
- sliceParams.slice_name = this.props.form_data.slice_name;
+ sliceParams.slice_name = this.props.slice.slice_name;
}
const addToDash = this.state.addToDash;
@@ -100,9 +100,13 @@ class SaveModal extends React.Component {
dashboard = null;
}
sliceParams.goto_dash = gotodash;
- const baseUrl = '/superset/explore/' +
- `${this.props.datasource_type}/${this.props.form_data.datasource}/`;
- const saveUrl = `${baseUrl}?${$.param(params, true)}&${$.param(sliceParams, true)}`;
+
+ const baseUrl = `/superset/explore/${this.props.datasource.type}/${this.props.datasource.id}/`;
+ sliceParams.datasource_name = this.props.datasource.name;
+
+ const saveUrl = `${baseUrl}?form_data=` +
+ `${encodeURIComponent(JSON.stringify(this.props.form_data))}` +
+ `&${$.param(sliceParams, true)}`;
this.props.actions.saveSlice(saveUrl);
this.props.onHide();
}
@@ -140,7 +144,7 @@ class SaveModal extends React.Component {
checked={this.state.action === 'overwrite'}
onChange={this.changeAction.bind(this, 'overwrite')}
>
- {`Overwrite slice ${this.props.form_data.slice_name}`}
+ {`Overwrite slice ${this.props.slice.slice_name}`}
{
- // filter out null fields
- if (form_data[field] !== null && field !== 'datasource'
- && !(saveNewSlice && field === 'slice_name')) {
- data[field] = form_data[field];
- }
- });
- return data;
-}
-
export function getExploreUrl(form_data, dummy, endpoint = 'base') {
const [datasource_id, datasource_type] = form_data.datasource.split('__');
let params = `${datasource_type}/${datasource_id}/`;
diff --git a/superset/assets/spec/javascripts/explorev2/components/SaveModal_spec.js b/superset/assets/spec/javascripts/explorev2/components/SaveModal_spec.js
index dd86bdf616126..fa21b2f7bc2b7 100644
--- a/superset/assets/spec/javascripts/explorev2/components/SaveModal_spec.js
+++ b/superset/assets/spec/javascripts/explorev2/components/SaveModal_spec.js
@@ -14,10 +14,8 @@ const defaultProps = {
saveSlice: sinon.spy(),
},
form_data: defaultFormData,
- datasource_id: 1,
- datasource_name: 'birth_names',
- datasource_type: 'table',
user_id: 1,
+ slice: {},
};
describe('SaveModal', () => {
diff --git a/superset/views.py b/superset/views.py
index 3c996c2802f34..56a8189973f88 100755
--- a/superset/views.py
+++ b/superset/views.py
@@ -1557,7 +1557,11 @@ def explore(self, datasource_type, datasource_id):
action = request.args.get('action')
if action in ('saveas', 'overwrite'):
return self.save_or_overwrite_slice(
- request.args, slc, slice_add_perm, slice_edit_perm)
+ request.args,
+ slc, slice_add_perm,
+ slice_edit_perm,
+ datasource_id,
+ datasource_type)
form_data['datasource'] = str(datasource_id) + '__' + datasource_type
standalone = request.args.get("standalone") == "true"
@@ -1632,36 +1636,24 @@ def filter(self, datasource_type, datasource_id, column):
mimetype="application/json")
def save_or_overwrite_slice(
- self, args, slc, slice_add_perm, slice_edit_perm):
+ self, args, slc, slice_add_perm, slice_edit_perm,
+ datasource_id, datasource_type):
"""Save or overwrite a slice"""
slice_name = args.get('slice_name')
action = args.get('action')
-
- # TODO use form processing form wtforms
- d = args.to_dict(flat=False)
- del d['action']
- if 'previous_viz_type' in d:
- del d['previous_viz_type']
+ form_data = self.get_form_data()
as_list = ('metrics', 'groupby', 'columns', 'all_columns',
'mapbox_label', 'order_by_cols')
- for k in d:
- v = d.get(k)
- if k in as_list and not isinstance(v, list):
- d[k] = [v] if v else []
- if k not in as_list and isinstance(v, list):
- d[k] = v[0]
-
- datasource_type = args.get('datasource_type')
- datasource_id = args.get('datasource_id')
if action in ('saveas'):
- d.pop('slice_id') # don't save old slice_id
+ if 'slice_id' in form_data:
+ form_data.pop('slice_id') # don't save old slice_id
slc = models.Slice(owners=[g.user] if g.user else [])
- slc.params = json.dumps(d, indent=4, sort_keys=True)
+ slc.params = json.dumps(form_data)
slc.datasource_name = args.get('datasource_name')
- slc.viz_type = args.get('viz_type')
+ slc.viz_type = form_data['viz_type']
slc.datasource_type = datasource_type
slc.datasource_id = datasource_id
slc.slice_name = slice_name
@@ -1700,13 +1692,9 @@ def save_or_overwrite_slice(
db.session.commit()
if request.args.get('goto_dash') == 'true':
- if request.args.get('V2') == 'true':
- return dash.url
- return redirect(dash.url)
+ return dash.url
else:
- if request.args.get('V2') == 'true':
- return slc.slice_url
- return redirect(slc.slice_url)
+ return slc.slice_url
def save_slice(self, slc):
session = db.session()