1- import React , { Component } from 'react' ;
1+ import { Icon , Loader , Popup , Table } from 'semantic-ui-react' ;
2+ import { Link } from "react-router-dom" ;
23import api from '../api/api.js' ;
3- import { Icon , Popup , Table } from 'semantic-ui-react' ;
4- import Loading from '../util/Loading.js' ;
54import CommandInstruction from '../util/CommandInstruction.js' ;
6- import { Link } from "react-router-dom" ;
5+ import Loading from '../util/Loading.js' ;
6+ import React , { Component } from 'react' ;
7+ import ReactTimeout from 'react-timeout' ;
8+ import styled from 'react-emotion' ;
9+
10+ const LoaderBox = styled ( 'span' ) `
11+ float: right;
12+ width: 0;
13+ padding-right: 1em;
14+ max-width: 0;
15+ display: inline-block;
16+ ` ;
717
8- const HeaderView = ( ) => (
18+ const HeaderView = ( { loading } ) => (
919 < Table . Header >
1020 < Table . Row >
1121 < Table . HeaderCell > State</ Table . HeaderCell >
@@ -15,7 +25,10 @@ const HeaderView = () => (
1525 < Table . HeaderCell > < Popup trigger = { < span > Pods</ span > } > Ready / Total</ Popup > </ Table . HeaderCell >
1626 < Table . HeaderCell > < Popup trigger = { < span > Volumes</ span > } > Bound / Total</ Popup > </ Table . HeaderCell >
1727 < Table . HeaderCell > StorageClass</ Table . HeaderCell >
18- < Table . HeaderCell > Actions</ Table . HeaderCell >
28+ < Table . HeaderCell >
29+ Actions
30+ < LoaderBox > < Loader size = "mini" active = { loading } inline /> </ LoaderBox >
31+ </ Table . HeaderCell >
1932 </ Table . Row >
2033 </ Table . Header >
2134) ;
@@ -83,9 +96,9 @@ const RowView = ({name, mode, environment, stateColor, version, license, readyPo
8396 </ Table . Row >
8497) ;
8598
86- const ListView = ( { items} ) => (
99+ const ListView = ( { items, loading } ) => (
87100 < Table striped celled >
88- < HeaderView />
101+ < HeaderView loading = { loading } />
89102 < Table . Body >
90103 {
91104 ( items ) ? items . map ( ( item ) =>
@@ -138,20 +151,29 @@ function getStateColorDescription(stateColor) {
138151}
139152
140153class DeploymentList extends Component {
141- state = { } ;
154+ state = {
155+ items : undefined ,
156+ error : undefined ,
157+ loading : true
158+ } ;
142159
143160 componentDidMount ( ) {
144- this . intervalId = setInterval ( this . reloadDeployments , 5000 ) ;
145161 this . reloadDeployments ( ) ;
146162 }
147163
148- componentWillUnmount ( ) {
149- clearInterval ( this . intervalId ) ;
150- }
151-
152164 reloadDeployments = async ( ) => {
153- const result = await api . get ( '/api/deployment' ) ;
154- this . setState ( { items :result . deployments } ) ;
165+ try {
166+ this . setState ( { loading : true } ) ;
167+ const result = await api . get ( '/api/deployment' ) ;
168+ this . setState ( {
169+ items : result . deployments ,
170+ loading : false ,
171+ error : undefined
172+ } ) ;
173+ } catch ( e ) {
174+ this . setState ( { error : e . message , loading : false } ) ;
175+ }
176+ this . props . setTimeout ( this . reloadDeployments , 5000 ) ;
155177 }
156178
157179 render ( ) {
@@ -162,8 +184,8 @@ class DeploymentList extends Component {
162184 if ( items . length === 0 ) {
163185 return ( < EmptyView /> ) ;
164186 }
165- return ( < ListView items = { items } /> ) ;
187+ return ( < ListView items = { items } loading = { this . state . loading } /> ) ;
166188 }
167189}
168190
169- export default DeploymentList ;
191+ export default ReactTimeout ( DeploymentList ) ;
0 commit comments