From 2095eaf00c590f63f5dd908ea254a1aeca8eab12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Wed, 11 Jan 2017 17:42:47 +0000 Subject: [PATCH] recursive service item with metrics --- frontend/src/components/service-item/index.js | 126 +++++++++++++----- ui/src/components/list/transfer-props.js | 2 +- 2 files changed, 92 insertions(+), 36 deletions(-) diff --git a/frontend/src/components/service-item/index.js b/frontend/src/components/service-item/index.js index 2680f894..c3e6e528 100644 --- a/frontend/src/components/service-item/index.js +++ b/frontend/src/components/service-item/index.js @@ -1,14 +1,23 @@ +const forceArray = require('force-array'); const React = require('react'); const ReactRouter = require('react-router'); +const Styled = require('styled-components'); const Anchor = require('@ui/components/anchor'); +const Column = require('@ui/components/column'); const List = require('@ui/components/list'); +const MiniMetric = require('@ui/components/mini-metric'); const PropTypes = require('@root/prop-types'); +const Row = require('@ui/components/row'); const { Link } = ReactRouter; +const { + default: styled +} = Styled; + const { ListItem, ListItemView, @@ -22,30 +31,84 @@ const { ListItemHeader } = List; +const { + MiniMetricGraph, + MiniMetricMeta, + MiniMetricTitle, + MiniMetricSubtitle, + MiniMetricView +} = MiniMetric; + +const MetricsRow = styled(Row)` + margin: 0; + + & > div { + padding-left: 0; + padding-right: 0; + } +`; + const ServiceItem = ({ org = '', project = '', service = {} }) => { + const isChild = !!service.parent; + + const childs = forceArray(service.services).map((service) => ( + + )); + const to = `/${org}/projects/${project}/services/${service.id}`; - const childs = service.services.map((service) => ( - 1} - > - - - {service.name} - {service.instances} instances - - - Metrics - - - + const title = isChild ? ( + {service.name} + ) : ( + + + {Anchor.fn( + + {service.name} + + )} + + + ); + + const subtitle = ( + {service.instances} instances + ); + + const description = ( + Flags + ); + + const header = isChild ? null : ( + + + {title} + {subtitle} + {description} + + + + ); + + const metrics = service.metrics.map((metric, i) => ( + + + + Memory: 54% + (1280/3000 MB) + + + + )); const view = childs.length ? ( @@ -55,10 +118,14 @@ const ServiceItem = ({ ) : ( - Flags + {isChild && title} + {isChild && subtitle} + {description} - Metrics + + {metrics} + ); @@ -66,23 +133,12 @@ const ServiceItem = ({ return ( 1)} > - - - - - {Anchor.fn( - - {service.name} - - )} - - - {service.instances} instance - - - + {header} {view} ); diff --git a/ui/src/components/list/transfer-props.js b/ui/src/components/list/transfer-props.js index 0d8f4284..275dc6e3 100644 --- a/ui/src/components/list/transfer-props.js +++ b/ui/src/components/list/transfer-props.js @@ -4,7 +4,7 @@ const React = require('react'); const transfer = (parentProps, props) => { // eslint-disable-next-line react/prop-types return React.Children.map(props.children, (c) => { - return React.cloneElement(c, { + return c && React.cloneElement(c, { ...c.props, ...parentProps.reduce((sum, name) => ({ ...sum,