2017-10-25 20:09:02 +03:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { compose, graphql } from 'react-apollo';
|
|
|
|
import find from 'lodash.find';
|
|
|
|
import get from 'lodash.get';
|
|
|
|
|
|
|
|
import {
|
|
|
|
ViewContainer,
|
|
|
|
StatusLoader,
|
|
|
|
Message,
|
|
|
|
MessageDescription,
|
|
|
|
MessageTitle
|
|
|
|
} from 'joyent-ui-toolkit';
|
|
|
|
|
|
|
|
import ListDNS from '@graphql/list-dns.gql';
|
|
|
|
|
|
|
|
const DNS = ({ instance, loading, error }) => {
|
2018-01-05 17:42:09 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
2017-10-25 20:09:02 +03:00
|
|
|
const { name, dns_names } = instance || {};
|
2018-01-05 17:42:09 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
2017-10-25 20:09:02 +03:00
|
|
|
const _loading = loading && !name && !dns_names && <StatusLoader />;
|
2017-11-23 14:18:38 +02:00
|
|
|
const _summary = !_loading &&
|
|
|
|
instance && <pre>{JSON.stringify(dns_names, null, 2)}</pre>;
|
2017-10-25 20:09:02 +03:00
|
|
|
|
|
|
|
const _error = error &&
|
2017-11-09 13:27:32 +02:00
|
|
|
!_loading &&
|
|
|
|
!instance && (
|
|
|
|
<Message error>
|
|
|
|
<MessageTitle>Ooops!</MessageTitle>
|
|
|
|
<MessageDescription>
|
|
|
|
An error occurred while loading your instance DNS
|
|
|
|
</MessageDescription>
|
|
|
|
</Message>
|
|
|
|
);
|
2017-10-25 20:09:02 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ViewContainer center={Boolean(_loading)} main>
|
|
|
|
{_loading}
|
|
|
|
{_error}
|
|
|
|
{_summary}
|
|
|
|
</ViewContainer>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
DNS.propTypes = {
|
|
|
|
loading: PropTypes.bool
|
|
|
|
};
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
graphql(ListDNS, {
|
|
|
|
options: ({ match }) => ({
|
|
|
|
variables: {
|
|
|
|
name: get(match, 'params.instance')
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
props: ({ data: { loading, error, variables, ...rest } }) => ({
|
|
|
|
instance: find(get(rest, 'machines', []), ['name', variables.name]),
|
|
|
|
loading,
|
|
|
|
error
|
|
|
|
})
|
|
|
|
})
|
|
|
|
)(DNS);
|