2017-01-11 19:42:47 +02:00
|
|
|
const forceArray = require('force-array');
|
2017-01-10 00:14:46 +02:00
|
|
|
const React = require('react');
|
2017-01-10 16:58:00 +02:00
|
|
|
const ReactRouter = require('react-router');
|
2017-01-11 19:42:47 +02:00
|
|
|
const Styled = require('styled-components');
|
2017-01-10 00:14:46 +02:00
|
|
|
|
2017-01-10 16:58:00 +02:00
|
|
|
const Anchor = require('@ui/components/anchor');
|
2017-01-11 19:42:47 +02:00
|
|
|
const Column = require('@ui/components/column');
|
2017-01-10 00:14:46 +02:00
|
|
|
const List = require('@ui/components/list');
|
2017-01-11 19:42:47 +02:00
|
|
|
const MiniMetric = require('@ui/components/mini-metric');
|
2017-01-10 00:14:46 +02:00
|
|
|
const PropTypes = require('@root/prop-types');
|
2017-01-11 19:42:47 +02:00
|
|
|
const Row = require('@ui/components/row');
|
2017-01-10 00:14:46 +02:00
|
|
|
|
2017-01-10 16:58:00 +02:00
|
|
|
const {
|
|
|
|
Link
|
|
|
|
} = ReactRouter;
|
2017-01-10 00:14:46 +02:00
|
|
|
|
2017-01-11 19:42:47 +02:00
|
|
|
const {
|
|
|
|
default: styled
|
|
|
|
} = Styled;
|
|
|
|
|
2017-01-10 00:14:46 +02:00
|
|
|
const {
|
|
|
|
ListItem,
|
|
|
|
ListItemView,
|
|
|
|
ListItemMeta,
|
|
|
|
ListItemTitle,
|
|
|
|
ListItemSubTitle,
|
|
|
|
ListItemDescription,
|
|
|
|
ListItemGroupView,
|
|
|
|
ListItemOutlet,
|
|
|
|
ListItemOptions,
|
|
|
|
ListItemHeader
|
|
|
|
} = List;
|
|
|
|
|
2017-01-11 19:42:47 +02:00
|
|
|
const {
|
|
|
|
MiniMetricGraph,
|
|
|
|
MiniMetricMeta,
|
|
|
|
MiniMetricTitle,
|
|
|
|
MiniMetricSubtitle,
|
|
|
|
MiniMetricView
|
|
|
|
} = MiniMetric;
|
|
|
|
|
|
|
|
const MetricsRow = styled(Row)`
|
|
|
|
margin: 0;
|
|
|
|
|
|
|
|
& > div {
|
|
|
|
padding-left: 0;
|
|
|
|
padding-right: 0;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2017-01-10 16:58:00 +02:00
|
|
|
const ServiceItem = ({
|
2017-01-10 00:14:46 +02:00
|
|
|
org = '',
|
|
|
|
project = '',
|
|
|
|
service = {}
|
|
|
|
}) => {
|
2017-01-11 19:42:47 +02:00
|
|
|
const isChild = !!service.parent;
|
2017-01-10 00:14:46 +02:00
|
|
|
|
2017-01-11 19:42:47 +02:00
|
|
|
const childs = forceArray(service.services).map((service) => (
|
|
|
|
<ServiceItem
|
2017-01-10 00:14:46 +02:00
|
|
|
key={service.uuid}
|
2017-01-11 19:42:47 +02:00
|
|
|
org={org}
|
|
|
|
project={project}
|
|
|
|
service={service}
|
|
|
|
/>
|
|
|
|
));
|
|
|
|
|
|
|
|
const to = `/${org}/projects/${project}/services/${service.id}`;
|
|
|
|
|
|
|
|
const title = isChild ? (
|
|
|
|
<ListItemTitle>{service.name}</ListItemTitle>
|
|
|
|
) : (
|
|
|
|
<ListItemTitle>
|
|
|
|
<Link to={to}>
|
|
|
|
{Anchor.fn(
|
|
|
|
<Anchor secondary>
|
|
|
|
{service.name}
|
|
|
|
</Anchor>
|
|
|
|
)}
|
|
|
|
</Link>
|
|
|
|
</ListItemTitle>
|
|
|
|
);
|
|
|
|
|
|
|
|
const subtitle = (
|
|
|
|
<ListItemSubTitle>{service.instances} instances</ListItemSubTitle>
|
|
|
|
);
|
|
|
|
|
|
|
|
const description = (
|
|
|
|
<ListItemDescription>Flags</ListItemDescription>
|
|
|
|
);
|
|
|
|
|
|
|
|
const header = isChild ? null : (
|
|
|
|
<ListItemHeader>
|
|
|
|
<ListItemMeta>
|
|
|
|
{title}
|
|
|
|
{subtitle}
|
|
|
|
{description}
|
|
|
|
</ListItemMeta>
|
|
|
|
<ListItemOptions>…</ListItemOptions>
|
|
|
|
</ListItemHeader>
|
|
|
|
);
|
|
|
|
|
|
|
|
const metrics = service.metrics.map((metric, i) => (
|
|
|
|
<Column key={i} xs={4}>
|
|
|
|
<MiniMetricView borderless>
|
|
|
|
<MiniMetricMeta>
|
|
|
|
<MiniMetricTitle>Memory: 54%</MiniMetricTitle>
|
|
|
|
<MiniMetricSubtitle>(1280/3000 MB)</MiniMetricSubtitle>
|
|
|
|
</MiniMetricMeta>
|
|
|
|
<MiniMetricGraph data={metric.data} />
|
|
|
|
</MiniMetricView>
|
|
|
|
</Column>
|
2017-01-10 00:14:46 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
const view = childs.length ? (
|
|
|
|
<ListItemGroupView>
|
|
|
|
{childs}
|
|
|
|
</ListItemGroupView>
|
|
|
|
) : (
|
|
|
|
<ListItemView>
|
|
|
|
<ListItemMeta>
|
2017-01-11 19:42:47 +02:00
|
|
|
{isChild && title}
|
|
|
|
{isChild && subtitle}
|
|
|
|
{description}
|
2017-01-10 00:14:46 +02:00
|
|
|
</ListItemMeta>
|
|
|
|
<ListItemOutlet>
|
2017-01-11 19:42:47 +02:00
|
|
|
<MetricsRow>
|
|
|
|
{metrics}
|
|
|
|
</MetricsRow>
|
2017-01-10 00:14:46 +02:00
|
|
|
</ListItemOutlet>
|
|
|
|
</ListItemView>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2017-01-10 16:58:00 +02:00
|
|
|
<ListItem
|
|
|
|
collapsed={service.collapsed}
|
2017-01-11 19:42:47 +02:00
|
|
|
flat={isChild}
|
|
|
|
headed={!isChild}
|
|
|
|
key={service.uuid}
|
|
|
|
stacked={isChild && (service.instances > 1)}
|
2017-01-10 16:58:00 +02:00
|
|
|
>
|
2017-01-11 19:42:47 +02:00
|
|
|
{header}
|
2017-01-10 00:14:46 +02:00
|
|
|
{view}
|
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2017-01-10 16:58:00 +02:00
|
|
|
ServiceItem.propTypes = {
|
2017-01-10 00:14:46 +02:00
|
|
|
org: React.PropTypes.string,
|
|
|
|
project: React.PropTypes.string,
|
|
|
|
service: PropTypes.service
|
|
|
|
};
|
|
|
|
|
2017-01-10 16:58:00 +02:00
|
|
|
module.exports = ServiceItem;
|