Pablo Solar VilariƱo
2020-06-19 49a69db8fa634d24fc03f35cb8589e87c260fa1f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React, { Component } from 'react';
import { Table, TableHeader, TableBody } from '@patternfly/react-table';
import { EmptyState, EmptyStateIcon, EmptyStateBody, EmptyStateVariant, Bullseye, Title } from '@patternfly/react-core';
import { ErrorCircleOIcon } from '@patternfly/react-icons'
 
class NewsBoard extends Component {
 
    normalize(data) {
        return data.map(function (element) {
            return {
                cells: [element.timestamp, element.title]
            }
        });
    }
 
    componentDidMount() {
        fetch(`http://${process.env.REACT_APP_GW_ENDPOINT}/news`)
            .then(res => res.json())
            .then((data) => {
                this.setState({ rows: this.normalize(data) });
            })
            .catch(console.log)
    }
 
    constructor(props) {
        super(props);
        this.state = {
            columns: ['Timestamp', 'Story'],
            rows: [{
                heightAuto: true,
                cells: [
                    {
                        props: { colSpan: 2 },
                        title: (
                            <Bullseye>
                                <EmptyState variant={EmptyStateVariant.small}>
                                    <EmptyStateIcon icon={ErrorCircleOIcon} />
                                    <Title headingLevel="h2" size="lg">
                                        No results found
                                    </Title>
                                    <EmptyStateBody>
                                        Unable to get news from external feed.
                                    </EmptyStateBody>
                                </EmptyState>
                            </Bullseye>
                        )
                    },
                ]
            }]
        }
    }
 
    render() {
        const { columns, rows } = this.state;
 
        return (
            <Table caption="Latest News" rows={rows} cells={columns}>
            <TableHeader />
            <TableBody />
            </Table>
        )
    }
}
 
export default NewsBoard;