This repository has been archived by the owner on Apr 25, 2019. It is now read-only.
/
index.jsx
101 lines (94 loc) · 2.6 KB
/
index.jsx
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import React from 'react';
import PropTypes from 'prop-types';
import { FaPlus, FaSync, FaUserTimes } from 'react-icons/fa';
import Toolbar from '../Toolbar';
import Button from '../Button';
import ThrobberButton from '../Throbber/ThrobberButton';
import Throbber from '../Throbber';
import ErrorBanner from '../ErrorBanner';
import ListTitle from '../ListTitle';
import ContainerCard from '../ContainerCard';
import style from './index.css';
/**
* Container's list.
* @param {Object} props Props of the component.
* @return {React.Component} List view of containers
*/
export default function ContainersList({
pending,
containersTotalCount,
containers,
filter,
error,
onRefresh,
onAdd,
onSelect,
onLogout,
onFilterChange,
}) {
let content;
if (pending || !Array.isArray(containers)) {
content = <Throbber label="Loading containers" />;
} else {
const count =
containers.length !== containersTotalCount
? `${containers.length} / ${containersTotalCount}`
: containers.length;
content = (
<>
<ListTitle key="size" count={count} filter={filter} onFilterChange={onFilterChange} />
<div key="containers" className={style.list}>
{containers.map(container => (
<ContainerCard key={container.Id} container={container} onClick={onSelect} />
))}
</div>
</>
);
}
return (
<span className={style.container}>
<Toolbar>
<Button onClick={onAdd} title="Deploy a new stack">
<FaPlus />
</Button>
<ThrobberButton
pending={pending}
onClick={onRefresh}
title="Refresh containers list"
vertical
horizontalSm
>
<FaSync />
</ThrobberButton>
<span className={style.fill} />
<Button onClick={onLogout} title="Logout" type="danger">
<FaUserTimes />
</Button>
</Toolbar>
<div className={style.content}>
<ErrorBanner error={error} />
{content}
</div>
</span>
);
}
ContainersList.displayName = 'ContainersList';
ContainersList.propTypes = {
pending: PropTypes.bool,
containersTotalCount: PropTypes.number,
containers: PropTypes.arrayOf(PropTypes.shape({})),
filter: PropTypes.string,
error: PropTypes.string,
onRefresh: PropTypes.func.isRequired,
onAdd: PropTypes.func.isRequired,
onSelect: PropTypes.func.isRequired,
onLogout: PropTypes.func.isRequired,
onFilterChange: PropTypes.func.isRequired,
};
ContainersList.defaultProps = {
pending: false,
containersTotalCount: 0,
containers: null,
filter: '',
error: '',
};