From c0dd1809e3b7a02169809098e8b810290e25d851 Mon Sep 17 00:00:00 2001 From: Tom Raithel Date: Tue, 21 Feb 2017 21:10:24 +0100 Subject: [PATCH] Add quadrant overview pages --- common/config.js | 19 ++++---- js/components/Badge.js | 22 +++++++++ js/components/Item.js | 20 ++++++++ js/components/PageOverview.js | 16 +++--- js/components/PageQuadrant.js | 18 +++++++ js/components/QuadrantGrid.js | 46 ++---------------- js/components/QuadrantSection.js | 83 ++++++++++++++++++++++++++++++++ js/components/Router.js | 37 ++++++++------ 8 files changed, 185 insertions(+), 76 deletions(-) create mode 100644 js/components/Badge.js create mode 100644 js/components/Item.js create mode 100644 js/components/PageQuadrant.js create mode 100644 js/components/QuadrantSection.js diff --git a/common/config.js b/common/config.js index 5480db8..60e999e 100644 --- a/common/config.js +++ b/common/config.js @@ -1,12 +1,3 @@ -export const getPageNames = (radar) => { - return [ - 'index', - 'overview', - 'help', - 'foo/bar', - ] -} - export const quadrants = [ 'languages-and-frameworks', 'methods-and-patterns', @@ -14,6 +5,16 @@ export const quadrants = [ 'tools', ]; +export const getPageNames = (radar) => { + return [ + 'index', + 'overview', + 'help', + ...quadrants, + ] +} + + export const rings = [ 'assess', 'trial', diff --git a/js/components/Badge.js b/js/components/Badge.js new file mode 100644 index 0000000..97bfc0a --- /dev/null +++ b/js/components/Badge.js @@ -0,0 +1,22 @@ +import React from 'react'; +import classNames from 'classnames'; + + +export default function Badge({ onClick, big, type, children }) { + const Comp = typeof onClick === 'function' ? 'a' : 'span'; + return ( + + {children} + + ); +} diff --git a/js/components/Item.js b/js/components/Item.js new file mode 100644 index 0000000..24c4680 --- /dev/null +++ b/js/components/Item.js @@ -0,0 +1,20 @@ +import React from 'react'; +import classNames from 'classnames'; + +export default function Item({ item, noLeadingBorder = false}) { + return ( + +
{item.title}
+ { + item.info && ( +
{item.info}
+ ) + } +
+ ); +} diff --git a/js/components/PageOverview.js b/js/components/PageOverview.js index 7856745..f3337e0 100644 --- a/js/components/PageOverview.js +++ b/js/components/PageOverview.js @@ -2,6 +2,7 @@ import React from 'react'; import classNames from 'classnames'; import HeadlineGroup from './HeadlineGroup'; import HeroHeadline from './HeroHeadline'; +import Badge from './Badge'; import { groupByFirstLetter } from '../../common/model'; import { translate } from '../../common/config'; @@ -52,16 +53,13 @@ class PageOverview extends React.Component { { rings.map(ringName => (
- {ringName} - +
)) } @@ -86,7 +84,9 @@ class PageOverview extends React.Component {
{translate(item.quadrant)}
-
{item.ring}
+
+ {item.ring} +
diff --git a/js/components/PageQuadrant.js b/js/components/PageQuadrant.js new file mode 100644 index 0000000..cb2f5fb --- /dev/null +++ b/js/components/PageQuadrant.js @@ -0,0 +1,18 @@ +import React from 'react'; +import HeroHeadline from './HeroHeadline'; +import HeadlineGroup from './HeadlineGroup'; +import QuadrantSection from './QuadrantSection'; +import { translate } from '../../common/config'; +import { groupByQuadrants } from '../../common/model'; + +export default function PageQuadrant({ pageName, items }) { + const groups = groupByQuadrants(items); + return ( +
+ + {translate(pageName)} + + +
+ ); +} diff --git a/js/components/QuadrantGrid.js b/js/components/QuadrantGrid.js index 6238703..56edbfe 100644 --- a/js/components/QuadrantGrid.js +++ b/js/components/QuadrantGrid.js @@ -1,52 +1,12 @@ import React from 'react'; import { groupByQuadrants } from '../../common/model'; -import { translate, quadrants, rings } from '../../common/config'; - -const renderRing = (ringName, quadrantName, groups) => { - if (!groups[quadrantName][ringName] || groups[quadrantName][ringName].length === 0) { - return null; - } - return ( -
-
-
{ringName}
- { - (groups[quadrantName][ringName]).map(item => ( - - {item.title} - - )) - } -
-
- ); -} +import { quadrants } from '../../common/config'; +import QuadrantSection from './QuadrantSection'; const renderQuadrant = (quadrantName, groups) => { return (
-
-
-
-
-

{translate(quadrantName)}

-
- -
-
-
- { - rings.map((ringName) => renderRing(ringName, quadrantName, groups)) - } -
-
+
); } diff --git a/js/components/QuadrantSection.js b/js/components/QuadrantSection.js new file mode 100644 index 0000000..f7d42af --- /dev/null +++ b/js/components/QuadrantSection.js @@ -0,0 +1,83 @@ +import React from 'react'; +import { translate, rings } from '../../common/config'; +import Badge from './Badge'; +import Item from './Item'; + +const renderList = (ringName, quadrantName, groups, big) => { + const itemsInRing = groups[quadrantName][ringName]; + + if (big === true) { + return ( +
+
+ {ringName} +
+
+ { + itemsInRing.map(item => ( + + )) + } +
+
+ ); + } + + return ( +
+
+ {ringName} +
+ { + itemsInRing.map(item => ( + + {item.title} + + )) + } +
+ ); +} + + +const renderRing = (ringName, quadrantName, groups, big) => { + if (!groups[quadrantName][ringName] || groups[quadrantName][ringName].length === 0) { + return null; + } + return ( +
+ {renderList(ringName, quadrantName, groups, big)} +
+ ); +} + +export default function QuadrantSection({ quadrantName, groups, big = false }) { + return ( +
+
+
+
+

{translate(quadrantName)}

+
+ { + !big && ( +
+ + Quadrant Overview + +
+ ) + } +
+
+
+ { + rings.map((ringName) => renderRing(ringName, quadrantName, groups, big)) + } +
+
+ ); +} diff --git a/js/components/Router.js b/js/components/Router.js index c364f2b..d8f69ef 100644 --- a/js/components/Router.js +++ b/js/components/Router.js @@ -2,23 +2,28 @@ import React from 'react'; import PageIndex from './PageIndex'; import PageOverview from './PageOverview'; import PageHelp from './PageHelp'; +import PageQuadrant from './PageQuadrant'; +import { quadrants } from '../../common/config'; -export default function Router({ pageName, ...props}) { - let Comp; - switch (pageName) { - case 'index': - Comp = PageIndex; - break; - case 'overview': - Comp = PageOverview; - break; - case 'help': - Comp = PageHelp; - break; - default: - Comp = 'div'; - break; + +const getPageByName = (pageName) => { + if (pageName === 'index') { + return PageIndex; + } + if (pageName === 'overview') { + return PageOverview; + } + if (pageName === 'help') { + return PageHelp; + } + if (quadrants.includes(pageName)) { + return PageQuadrant; } - return ; + return 'div'; +} + +export default function Router({ pageName, ...props}) { + const Comp = getPageByName(pageName); + return ; }