2018-01-17 21:10:39 +02:00
|
|
|
import React from 'react';
|
|
|
|
import emotion from 'preact-emotion';
|
|
|
|
import { graphql, compose } from 'react-apollo';
|
|
|
|
import gql from 'graphql-tag';
|
|
|
|
import remcalc from 'remcalc';
|
2018-03-22 17:34:49 +02:00
|
|
|
import groupBy from 'lodash.groupby';
|
2018-01-17 21:10:39 +02:00
|
|
|
|
|
|
|
import { Grid, Row, Col } from 'preact-emotion-flexboxgrid';
|
2018-04-06 16:44:08 +03:00
|
|
|
|
2018-01-17 21:10:39 +02:00
|
|
|
import {
|
|
|
|
DatacenterPlace,
|
|
|
|
DatacenterRegion,
|
|
|
|
Datacenter,
|
2018-03-22 17:34:49 +02:00
|
|
|
Overlay,
|
|
|
|
Anchor
|
2018-01-17 21:10:39 +02:00
|
|
|
} from '../components';
|
|
|
|
|
2018-03-22 17:34:49 +02:00
|
|
|
const fixContinentName = name =>
|
|
|
|
name
|
|
|
|
.toLowerCase()
|
|
|
|
.split('_')
|
|
|
|
.join(' ');
|
|
|
|
|
2018-01-17 21:10:39 +02:00
|
|
|
const Container = emotion('div')`
|
|
|
|
background-color: #ffffff;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const TitleContainer = emotion('div')`
|
|
|
|
background-color: ${props => props.theme.background};
|
2018-03-22 17:34:49 +02:00
|
|
|
text-transform:capitalize;
|
2018-01-17 21:10:39 +02:00
|
|
|
`;
|
|
|
|
|
|
|
|
const RegionContainer = emotion('div')`
|
|
|
|
padding-top: ${remcalc(18)};
|
|
|
|
padding-bottom: ${remcalc(24)};
|
|
|
|
`;
|
|
|
|
|
2018-02-20 02:35:31 +02:00
|
|
|
const GetDatacenters = gql`
|
2018-01-17 21:10:39 +02:00
|
|
|
{
|
2018-03-22 17:34:49 +02:00
|
|
|
regions {
|
2018-01-17 21:10:39 +02:00
|
|
|
name
|
2018-03-22 17:34:49 +02:00
|
|
|
continent
|
|
|
|
datacenters {
|
|
|
|
name
|
|
|
|
url
|
|
|
|
}
|
2018-01-17 21:10:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2018-01-25 18:23:30 +02:00
|
|
|
const Datacenters = ({ expanded, regions = [] }) =>
|
|
|
|
expanded ? (
|
|
|
|
<Overlay>
|
2018-03-22 17:34:49 +02:00
|
|
|
{Object.keys(regions).map(region => (
|
|
|
|
<div key={region}>
|
2018-01-25 18:23:30 +02:00
|
|
|
<TitleContainer>
|
|
|
|
<Grid>
|
2018-01-17 21:10:39 +02:00
|
|
|
<Row>
|
2018-01-25 18:23:30 +02:00
|
|
|
<Col>
|
2018-03-22 17:34:49 +02:00
|
|
|
<DatacenterRegion>
|
|
|
|
{fixContinentName(region)}
|
|
|
|
</DatacenterRegion>
|
2018-01-25 18:23:30 +02:00
|
|
|
</Col>
|
2018-01-17 21:10:39 +02:00
|
|
|
</Row>
|
2018-01-25 18:23:30 +02:00
|
|
|
</Grid>
|
|
|
|
</TitleContainer>
|
|
|
|
<Container>
|
|
|
|
<Grid>
|
|
|
|
<RegionContainer>
|
|
|
|
<Row>
|
2018-03-22 17:34:49 +02:00
|
|
|
{regions[region].map(({ name, datacenters }) => (
|
2018-05-23 19:29:04 +03:00
|
|
|
<Col key={name} xs="12" md="6" lg="3">
|
2018-01-25 18:23:30 +02:00
|
|
|
<DatacenterPlace>{name}</DatacenterPlace>
|
2018-03-22 17:34:49 +02:00
|
|
|
{datacenters.map(({ name, url }) => (
|
|
|
|
<Datacenter key={name}>
|
|
|
|
<Anchor href={url}>{name}</Anchor>
|
|
|
|
</Datacenter>
|
2018-01-25 18:23:30 +02:00
|
|
|
))}
|
|
|
|
</Col>
|
|
|
|
))}
|
|
|
|
</Row>
|
|
|
|
</RegionContainer>
|
|
|
|
</Grid>
|
|
|
|
</Container>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</Overlay>
|
|
|
|
) : null;
|
2018-01-17 21:10:39 +02:00
|
|
|
|
|
|
|
export default compose(
|
2018-02-20 02:35:31 +02:00
|
|
|
graphql(GetDatacenters, {
|
|
|
|
options: () => ({
|
|
|
|
ssr: false
|
|
|
|
}),
|
2018-03-22 17:34:49 +02:00
|
|
|
props: ({ data: { regions = [], loading = false, error = null } }) => ({
|
|
|
|
regions: groupBy(regions, 'continent'),
|
|
|
|
loading,
|
|
|
|
error
|
|
|
|
})
|
2018-01-17 21:10:39 +02:00
|
|
|
})
|
|
|
|
)(Datacenters);
|