-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1485 from weaveworks/loading-indicator
Loading indicator
- Loading branch information
Showing
10 changed files
with
208 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from 'react'; | ||
import _ from 'lodash'; | ||
|
||
import { findTopologyById } from '../utils/topology-utils'; | ||
import NodesError from '../charts/nodes-error'; | ||
|
||
|
||
const LOADING_TEMPLATES = [ | ||
'Loading THINGS', | ||
'Verifying THINGS', | ||
'Fetching THINGS', | ||
'Processing THINGS', | ||
'Reticulating THINGS', | ||
'Locating THINGS', | ||
'Optimizing THINGS', | ||
'Transporting THINGS', | ||
]; | ||
|
||
|
||
export function getNodeType(topology, topologies) { | ||
if (!topology || topologies.size === 0) { | ||
return ''; | ||
} | ||
let name = topology.get('name'); | ||
if (topology.get('parentId')) { | ||
const parentTopology = findTopologyById(topologies, topology.get('parentId')); | ||
name = parentTopology.get('name'); | ||
} | ||
return name.toLowerCase(); | ||
} | ||
|
||
|
||
function renderTemplate(nodeType, template) { | ||
return template.replace('THINGS', nodeType); | ||
} | ||
|
||
|
||
export class Loading extends React.Component { | ||
|
||
constructor(props, context) { | ||
super(props, context); | ||
|
||
this.state = { | ||
template: _.sample(LOADING_TEMPLATES) | ||
}; | ||
} | ||
|
||
render() { | ||
const { itemType, show } = this.props; | ||
const message = renderTemplate(itemType, this.state.template); | ||
return ( | ||
<NodesError mainClassName="nodes-chart-loading" faIconClass="fa-circle-thin" hidden={!show}> | ||
<div className="heading">{message}</div> | ||
</NodesError> | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react'; | ||
|
||
|
||
export class DelayedShow extends React.Component { | ||
constructor(props, context) { | ||
super(props, context); | ||
this.state = { | ||
show: false | ||
}; | ||
} | ||
|
||
componentWillMount() { | ||
if (this.props.show) { | ||
this.scheduleShow(); | ||
} | ||
} | ||
|
||
componentWillUnmount() { | ||
this.cancelShow(); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (nextProps.show === this.props.show) { | ||
return; | ||
} | ||
|
||
if (nextProps.show) { | ||
this.scheduleShow(); | ||
} else { | ||
this.cancelShow(); | ||
this.setState({ show: false }); | ||
} | ||
} | ||
|
||
scheduleShow() { | ||
this.showTimeout = setTimeout(() => this.setState({ show: true }), this.props.delay); | ||
} | ||
|
||
cancelShow() { | ||
clearTimeout(this.showTimeout); | ||
} | ||
|
||
render() { | ||
const { children } = this.props; | ||
const { show } = this.state; | ||
const style = { | ||
opacity: show ? 1 : 0, | ||
transition: 'opacity 0.5s ease-in-out', | ||
}; | ||
return ( | ||
<div style={style}> | ||
{children} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
|
||
DelayedShow.defaultProps = { | ||
delay: 1000 | ||
}; |
Oops, something went wrong.