2017-05-18 21:21:33 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { compose, graphql } from 'react-apollo';
|
2017-06-01 12:28:59 +03:00
|
|
|
import { connect } from 'react-redux';
|
2017-05-18 21:21:33 +03:00
|
|
|
import styled from 'styled-components';
|
|
|
|
import ServicesQuery from '@graphql/ServicesTopology.gql';
|
|
|
|
import unitcalc from 'unitcalc';
|
|
|
|
|
|
|
|
import { processServices } from '@root/state/selectors';
|
2017-06-01 12:28:59 +03:00
|
|
|
import { toggleServicesQuickActions } from '@root/state/actions';
|
2017-05-18 21:21:33 +03:00
|
|
|
|
|
|
|
import { LayoutContainer } from '@components/layout';
|
|
|
|
import { Loader, ErrorMessage } from '@components/messaging';
|
2017-06-01 12:28:59 +03:00
|
|
|
import { ServicesQuickActions } from '@components/services';
|
2017-05-18 21:21:33 +03:00
|
|
|
|
2017-05-25 19:32:19 +03:00
|
|
|
import { Topology } from 'joyent-ui-toolkit';
|
2017-05-18 21:21:33 +03:00
|
|
|
|
|
|
|
const StyledBackground = styled.div`
|
2017-06-01 12:28:59 +03:00
|
|
|
padding: ${unitcalc(4)};
|
2017-05-18 21:21:33 +03:00
|
|
|
background-color: ${props => props.theme.whiteActive};
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledContainer = styled.div`
|
|
|
|
position: relative;
|
|
|
|
`;
|
|
|
|
|
2017-06-01 12:28:59 +03:00
|
|
|
const ServicesTopology = ({
|
|
|
|
url,
|
|
|
|
push,
|
|
|
|
services,
|
|
|
|
datacenter,
|
|
|
|
loading,
|
|
|
|
error,
|
|
|
|
servicesQuickActions,
|
|
|
|
toggleServicesQuickActions
|
|
|
|
}) => {
|
2017-05-18 21:21:33 +03:00
|
|
|
if (loading) {
|
|
|
|
return (
|
|
|
|
<LayoutContainer>
|
|
|
|
<Loader />
|
|
|
|
</LayoutContainer>
|
|
|
|
);
|
|
|
|
} else if (error) {
|
|
|
|
return (
|
|
|
|
<LayoutContainer>
|
|
|
|
<ErrorMessage message="Oops, and error occured while loading your services." />
|
|
|
|
</LayoutContainer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-06-01 12:28:59 +03:00
|
|
|
const handleQuickActionsClick = (evt, tooltipData) => {
|
|
|
|
toggleServicesQuickActions(tooltipData);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleTooltipBlur = evt => {
|
|
|
|
toggleServicesQuickActions({ show: false });
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleNodeTitleClick = (evt, { service }) => {
|
|
|
|
push(`${url.split('/').slice(0, 3).join('/')}/services/${service.slug}`);
|
|
|
|
};
|
|
|
|
|
2017-05-18 21:21:33 +03:00
|
|
|
return (
|
|
|
|
<StyledBackground>
|
|
|
|
<StyledContainer>
|
2017-06-01 12:28:59 +03:00
|
|
|
<Topology
|
|
|
|
services={services}
|
|
|
|
onQuickActionsClick={handleQuickActionsClick}
|
|
|
|
onNodeTitleClick={handleNodeTitleClick}
|
|
|
|
/>
|
|
|
|
<ServicesQuickActions
|
|
|
|
show={servicesQuickActions.show}
|
|
|
|
position={servicesQuickActions.position}
|
|
|
|
onBlur={handleTooltipBlur}
|
|
|
|
/>
|
2017-05-18 21:21:33 +03:00
|
|
|
</StyledContainer>
|
|
|
|
</StyledBackground>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2017-06-01 12:28:59 +03:00
|
|
|
const mapStateToProps = (state, ownProps) => ({
|
|
|
|
servicesQuickActions: state.ui.services.quickActions,
|
|
|
|
url: ownProps.match.url,
|
|
|
|
push: ownProps.history.push
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
toggleServicesQuickActions: data => dispatch(toggleServicesQuickActions(data))
|
|
|
|
});
|
|
|
|
|
|
|
|
const UiConnect = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
|
2017-05-18 21:21:33 +03:00
|
|
|
const ServicesGql = graphql(ServicesQuery, {
|
|
|
|
options(props) {
|
|
|
|
return {
|
|
|
|
variables: {
|
|
|
|
deploymentGroupSlug: props.match.params.deploymentGroup
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
props: ({ data: { deploymentGroup, loading, error } }) => ({
|
|
|
|
services: deploymentGroup
|
|
|
|
? processServices(deploymentGroup.services, null)
|
|
|
|
: null,
|
|
|
|
loading,
|
|
|
|
error
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-06-01 12:28:59 +03:00
|
|
|
const ServicesTopologyWithData = compose(ServicesGql, UiConnect)(
|
|
|
|
ServicesTopology
|
|
|
|
);
|
2017-05-18 21:21:33 +03:00
|
|
|
|
|
|
|
export default ServicesTopologyWithData;
|