import React from 'react'; import ReactJson from 'react-json-view'; import PropTypes from 'prop-types'; import forceArray from 'force-array'; import { compose, graphql } from 'react-apollo'; import find from 'lodash.find'; import get from 'lodash.get'; import { ViewContainer, Title, StatusLoader, Message } from 'joyent-ui-toolkit'; import GetSnapshots from '@graphql/list-snapshots.gql'; const Snapshots = ({ snapshots = [], loading, error }) => { const _title = Snapshots; const _loading = !(loading && !forceArray(snapshots).length) ? null : ( ); const _summary = !_loading && ; const _error = !(error && !_loading) ? null : ( ); return ( {_title} {_loading} {_error} {_summary} ); }; Snapshots.propTypes = { loading: PropTypes.bool }; export default compose( graphql(GetSnapshots, { options: ({ match }) => ({ pollInterval: 1000, variables: { name: get(match, 'params.instance') } }), props: ({ data: { loading, error, variables, ...rest } }) => ({ snapshots: get( find(get(rest, 'machines', []), ['name', variables.name]), 'snapshots', [] ), loading, error }) }) )(Snapshots);