From c479ca0161a55cc6fe924e419f599ed2cbbd5454 Mon Sep 17 00:00:00 2001 From: Domas Date: Mon, 15 Mar 2021 11:02:45 +0200 Subject: [PATCH] RoutingNG: fix locationSrv.update when query is provided (#31978) --- .../src/services/LocationService.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/grafana-runtime/src/services/LocationService.ts b/packages/grafana-runtime/src/services/LocationService.ts index 9131427a498..518b37f4dcf 100644 --- a/packages/grafana-runtime/src/services/LocationService.ts +++ b/packages/grafana-runtime/src/services/LocationService.ts @@ -1,4 +1,4 @@ -import { UrlQueryMap, urlUtil } from '@grafana/data'; +import { deprecationWarning, UrlQueryMap, urlUtil } from '@grafana/data'; import * as H from 'history'; import { LocationUpdate } from './LocationSrv'; import { createLogger } from '@grafana/ui'; @@ -123,14 +123,23 @@ export class HistoryWrapper implements LocationService { return locationSearchToObject(this.history.location.search); } - /** @depecreated */ + /** @deprecated use partial, push or replace instead */ update(options: LocationUpdate) { + deprecationWarning('LocationSrv', 'update', 'partial, push or replace'); if (options.partial && options.query) { this.partial(options.query, options.partial); - } else if (options.replace) { - this.replace(options.path!); } else { - this.push(options.path!); + const newLocation: H.LocationDescriptor = { + pathname: options.path, + }; + if (options.query) { + newLocation.search = urlUtil.toUrlParams(options.query); + } + if (options.replace) { + this.replace(newLocation); + } else { + this.push(newLocation); + } } } }