mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Events: Migrate old timeRangeUpdate event to new event system to get rid of console.log warning (#35767)
* Events: Migrate old timeRangeUpdate event to new event system to get rid of console.log warning * Review feedback
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React, { FC, useReducer } from 'react';
|
||||
import { Icon, IconName, Tooltip } from '@grafana/ui';
|
||||
import React, { FC } from 'react';
|
||||
import { Icon, IconName, Tooltip, useForceUpdate } from '@grafana/ui';
|
||||
import { sanitizeUrl } from '@grafana/data/src/text/sanitize';
|
||||
import { DashboardLinksDashboard } from './DashboardLinksDashboard';
|
||||
import { getLinkSrv } from '../../../panel/panellinks/link_srv';
|
||||
@@ -8,8 +8,8 @@ import { DashboardModel } from '../../state';
|
||||
import { DashboardLink } from '../../state/DashboardModel';
|
||||
import { linkIconMap } from '../LinksSettings/LinkSettingsEdit';
|
||||
import { useEffectOnce } from 'react-use';
|
||||
import { CoreEvents } from 'app/types';
|
||||
import { selectors } from '@grafana/e2e-selectors';
|
||||
import { TimeRangeUpdatedEvent } from 'app/types/events';
|
||||
|
||||
export interface Props {
|
||||
dashboard: DashboardModel;
|
||||
@@ -17,15 +17,11 @@ export interface Props {
|
||||
}
|
||||
|
||||
export const DashboardLinks: FC<Props> = ({ dashboard, links }) => {
|
||||
// Emulate forceUpdate (https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate)
|
||||
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
||||
const forceUpdate = useForceUpdate();
|
||||
|
||||
useEffectOnce(() => {
|
||||
dashboard.on(CoreEvents.timeRangeUpdated, forceUpdate);
|
||||
|
||||
return () => {
|
||||
dashboard.off(CoreEvents.timeRangeUpdated, forceUpdate);
|
||||
};
|
||||
const sub = dashboard.events.subscribe(TimeRangeUpdatedEvent, forceUpdate);
|
||||
return () => sub.unsubscribe();
|
||||
});
|
||||
|
||||
if (!links.length) {
|
||||
|
||||
Reference in New Issue
Block a user