feat(cp-frontend): Move portal query to header, display result, return user from mock server

This commit is contained in:
JUDIT GRESKOVITS 2017-05-25 17:32:19 +01:00
parent d2ac10ae28
commit 5ffa07aeee
10 changed files with 271 additions and 192 deletions

View File

@ -1,4 +1,5 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import styled from 'styled-components'; import styled from 'styled-components';
import { Img } from 'normalized-styled-components'; import { Img } from 'normalized-styled-components';
@ -7,6 +8,7 @@ import unitcalc from 'unitcalc';
import Logo from '@assets/triton_logo.png'; import Logo from '@assets/triton_logo.png';
import { Col, Row } from 'react-styled-flexboxgrid'; import { Col, Row } from 'react-styled-flexboxgrid';
import { P } from 'joyent-ui-toolkit';
const StyledHeader = styled.div` const StyledHeader = styled.div`
background-color: ${props => props.theme.primaryDarkBrand}; background-color: ${props => props.theme.primaryDarkBrand};
@ -18,14 +20,33 @@ const StyledLogo = styled(Img)`
height: ${remcalc(25)}; height: ${remcalc(25)};
`; `;
export default () => ( const StyledP = styled(P)`
color: ${props => props.theme.white};
font-weight: 600;
margin: ${unitcalc(0.5)} 0 0 0;
`;
const Header = ({ datacenter, username }) => (
<StyledHeader> <StyledHeader>
<Row> <Row>
<Col lg={12} xs={12}> <Col xs={6} sm={8} md={10}>
<Link to="/"> <Link to="/">
<StyledLogo src={Logo} /> <StyledLogo src={Logo} />
</Link> </Link>
</Col> </Col>
<Col xs={3} sm={2} md={1}>
<StyledP>{datacenter}</StyledP>
</Col>
<Col xs={3} sm={2} md={1}>
<StyledP>{username}</StyledP>
</Col>
</Row> </Row>
</StyledHeader> </StyledHeader>
); );
Header.propTypes = {
datacenter: PropTypes.string,
username: PropTypes.string
};
export default Header;

View File

@ -1,7 +1,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
// import PropTypes from 'prop-types'; // Import PropTypes from 'prop-types';
import { compose, graphql } from 'react-apollo'; import { compose, graphql } from 'react-apollo';
import PortalQuery from '@graphql/Portal.gql';
import InstancesQuery from '@graphql/Instances.gql'; import InstancesQuery from '@graphql/Instances.gql';
import { LayoutContainer } from '@components/layout'; import { LayoutContainer } from '@components/layout';
@ -49,8 +48,6 @@ class InstanceList extends Component {
} }
} }
const PortalGql = graphql(PortalQuery, {});
const InstanceListGql = graphql(InstancesQuery, { const InstanceListGql = graphql(InstancesQuery, {
options(props) { options(props) {
const params = props.match.params; const params = props.match.params;
@ -75,6 +72,6 @@ const InstanceListGql = graphql(InstancesQuery, {
}) })
}); });
const InstanceListWithData = compose(PortalGql, InstanceListGql)(InstanceList); const InstanceListWithData = compose(InstanceListGql)(InstanceList);
export default InstanceListWithData; export default InstanceListWithData;

View File

@ -0,0 +1,32 @@
import React from 'react';
import { graphql } from 'react-apollo';
import PortalQuery from '@graphql/Portal.gql';
import { Header as HeaderComponent } from '@components/navigation';
const Header = ({
portal = {
datacenter: {
region: ''
},
user: {
firstName: ''
}
},
loading,
error
}) => (
<HeaderComponent
datacenter={portal.datacenter.region}
username={portal.user.firstName}
/>
);
const HeaderWithData = graphql(PortalQuery, {
props: ({ data: { portal, loading, error } }) => ({
portal,
loading,
error
})
})(Header);
export default HeaderWithData;

View File

@ -1,2 +1,3 @@
export { default as Header } from './header';
export { default as Breadcrumb } from './breadcrumb'; export { default as Breadcrumb } from './breadcrumb';
export { default as Menu } from './menu'; export { default as Menu } from './menu';

View File

@ -1,9 +1,8 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { compose, graphql } from 'react-apollo'; import { compose, graphql } from 'react-apollo';
// import { connect } from 'react-redux'; // Import { connect } from 'react-redux';
import styled from 'styled-components'; import styled from 'styled-components';
// import { Link } from 'react-router-dom'; // Import { Link } from 'react-router-dom';
import PortalQuery from '@graphql/Portal.gql';
import ServicesQuery from '@graphql/Services.gql'; import ServicesQuery from '@graphql/Services.gql';
import { processServices } from '@root/state/selectors'; import { processServices } from '@root/state/selectors';
@ -58,8 +57,6 @@ class ServiceList extends Component {
} }
} }
const PortalGql = graphql(PortalQuery, {});
const ServicesGql = graphql(ServicesQuery, { const ServicesGql = graphql(ServicesQuery, {
options(props) { options(props) {
return { return {
@ -78,6 +75,6 @@ const ServicesGql = graphql(ServicesQuery, {
}) })
}); });
const ServiceListWithData = compose(PortalGql, ServicesGql)(ServiceList); const ServiceListWithData = compose(ServicesGql)(ServiceList);
export default ServiceListWithData; export default ServiceListWithData;

View File

@ -1,8 +1,7 @@
import React from 'react'; import React from 'react';
import { compose, graphql } from 'react-apollo'; import { compose, graphql } from 'react-apollo';
// import { connect } from 'react-redux'; // Import { connect } from 'react-redux';
import styled from 'styled-components'; import styled from 'styled-components';
import PortalQuery from '@graphql/Portal.gql';
import ServicesQuery from '@graphql/ServicesTopology.gql'; import ServicesQuery from '@graphql/ServicesTopology.gql';
import unitcalc from 'unitcalc'; import unitcalc from 'unitcalc';
@ -10,12 +9,12 @@ import { processServices } from '@root/state/selectors';
import { LayoutContainer } from '@components/layout'; import { LayoutContainer } from '@components/layout';
import { Loader, ErrorMessage } from '@components/messaging'; import { Loader, ErrorMessage } from '@components/messaging';
// import { ServicesTooltip } from '@components/services'; // Import { ServicesTooltip } from '@components/services';
/* import { Topology } from 'joyent-ui-toolkit'; */ import { Topology } from 'joyent-ui-toolkit';
/*import ServicesTooltip from '@components/services/tooltip'; /* Import ServicesTooltip from '@components/services/tooltip';
import { toggleTooltip } from '@state/actions';*/ import { toggleTooltip } from '@state/actions'; */
const StyledBackground = styled.div` const StyledBackground = styled.div`
background-color: ${props => props.theme.whiteActive}; background-color: ${props => props.theme.whiteActive};
@ -44,14 +43,12 @@ const ServicesTopology = ({ push, services, datacenter, loading, error }) => {
return ( return (
<StyledBackground> <StyledBackground>
<StyledContainer> <StyledContainer>
{/* <Topology services={services} /> */} <Topology services={services} />
</StyledContainer> </StyledContainer>
</StyledBackground> </StyledBackground>
); );
}; };
const PortalGql = graphql(PortalQuery, {});
const ServicesGql = graphql(ServicesQuery, { const ServicesGql = graphql(ServicesQuery, {
options(props) { options(props) {
return { return {
@ -69,8 +66,6 @@ const ServicesGql = graphql(ServicesQuery, {
}) })
}); });
const ServicesTopologyWithData = compose(PortalGql, ServicesGql)( const ServicesTopologyWithData = compose(ServicesGql)(ServicesTopology);
ServicesTopology
);
export default ServicesTopologyWithData; export default ServicesTopologyWithData;

View File

@ -1,6 +1,8 @@
query Portal { query Portal {
portal { portal {
username user {
firstName
}
datacenter { datacenter {
uuid uuid
region region

View File

@ -1,9 +1,7 @@
import React from 'react'; import React from 'react';
import { BrowserRouter, Redirect, Route, Switch } from 'react-router-dom'; import { BrowserRouter, Redirect, Route, Switch } from 'react-router-dom';
import { Header } from '@components/navigation'; import { Header, Breadcrumb, Menu } from '@containers/navigation';
import { Breadcrumb, Menu } from '@containers/navigation';
import { DeploymentGroupList } from '@containers/deployment-groups'; import { DeploymentGroupList } from '@containers/deployment-groups';
import { import {

View File

@ -4,7 +4,13 @@
"region": "us-east-1" "region": "us-east-1"
}, },
"portal": { "portal": {
"username": "juditgreskovits" "user": {
"uuid": "uuid",
"login": "juditgreskovits",
"firstName": "Judit",
"lastName": "Greskovits",
"email": "name@email.com"
}
}, },
"deploymentGroups": [ "deploymentGroups": [
{ {

View File

@ -1,183 +1,213 @@
scalar Date
scalar Object
type Portal { scalar Date
username: String! scalar Object
datacenter: Datacenter! # we can infer dockerhost from this
deploymentGroups: [DeploymentGroup]!
}
type DeploymentGroup { type Portal {
uuid: ID! user: User!
name: String! datacenter: Datacenter!
slug: String! deploymentGroups: [DeploymentGroup]!
services(slug: String): [Service]! }
version: Version!
history: [Version]!
}
type ServiceScale { type User {
uuid: ID! uuid: ID!
serviceName: String! firstName: String!
replicas: Int! lastName: String!
} email: String!
login: String!
}
enum ConvergenceActionType { type DeploymentGroup {
NOOP uuid: ID!
CREATE name: String!
RECREATE slug: String!
START services(slug: String): [Service]!
} version: Version!
history: [Version]!
}
type ConvergenceAction { type ServiceScale {
uuid: ID! uuid: ID!
type: ConvergenceActionType! serviceName: String!
service: String! # service name replicas: Int!
machines: [String]! # instance machine ids }
}
type StateConvergencePlan { enum ConvergenceActionType {
uuid: ID! NOOP
running: Boolean! CREATE
actions: [ConvergenceAction]! RECREATE
} START
}
type Version { type ConvergenceAction {
uuid: ID! uuid: String!
created: Date! # Either Int or define scalar type: ConvergenceActionType!
manifest: Manifest! service: String! # service name
scale: [ServiceScale]! machines: [String]! # instance machine ids
plan: StateConvergencePlan }
}
enum ManifestType { type StateConvergencePlan {
COMPOSE uuid: String!
MARIPOSA running: Boolean!
} actions: [ConvergenceAction]!
}
enum ManifestFormat { type Version {
JSON created: Date! # Either Int or define scalar
YAML manifest: Manifest!
} scale: [ServiceScale]!
plan: StateConvergencePlan
}
type Manifest { enum ManifestType {
uuid: ID! COMPOSE
created: Date! MARIPOSA
type: ManifestType! }
format: ManifestFormat!
raw: String!
obj: Object!
}
# immutable enum ManifestFormat {
type Service { JSON
uuid: ID! # unique id for db row YAML
hash: String! # unique id for version of service }
name: String! # human readable name
slug: String!
instances: [Instance]!
# metrics: [MetricType]!
currentMetrics: [CurrentMetric]!
connections: [String!] # list of serviceUuids
parent: ID # parent service uuid
package: Package! # we don't have this in current mock data
}
# for metrics max / min (I guess) type Manifest {
type Package { uuid: String!
uuid: ID! created: Date!
name: String! type: ManifestType!
type: String! format: ManifestFormat!
memory: Float! raw: String!
disk: Float! obj: Object!
swap: Float! }
lwps: Int!
vcpus: Int!
version: String!
group: String!
}
enum InstanceStatus { # immutable
CREATED type Service {
RESTARTING uuid: String! # unique id for db row
RUNNING hash: String! # unique id for version of service
PAUSED name: String! # human readable name
EXITED slug: String!
DELETED instances: [Instance]!
} # metrics: [MetricType]!
currentMetrics: [CurrentMetric]!
connections: [String!] # list of serviceUuids
parent: ID # parent service uuid
package: Package! # we don't have this in current mock data
}
type Instance { # for metrics max / min (I guess)
uuid: ID! type Package {
slug: String! uuid: ID!
name: String! name: String!
machineId: String! type: String!
status: InstanceStatus! memory: Float!
# metrics: [InstanceMetric]! disk: Float!
} swap: Float!
lwps: Int!
vcpus: Int!
version: String!
group: String!
}
type Datacenter { enum InstanceStatus {
uuid: String! CREATED
# name: String! # Do we have 'official' human readable names? RESTARTING
region: String! RUNNING
} PAUSED
EXITED
DELETED
}
type InstanceMetric { type Instance {
type: MetricType! uuid: String!
data: [MetricData]! name: String!
} machineId: String!
status: InstanceStatus!
# metrics: [InstanceMetric]!
}
type CurrentMetric { type Datacenter {
name: String! uuid: String!
value: Float! # name: String! # Do we have 'official' human readable names?
measurement: String! region: String!
} }
type MetricType { type InstanceMetric {
uuid: ID! type: MetricType!
name: String! data: [MetricData]!
id: String! }
}
type MetricData { type CurrentMetric {
timestamp: Int! name: String!
value: Float! value: Float!
} measurement: String!
}
# we probably wont use some of these queries or arguments type MetricType {
# but this way we expose the entire db through gql uuid: String!
type Query { name: String!
portal: Portal id: String!
deploymentGroups(name: String, slug: String): [DeploymentGroup] }
deploymentGroup(uuid: ID, name: String, slug: String): DeploymentGroup
serviceScales(serviceName: String, versionUuid: ID): [ServiceScale]
serviceScale(uuid: ID!): ServiceScale
convergenceActions(type: ConvergenceActionType, service: String, versionUuid: ID): [ConvergenceAction]
convergenceAction(uuid: ID!): ConvergenceAction
stateConvergencePlans(running: Boolean, versionUuid: ID): [StateConvergencePlan]
stateConvergencePlan(uuid: ID!): StateConvergencePlan
versions(manifestUuid: ID, deploymentGroupUuid: ID): [Version]
version(uuid: ID, manifestUuid: ID): Version
manifests(type: String, deploymentGroupUuid: ID): [Manifest]
manifest(uuid: ID!): Manifest
services(name: String, slug: String, parentUuid: ID, deploymentGroupUuid: ID, deploymentGroupSlug: String): [Service]
service(uuid: ID, hash: ID): Service
packages(name: String, type: String, memory: Int, disk: Int, swap: Int, lwps: Int, vcpus: Int, version: String, group: String): [Package]
package(uuid: ID!): Package
instances(name: String!, machineId: ID, status: InstanceStatus, serviceUuid: ID, serviceSlug: String, deploymentGroupUuid: ID, deploymentGroupSlug: String): [Instance]
instance(uuid: ID!): Instance
datacenter(uuid: ID, region: String): Datacenter
}
type Mutation { type MetricData {
createDeploymentGroup(name: String!) : DeploymentGroup timestamp: Int!
updateDeploymentGroup(uuid: ID!, name: String!) : DeploymentGroup value: Float!
provisionManifest(deploymentGroupUuid: ID!, type: ManifestType!, format: ManifestFormat!, raw: String!) : Version }
scale(service: ID!, replicas: Int!) : Version
stopServices(uuids: [ID]!) : [Service] # Need to review queries
startServices(uuids: [ID]!) : [Service] type Query {
restartServices(uuids: [ID]!) : [Service] portal: Portal
deleteServices(uuids: [ID]!) : [Service] deploymentGroups: [DeploymentGroup]
stopInstances(uuids: [ID]!) : [Instance] deploymentGroup(uuid: String, slug: String): DeploymentGroup
startInstances(uuids: [ID]!) : [Instance] services(deploymentGroupUuid: String, deploymentGroupSlug: String): [Service]
restartInstances(uuids: [ID]!) : [Instance] service(uuid: String, slug: String): Service
} instances(serviceUuid: String, serviceSlug: String): [Instance]
instance(uuid: String, machineId: String): Instance
metricTypes: [MetricType]
metricData(instanceUuid: String!, metricType: String!, from: Date!, to: Date!): [InstanceMetric]!
package: Package
datacenters: [Datacenter]
# tmp test
instanceMetric: InstanceMetric!
}
# we probably wont use some of these queries or arguments
# but this way we expose the entire db through gql
type Query {
portal: Portal
user: User
deploymentGroups(name: String, slug: String): [DeploymentGroup]
deploymentGroup(uuid: ID, name: String, slug: String): DeploymentGroup
serviceScales(serviceName: String, versionUuid: ID): [ServiceScale]
serviceScale(uuid: ID!): ServiceScale
convergenceActions(type: ConvergenceActionType, service: String, versionUuid: ID): [ConvergenceAction]
convergenceAction(uuid: ID!): ConvergenceAction
stateConvergencePlans(running: Boolean, versionUuid: ID): [StateConvergencePlan]
stateConvergencePlan(uuid: ID!): StateConvergencePlan
versions(manifestUuid: ID, deploymentGroupUuid: ID): [Version]
version(uuid: ID, manifestUuid: ID): Version
manifests(type: String, deploymentGroupUuid: ID): [Manifest]
manifest(uuid: ID!): Manifest
services(name: String, slug: String, parentUuid: ID, deploymentGroupUuid: ID, deploymentGroupSlug: String): [Service]
service(uuid: ID, hash: ID): Service
packages(name: String, type: String, memory: Int, disk: Int, swap: Int, lwps: Int, vcpus: Int, version: String, group: String): [Package]
package(uuid: ID!): Package
instances(name: String!, machineId: ID, status: InstanceStatus, serviceUuid: ID, serviceSlug: String, deploymentGroupUuid: ID, deploymentGroupSlug: String): [Instance]
instance(uuid: ID!): Instance
datacenter(uuid: ID, region: String): Datacenter
}
type Mutation {
createDeploymentGroup(name: String!) : DeploymentGroup
updateDeploymentGroup(uuid: ID!, name: String!) : DeploymentGroup
provisionManifest(deploymentGroupUuid: ID!, type: ManifestType!, format: ManifestFormat!, raw: String!) : Version
scale(service: ID!, replicas: Int!) : Version
stopServices(uuids: [ID]!) : [Service]
startServices(uuids: [ID]!) : [Service]
restartServices(uuids: [ID]!) : [Service]
deleteServices(uuids: [ID]!) : [Service]
stopInstances(uuids: [ID]!) : [Instance]
startInstances(uuids: [ID]!) : [Instance]
restartInstances(uuids: [ID]!) : [Instance]
# reprovision() ???
}