1
0
mirror of https://github.com/yldio/copilot.git synced 2025-01-10 02:50:11 +02:00
copilot/frontend/src/containers/service/instances.js

62 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-01-03 00:32:29 +02:00
const React = require('react');
2017-01-09 21:08:47 +02:00
const ReactRedux = require('react-redux');
2017-01-03 00:32:29 +02:00
2017-01-11 23:11:48 +02:00
const actions = require('@state/actions');
2017-01-09 21:08:47 +02:00
const EmptyInstances = require('@components/empty/instances');
const PropTypes = require('@root/prop-types');
2017-01-12 18:13:45 +02:00
const InstanceList = require('@components/instance-list');
2017-01-09 21:08:47 +02:00
const selectors = require('@state/selectors');
2017-01-11 23:11:48 +02:00
const {
toggleInstanceCollapsed
} = actions;
2017-01-09 21:08:47 +02:00
const {
connect
} = ReactRedux;
const {
instancesByServiceIdSelector
} = selectors;
2017-01-12 18:13:45 +02:00
const Instances = (props) => {
const {
instances = [],
toggleCollapsed = () => null
} = props;
2017-01-11 23:11:48 +02:00
2017-01-09 21:08:47 +02:00
const empty = instances.length ? null : (
<EmptyInstances />
);
return (
<div>
{empty}
2017-01-12 18:13:45 +02:00
<InstanceList
instances={instances}
toggleCollapsed={toggleCollapsed}
/>
2017-01-09 21:08:47 +02:00
</div>
);
};
Instances.propTypes = {
2017-01-11 23:11:48 +02:00
instances: React.PropTypes.arrayOf(PropTypes.instance),
toggleCollapsed: React.PropTypes.func
2017-01-09 21:08:47 +02:00
};
const mapStateToProps = (state, {
2017-02-06 20:27:10 +02:00
match = {}
2017-01-09 21:08:47 +02:00
}) => ({
2017-02-06 20:27:10 +02:00
instances: instancesByServiceIdSelector(match.params.serviceId)(state)
2017-01-09 21:08:47 +02:00
});
2017-01-11 23:11:48 +02:00
const mapDispatchToProps = (dispatch) => ({
toggleCollapsed: (uuid) => dispatch(toggleInstanceCollapsed(uuid))
});
2017-01-09 21:08:47 +02:00
module.exports = connect(
2017-01-11 23:11:48 +02:00
mapStateToProps,
mapDispatchToProps
2017-01-09 21:08:47 +02:00
)(Instances);