mirror of
https://github.com/grafana/grafana.git
synced 2025-01-11 16:42:15 -06:00
Playlists: Check if playlist is playing before reloading for assets (#93605)
* Check if playlist is playing before updating * add tests
This commit is contained in:
parent
f04e032cf1
commit
7f7fed8c3c
@ -1,4 +1,7 @@
|
||||
import { Location } from 'history';
|
||||
|
||||
import { locationService, setBackendSrv, BackendSrv } from '@grafana/runtime';
|
||||
import { playlistSrv } from 'app/features/playlist/PlaylistSrv';
|
||||
|
||||
import { NewFrontendAssetsChecker } from './NewFrontendAssetsChecker';
|
||||
|
||||
@ -46,4 +49,28 @@ describe('NewFrontendAssetsChecker', () => {
|
||||
|
||||
expect(backendApiGet).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('should skip reloading if we are playing a playlist', () => {
|
||||
const checker = new NewFrontendAssetsCheckerExposedLocationUpdate();
|
||||
const reloadMock = jest.fn();
|
||||
checker.reloadIfUpdateDetected = reloadMock;
|
||||
playlistSrv.state.isPlaying = true;
|
||||
checker.doLocationUpdated({ hash: 'foo', pathname: '/d/dashboarduid', state: {}, search: '' });
|
||||
expect(reloadMock).not.toHaveBeenCalled();
|
||||
playlistSrv.state.isPlaying = false;
|
||||
});
|
||||
|
||||
it('should reload if we are accessing a dashboard', () => {
|
||||
const checker = new NewFrontendAssetsCheckerExposedLocationUpdate();
|
||||
const reloadMock = jest.fn();
|
||||
checker.reloadIfUpdateDetected = reloadMock;
|
||||
checker.doLocationUpdated({ hash: 'foo', pathname: '/d/dashboarduid', state: {}, search: '' });
|
||||
expect(reloadMock).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
class NewFrontendAssetsCheckerExposedLocationUpdate extends NewFrontendAssetsChecker {
|
||||
public doLocationUpdated(location: Location) {
|
||||
this.locationUpdated(location);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import { Location } from 'history';
|
||||
import { isEqual } from 'lodash';
|
||||
|
||||
import { getBackendSrv, getGrafanaLiveSrv, locationService, reportInteraction } from '@grafana/runtime';
|
||||
import { playlistSrv } from 'app/features/playlist/PlaylistSrv';
|
||||
|
||||
export class NewFrontendAssetsChecker {
|
||||
private hasUpdates = false;
|
||||
@ -35,7 +36,7 @@ export class NewFrontendAssetsChecker {
|
||||
/**
|
||||
* Tries to detect some navigation events where it's safe to trigger a reload
|
||||
*/
|
||||
private locationUpdated(location: Location) {
|
||||
protected locationUpdated(location: Location) {
|
||||
if (this.prevLocationPath === location.pathname) {
|
||||
return;
|
||||
}
|
||||
@ -46,8 +47,8 @@ export class NewFrontendAssetsChecker {
|
||||
if (newLocationSegments[1] === '/' && this.prevLocationPath !== '/') {
|
||||
this.reloadIfUpdateDetected();
|
||||
}
|
||||
// Moving to dashboard (or changing dashboards)
|
||||
else if (newLocationSegments[1] === 'd') {
|
||||
// Moving to dashboard (or changing dashboards, except when we're playing a playlist)
|
||||
else if (newLocationSegments[1] === 'd' && !playlistSrv.state.isPlaying) {
|
||||
this.reloadIfUpdateDetected();
|
||||
}
|
||||
// Track potential page change
|
||||
|
Loading…
Reference in New Issue
Block a user