diff --git a/public/app/plugins/panel/news/rss.ts b/public/app/plugins/panel/news/rss.ts index 71409f38f0a..80f87a11a17 100644 --- a/public/app/plugins/panel/news/rss.ts +++ b/public/app/plugins/panel/news/rss.ts @@ -9,12 +9,20 @@ export async function loadRSSFeed(url: string): Promise { items: [], }; + const getProperty = (node: Element, property: string) => { + const propNode = node.querySelector(property); + if (propNode) { + return propNode.textContent ?? ''; + } + return ''; + }; + doc.querySelectorAll('item').forEach(node => { const item: RssItem = { - title: node.querySelector('title').textContent, - link: node.querySelector('link').textContent, - content: node.querySelector('description').textContent, - pubDate: node.querySelector('pubDate').textContent, + title: getProperty(node, 'title'), + link: getProperty(node, 'link'), + content: getProperty(node, 'description'), + pubDate: getProperty(node, 'pubDate'), }; feed.items.push(item); diff --git a/public/app/plugins/panel/news/utils.ts b/public/app/plugins/panel/news/utils.ts index 28ae0eb151d..96d7c5a2b65 100644 --- a/public/app/plugins/panel/news/utils.ts +++ b/public/app/plugins/panel/news/utils.ts @@ -15,13 +15,10 @@ export function feedToDataFrame(feed: RssFeed): DataFrame { title.buffer.push(item.title); link.buffer.push(item.link); - let body = item.content.replace(/<\/?[^>]+(>|$)/g, ''); - - if (body && body.length > 300) { - body = body.substr(0, 300); + if (item.content) { + const body = item.content.replace(/<\/?[^>]+(>|$)/g, ''); + content.buffer.push(body); } - - content.buffer.push(body); } catch (err) { console.warn('Error reading news item:', err, item); } diff --git a/public/app/plugins/panel/singlestat/specs/singlestat.test.ts b/public/app/plugins/panel/singlestat/specs/singlestat.test.ts index 3b39a912c3b..44f02ecc7c1 100644 --- a/public/app/plugins/panel/singlestat/specs/singlestat.test.ts +++ b/public/app/plugins/panel/singlestat/specs/singlestat.test.ts @@ -73,7 +73,7 @@ describe('SingleStatCtrl', () => { }); it('should set formatted falue', () => { - expect(ctx.data.display.text).toBe('15'); + expect(ctx.data.display!.text).toBe('15'); }); }); @@ -96,7 +96,7 @@ describe('SingleStatCtrl', () => { }); it('should set formatted value', () => { - expect(ctx.data.display.text).toBe('test.cpu1'); + expect(ctx.data.display!.text).toBe('test.cpu1'); }); }); @@ -121,7 +121,7 @@ describe('SingleStatCtrl', () => { }); it('should set formatted value', () => { - expect(dateTime(ctx.data.display.text).valueOf()).toBe(1505634997000); + expect(dateTime(ctx.data.display!.text).valueOf()).toBe(1505634997000); }); }); @@ -142,7 +142,7 @@ describe('SingleStatCtrl', () => { }); it('should set value', () => { - expect(ctx.data.display.text).toBe('1970-01-01 00:00:05'); + expect(ctx.data.display!.text).toBe('1970-01-01 00:00:05'); }); }); @@ -167,7 +167,7 @@ describe('SingleStatCtrl', () => { }); it('should set formatted value', () => { - expect(ctx.data.display.text).toBe(dateTime(1505634997920).format('MM/DD/YYYY h:mm:ss a')); + expect(ctx.data.display!.text).toBe(dateTime(1505634997920).format('MM/DD/YYYY h:mm:ss a')); }); }); @@ -188,7 +188,7 @@ describe('SingleStatCtrl', () => { }); it('should set formatted value', () => { - expect(ctx.data.display.text).toBe('01/01/1970 12:00:05 am'); + expect(ctx.data.display!.text).toBe('01/01/1970 12:00:05 am'); }); }); @@ -212,7 +212,7 @@ describe('SingleStatCtrl', () => { }); it('should set formatted value', () => { - expect(ctx.data.display.text).toBe('2 days ago'); + expect(ctx.data.display!.text).toBe('2 days ago'); }); }); @@ -232,7 +232,7 @@ describe('SingleStatCtrl', () => { }); it('should set formatted value', () => { - expect(ctx.data.display.text).toBe('2 days ago'); + expect(ctx.data.display!.text).toBe('2 days ago'); }); }); @@ -258,7 +258,7 @@ describe('SingleStatCtrl', () => { }); it('should set formatted value', () => { - expect(ctx.data.display.text).toBe('100'); + expect(ctx.data.display!.text).toBe('100'); }); } ); @@ -274,7 +274,7 @@ describe('SingleStatCtrl', () => { }); it('Should replace value with text', () => { - expect(ctx.data.display.text).toBe('OK'); + expect(ctx.data.display!.text).toBe('OK'); }); }); @@ -289,7 +289,7 @@ describe('SingleStatCtrl', () => { }); it('Should replace value with text', () => { - expect(ctx.data.display.text).toBe('XYZ'); + expect(ctx.data.display!.text).toBe('XYZ'); }); }); @@ -304,7 +304,7 @@ describe('SingleStatCtrl', () => { }); it('Should replace value with text OK', () => { - expect(ctx.data.display.text).toBe('OK'); + expect(ctx.data.display!.text).toBe('OK'); }); }); @@ -319,7 +319,7 @@ describe('SingleStatCtrl', () => { }); it('Should replace value with text NOT OK', () => { - expect(ctx.data.display.text).toBe('NOT OK'); + expect(ctx.data.display!.text).toBe('NOT OK'); }); }); @@ -347,7 +347,7 @@ describe('SingleStatCtrl', () => { }); it('should set formatted value', () => { - expect(ctx.data.display.text).toBe('15'); + expect(ctx.data.display!.text).toBe('15'); }); }); @@ -377,7 +377,7 @@ describe('SingleStatCtrl', () => { }); it('should set formatted falue', () => { - expect(ctx.data.display.text).toBe('100'); + expect(ctx.data.display!.text).toBe('100'); }); } ); @@ -396,7 +396,7 @@ describe('SingleStatCtrl', () => { }); it('Should replace value with text', () => { - expect(ctx.data.display.text).toBe('OK'); + expect(ctx.data.display!.text).toBe('OK'); }); }); @@ -413,7 +413,7 @@ describe('SingleStatCtrl', () => { }); it('Should replace value with text OK', () => { - expect(ctx.data.display.text).toBe('OK'); + expect(ctx.data.display!.text).toBe('OK'); }); }); @@ -430,7 +430,7 @@ describe('SingleStatCtrl', () => { }); it('Should replace value with text NOT OK', () => { - expect(ctx.data.display.text).toBe('NOT OK'); + expect(ctx.data.display!.text).toBe('NOT OK'); }); }); @@ -443,7 +443,7 @@ describe('SingleStatCtrl', () => { }); it('Should replace value with text NOT OK', () => { - expect(ctx.data.display.text).toBe('ignore1'); + expect(ctx.data.display!.text).toBe('ignore1'); }); }); diff --git a/public/dashboards/home.json b/public/dashboards/home.json index 8fc2b8fd6d1..21561a1113e 100644 --- a/public/dashboards/home.json +++ b/public/dashboards/home.json @@ -53,7 +53,7 @@ "id": 4, "links": [], "options": { - "feedUrl": "https://grafana.com/blog/index.xml" + "feedUrl": "https://grafana.com/blog/news.xml" }, "title": "Latest from the blog", "type": "news"