mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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>
This commit is contained in:
parent
b4b0a80e86
commit
34875344ed
@ -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…
Reference in New Issue
Block a user