Skip to content

Commit

Permalink
[Explore] Save url parameters when user save slices
Browse files Browse the repository at this point in the history
  • Loading branch information
Grace Guo committed Mar 8, 2018
1 parent 42ebcaa commit 8e0ba8d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,13 @@ ExploreViewContainer.propTypes = propTypes;

function mapStateToProps({ explore, charts, impressionId }) {
const form_data = getFormDataFromControls(explore.controls);
// fill in additional params stored in form_data but not used by control
Object.keys(explore.rawFormData)
.forEach((key) => {
if (form_data[key] === undefined) {
form_data[key] = explore.rawFormData[key];
}
});
const chartKey = Object.keys(charts)[0];
const chart = charts[chartKey];
return {
Expand Down
2 changes: 2 additions & 0 deletions superset/assets/javascripts/explore/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ initJQueryAjax();
const exploreViewContainer = document.getElementById('app');
const bootstrapData = JSON.parse(exploreViewContainer.getAttribute('data-bootstrap'));
const controls = getControlsState(bootstrapData, bootstrapData.form_data);
const rawFormData = { ...bootstrapData.form_data };
delete bootstrapData.form_data;
delete bootstrapData.common.locale;
delete bootstrapData.common.language_pack;

// Initial state
const bootstrappedState = Object.assign(
bootstrapData, {
rawFormData,
controls,
filterColumnOpts: [],
isDatasourceMetaLoading: false,
Expand Down
7 changes: 7 additions & 0 deletions superset/assets/javascripts/explore/stores/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ export function applyDefaultFormData(form_data) {
formData[k] = form_data[k];
}
});
// fill in additional params stored in form_data but not used by control
Object.keys(form_data)
.forEach((key) => {
if (formData[key] === undefined) {
formData[key] = form_data[key];
}
});
return formData;
}

Expand Down
16 changes: 12 additions & 4 deletions superset/jinja_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from datetime import datetime, timedelta
import inspect
import json
import random
import time
import uuid
Expand All @@ -30,15 +31,22 @@


def url_param(param, default=None):
"""Get a url paramater
"""Get a url or post data parameter
:param param: the url parameter to lookup
:param param: the parameter to lookup
:type param: str
:param default: the value to return in the absence of the parameter
:type default: str
"""
print(request.args)
return request.args.get(param, default)
print('request args', request.args)
print('request form', request.form)
if request.args.get(param):
return request.args.get(param, default)
# Supporting POST as well as get
if request.form.get('form_data'):
form_data = json.loads(request.form.get('form_data'))
return form_data.get(param, default)
return default


def current_user_id():
Expand Down
8 changes: 8 additions & 0 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,14 @@ def explore(self, datasource_type=None, datasource_id=None):
# On explore, merge extra filters into the form data
merge_extra_filters(form_data)

# merge request url params
if request.method == 'GET':
url_params = request.args
for key, value in url_params.items():
if key == 'form_data':
continue
form_data[key] = value

# handle save or overwrite
action = request.args.get('action')

Expand Down

0 comments on commit 8e0ba8d

Please sign in to comment.