2017-02-28 20:34:48 +02:00
|
|
|
import React from 'react';
|
2017-03-09 17:17:47 +02:00
|
|
|
import styled from 'styled-components';
|
2017-02-28 20:34:48 +02:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import PropTypes from '@root/prop-types';
|
2017-03-22 18:50:26 +02:00
|
|
|
import { LayoutContainer } from '@components/layout';
|
2017-02-28 20:34:48 +02:00
|
|
|
import ServiceItem from '@components/service/item';
|
2017-03-07 14:03:55 +02:00
|
|
|
import UnmanagedInstances from '@components/services/unmanaged-instances';
|
2017-03-09 17:17:47 +02:00
|
|
|
import { toggleTooltip } from '@state/actions';
|
|
|
|
import ServicesTooltip from '@components/services/tooltip';
|
2017-03-17 21:27:15 +02:00
|
|
|
import { subscribeMetric } from '@state/thunks';
|
2017-02-28 20:34:48 +02:00
|
|
|
|
|
|
|
import {
|
|
|
|
orgByIdSelector,
|
|
|
|
projectByIdSelector,
|
2017-03-09 17:17:47 +02:00
|
|
|
servicesByProjectIdSelector,
|
|
|
|
serviceUiTooltipSelector
|
2017-02-28 20:34:48 +02:00
|
|
|
} from '@state/selectors';
|
|
|
|
|
2017-03-09 17:17:47 +02:00
|
|
|
const StyledContainer = styled.div`
|
|
|
|
position: relative;
|
|
|
|
`;
|
|
|
|
|
2017-03-17 21:27:15 +02:00
|
|
|
// TMP - single source of truth
|
|
|
|
const duration = '1 hour';
|
|
|
|
const interval = '2 minutes';
|
|
|
|
|
2017-03-09 17:17:47 +02:00
|
|
|
class Services extends React.Component {
|
2017-03-17 21:27:15 +02:00
|
|
|
// we DON'T want to unsubscribe once we started going
|
|
|
|
componentWillMount() {
|
|
|
|
this.props.subscribeMetric(interval);
|
|
|
|
}
|
|
|
|
|
2017-03-09 17:17:47 +02:00
|
|
|
ref(name) {
|
|
|
|
this._refs = this._refs || {};
|
|
|
|
|
|
|
|
return (el) => {
|
|
|
|
this._refs[name] = el;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
org = {},
|
|
|
|
project = {},
|
|
|
|
services = [],
|
2017-03-17 21:27:15 +02:00
|
|
|
toggleTooltip = () => ({}),
|
2017-03-09 17:17:47 +02:00
|
|
|
uiTooltip = {}
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const onQuickActions = (evt, service) => {
|
|
|
|
const list = this._refs.container;
|
|
|
|
const listRect = list.getBoundingClientRect();
|
|
|
|
const button = evt.currentTarget;
|
|
|
|
const buttonRect = button.getBoundingClientRect();
|
|
|
|
|
|
|
|
const position = {
|
|
|
|
left: buttonRect.left - listRect.left
|
|
|
|
+ (buttonRect.right - buttonRect.left)/2,
|
|
|
|
top: buttonRect.bottom - listRect.top
|
|
|
|
};
|
|
|
|
|
|
|
|
toggleTooltip({
|
|
|
|
service: service,
|
2017-03-23 14:19:30 +02:00
|
|
|
position: position,
|
|
|
|
data: {
|
|
|
|
serviceId: service.id,
|
|
|
|
orgId: org.id,
|
|
|
|
projectId: project.id
|
|
|
|
}
|
2017-03-09 17:17:47 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-03-22 18:50:21 +02:00
|
|
|
const handleTooltipBlur = (evt) => onQuickActions(evt, uiTooltip.service);
|
2017-03-09 17:17:47 +02:00
|
|
|
|
|
|
|
const serviceList = services.map((service) => (
|
|
|
|
<ServiceItem
|
|
|
|
key={service.uuid}
|
|
|
|
onQuickActions={onQuickActions}
|
|
|
|
org={org.id}
|
|
|
|
project={project.id}
|
|
|
|
service={service}
|
|
|
|
uiTooltip={uiTooltip}
|
|
|
|
/>
|
|
|
|
));
|
|
|
|
|
2017-03-22 18:50:21 +02:00
|
|
|
// TODO replace `false` with a check for existence unmanaged instances
|
|
|
|
// eslint-disable-next-line no-constant-condition
|
|
|
|
const unmanagedInstances = false ? (
|
|
|
|
<UnmanagedInstances instances={0} />
|
|
|
|
) : null;
|
|
|
|
|
2017-03-09 17:17:47 +02:00
|
|
|
return (
|
2017-03-22 18:50:26 +02:00
|
|
|
<LayoutContainer>
|
2017-03-22 18:50:21 +02:00
|
|
|
{unmanagedInstances}
|
2017-03-09 17:17:47 +02:00
|
|
|
<StyledContainer>
|
|
|
|
<div ref={this.ref('container')}>
|
|
|
|
{serviceList}
|
2017-03-22 18:50:21 +02:00
|
|
|
<ServicesTooltip {...uiTooltip} onBlur={handleTooltipBlur} />
|
2017-03-09 17:17:47 +02:00
|
|
|
</div>
|
|
|
|
</StyledContainer>
|
2017-03-22 18:50:26 +02:00
|
|
|
</LayoutContainer>
|
2017-03-09 17:17:47 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-02-28 20:34:48 +02:00
|
|
|
|
|
|
|
Services.propTypes = {
|
|
|
|
org: PropTypes.org,
|
|
|
|
project: PropTypes.project,
|
2017-03-09 17:17:47 +02:00
|
|
|
services: React.PropTypes.arrayOf(PropTypes.service),
|
|
|
|
toggleTooltip: React.PropTypes.func,
|
2017-03-17 21:27:15 +02:00
|
|
|
uiTooltip: React.PropTypes.object,
|
|
|
|
subscribeMetric: React.PropTypes.func
|
2017-02-28 20:34:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const mapStateToProps = (state, {
|
|
|
|
match = {
|
|
|
|
params: {}
|
|
|
|
},
|
|
|
|
push
|
|
|
|
}) => ({
|
|
|
|
org: orgByIdSelector(match.params.org)(state),
|
|
|
|
project: projectByIdSelector(match.params.projectId)(state),
|
2017-03-17 21:27:15 +02:00
|
|
|
services: servicesByProjectIdSelector(match.params.projectId, {
|
|
|
|
duration,
|
|
|
|
interval
|
|
|
|
})(state),
|
2017-03-09 17:17:47 +02:00
|
|
|
uiTooltip: serviceUiTooltipSelector(state)
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
2017-03-17 21:27:15 +02:00
|
|
|
toggleTooltip: (data) => dispatch(toggleTooltip(data)),
|
|
|
|
subscribeMetric: (payload) => dispatch(subscribeMetric(payload))
|
2017-02-28 20:34:48 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(
|
2017-03-09 17:17:47 +02:00
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
2017-02-28 20:34:48 +02:00
|
|
|
)(Services);
|