import { useEffect } from 'react'; import { PanelProps } from '@grafana/data'; import { RefreshEvent } from '@grafana/runtime'; import { Alert, Icon, ScrollContainer } from '@grafana/ui'; import { News } from './component/News'; import { DEFAULT_FEED_URL } from './constants'; import { Options } from './panelcfg.gen'; import { useNewsFeed } from './useNewsFeed'; interface NewsPanelProps extends PanelProps {} export function NewsPanel(props: NewsPanelProps) { const { width, options: { feedUrl = DEFAULT_FEED_URL, showImage }, } = props; const { state, getNews } = useNewsFeed(feedUrl); useEffect(() => { const sub = props.eventBus.subscribe(RefreshEvent, getNews); return () => { sub.unsubscribe(); }; }, [getNews, props.eventBus]); useEffect(() => { getNews(); }, [getNews]); if (state.error) { return ( Make sure that the feed URL is correct and that CORS is configured correctly on the server. See{' '} News panel documentation. ); } if (state.loading) { return
Loading...
; } if (!state.value) { return null; } return ( {state.value.map((_, index) => { return ; })} ); }