1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/packages/unleash-frontend/public/js/UnleashApp.jsx

99 lines
3.2 KiB
React
Raw Normal View History

2016-06-18 21:53:18 +02:00
'use strict';
const React = require('react');
const Router = require('react-router');
const Menu = require('./components/Menu');
const ErrorMessages = require('./components/ErrorMessages');
const initalizer = require('./stores/initalizer');
const FeatureToggleStore = require('./stores/FeatureToggleStore');
const StrategyStore = require('./stores/StrategyStore');
const ArchiveStore = require('./stores/ArchivedToggleStore');
const Link = Router.Link;
const RouteHandler = Router.RouteHandler;
2015-03-17 22:21:49 +01:00
2016-06-18 21:53:18 +02:00
const UnleashApp = React.createClass({
contextTypes: {
2016-06-18 21:55:46 +02:00
router: React.PropTypes.func,
},
2016-07-02 11:54:50 +02:00
getInitialState () {
return {
2016-06-18 21:55:46 +02:00
features: FeatureToggleStore.getFeatureToggles(),
strategies: StrategyStore.getStrategies(),
archivedFeatures: ArchiveStore.getArchivedToggles(),
};
},
2016-07-02 11:54:50 +02:00
onFeatureToggleChange () {
this.setState({
2016-06-18 21:55:46 +02:00
features: FeatureToggleStore.getFeatureToggles(),
});
},
2016-07-02 11:54:50 +02:00
onStrategiesChange () {
this.setState({
2016-06-18 21:55:46 +02:00
strategies: StrategyStore.getStrategies(),
});
},
2016-07-02 11:54:50 +02:00
onArchiveChange () {
this.setState({
2016-06-18 21:55:46 +02:00
archivedFeatures: ArchiveStore.getArchivedToggles(),
});
},
2016-07-02 11:54:50 +02:00
componentDidMount () {
this.unsubscribeFS = FeatureToggleStore.listen(this.onFeatureToggleChange);
this.unsubscribeSS = StrategyStore.listen(this.onStrategiesChange);
this.unsubscribeAS = ArchiveStore.listen(this.onArchiveChange);
},
2016-07-02 11:54:50 +02:00
componentWillUnmount () {
this.unsubscribeFS();
this.unsubscribeSS();
this.unsubscribeAS();
},
2016-07-02 11:54:50 +02:00
componentWillMount () {
2015-03-17 22:52:10 +01:00
initalizer(30);
2015-03-17 22:21:49 +01:00
},
2016-07-02 11:54:50 +02:00
renderLink (id, label) {
2015-03-27 10:55:42 +01:00
return (
<Link to={id} className="nav-element centerify" activeClassName="nav-active">
<span className="topbar-nav-svg-caption caption showbydefault no-break">{label}</span>
</Link>
);
},
2016-07-02 11:54:50 +02:00
render () {
2015-03-17 22:21:49 +01:00
return (
<div>
<Menu>
2016-06-18 21:55:46 +02:00
{this.renderLink('features', 'Toggles')}
{this.renderLink('strategies', 'Strategies')}
{this.renderLink('log', 'Log')}
{this.renderLink('archive', 'Archive')}
</Menu>
2015-03-17 22:21:49 +01:00
<div className="container">
<div className="page">
<ErrorMessages />
<div className="mod shadow mrn pan">
<div className="inner pan">
<div className="bd">
<RouteHandler
features={this.state.features}
strategies={this.state.strategies}
archivedFeatures={this.state.archivedFeatures}
/>
</div>
</div>
</div>
2015-03-17 22:21:49 +01:00
</div>
</div>
</div>
);
2016-06-18 21:55:46 +02:00
},
2015-03-17 22:21:49 +01:00
});
2015-03-17 22:21:49 +01:00
module.exports = UnleashApp;