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:
Torkel Ödegaard
2021-06-16 15:44:50 +02:00
committed by GitHub
parent ef59020f3d
commit cfae7d8b97
6 changed files with 25 additions and 41 deletions

View File

@@ -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) {