[v11.0.x] datatrails: fix: clear undefined query params on history step change (#85955)

datatrails: fix: clear undefined query params on history step change (#85607)

* fix: clear undefined query params on history step change

* Minor tweak

* fix: resolve CodeQL check: Client-side cross-site scripting

---------

Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
(cherry picked from commit 34875344ed)

Co-authored-by: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com>
pull/85973/head
grafana-delivery-bot[bot] 1 year ago committed by GitHub
parent a39501f9d5
commit b581a71ee7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      public/app/features/trails/DataTrail.test.tsx
  2. 7
      public/app/features/trails/DataTrail.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);
});
});
});
});

@ -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<DataTrailState> {
// 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) {

Loading…
Cancel
Save