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

crmRouteBinder - Remove params from url if they equal their defaults #14211

Merged
merged 1 commit into from
May 23, 2019

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented May 7, 2019

Overview

Reduces url clutter in the Api4 explorer and fixes a bug with null being cast to 0.

Before

When removing a param in the api4 explorer, it persists in the url. This is a problem in the case of the Relationship api and the $current param. To reproduce:

  1. Go to the api explorer and select Relationship get.
  2. Click a Current radio button.
  3. Click the x to clear the Current radio selection.
  4. Note that current=0 is still in the url.
  5. Refresh the page and the false radio will be selected inappropriately.

After

Clearing a selection from the api explorer will remove it from the url, which reduces clutter and prevents errors.

@civibot
Copy link

civibot bot commented May 7, 2019

(Standard links)

@civibot civibot bot added the master label May 7, 2019
@@ -50,18 +50,18 @@
registerGlobalListener($injector);

options.format = options.format || 'json';
var fmt = formats[options.format];
var fmt = _.clone(formats[options.format]);
if (options.deep) {
fmt.watcher = '$watch';
Copy link
Member Author

Choose a reason for hiding this comment

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

Adding _.clone() on l53 prevents line 55 here from modifying the global defaults.


var $route = $injector.get('$route'), $timeout = $injector.get('$timeout');

var value;
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 some cleanup

if (p[k] === v) {
delete p[k];
}
});
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 cleanup - expanded the 1-liner on l82 to be more readable.

@totten
Copy link
Member

totten commented May 7, 2019

I haven't tested, but want to give a conceptual 👍 -- if the same value would be loaded as a default, then it's preferable to appear shorter and normalized.

For someone r-running this, it's worth considering the different paths that can bring one to a route, e.g.:

  • Clicking a widget in a GUI that updates a filter and automatically updates the URL
  • Clicking backward and forward buttons
  • Opening the base-page, clicking around, and then editing the URL to specify a different set of filters/route.
  • Opening the base-page and clicking a hyperlink which goes to a different set of filters/route.
  • Starting from an external page -- and following a hyperlink which has a bunch of parameters

@wadelson
Copy link

  • (r-run) Good:
    I ran it locally and I can confirm this solves the case described in the PR's description.
    I also tested everything Totten mentioned.
* Clicking a widget in a GUI that updates a filter and automatically updates the URL

This works as nicely as before

* Clicking backward and forward buttons

This works too. I managed to break this if I added multiple parameters with the same key but it's also the case without this commit, I checked.

* Opening the base-page, clicking around, and then editing the URL  to specify a different set of filters/route.

This is fine. No problem modifying the existing parameters nor adding new one.

* Opening the base-page and clicking a hyperlink which goes to a different set of filters/route.

It works

* Starting from an external page -- and following a hyperlink which has a bunch of parameters

It works too

I tested all those points against dmaster using firefox nightly (for maximum breakage) and chromium.
For what it's worth, I approve merging that PR 👍

@colemanw colemanw merged commit 2cef24b into civicrm:master May 23, 2019
@colemanw colemanw deleted the routeBinder branch January 30, 2020 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants