joyent-portal/packages/cp-frontend/src/containers/instances/list.js

78 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-05-11 20:16:52 +03:00
import React, { Component } from 'react';
// Import PropTypes from 'prop-types';
2017-05-22 20:13:24 +03:00
import { compose, graphql } from 'react-apollo';
2017-05-11 20:16:52 +03:00
import InstancesQuery from '@graphql/Instances.gql';
2017-05-22 20:13:24 +03:00
import { LayoutContainer } from '@components/layout';
import { Loader, ErrorMessage } from '@components/messaging';
import { InstanceListItem, EmptyInstances } from '@components/instances';
2017-05-11 20:16:52 +03:00
class InstanceList extends Component {
render() {
const { instances, loading, error } = this.props;
2017-05-22 20:13:24 +03:00
console.log('instances = ', instances);
console.log('loading = ', loading);
console.log('error = ', error);
if (loading) {
2017-05-22 20:13:24 +03:00
return (
<LayoutContainer>
<Loader />
</LayoutContainer>
);
} else if (error) {
2017-05-22 20:13:24 +03:00
return (
<LayoutContainer>
<ErrorMessage message="Oops, and error occured while loading your instances." />
2017-05-22 20:13:24 +03:00
</LayoutContainer>
);
2017-05-22 20:13:24 +03:00
}
2017-05-11 20:16:52 +03:00
const instanceList = instances
? instances.map((instance, index) =>
<InstanceListItem
instance={instance}
key={instance.id}
toggleCollapsed={() => null}
/>
)
: <EmptyInstances />;
2017-05-11 20:16:52 +03:00
return (
2017-05-22 20:13:24 +03:00
<LayoutContainer>
2017-05-11 20:16:52 +03:00
<div>
<h2>Instance List</h2>
</div>
{instanceList}
2017-05-22 20:13:24 +03:00
</LayoutContainer>
2017-05-11 20:16:52 +03:00
);
}
}
2017-05-22 20:13:24 +03:00
const InstanceListGql = graphql(InstancesQuery, {
2017-05-11 20:16:52 +03:00
options(props) {
2017-05-22 20:13:24 +03:00
const params = props.match.params;
const deploymentGroupSlug = params.deploymentGroup;
const serviceSlug = params.service;
2017-05-11 20:16:52 +03:00
return {
variables: {
deploymentGroupSlug,
serviceSlug
}
2017-05-11 20:16:52 +03:00
};
},
props: ({ data: { deploymentGroup, loading, error } }) => ({
instances: deploymentGroup && deploymentGroup.services
? deploymentGroup.services.reduce(
(instances, service) => instances.concat(service.instances),
[]
)
: null,
2017-05-11 20:16:52 +03:00
loading,
error
})
2017-05-22 20:13:24 +03:00
});
const InstanceListWithData = compose(InstanceListGql)(InstanceList);
2017-05-11 20:16:52 +03:00
export default InstanceListWithData;