2023-04-18 08:58:00 -05:00
|
|
|
import React, { useLayoutEffect } from 'react';
|
2022-07-06 10:00:56 -05:00
|
|
|
|
2022-07-23 10:09:03 -05:00
|
|
|
import { useGrafana } from 'app/core/context/GrafanaContext';
|
2022-07-06 10:00:56 -05:00
|
|
|
|
|
|
|
export interface AppChromeUpdateProps {
|
|
|
|
actions?: React.ReactNode;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* This needs to be moved to @grafana/ui or runtime.
|
|
|
|
* This is the way core pages and plugins update the breadcrumbs and page toolbar actions
|
|
|
|
*/
|
2022-09-12 08:45:14 -05:00
|
|
|
export const AppChromeUpdate = React.memo<AppChromeUpdateProps>(({ actions }: AppChromeUpdateProps) => {
|
2022-07-23 10:09:03 -05:00
|
|
|
const { chrome } = useGrafana();
|
|
|
|
|
2023-04-18 08:58:00 -05:00
|
|
|
// We use useLayoutEffect here to make sure that the chrome is updated before the page is rendered
|
2023-05-24 12:31:57 -05:00
|
|
|
// This prevents flickering actions when going from one dashboard to another for example
|
2023-04-18 08:58:00 -05:00
|
|
|
useLayoutEffect(() => {
|
2022-09-12 08:45:14 -05:00
|
|
|
chrome.update({ actions });
|
2022-07-06 10:00:56 -05:00
|
|
|
});
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
AppChromeUpdate.displayName = 'TopNavUpdate';
|