mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
url: fix for boolean querystring parameters
Without this fix then the querystring looks like ?abool=true which causes a mismatch with the angular routing. This results in a redirect and messes up the browser history and back button.
This commit is contained in:
@@ -12,7 +12,11 @@ export function toUrlParams(a) {
|
||||
|
||||
let add = function(k, v) {
|
||||
v = typeof v === 'function' ? v() : v === null ? '' : v === undefined ? '' : v;
|
||||
s[s.length] = encodeURIComponent(k) + '=' + encodeURIComponent(v);
|
||||
if (typeof v !== 'boolean') {
|
||||
s[s.length] = encodeURIComponent(k) + '=' + encodeURIComponent(v);
|
||||
} else {
|
||||
s[s.length] = encodeURIComponent(k);
|
||||
}
|
||||
};
|
||||
|
||||
let buildParams = function(prefix, obj) {
|
||||
|
||||
@@ -23,4 +23,10 @@ describe('ViewStore', () => {
|
||||
expect(toJS(store.query.get('values'))).toMatchObject(['A', 'B']);
|
||||
expect(store.currentUrl).toBe('/hello?values=A&values=B');
|
||||
});
|
||||
|
||||
it('Query can contain boolean', () => {
|
||||
store.updatePathAndQuery('/hello', { abool: true });
|
||||
expect(toJS(store.query.get('abool'))).toBe(true);
|
||||
expect(store.currentUrl).toBe('/hello?abool');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user