ReturnToPrevious: make href optional (#81691)

This commit is contained in:
Laura Fernández
2024-02-02 13:14:58 +01:00
committed by GitHub
parent e1197641f3
commit 42cd4266b4
6 changed files with 22 additions and 18 deletions

View File

@ -1,8 +1,7 @@
import React, { useContext } from 'react';
import React, { useCallback, useContext } from 'react';
import { GrafanaConfig } from '@grafana/data';
import { LocationService } from '@grafana/runtime/src/services/LocationService';
import { BackendSrv } from '@grafana/runtime/src/services/backendSrv';
import { LocationService, locationService, BackendSrv } from '@grafana/runtime';
import { AppChromeService } from '../components/AppChrome/AppChromeService';
import { NewFrontendAssetsChecker } from '../services/NewFrontendAssetsChecker';
@ -31,5 +30,14 @@ export function useGrafana(): GrafanaContextType {
// @grafana/runtime
export function useReturnToPreviousInternal() {
const { chrome } = useGrafana();
return chrome.setReturnToPrevious;
return useCallback(
(title: string, href?: string) => {
const { pathname, search } = locationService.getLocation();
chrome.setReturnToPrevious({
title: title,
href: href ?? pathname + search,
});
},
[chrome]
);
}