Commit d4e85e48 by kay delaney Committed by GitHub

Dashboard Links: Links kept in sync with dashboard time range (#26845)

Closes #26694
parent 2cd9b9a7
import React, { FC } from 'react';
import React, { FC, useReducer } from 'react';
import { Icon, IconName, Tooltip } from '@grafana/ui';
import { sanitize, sanitizeUrl } from '@grafana/data/src/text/sanitize';
import { DashboardLinksDashboard } from './DashboardLinksDashboard';
......@@ -7,6 +7,8 @@ import { getLinkSrv } from '../../../panel/panellinks/link_srv';
import { DashboardModel } from '../../state';
import { DashboardLink } from '../../state/DashboardModel';
import { iconMap } from '../DashLinks/DashLinksEditorCtrl';
import { useEffectOnce } from 'react-use';
import { CoreEvents } from 'app/types';
export interface Props {
dashboard: DashboardModel;
......@@ -18,6 +20,17 @@ export const DashboardLinks: FC<Props> = ({ dashboard, links }) => {
return null;
}
// Emulate forceUpdate (https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate)
const [, forceUpdate] = useReducer(x => x + 1, 0);
useEffectOnce(() => {
dashboard.on(CoreEvents.timeRangeUpdated, forceUpdate);
return () => {
dashboard.off(CoreEvents.timeRangeUpdated, forceUpdate);
};
});
return (
<>
{links.map((link: DashboardLink, index: number) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment