diff --git a/public/app/features/trails/DataTrail.test.tsx b/public/app/features/trails/DataTrail.test.tsx index 21b24017da6..9b62ddeff41 100644 --- a/public/app/features/trails/DataTrail.test.tsx +++ b/public/app/features/trails/DataTrail.test.tsx @@ -130,5 +130,19 @@ describe('DataTrail', () => { }); }); }); + describe('When going back to history step 0', () => { + beforeEach(() => { + trail.publishEvent(new MetricSelectedEvent('first_metric')); + trail.publishEvent(new MetricSelectedEvent('second_metric')); + trail.state.history.goBackToStep(0); + }); + + it('Should remove metric from state and url', () => { + expect(trail.state.metric).toBe(undefined); + + expect(locationService.getSearchObject().metric).toBe(undefined); + expect(locationService.getSearch().has('metric')).toBe(false); + }); + }); }); }); diff --git a/public/app/features/trails/DataTrail.tsx b/public/app/features/trails/DataTrail.tsx index 938d3f179be..4b33114ab02 100644 --- a/public/app/features/trails/DataTrail.tsx +++ b/public/app/features/trails/DataTrail.tsx @@ -1,7 +1,7 @@ import { css } from '@emotion/css'; import React from 'react'; -import { AdHocVariableFilter, GrafanaTheme2, VariableHide } from '@grafana/data'; +import { AdHocVariableFilter, GrafanaTheme2, VariableHide, urlUtil } from '@grafana/data'; import { locationService } from '@grafana/runtime'; import { AdHocFiltersVariable, @@ -152,8 +152,11 @@ export class DataTrail extends SceneObjectBase { // Embedded trails should not be altering the URL return; } + const urlState = getUrlSyncManager().getUrlState(this); - locationService.partial(urlState, true); + const fullUrl = urlUtil.renderUrl(locationService.getLocation().pathname, urlState); + + locationService.replace(encodeURI(fullUrl)); } private _handleMetricSelectedEvent(evt: MetricSelectedEvent) {