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

fix(key-value): lost url_params after long-url feature #18846

Merged
merged 2 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ const updateHistory = debounce(
additionalParam[URL_PARAMS.datasetId.name] = datasetId;
}

const urlParams = payload?.url_params || {};
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't be cleaner to just initialize additionalParam with payload?.url_params? If some of the parameters are already in the URL they will be overridden anyway. This way you don't need the forEach and the if check.

Copy link
Member Author

@zhaoyongjie zhaoyongjie Feb 22, 2022

Choose a reason for hiding this comment

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

Wouldn't be cleaner to just initialize additionalParam with payload?.url_params?

  1. formDataKey in urlParams
  2. it isn't known which url_params don't need to be put into additionalParams in the future.

If some of the parameters are already in the URL they will be overridden anyway. This way you don't need the forEach and the if check.

There needs to be a pattern that controls which params can be put in, and which do not.

BTW, chartId and datasetId come from elsewhere even though they are the same as urlParams. (link)

Object.entries(urlParams).forEach(([key, value]) => {
if (
![
URL_PARAMS.sliceId.name,
URL_PARAMS.formDataKey.name,
URL_PARAMS.datasetId.name,
].includes(key)
) {
additionalParam[key] = value;
}
});

try {
let key;
let stateModifier;
Expand Down
3 changes: 1 addition & 2 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,7 @@ def explore(
if form_data_key:
parameters = CommandParameters(actor=g.user, key=form_data_key,)
value = GetFormDataCommand(parameters).run()
if value:
initial_form_data = json.loads(value)
initial_form_data = json.loads(value) if value else {}
Copy link
Member Author

Choose a reason for hiding this comment

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

just code smell


if not initial_form_data:
slice_id = request.args.get("slice_id")
Expand Down