diff --git a/server/dataLoader.js b/server/dataLoader.js index d2223350..145a4123 100644 --- a/server/dataLoader.js +++ b/server/dataLoader.js @@ -4,7 +4,7 @@ const log = require('./log'); exports.loadData = function(requestUrl, sdk) { const { pathname, query } = url.parse(requestUrl); - const matchedRoutes = matchPathname(pathname, routeConfiguration); + const matchedRoutes = matchPathname(pathname, routeConfiguration()); const store = configureStore(sdk); diff --git a/src/Routes.js b/src/Routes.js index 0428b21f..a399b171 100644 --- a/src/Routes.js +++ b/src/Routes.js @@ -2,13 +2,13 @@ import React, { Component, PropTypes } from 'react'; import { compose } from 'redux'; import { connect } from 'react-redux'; import { Switch, Route, withRouter } from 'react-router-dom'; +import routeConfiguration from './routeConfiguration'; import { NotFoundPage } from './containers'; import { NamedRedirect } from './components'; -import { withFlattenedRoutes } from './util/contextHelpers'; import * as propTypes from './util/propTypes'; import * as log from './util/log'; -const { bool, arrayOf, object, func, shape, string, any } = PropTypes; +const { bool, object, func, shape, string } = PropTypes; const canShowComponent = props => { const { isAuthenticated, route } = props; @@ -49,18 +49,14 @@ class RouteComponentRenderer extends Component { } render() { - const { route, match, location, staticContext, flattenedRoutes } = this.props; + const { route, match, location, staticContext } = this.props; const { component: RouteComponent, authPage = 'SignupPage' } = route; const canShow = canShowComponent(this.props); if (!canShow) { staticContext.unauthorized = true; } return canShow - ? + ? : { - const { isAuthenticated, logoutInProgress, flattenedRoutes, staticContext, dispatch } = props; + const { isAuthenticated, logoutInProgress, staticContext, dispatch } = props; const toRouteComponent = route => { const renderProps = { @@ -95,7 +90,6 @@ const Routes = props => { route, staticContext, dispatch, - flattenedRoutes, }; return ( { return ( - {flattenedRoutes.map(toRouteComponent)} + {routeConfiguration().map(toRouteComponent)} ); @@ -127,9 +121,6 @@ Routes.propTypes = { isAuthenticated: bool.isRequired, logoutInProgress: bool.isRequired, - // from withFlattenedRoutes - flattenedRoutes: arrayOf(propTypes.route).isRequired, - // from withRouter staticContext: object, @@ -148,4 +139,4 @@ const mapStateToProps = state => { // lifecycle hook. // // See: https://github.com/ReactTraining/react-router/issues/4671 -export default compose(withRouter, connect(mapStateToProps), withFlattenedRoutes)(Routes); +export default compose(withRouter, connect(mapStateToProps))(Routes); diff --git a/src/app.js b/src/app.js index 81576691..2f6d5475 100644 --- a/src/app.js +++ b/src/app.js @@ -7,23 +7,17 @@ import { IntlProvider, addLocaleData } from 'react-intl'; import en from 'react-intl/locale-data/en'; import configureStore from './store'; import Routes from './Routes'; -import { RoutesProvider } from './components'; -import routesConfiguration from './routesConfiguration'; -import { flattenRoutes } from './util/routes'; import localeData from './translations/en.json'; export const ClientApp = props => { const { store } = props; addLocaleData([...en]); - const flattenedRoutes = flattenRoutes(routesConfiguration); return ( - - - - - + + + ); @@ -36,15 +30,12 @@ ClientApp.propTypes = { store: any.isRequired }; export const ServerApp = props => { const { url, context, store } = props; addLocaleData([...en]); - const flattenedRoutes = flattenRoutes(routesConfiguration); return ( - - - - - + + + ); diff --git a/src/components/EditListingWizard/EditListingWizard.example.js b/src/components/EditListingWizard/EditListingWizard.example.js index 7b67bf4e..8bfbde42 100644 --- a/src/components/EditListingWizard/EditListingWizard.example.js +++ b/src/components/EditListingWizard/EditListingWizard.example.js @@ -1,6 +1,4 @@ import { createListing } from '../../util/test-data'; -import { flattenRoutes } from '../../util/routes'; -import routesConfiguration from '../../routesConfiguration'; import EditListingWizard from './EditListingWizard'; const noop = () => null; @@ -16,7 +14,6 @@ export const NoPhotos = { }, fetchInProgress: false, newListingCreated: false, - flattenedRoutes: flattenRoutes(routesConfiguration), history: { push: noop }, images: [], listing: createListing('listing1'), diff --git a/src/components/EditListingWizard/EditListingWizard.js b/src/components/EditListingWizard/EditListingWizard.js index 3efb9219..bec8db07 100644 --- a/src/components/EditListingWizard/EditListingWizard.js +++ b/src/components/EditListingWizard/EditListingWizard.js @@ -1,6 +1,7 @@ import React, { PropTypes } from 'react'; import { injectIntl, intlShape } from 'react-intl'; import classNames from 'classnames'; +import routeConfiguration from '../../routeConfiguration'; import * as propTypes from '../../util/propTypes'; import { ensureListing } from '../../util/data'; import { createResourceLocatorString } from '../../util/routes'; @@ -76,7 +77,6 @@ const EditListingWizard = props => { errors, fetchInProgress, newListingCreated, - flattenedRoutes, history, images, listing, @@ -142,7 +142,7 @@ const EditListingWizard = props => { const pathParams = tabParams(LOCATION); // Redirect to location tab history.push( - createResourceLocatorString('EditListingPage', flattenedRoutes, pathParams, {}) + createResourceLocatorString('EditListingPage', routeConfiguration(), pathParams, {}) ); } else { update(DESCRIPTION, values); @@ -175,7 +175,7 @@ const EditListingWizard = props => { const pathParams = tabParams(PRICING); // Redirect to pricing tab history.push( - createResourceLocatorString('EditListingPage', flattenedRoutes, pathParams, {}) + createResourceLocatorString('EditListingPage', routeConfiguration(), pathParams, {}) ); } else { update(LOCATION, updateValues); @@ -200,7 +200,7 @@ const EditListingWizard = props => { const pathParams = tabParams(PHOTOS); // Redirect to photos tab history.push( - createResourceLocatorString('EditListingPage', flattenedRoutes, pathParams, {}) + createResourceLocatorString('EditListingPage', routeConfiguration(), pathParams, {}) ); } else { update(PRICING, values); @@ -253,7 +253,7 @@ EditListingWizard.defaultProps = { updatedTab: null, }; -const { array, arrayOf, bool, func, object, oneOf, shape, string } = PropTypes; +const { array, bool, func, object, oneOf, shape, string } = PropTypes; EditListingWizard.propTypes = { className: string, @@ -271,7 +271,6 @@ EditListingWizard.propTypes = { }).isRequired, fetchInProgress: bool.isRequired, newListingCreated: bool.isRequired, - flattenedRoutes: arrayOf(propTypes.route).isRequired, history: shape({ push: func.isRequired, }).isRequired, diff --git a/src/components/FilterPanel/__snapshots__/FilterPanel.test.js.snap b/src/components/FilterPanel/__snapshots__/FilterPanel.test.js.snap index f25c5d6d..d2660d12 100644 --- a/src/components/FilterPanel/__snapshots__/FilterPanel.test.js.snap +++ b/src/components/FilterPanel/__snapshots__/FilterPanel.test.js.snap @@ -3,13 +3,13 @@ exports[`FilterPanel matches snapshot 1`] = `

Filters

- See studios - - + X - + `; diff --git a/src/components/HeroSection/HeroSection.js b/src/components/HeroSection/HeroSection.js index 807b10b6..d56ab05a 100644 --- a/src/components/HeroSection/HeroSection.js +++ b/src/components/HeroSection/HeroSection.js @@ -1,16 +1,16 @@ import React, { PropTypes } from 'react'; import { FormattedMessage } from 'react-intl'; import classNames from 'classnames'; -import { IconSearch, Button } from '../../components'; -import { LocationSearchForm } from '../../containers'; import { stringify } from '../../util/urlHelpers'; import { createResourceLocatorString } from '../../util/routes'; -import * as propTypes from '../../util/propTypes'; +import routeConfiguration from '../../routeConfiguration'; +import { IconSearch, Button } from '../../components'; +import { LocationSearchForm } from '../../containers'; import css from './HeroSection.css'; const HeroSection = props => { - const { rootClassName, className, flattenedRoutes, history, location } = props; + const { rootClassName, className, history, location } = props; const handleMobileSearchClick = () => { const params = { mobilesearch: 'open' }; @@ -22,7 +22,7 @@ const HeroSection = props => { const { search, selectedPlace } = values.location; const { origin, bounds, country } = selectedPlace; const searchParams = { address: search, origin, bounds, country }; - history.push(createResourceLocatorString('SearchPage', flattenedRoutes, {}, searchParams)); + history.push(createResourceLocatorString('SearchPage', routeConfiguration(), {}, searchParams)); }; const classes = classNames(rootClassName || css.root, className); @@ -46,13 +46,12 @@ const HeroSection = props => { HeroSection.defaultProps = { rootClassName: null, className: null }; -const { string, shape, func, arrayOf } = PropTypes; +const { string, shape, func } = PropTypes; HeroSection.propTypes = { rootClassName: string, className: string, - flattenedRoutes: arrayOf(propTypes.route).isRequired, history: shape({ push: func.isRequired, }).isRequired, diff --git a/src/components/HeroSection/HeroSection.test.js b/src/components/HeroSection/HeroSection.test.js index c92c789d..cf5374ec 100644 --- a/src/components/HeroSection/HeroSection.test.js +++ b/src/components/HeroSection/HeroSection.test.js @@ -8,7 +8,6 @@ describe('HeroSection', () => { it('matches snapshot', () => { window.google = { maps: {} }; const heroProps = { - flattenedRoutes: [], history: { push: noop }, location: { search: '' }, }; diff --git a/src/components/ListingCard/__snapshots__/ListingCard.test.js.snap b/src/components/ListingCard/__snapshots__/ListingCard.test.js.snap index da9b2dab..ecfaf4ae 100644 --- a/src/components/ListingCard/__snapshots__/ListingCard.test.js.snap +++ b/src/components/ListingCard/__snapshots__/ListingCard.test.js.snap @@ -1,5 +1,5 @@ exports[`ListingCard matches snapshot 1`] = ` - - + `; diff --git a/src/components/ManageListingCard/ManageListingCard.example.js b/src/components/ManageListingCard/ManageListingCard.example.js index 1cdec197..f02f3d39 100644 --- a/src/components/ManageListingCard/ManageListingCard.example.js +++ b/src/components/ManageListingCard/ManageListingCard.example.js @@ -22,7 +22,6 @@ export const ManageListingCardWrapped = { onCloseListing: noop, onOpenListing: noop, onToggleMenu: noop, - flattenedRoutes: [], history: { push: noop }, }, }; diff --git a/src/components/ManageListingCard/ManageListingCard.js b/src/components/ManageListingCard/ManageListingCard.js index d3d2352b..214d517e 100644 --- a/src/components/ManageListingCard/ManageListingCard.js +++ b/src/components/ManageListingCard/ManageListingCard.js @@ -3,11 +3,11 @@ import { compose } from 'redux'; import { withRouter } from 'react-router-dom'; import { FormattedMessage, intlShape, injectIntl } from 'react-intl'; import classNames from 'classnames'; +import routeConfiguration from '../../routeConfiguration'; import * as propTypes from '../../util/propTypes'; import { formatMoney } from '../../util/currency'; import { ensureListing } from '../../util/data'; import { createSlug } from '../../util/urlHelpers'; -import { withFlattenedRoutes } from '../../util/contextHelpers'; import { createResourceLocatorString } from '../../util/routes'; import { InlineTextButton, @@ -46,19 +46,18 @@ const priceData = (price, intl) => { return {}; }; -const createURL = (flattenedRoutes, listing) => { +const createURL = (routes, listing) => { const id = listing.id.uuid; const slug = createSlug(listing.attributes.title); const pathParams = { id, slug, type: 'edit', tab: 'description' }; - return createResourceLocatorString('EditListingPage', flattenedRoutes, pathParams, {}); + return createResourceLocatorString('EditListingPage', routes, pathParams, {}); }; export const ManageListingCardComponent = props => { const { className, rootClassName, - flattenedRoutes, hasClosingError, hasOpeningError, history, @@ -232,7 +231,7 @@ export const ManageListingCardComponent = props => { onClick={event => { event.preventDefault(); event.stopPropagation(); - history.push(createURL(flattenedRoutes, listing)); + history.push(createURL(routeConfiguration(), listing)); }} > @@ -248,7 +247,7 @@ ManageListingCardComponent.defaultProps = { actionsInProgressListingId: null, }; -const { arrayOf, bool, func, shape, string } = PropTypes; +const { bool, func, shape, string } = PropTypes; ManageListingCardComponent.propTypes = { className: string, @@ -263,13 +262,10 @@ ManageListingCardComponent.propTypes = { onOpenListing: func.isRequired, onToggleMenu: func.isRequired, - // from withFlattenedRoutes - flattenedRoutes: arrayOf(propTypes.route).isRequired, - // from withRouter history: shape({ push: func.isRequired, }).isRequired, }; -export default compose(withRouter, withFlattenedRoutes, injectIntl)(ManageListingCardComponent); +export default compose(withRouter, injectIntl)(ManageListingCardComponent); diff --git a/src/components/ManageListingCard/ManageListingCard.test.js b/src/components/ManageListingCard/ManageListingCard.test.js index 511fb036..bb7658a4 100644 --- a/src/components/ManageListingCard/ManageListingCard.test.js +++ b/src/components/ManageListingCard/ManageListingCard.test.js @@ -9,7 +9,6 @@ describe('ManageListingCard', () => { it('matches snapshot', () => { const tree = renderShallow( - + `; diff --git a/src/components/MapPanel/__snapshots__/MapPanel.test.js.snap b/src/components/MapPanel/__snapshots__/MapPanel.test.js.snap index 96d8ea82..6f63cef7 100644 --- a/src/components/MapPanel/__snapshots__/MapPanel.test.js.snap +++ b/src/components/MapPanel/__snapshots__/MapPanel.test.js.snap @@ -4,13 +4,13 @@ exports[`MapPanel matches snapshot 1`] = ` Map
- Filters - - + X - +
`; diff --git a/src/components/NamedLink/NamedLink.js b/src/components/NamedLink/NamedLink.js index 90f5842e..c97cdb4f 100644 --- a/src/components/NamedLink/NamedLink.js +++ b/src/components/NamedLink/NamedLink.js @@ -2,7 +2,7 @@ * This component wraps React-Router's Link by providing name-based routing. * * The `name` prop should match a route in the flattened - * routesConfiguration passed in context by the RoutesProvider + * routeConfiguration passed in context by the RoutesProvider * component. The `params` props is the route params for the route * path of the given route name. * @@ -20,17 +20,15 @@ import React, { PropTypes } from 'react'; import { Link, withRouter } from 'react-router-dom'; import classNames from 'classnames'; +import routeConfiguration from '../../routeConfiguration'; import { pathByRouteName } from '../../util/routes'; -import { withFlattenedRoutes } from '../../util/contextHelpers'; -import * as propTypes from '../../util/propTypes'; export const NamedLinkComponent = props => { - const { name, params, flattenedRoutes, title } = props; + const { name, params, title } = props; // Link props const { to, children } = props; - - const pathname = pathByRouteName(name, flattenedRoutes, params); + const pathname = pathByRouteName(name, routeConfiguration(), params); const { match } = props; const active = match.url && match.url === pathname; @@ -45,7 +43,7 @@ export const NamedLinkComponent = props => { return {children}; }; -const { arrayOf, object, string, shape, any } = PropTypes; +const { object, string, shape, any } = PropTypes; NamedLinkComponent.defaultProps = { params: {}, @@ -62,7 +60,7 @@ NamedLinkComponent.defaultProps = { NamedLinkComponent.displayName = 'NamedLink'; NamedLinkComponent.propTypes = { - // name of the route in routesConfiguration + // name of the route in routeConfiguration name: string.isRequired, // params object for the named route params: object, @@ -76,11 +74,11 @@ NamedLinkComponent.propTypes = { activeClassName: string, title: string, - // from withFlattenedRoutes - flattenedRoutes: arrayOf(propTypes.route).isRequired, - // from withRouter match: object, }; -export default withFlattenedRoutes(withRouter(NamedLinkComponent)); +const NamedLink = withRouter(NamedLinkComponent); +NamedLink.displayName = 'NamedLink'; + +export default NamedLink; diff --git a/src/components/NamedLink/NamedLink.test.js b/src/components/NamedLink/NamedLink.test.js index 55ab0e3d..18edf007 100644 --- a/src/components/NamedLink/NamedLink.test.js +++ b/src/components/NamedLink/NamedLink.test.js @@ -1,33 +1,27 @@ import React from 'react'; -import { RoutesProvider } from '../index'; import { renderShallow, renderDeep } from '../../util/test-helpers'; import NamedLink, { NamedLinkComponent } from './NamedLink'; describe('NamedLinkComponent', () => { it('should mark the link as active if the current URL matches', () => { - const routesConf = [ - { path: '/a', name: 'APage', component: () => null }, - { path: '/b', name: 'BPage', component: () => null }, - ]; const activeClassName = 'my-active-class'; - const aProps = { - name: 'APage', + const landingPageProps = { + name: 'LandingPage', activeClassName, - flattenedRoutes: routesConf, - match: { url: '/a' }, + match: { url: '/' }, }; - const bProps = { - name: 'BPage', + const searchPageProps = { + name: 'SearchPage', activeClassName, - flattenedRoutes: routesConf, - match: { url: '/a' }, + match: { url: '/' }, }; const tree = renderDeep(
- link to a - link to b + link to a + link to b
); + const aLink = tree.children[0]; const bLink = tree.children[1]; expect(aLink.type).toEqual('a'); @@ -40,16 +34,11 @@ describe('NamedLinkComponent', () => { describe('NamedLink', () => { it('should contain correct link', () => { const id = 12; - const routesConf = [ - { path: '/somepage/:id', name: 'SomePage', component: () =>
blaa
}, - ]; const tree = renderDeep( - - to SomePage - + to ListingPage ); expect(tree.type).toEqual('a'); - expect(tree.props.href).toEqual(`/somepage/${id}`); - expect(tree.children).toEqual(['to SomePage']); + expect(tree.props.href).toEqual(`/l/${id}`); + expect(tree.children).toEqual(['to ListingPage']); }); }); diff --git a/src/components/NamedRedirect/NamedRedirect.js b/src/components/NamedRedirect/NamedRedirect.js index a4a1f501..be72638a 100644 --- a/src/components/NamedRedirect/NamedRedirect.js +++ b/src/components/NamedRedirect/NamedRedirect.js @@ -4,17 +4,16 @@ */ import React, { PropTypes } from 'react'; import { Redirect } from 'react-router-dom'; +import routeConfiguration from '../../routeConfiguration'; import { pathByRouteName } from '../../util/routes'; -import { withFlattenedRoutes } from '../../util/contextHelpers'; -import * as propTypes from '../../util/propTypes'; const NamedRedirect = props => { - const { name, search, state, params, flattenedRoutes, push } = props; - const pathname = pathByRouteName(name, flattenedRoutes, params); + const { name, search, state, params, push } = props; + const pathname = pathByRouteName(name, routeConfiguration(), params); return ; }; -const { arrayOf, object, string, bool } = PropTypes; +const { bool, object, string } = PropTypes; NamedRedirect.defaultProps = { search: '', state: {}, push: false, params: {} }; @@ -24,7 +23,6 @@ NamedRedirect.propTypes = { state: object, push: bool, params: object, - flattenedRoutes: arrayOf(propTypes.route).isRequired, }; -export default withFlattenedRoutes(NamedRedirect); +export default NamedRedirect; diff --git a/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap b/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap index 56ef5ad2..647e5804 100644 --- a/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap +++ b/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap @@ -60,7 +60,7 @@ exports[`OrderDetailsPanel accepted matches snapshot 1`] = ` id="OrderDetailsPanel.orderAcceptedSubtitle" values={ Object { - "listingLink": listing1 title - , + , } } /> @@ -452,7 +452,7 @@ exports[`OrderDetailsPanel autorejected matches snapshot 1`] = ` id="OrderDetailsPanel.orderAutoRejectedTitle" values={ Object { - "listingLink": listing1 title - , + , } } /> @@ -853,7 +853,7 @@ exports[`OrderDetailsPanel canceled matches snapshot 1`] = ` id="OrderDetailsPanel.orderPreauthorizedSubtitle" values={ Object { - "listingLink": listing1 title - , + , } } /> @@ -1238,7 +1238,7 @@ exports[`OrderDetailsPanel delivered matches snapshot 1`] = ` id="OrderDetailsPanel.orderDeliveredTitle" values={ Object { - "listingLink": listing1 title - , + , } } /> @@ -1639,7 +1639,7 @@ exports[`OrderDetailsPanel preauthorized matches snapshot 1`] = ` id="OrderDetailsPanel.orderPreauthorizedSubtitle" values={ Object { - "listingLink": listing1 title - , + , } } /> @@ -2024,7 +2024,7 @@ exports[`OrderDetailsPanel rejected matches snapshot 1`] = ` id="OrderDetailsPanel.orderRejectedTitle" values={ Object { - "listingLink": listing1 title - , + , } } /> diff --git a/src/components/PaginationLinks/__snapshots__/PaginationLinks.test.js.snap b/src/components/PaginationLinks/__snapshots__/PaginationLinks.test.js.snap index fb529177..0726418c 100644 --- a/src/components/PaginationLinks/__snapshots__/PaginationLinks.test.js.snap +++ b/src/components/PaginationLinks/__snapshots__/PaginationLinks.test.js.snap @@ -8,7 +8,7 @@ exports[`PaginationLinks should match snapshot with both links disabled 1`] = `
- 1 - +
@@ -36,7 +36,7 @@ exports[`PaginationLinks should match snapshot with both links disabled 1`] = ` exports[`PaginationLinks should match snapshot with both links enabled 1`] = ` `; @@ -132,7 +132,7 @@ exports[`PaginationLinks should match snapshot with prev disabled and next enabl
- 1 - - + 2 - - + 3 - +
- - + `; exports[`PaginationLinks should match snapshot with prev enabled and next disabled 1`] = `