2017-01-03 00:32:29 +02:00
|
|
|
const React = require('react');
|
2017-01-12 12:25:20 +02:00
|
|
|
const ReactRedux = require('react-redux');
|
|
|
|
const PropTypes = require('@root/prop-types');
|
|
|
|
const selectors = require('@state/selectors');
|
2017-01-11 12:14:56 +02:00
|
|
|
const AddMetrics = require('../metrics/add-metrics');
|
2017-01-12 12:25:20 +02:00
|
|
|
const actions = require('@state/actions');
|
2017-01-03 00:32:29 +02:00
|
|
|
|
2017-01-12 12:25:20 +02:00
|
|
|
const {
|
|
|
|
connect
|
|
|
|
} = ReactRedux;
|
|
|
|
|
|
|
|
const {
|
|
|
|
metricsByServiceIdSelector,
|
|
|
|
serviceByIdSelector
|
|
|
|
} = selectors;
|
|
|
|
|
|
|
|
const {
|
|
|
|
addMetric
|
|
|
|
} = actions;
|
|
|
|
|
|
|
|
const Metrics = ({
|
|
|
|
addMetric,
|
|
|
|
metrics,
|
|
|
|
metricTypes,
|
|
|
|
service
|
|
|
|
}) => {
|
|
|
|
|
|
|
|
const onAddMetric = (metric) => {
|
|
|
|
addMetric({
|
|
|
|
id: metric,
|
|
|
|
service: service.uuid
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2017-01-11 12:14:56 +02:00
|
|
|
<div>
|
2017-01-12 12:25:20 +02:00
|
|
|
<p>metrics</p>
|
|
|
|
<div>
|
|
|
|
<AddMetrics
|
|
|
|
metricTypes={metricTypes}
|
|
|
|
metrics={metrics}
|
|
|
|
onAddMetric={onAddMetric}
|
|
|
|
/>
|
|
|
|
</div>
|
2017-01-11 12:14:56 +02:00
|
|
|
</div>
|
2017-01-12 12:25:20 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Metrics.propTypes = {
|
|
|
|
addMetric: React.PropTypes.func.isRequired,
|
|
|
|
metricTypes: PropTypes.metricTypes,
|
|
|
|
metrics: React.PropTypes.arrayOf(PropTypes.metric),
|
|
|
|
service: PropTypes.service
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapStateToProps = (state, {
|
|
|
|
params = {}
|
|
|
|
}) => ({
|
|
|
|
metrics: metricsByServiceIdSelector(params.serviceId)(state),
|
|
|
|
metricTypes: state.metrics.ui.types,
|
|
|
|
service: serviceByIdSelector(params.serviceId)(state)
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
addMetric: (payload) => dispatch(addMetric(payload))
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(Metrics);
|