From 67c3c50b9b39dfcc551898c57a4bbf87fe5ba6a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Tue, 24 Mar 2015 21:25:32 +0100 Subject: [PATCH] Move to react-router. Replaced our home built tab-view with the react-router. This makes routing super simple for us. https://github.com/rackt/react-router/ relates to #95 --- package.json | 1 + public/js/UnleashApp.jsx | 82 +++++++++++++++++++------------- public/js/components/Menu.jsx | 3 +- public/js/components/TabView.jsx | 62 ------------------------ webpack.config.js | 2 +- 5 files changed, 54 insertions(+), 96 deletions(-) delete mode 100644 public/js/components/TabView.jsx diff --git a/package.json b/package.json index 34ccfa1c7b..ab8b89bec0 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "nconf": "0.7.1", "pg": "4.3.0", "react": "^0.13.1", + "react-router": "^0.13.2", "reflux": "^0.2.5", "reqwest": "^1.1.4", "webpack": "1.7.3", diff --git a/public/js/UnleashApp.jsx b/public/js/UnleashApp.jsx index fb804ed8a9..2ec4379c05 100644 --- a/public/js/UnleashApp.jsx +++ b/public/js/UnleashApp.jsx @@ -1,52 +1,56 @@ var React = require('react'); -var TabView = require('./components/TabView'); -var Menu = require('./components/Menu'); var UserStore = require('./stores/UserStore'); +var Menu = require('./components/Menu'); var ErrorMessages = require('./components/ErrorMessages'); var initalizer = require('./stores/initalizer'); -var LogEntriesComponent = React.createFactory(require('./components/log/LogEntriesComponent')); -var FeatureTogglesComponent = React.createFactory(require('./components/feature/FeatureTogglesComponent')); -var StrategiesComponent = React.createFactory(require('./components/strategy/StrategiesComponent')); -var ArchiveFeatureComponent = React.createFactory(require('./components/feature/ArchiveFeatureComponent')); +var LogEntriesComponent = require('./components/log/LogEntriesComponent'); +var FeatureTogglesComponent = require('./components/feature/FeatureTogglesComponent'); +var StrategiesComponent = require('./components/strategy/StrategiesComponent'); +var ArchiveFeatureComponent = require('./components/feature/ArchiveFeatureComponent'); +var Router = require('react-router'); +var DefaultRoute = Router.DefaultRoute; +var Link = Router.Link; +var Route = Router.Route; +var RouteHandler = Router.RouteHandler; UserStore.init(); -var tabPanes = [ -{ - name: 'Feature Toggles', - slug: 'feature-toggles', - content: FeatureTogglesComponent -}, -{ - name: 'Strategies', - slug: 'strategies', - content: StrategiesComponent -}, -{ - name: "Log", - slug: 'log', - content: LogEntriesComponent -}, -{ - name: "Archive", - slug: 'archive', - content: ArchiveFeatureComponent -} -]; - - var UnleashApp = React.createClass({ + contextTypes: { + router: React.PropTypes.func + }, + componentWillMount: function() { initalizer(30); }, + render: function () { return (
- + + + Features + + + Strategies + + + Log + + + Archive + +
- +
+
+
+ +
+
+
@@ -54,4 +58,18 @@ var UnleashApp = React.createClass({ } }); +var routes = ( + + + + + + +); + +Router.run(routes, function (Handler) { + React.render(, document.getElementById('content')); +}); + + module.exports = UnleashApp; diff --git a/public/js/components/Menu.jsx b/public/js/components/Menu.jsx index 49442f3f05..d00572f313 100644 --- a/public/js/components/Menu.jsx +++ b/public/js/components/Menu.jsx @@ -10,7 +10,7 @@ var Menu = React.createClass({
- + - - {tabPane.name} - - - ); - }.bind(this)); - - return ( -
-
    - {tabNodes} -
-
-
-
-
-
- {new this.state.activeTab.content()} -
-
-
-
-
-
- ); - } -}); - -module.exports = TabView; diff --git a/webpack.config.js b/webpack.config.js index efbae1e6d8..97421d878c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,7 +7,7 @@ var js_root = path.join(path.join(root, 'public'), 'js'); module.exports = { context: js_root, - entry: 'app', + entry: 'UnleashApp', output: { path: js_root,