2018-01-17 21:10:39 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { graphql, compose } from 'react-apollo';
|
|
|
|
import gql from 'graphql-tag';
|
|
|
|
import pascalCase from 'pascal-case';
|
2018-01-25 18:23:30 +02:00
|
|
|
import keys from 'lodash.keys';
|
2018-01-17 21:10:39 +02:00
|
|
|
|
|
|
|
import { DataCenterIcon, TritonIcon, ServicesIcon } from './components';
|
|
|
|
import * as Overlays from './containers';
|
|
|
|
|
|
|
|
import {
|
|
|
|
Avatar,
|
|
|
|
Header,
|
|
|
|
HeaderRow,
|
|
|
|
HeaderItem,
|
|
|
|
HeaderItemContent,
|
|
|
|
HeaderItemSubContent,
|
|
|
|
HeaderItemIcon,
|
|
|
|
HeaderFlexibleSpaceItem,
|
2018-01-25 18:23:30 +02:00
|
|
|
HeaderDividerItem,
|
|
|
|
HeaderSpace
|
2018-01-17 21:10:39 +02:00
|
|
|
} from './components';
|
|
|
|
|
2018-02-20 02:35:31 +02:00
|
|
|
const UpdateHeaderMutation = gql`
|
2018-01-17 21:10:39 +02:00
|
|
|
mutation updateHeader($isOpen: Boolean!, $activePanel: String!) {
|
|
|
|
updateHeader(isOpen: $isOpen, activePanel: $activePanel) @client
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2018-02-20 02:35:31 +02:00
|
|
|
const GetHeader = gql`
|
2018-01-17 21:10:39 +02:00
|
|
|
{
|
|
|
|
isOpen @client
|
|
|
|
activePanel @client
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2018-03-26 22:34:42 +03:00
|
|
|
const GetAccount = gql`
|
|
|
|
{
|
|
|
|
datacenter {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
account {
|
|
|
|
login
|
2018-03-28 16:26:25 +03:00
|
|
|
emailHash
|
2018-03-26 22:34:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2018-03-02 16:10:32 +02:00
|
|
|
|
2018-03-02 00:35:37 +02:00
|
|
|
const Navigation = ({
|
2018-03-28 16:26:25 +03:00
|
|
|
user = {},
|
|
|
|
datacenter,
|
2018-03-02 00:35:37 +02:00
|
|
|
toggleSectionOpen,
|
|
|
|
isOpen,
|
|
|
|
activePanel
|
|
|
|
}) => (
|
2018-01-17 21:10:39 +02:00
|
|
|
<Header onOutsideClick={() => toggleSectionOpen()}>
|
|
|
|
<HeaderRow>
|
|
|
|
<HeaderItem>
|
|
|
|
<TritonIcon light />
|
|
|
|
</HeaderItem>
|
2018-03-22 17:34:49 +02:00
|
|
|
<HeaderDividerItem />
|
|
|
|
<HeaderItem
|
|
|
|
onClick={() => toggleSectionOpen('services')}
|
|
|
|
active={isOpen && activePanel === 'services'}
|
|
|
|
>
|
|
|
|
<HeaderItemContent>Products & Services</HeaderItemContent>
|
|
|
|
<HeaderItemIcon>
|
|
|
|
<ServicesIcon light />
|
|
|
|
</HeaderItemIcon>
|
|
|
|
</HeaderItem>
|
|
|
|
<HeaderDividerItem />
|
2018-01-17 21:10:39 +02:00
|
|
|
<HeaderFlexibleSpaceItem />
|
|
|
|
<HeaderDividerItem />
|
2018-03-02 00:35:37 +02:00
|
|
|
{datacenter ? (
|
|
|
|
<HeaderItem
|
|
|
|
onClick={() => toggleSectionOpen('datacenter')}
|
|
|
|
active={isOpen && activePanel === 'datacenter'}
|
|
|
|
>
|
|
|
|
<HeaderItemContent>
|
|
|
|
<HeaderItemSubContent>Data Center:</HeaderItemSubContent>
|
|
|
|
<HeaderSpace />
|
2018-03-27 17:39:46 +03:00
|
|
|
<span>{datacenter}</span>
|
2018-03-02 00:35:37 +02:00
|
|
|
</HeaderItemContent>
|
|
|
|
<HeaderItemIcon>
|
|
|
|
<DataCenterIcon light />
|
|
|
|
</HeaderItemIcon>
|
|
|
|
</HeaderItem>
|
|
|
|
) : null}
|
2018-03-06 03:14:33 +02:00
|
|
|
{datacenter ? <HeaderDividerItem /> : null}
|
2018-03-28 16:26:25 +03:00
|
|
|
{user.login ? (
|
|
|
|
<HeaderItem
|
|
|
|
onClick={() => toggleSectionOpen('account')}
|
|
|
|
active={isOpen && activePanel === 'account'}
|
|
|
|
>
|
2018-03-26 22:34:42 +03:00
|
|
|
<HeaderItemContent>
|
|
|
|
<HeaderItemSubContent>Account:</HeaderItemSubContent>
|
|
|
|
<HeaderSpace />
|
2018-03-28 16:26:25 +03:00
|
|
|
{`${user.login}`}
|
2018-03-26 22:34:42 +03:00
|
|
|
</HeaderItemContent>
|
|
|
|
<HeaderItemIcon>
|
2018-03-28 16:26:25 +03:00
|
|
|
<Avatar src={user.image} />
|
2018-03-26 22:34:42 +03:00
|
|
|
</HeaderItemIcon>
|
|
|
|
</HeaderItem>
|
|
|
|
) : null}
|
2018-01-17 21:10:39 +02:00
|
|
|
</HeaderRow>
|
2018-01-25 18:23:30 +02:00
|
|
|
{keys(Overlays).map(panelName =>
|
|
|
|
React.createElement(Overlays[panelName], {
|
|
|
|
expanded: isOpen && panelName === pascalCase(activePanel)
|
|
|
|
})
|
|
|
|
)}
|
2018-01-17 21:10:39 +02:00
|
|
|
</Header>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default compose(
|
2018-03-26 22:34:42 +03:00
|
|
|
graphql(GetAccount, {
|
|
|
|
options: () => ({
|
|
|
|
ssr: false
|
|
|
|
}),
|
|
|
|
props: ({ data }) => {
|
|
|
|
const {
|
|
|
|
account = {},
|
|
|
|
datacenter = {},
|
|
|
|
loading = false,
|
|
|
|
error = null
|
|
|
|
} = data;
|
2018-01-08 17:13:05 +02:00
|
|
|
|
2018-03-26 22:34:42 +03:00
|
|
|
const { name } = datacenter;
|
|
|
|
|
2018-03-28 16:26:25 +03:00
|
|
|
const user = {
|
|
|
|
...account,
|
|
|
|
image: `https://www.gravatar.com/avatar/${account.emailHash}`
|
|
|
|
};
|
|
|
|
|
|
|
|
return { user, datacenter: name, loading, error };
|
2018-03-26 22:34:42 +03:00
|
|
|
}
|
|
|
|
}),
|
2018-02-20 02:35:31 +02:00
|
|
|
graphql(GetHeader, {
|
|
|
|
options: () => ({
|
|
|
|
ssr: false
|
|
|
|
}),
|
2018-01-17 21:10:39 +02:00
|
|
|
props: ({ data }) => {
|
|
|
|
const {
|
|
|
|
isOpen = false,
|
|
|
|
activePanel = '',
|
|
|
|
loading = false,
|
|
|
|
error = null
|
|
|
|
} = data;
|
|
|
|
|
|
|
|
return { isOpen, activePanel, loading, error };
|
|
|
|
}
|
|
|
|
}),
|
2018-02-20 02:35:31 +02:00
|
|
|
graphql(UpdateHeaderMutation, {
|
2018-01-17 21:10:39 +02:00
|
|
|
props: ({ mutate, ownProps }) => ({
|
|
|
|
toggleSectionOpen: (name = '') => {
|
|
|
|
const { isOpen, activePanel } = ownProps;
|
|
|
|
return mutate({
|
|
|
|
variables: {
|
|
|
|
isOpen: !(isOpen && name === activePanel),
|
|
|
|
activePanel: name
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
)(Navigation);
|