From db84db990f47bc4f496f100f980111d4b8a78218 Mon Sep 17 00:00:00 2001 From: Matthew Riley MacPherson Date: Thu, 10 Nov 2016 00:33:33 +0000 Subject: [PATCH] Improve reducers and actions --- config/default.js | 7 +- src/amo/components/Categories.js | 43 +++--- src/amo/containers/CategoriesPage.js | 12 +- src/amo/containers/CategoryAddons.js | 25 +++ src/core/actions/categories.js | 4 +- src/core/reducers/categories.js | 46 +++++- .../client/amo/components/TestCategeories.js | 21 +-- .../amo/containers/TestCategoriesPage.js | 12 +- tests/client/core/actions/test_categories.js | 4 +- tests/client/core/reducers/test_categories.js | 145 ++++++++++++++++-- 10 files changed, 248 insertions(+), 71 deletions(-) create mode 100644 src/amo/containers/CategoryAddons.js diff --git a/config/default.js b/config/default.js index 8c8c158c92f..b979c5516e6 100644 --- a/config/default.js +++ b/config/default.js @@ -81,6 +81,7 @@ module.exports = { 'trackingEnabled', 'trackingId', 'trackingSendInitPageView', + 'validClientApplications', ], // Content Security Policy. @@ -158,11 +159,11 @@ module.exports = { enablePostCssLoader: true, - // The list of valid client application names. These are derived from UA strings when - // not supplied in the URL. + // The list of valid client application names. + // These are derived from UA strings when not supplied in the URL. validClientApplications: [ - 'firefox', 'android', + 'firefox', ], // The default app used in the URL. diff --git a/src/amo/components/Categories.js b/src/amo/components/Categories.js index e947198e74b..827827069eb 100644 --- a/src/amo/components/Categories.js +++ b/src/amo/components/Categories.js @@ -7,54 +7,51 @@ import translate from 'core/i18n/translate'; import './Categories.scss'; -export function filterAndSortCategories(categories, addonType, clientApp) { - return categories.filter((category) => { - return category.type === addonType && category.application === clientApp; - }).sort((a, b) => { - return a.name > b.name; - }); -} - export class CategoriesBase extends React.Component { static propTypes = { addonType: PropTypes.string.isRequired, categories: PropTypes.arrayOf(PropTypes.object), - clientApp: PropTypes.string.isRequired, error: PropTypes.bool, loading: PropTypes.bool.isRequired, i18n: PropTypes.object.isRequired, } render() { - const { - addonType, categories, clientApp, error, loading, i18n, - } = this.props; + const { addonType, categories, error, loading, i18n } = this.props; - if (loading && !categories.length) { - return
{i18n.gettext('Loading...')}
; + if (loading) { + return ( +
+

{i18n.gettext('Loading...')}

+
+ ); } if (error) { - return
{i18n.gettext('Failed to load categories.')}
; + return ( +
+

{i18n.gettext('Failed to load categories.')}

+
+ ); } - const categoriesToShow = filterAndSortCategories( - categories, addonType, clientApp); - - if (!loading && !categoriesToShow.length) { - return
{i18n.gettext('No categories found.')}
; + if (!Object.values(categories).length) { + return ( +
+

{i18n.gettext('No categories found.')}

+
+ ); } return (