mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
ReturnToPrevious: make href
optional (#81691)
This commit is contained in:
parent
e1197641f3
commit
42cd4266b4
@ -1,9 +1,4 @@
|
||||
interface ReturnToPreviousData {
|
||||
title: string;
|
||||
href: string;
|
||||
}
|
||||
|
||||
type ReturnToPreviousHook = () => (rtp: ReturnToPreviousData) => void;
|
||||
type ReturnToPreviousHook = () => (title: string, href?: string) => void;
|
||||
|
||||
let rtpHook: ReturnToPreviousHook | undefined = undefined;
|
||||
|
||||
|
@ -55,17 +55,18 @@ export function AppChrome({ children }: Props) {
|
||||
chrome.setMegaMenuOpen(!state.megaMenuOpen);
|
||||
};
|
||||
|
||||
const path = locationService.getLocation().pathname;
|
||||
const { pathname, search } = locationService.getLocation();
|
||||
const url = pathname + search;
|
||||
const shouldShowReturnToPrevious =
|
||||
config.featureToggles.returnToPrevious && state.returnToPrevious && path !== state.returnToPrevious.href;
|
||||
config.featureToggles.returnToPrevious && state.returnToPrevious && url !== state.returnToPrevious.href;
|
||||
|
||||
useEffect(() => {
|
||||
if (state.returnToPrevious && path === state.returnToPrevious.href) {
|
||||
if (state.returnToPrevious && url === state.returnToPrevious.href) {
|
||||
chrome.clearReturnToPrevious();
|
||||
}
|
||||
// We only want to pay attention when the location changes
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [chrome, path]);
|
||||
}, [chrome, url]);
|
||||
|
||||
// Chromeless routes are without topNav, mega menu, search & command palette
|
||||
// We check chromeless twice here instead of having a separate path so {children}
|
||||
|
@ -24,8 +24,8 @@ export interface AppChromeState {
|
||||
kioskMode: KioskMode | null;
|
||||
layout: PageLayoutType;
|
||||
returnToPrevious?: {
|
||||
href: ReturnToPreviousProps['href'];
|
||||
title: ReturnToPreviousProps['title'];
|
||||
href: ReturnToPreviousProps['href'];
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,8 @@ import { t } from 'app/core/internationalization';
|
||||
import { DismissableButton } from './DismissableButton';
|
||||
|
||||
export interface ReturnToPreviousProps {
|
||||
href: string;
|
||||
title: string;
|
||||
href: string;
|
||||
}
|
||||
|
||||
export const ReturnToPrevious = ({ href, title }: ReturnToPreviousProps) => {
|
||||
|
@ -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]
|
||||
);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import React, { Fragment, useState } from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
|
||||
import { GrafanaTheme2, textUtil, urlUtil } from '@grafana/data';
|
||||
import { config, locationService, useReturnToPrevious } from '@grafana/runtime';
|
||||
import { config, useReturnToPrevious } from '@grafana/runtime';
|
||||
import {
|
||||
Button,
|
||||
ClipboardButton,
|
||||
@ -145,7 +145,7 @@ export const RuleDetailsActionButtons = ({ rule, rulesSource, isViewMode }: Prop
|
||||
icon="apps"
|
||||
href={`d/${encodeURIComponent(dashboardUID)}`}
|
||||
onClick={() => {
|
||||
setReturnToPrevious({ title: rule.name, href: locationService.getLocation().pathname });
|
||||
setReturnToPrevious(rule.name);
|
||||
}}
|
||||
>
|
||||
Go to dashboard
|
||||
|
Loading…
Reference in New Issue
Block a user