grafana/public/app/plugins/panel/news/utils.ts
Josh Hunt 3c6e0e8ef8
Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

41 lines
1.3 KiB
TypeScript

import { ArrayVector, FieldType, DataFrame, dateTime } from '@grafana/data';
import { Feed } from './types';
export function feedToDataFrame(feed: Feed): DataFrame {
const date = new ArrayVector<number>([]);
const title = new ArrayVector<string>([]);
const link = new ArrayVector<string>([]);
const content = new ArrayVector<string>([]);
const ogImage = new ArrayVector<string | undefined | null>([]);
for (const item of feed.items) {
const val = dateTime(item.pubDate);
try {
date.buffer.push(val.valueOf());
title.buffer.push(item.title);
link.buffer.push(item.link);
ogImage.buffer.push(item.ogImage);
if (item.content) {
const body = item.content.replace(/<\/?[^>]+(>|$)/g, '');
content.buffer.push(body);
}
} catch (err) {
console.warn('Error reading news item:', err, item);
}
}
return {
fields: [
{ name: 'date', type: FieldType.time, config: { displayName: 'Date' }, values: date },
{ name: 'title', type: FieldType.string, config: {}, values: title },
{ name: 'link', type: FieldType.string, config: {}, values: link },
{ name: 'content', type: FieldType.string, config: {}, values: content },
{ name: 'ogImage', type: FieldType.string, config: {}, values: ogImage },
],
length: date.length,
};
}