1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-14 15:20:06 +02:00
copilot/frontend/src/components/service-item/index.js

116 lines
2.3 KiB
JavaScript
Raw Normal View History

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');
const ReactRouter = require('react-router');
2017-01-10 00:14:46 +02:00
const Anchor = require('@ui/components/anchor');
2017-01-10 00:14:46 +02:00
const List = require('@ui/components/list');
2017-01-11 23:11:48 +02:00
const MetricsRow = require('@components/metrics-row');
2017-01-10 00:14:46 +02:00
const PropTypes = require('@root/prop-types');
const {
Link
} = ReactRouter;
2017-01-10 00:14:46 +02:00
const {
ListItem,
ListItemView,
ListItemMeta,
ListItemTitle,
ListItemSubTitle,
ListItemDescription,
ListItemGroupView,
ListItemOutlet,
ListItemOptions,
ListItemHeader
} = List;
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>
);
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 23:11:48 +02:00
<MetricsRow metrics={service.metrics} />
2017-01-10 00:14:46 +02:00
</ListItemOutlet>
</ListItemView>
);
return (
<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-11 19:42:47 +02:00
{header}
2017-01-10 00:14:46 +02:00
{view}
</ListItem>
);
};
ServiceItem.propTypes = {
2017-01-10 00:14:46 +02:00
org: React.PropTypes.string,
project: React.PropTypes.string,
service: PropTypes.service
};
module.exports = ServiceItem;