import React from 'react'; import emotion from 'preact-emotion'; import { graphql, compose } from 'react-apollo'; import gql from 'graphql-tag'; import remcalc from 'remcalc'; import groupBy from 'lodash.groupby'; import { Grid, Row, Col } from 'preact-emotion-flexboxgrid'; import { DatacenterPlace, DatacenterRegion, Datacenter, Overlay, Anchor } from '../components'; const fixContinentName = name => name .toLowerCase() .split('_') .join(' '); const Container = emotion('div')` background-color: #ffffff; `; const TitleContainer = emotion('div')` background-color: ${props => props.theme.background}; text-transform:capitalize; `; const RegionContainer = emotion('div')` padding-top: ${remcalc(18)}; padding-bottom: ${remcalc(24)}; `; const GetDatacenters = gql` { regions { name continent datacenters { name url } } } `; const Datacenters = ({ expanded, regions = [] }) => expanded ? ( {Object.keys(regions).map(region => (
{fixContinentName(region)} {regions[region].map(({ name, datacenters }) => ( {name} {datacenters.map(({ name, url }) => ( {name} ))} ))}
))}
) : null; export default compose( graphql(GetDatacenters, { options: () => ({ ssr: false }), props: ({ data: { regions = [], loading = false, error = null } }) => ({ regions: groupBy(regions, 'continent'), loading, error }) }) )(Datacenters);