1
0
mirror of https://github.com/yldio/copilot.git synced 2025-01-26 02:40:12 +02:00
copilot/frontend/src/containers/service/instances.js
2017-02-07 09:55:18 +00:00

64 lines
1.3 KiB
JavaScript

const React = require('react');
const ReactRedux = require('react-redux');
const actions = require('@state/actions');
const EmptyInstances = require('@components/empty/instances');
const PropTypes = require('@root/prop-types');
const InstanceList = require('@components/instance-list');
const selectors = require('@state/selectors');
const {
toggleInstanceCollapsed
} = actions;
const {
connect
} = ReactRedux;
const {
instancesByServiceIdSelector
} = selectors;
const Instances = (props) => {
const {
instances = [],
toggleCollapsed = () => null
} = props;
const empty = instances.length ? null : (
<EmptyInstances />
);
return (
<div>
{empty}
<InstanceList
instances={instances}
toggleCollapsed={toggleCollapsed}
/>
</div>
);
};
Instances.propTypes = {
instances: React.PropTypes.arrayOf(PropTypes.instance),
toggleCollapsed: React.PropTypes.func
};
const mapStateToProps = (state, {
match = {
params: {}
}
}) => ({
instances: instancesByServiceIdSelector(match.params.serviceId)(state)
});
const mapDispatchToProps = (dispatch) => ({
toggleCollapsed: (uuid) => dispatch(toggleInstanceCollapsed(uuid))
});
module.exports = connect(
mapStateToProps,
mapDispatchToProps
)(Instances);