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 { Grid, Row, Col } from 'preact-emotion-flexboxgrid'; import { DatacenterPlace, DatacenterRegion, Datacenter, Overlay } from '../components'; const Container = emotion('div')` background-color: #ffffff; `; const TitleContainer = emotion('div')` background-color: ${props => props.theme.background}; `; const RegionContainer = emotion('div')` padding-top: ${remcalc(18)}; padding-bottom: ${remcalc(24)}; `; const GetDatacenters = gql` { regions @client { name slug } places @client { name slug region } datacenters @client { name slug place } } `; const Datacenters = ({ expanded, regions = [] }) => expanded ? ( {regions.map(({ name, slug, places }) => (
{name} {places.map(({ name, slug, datacenters }) => ( {name} {datacenters.map(({ name, slug }) => ( {name} ))} ))}
))}
) : null; export default compose( graphql(GetDatacenters, { options: () => ({ ssr: false }), props: ({ data }) => { const { regions = [], places = [], datacenters = [], loading = false, error = null } = data; const _regions = regions.map(({ slug, ...region }) => ({ ...region, places: places .filter(({ region }) => region === slug) .map(({ slug, ...place }) => ({ ...place, datacenters: datacenters.filter(({ place }) => place === slug), slug })), slug })); return { regions: _regions, loading, error }; } }) )(Datacenters);