NewsPanel: Remove Use Proxy option and update documentation with recommendations (#47189)

* NewsPanel: Remove CORS proxy and update documentation with recommendations

* Updated generated model

* Update news-panel.md

* Update docs/sources/visualizations/news-panel.md

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>

* Update docs/sources/visualizations/news-panel.md

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>

* Update news-panel.md

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
This commit is contained in:
Josh Hunt 2022-04-05 14:16:28 +01:00 committed by GitHub
parent c5ac19d499
commit 2fe6eca7a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 25 deletions

View File

@ -10,3 +10,7 @@ weight = 800
This panel visualization displays an RSS feed. By default, it displays articles from the Grafana Labs blog.
Enter the URL of an RSS in the URL field in the Display section. This panel type does not accept any other queries.
In version 8.5, we discontinued the "Use Proxy" option for Grafana news panels. As a result, RSS feeds that are not configured for request by Grafana's frontend (with the appropriate [CORS headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)) may not load.
If the RSS feed you're trying to display fails to load, consider rehosting the RSS feed or prefixing the RSS URL with your own "CORS proxy". Alternatively, you can use the community [RSS/Atom data source](https://grafana.com/grafana/plugins/volkovlabs-rss-datasource/) in combination with the [Dynamic text](https://grafana.com/grafana/plugins/marcusolsson-dynamictext-panel/) community panel to display the RSS feed.

View File

@ -12,7 +12,7 @@ import { loadFeed } from './feed';
import { PanelProps, DataFrameView, dateTimeFormat, GrafanaTheme2, textUtil } from '@grafana/data';
import { NewsItem } from './types';
import { PanelOptions } from './models.gen';
import { DEFAULT_FEED_URL, PROXY_PREFIX } from './constants';
import { DEFAULT_FEED_URL } from './constants';
import { css, cx } from '@emotion/css';
import { RefreshEvent } from '@grafana/runtime';
import { Unsubscribable } from 'rxjs';
@ -50,20 +50,18 @@ export class NewsPanel extends PureComponent<Props, State> {
async loadChannel() {
const { options } = this.props;
try {
const url = options.feedUrl
? options.useProxy
? `${PROXY_PREFIX}${options.feedUrl}`
: options.feedUrl
: DEFAULT_FEED_URL;
const url = options.feedUrl || DEFAULT_FEED_URL;
const feed = await loadFeed(url);
const frame = feedToDataFrame(feed);
this.setState({
news: new DataFrameView<NewsItem>(frame),
isError: false,
});
} catch (err) {
console.error('Error Loading News', err);
this.setState({
news: undefined,
isError: true,
@ -79,10 +77,10 @@ export class NewsPanel extends PureComponent<Props, State> {
const useWideLayout = width > 600;
if (isError) {
return <div>Error Loading News</div>;
return <div>Error loading RSS feed.</div>;
}
if (!news) {
return <div>loading...</div>;
return <div>Loading...</div>;
}
return (

View File

@ -1,2 +1 @@
export const DEFAULT_FEED_URL = 'https://grafana.com/blog/news.xml';
export const PROXY_PREFIX = 'https://cors-anywhere.herokuapp.com/';

View File

@ -21,7 +21,6 @@ Panel: {
PanelOptions: {
// empty/missing will default to grafana blog
feedUrl?: string
useProxy?: bool
showImage?: bool | *true
}
}

View File

@ -9,7 +9,6 @@ export const modelVersion = Object.freeze([0, 0]);
export interface PanelOptions {
feedUrl?: string;
showImage?: boolean;
useProxy?: boolean;
}
export const defaultPanelOptions: PanelOptions = {

View File

@ -1,8 +1,7 @@
import { isString } from 'lodash';
import { PanelPlugin } from '@grafana/data';
import { NewsPanel } from './NewsPanel';
import { PanelOptions, defaultPanelOptions } from './models.gen';
import { DEFAULT_FEED_URL, PROXY_PREFIX } from './constants';
import { DEFAULT_FEED_URL } from './constants';
export const plugin = new PanelPlugin<PanelOptions>(NewsPanel).setPanelOptions((builder) => {
builder
@ -19,18 +18,6 @@ export const plugin = new PanelPlugin<PanelOptions>(NewsPanel).setPanelOptions((
path: 'showImage',
name: 'Show image',
description: 'Controls if the news item social (og:image) image is shown above text content',
showIf: (currentConfig: PanelOptions) => {
return isString(currentConfig.feedUrl) && !currentConfig.feedUrl.startsWith(PROXY_PREFIX);
},
defaultValue: defaultPanelOptions.showImage,
})
.addBooleanSwitch({
path: 'useProxy',
name: 'Use Proxy',
description: 'If the feed is unable to connect, consider a CORS proxy',
showIf: (currentConfig: PanelOptions) => {
return isString(currentConfig.feedUrl) && !currentConfig.feedUrl.startsWith(PROXY_PREFIX);
},
defaultValue: defaultPanelOptions.useProxy,
});
});