Commit b087edc2 by Torkel Ödegaard Committed by GitHub

Typescript: null check fixes, and news panel fix (#21595)

parent e7621906
......@@ -9,12 +9,20 @@ export async function loadRSSFeed(url: string): Promise<RssFeed> {
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);
......
......@@ -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);
}
} catch (err) {
console.warn('Error reading news item:', err, item);
}
......
......@@ -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');
});
});
......
......@@ -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"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment