This repository has been archived by the owner on May 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
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 #37 from andymikulski/normandy-remove-lilrouter
#31: Use react-router in Normandy
- Loading branch information
Showing
38 changed files
with
623 additions
and
513 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import App from './App'; | ||
import { shallow } from 'enzyme'; | ||
|
||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
ReactDOM.render(<App />, div); | ||
ReactDOM.unmountComponentAtNode(div); | ||
describe('delivery-console', () => { | ||
it('renders without crashing', () => { | ||
const wrapper = () => shallow(<App />); | ||
expect(wrapper).not.toThrow(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,38 +1,40 @@ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { applyMiddleware, compose, createStore } from 'redux'; | ||
import { initializeCurrentLocation } from 'redux-little-router'; | ||
import thunk from 'redux-thunk'; | ||
|
||
import App from 'normandy/components/App'; | ||
import NormandyRouter, { NormandyLink } from './Router'; | ||
|
||
import './less/main.less'; | ||
|
||
import Router, { | ||
enhancer as routerEnhancer, | ||
middleware as routerMiddleware, | ||
} from 'normandy/routes'; | ||
import reducers from 'normandy/state'; | ||
|
||
const middleware = [routerMiddleware, thunk]; | ||
const middleware = [thunk]; | ||
|
||
const store = createStore( | ||
reducers, | ||
reducers(undefined, { type: 'initial' }), | ||
compose(applyMiddleware(...middleware), routerEnhancer), | ||
compose(applyMiddleware(...middleware)), | ||
); | ||
|
||
const initialLocation = store.getState().router; | ||
if (initialLocation) { | ||
store.dispatch(initializeCurrentLocation(initialLocation)); | ||
} | ||
export default class Root extends React.Component { | ||
componentWillMount() { | ||
// `NormandyLinks` are wrapped Links which append a prefix for nested apps. | ||
// At this point we know the prefix, so we can update all instances of the | ||
// Link here via the static PREFIX property. | ||
NormandyLink.PREFIX = this.props.urlPrefix || ''; | ||
} | ||
|
||
export default class Root extends React.PureComponent { | ||
render() { | ||
const urlPrefix = this.props.urlPrefix; | ||
|
||
return ( | ||
<div id="normandy-app"> | ||
<Provider store={store}> | ||
<Router /> | ||
</Provider> | ||
</div> | ||
<Provider store={store}> | ||
<App> | ||
<NormandyRouter urlPrefix={urlPrefix} /> | ||
</App> | ||
</Provider> | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,22 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import App from './App'; | ||
import { shallow } from 'enzyme'; | ||
|
||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
ReactDOM.render(<App />, div); | ||
ReactDOM.unmountComponentAtNode(div); | ||
describe('normandy', () => { | ||
beforeAll(() => { | ||
const fakeStorage = { | ||
store: {}, | ||
getItem: key => fakeStorage.store[key] || null, | ||
setItem: (key, value) => (fakeStorage.store[key] = value), | ||
}; | ||
Object.defineProperty(window, 'localStorage', { | ||
value: fakeStorage, | ||
}); | ||
}); | ||
|
||
it('renders without crashing', () => { | ||
const wrapper = () => shallow(<App />); | ||
expect(wrapper).not.toThrow(); | ||
}); | ||
}); |
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,99 @@ | ||
import React from 'react'; | ||
import { Switch } from 'react-router-dom'; | ||
import { Route } from 'react-router'; | ||
|
||
import CreateExtensionPage from 'normandy/components/extensions/CreateExtensionPage'; | ||
import EditExtensionPage from 'normandy/components/extensions/EditExtensionPage'; | ||
import ApprovalHistoryPage from 'normandy/components/recipes/ApprovalHistoryPage'; | ||
import CreateRecipePage from 'normandy/components/recipes/CreateRecipePage'; | ||
import CloneRecipePage from 'normandy/components/recipes/CloneRecipePage'; | ||
import EditRecipePage from 'normandy/components/recipes/EditRecipePage'; | ||
import ExtensionListing from 'normandy/components/extensions/ExtensionListing'; | ||
import Gateway from 'normandy/components/pages/Gateway'; | ||
import RecipeListing from 'normandy/components/recipes/RecipeListing'; | ||
import RecipeDetailPage from 'normandy/components/recipes/RecipeDetailPage'; | ||
|
||
import { NavLink } from 'react-router-dom'; | ||
|
||
export default class NormandyRouter extends React.Component { | ||
static ROUTES = { | ||
'/': { | ||
component: Gateway, | ||
}, | ||
// Recipes --- | ||
'/recipe': { | ||
component: RecipeListing, | ||
}, | ||
'/recipe/new': { | ||
component: CreateRecipePage, | ||
}, | ||
'/recipe/:recipeId': { | ||
component: RecipeDetailPage, | ||
}, | ||
'/recipe/:recipeId/edit': { | ||
component: EditRecipePage, | ||
}, | ||
'/recipe/:recipeId/approval_history': { | ||
component: ApprovalHistoryPage, | ||
}, | ||
'/recipe/:recipeId/clone': { | ||
component: CloneRecipePage, | ||
}, | ||
// Recipe Revisions --- | ||
'/recipe/:recipeId/rev/:revisionId': { | ||
component: RecipeDetailPage, | ||
}, | ||
'/recipe/:recipeId/rev/:revisionId/clone': { | ||
component: CloneRecipePage, | ||
}, | ||
// Extensions --- | ||
'/extension': { | ||
component: ExtensionListing, | ||
}, | ||
'/extension/new': { | ||
component: CreateExtensionPage, | ||
}, | ||
'/extension/:extensionId': { | ||
component: EditExtensionPage, | ||
}, | ||
}; | ||
|
||
render() { | ||
const urlPrefix = this.props.urlPrefix || ''; | ||
|
||
return ( | ||
<Switch> | ||
{Object.keys(NormandyRouter.ROUTES).map(route => { | ||
return ( | ||
<Route | ||
key={route} | ||
exact | ||
path={`${urlPrefix}${route}`} | ||
{...NormandyRouter.ROUTES[route]} | ||
/> | ||
); | ||
})} | ||
|
||
<Route | ||
component={({ location }) => ( | ||
<div> | ||
<h2>404 - Page Not Found</h2> | ||
<p> | ||
No normandy match for <code>{location.pathname}</code> | ||
</p> | ||
</div> | ||
)} | ||
/> | ||
</Switch> | ||
); | ||
} | ||
} | ||
|
||
export class NormandyLink extends React.Component { | ||
static PREFIX = ''; | ||
render() { | ||
const { to, ...rest } = this.props; | ||
|
||
return <NavLink to={`${NormandyLink.PREFIX}${to}`} {...rest} />; | ||
} | ||
} |
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
Oops, something went wrong.