diff --git a/frontend/src/components/services/view.js b/frontend/src/components/services/view.js index b708f1a0..adbcbc43 100644 --- a/frontend/src/components/services/view.js +++ b/frontend/src/components/services/view.js @@ -21,39 +21,30 @@ const StyledLegend = styled(Legend)` const ServicesView = ({ children, - org = {}, - match = {}, - project = {}, - services = [], - router = {} + onToggle, + services, + toggleValue }) => { - const toggle = () => { - if(!services) { - return null; + + const onToggleChange = (evt) => { + evt.preventDefault(); + + const value = evt.target.value; + if(value !== toggleValue) { + onToggle(value); } - - const value = match.path === '/:org/projects/:projectId/services' ? - 'topology' : 'list'; - - const onToggleChange = (evt) => { - evt.preventDefault(); - - router.push(`/${org.id}/projects/${project.id}/services${ - evt.target.value === 'list' ? '/list' : '' - }`); - }; - - return ( - - View - - Topology - List - - - ); }; + const toggle = services ? ( + + View + + Topology + List + + + ) : null; + const content = services.length ? children : ( ); @@ -62,7 +53,7 @@ const ServicesView = ({

Services

- { toggle() } + { toggle } { content }
@@ -71,11 +62,9 @@ const ServicesView = ({ ServicesView.propTypes = { children: React.PropTypes.node, - match: React.PropTypes.object.isRequired, - org: PropTypes.org, - project: PropTypes.project, - router: React.PropTypes.object, - services: React.PropTypes.arrayOf(PropTypes.service) + onToggle: React.PropTypes.func.isRequired, + services: React.PropTypes.arrayOf(PropTypes.service), + toggleValue: React.PropTypes.string.isRequired }; export default ServicesView; diff --git a/frontend/src/containers/project/services.js b/frontend/src/containers/project/services.js index 7c0f3af9..ae6e5048 100644 --- a/frontend/src/containers/project/services.js +++ b/frontend/src/containers/project/services.js @@ -1,20 +1,25 @@ import React from 'react'; import { Switch, Route } from 'react-router-dom'; import Section from './section'; -import ServicesTopology from '@containers/services'; +import ServicesTopology from '@containers/services/topology'; import ServicesList from '@containers/services/list'; +import Services from '@containers/services'; import Service from '@containers/service'; export default () => { const topology = (props) => (
- + + +
); - + const list = (props) => (
- + + +
); diff --git a/frontend/src/containers/services/index.js b/frontend/src/containers/services/index.js index 30ccadbe..3284f04f 100644 --- a/frontend/src/containers/services/index.js +++ b/frontend/src/containers/services/index.js @@ -1,7 +1,6 @@ import React from 'react'; import { connect } from 'react-redux'; import PropTypes from '@root/prop-types'; -import { TopologyGraph } from '@ui/components/topology'; import ServicesView from '@components/services/view'; import { @@ -12,29 +11,56 @@ import { const Services = (props) => { const { - services = [] + org = {}, + project = {}, + services = [], + children, + path, + push } = props; + const toggleValue = path === '/:org/projects/:projectId/services' ? + 'topology' : 'list'; + + const onToggle = (value) => { + const path = `/${org.id}/projects/${project.id}/services${ + value === 'list' ? '/list' : '' + }`; + push(path); + }; + return ( - - + + {children} ); }; Services.propTypes = { + children: React.PropTypes.node, + org: PropTypes.org, + path: React.PropTypes.string.isRequired, + project: PropTypes.project, + push: React.PropTypes.func.isRequired, services: React.PropTypes.arrayOf(PropTypes.service) }; const mapStateToProps = (state, { match = { - params: {} + params: {}, + path: '' }, push }) => ({ org: orgByIdSelector(match.params.org)(state), project: projectByIdSelector(match.params.projectId)(state), - services: servicesForTopologySelector(match.params.projectId)(state) + services: servicesForTopologySelector(match.params.projectId)(state), + path: match.path, + push: push }); export default connect( diff --git a/frontend/src/containers/services/list.js b/frontend/src/containers/services/list.js index c65e4c20..7026abdf 100644 --- a/frontend/src/containers/services/list.js +++ b/frontend/src/containers/services/list.js @@ -2,7 +2,6 @@ import React from 'react'; import { connect } from 'react-redux'; import PropTypes from '@root/prop-types'; import ServiceItem from '@components/service/item'; -import ServicesView from '@components/services/view'; import { orgByIdSelector, @@ -27,9 +26,9 @@ const Services = (props) => { )); return ( - +
{serviceList} - +
); }; diff --git a/frontend/src/containers/services/topology.js b/frontend/src/containers/services/topology.js new file mode 100644 index 00000000..e00a5691 --- /dev/null +++ b/frontend/src/containers/services/topology.js @@ -0,0 +1,38 @@ +import React from 'react'; +import { connect } from 'react-redux'; +import PropTypes from '@root/prop-types'; +import { TopologyGraph } from '@ui/components/topology'; + +import { + orgByIdSelector, + projectByIdSelector, + servicesForTopologySelector +} from '@state/selectors'; + +const Services = (props) => { + const { + services = [] + } = props; + + return ( + + ); +}; + +Services.propTypes = { + services: React.PropTypes.arrayOf(PropTypes.service) +}; + +const mapStateToProps = (state, { + match = { + params: {} + } +}) => ({ + org: orgByIdSelector(match.params.org)(state), + project: projectByIdSelector(match.params.projectId)(state), + services: servicesForTopologySelector(match.params.projectId)(state) +}); + +export default connect( + mapStateToProps +)(Services); diff --git a/ui/src/components/topology/constants.js b/ui/src/components/topology/constants.js index 8bc0ae91..e628ed96 100644 --- a/ui/src/components/topology/constants.js +++ b/ui/src/components/topology/constants.js @@ -65,8 +65,8 @@ const Rects = { nodeRectWithChildren: { left: -Sizes.nodeSizeWithChildren.width/2, right: Sizes.nodeSizeWithChildren.width/2, - top: -Sizes.nodeSizeWithChildren.height/2 + Sizes.contentSize.height/2, - bottom: Sizes.nodeSizeWithChildren.height/2 + Sizes.contentSize.height/2 + top: -Sizes.nodeSizeWithChildren.height/2 + Sizes.contentSize.height/3, + bottom: Sizes.nodeSizeWithChildren.height/2 + Sizes.contentSize.height/3 } };