2019-01-07 01:25:33 +00:00
|
|
|
import { Component } from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
2016-11-07 16:42:39 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
|
|
import entityGetter from 'redux/utilities/entityGetter';
|
|
|
|
|
import helpers from 'components/queries/QueryPageWrapper/helpers';
|
|
|
|
|
import queryInterface from 'interfaces/query';
|
2016-09-30 18:55:15 +00:00
|
|
|
|
|
|
|
|
class QueryPageWrapper extends Component {
|
|
|
|
|
static propTypes = {
|
|
|
|
|
children: PropTypes.node,
|
2016-11-07 16:42:39 +00:00
|
|
|
dispatch: PropTypes.func,
|
|
|
|
|
query: queryInterface,
|
|
|
|
|
queryID: PropTypes.string,
|
2016-09-30 18:55:15 +00:00
|
|
|
};
|
|
|
|
|
|
2016-11-07 16:42:39 +00:00
|
|
|
componentDidMount () {
|
|
|
|
|
const { dispatch, query, queryID } = this.props;
|
|
|
|
|
const { fetchQuery } = helpers;
|
|
|
|
|
|
|
|
|
|
if (queryID && !query) {
|
|
|
|
|
fetchQuery(dispatch, queryID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-30 18:55:15 +00:00
|
|
|
render () {
|
|
|
|
|
const { children } = this.props;
|
|
|
|
|
|
2016-12-15 14:44:45 +00:00
|
|
|
if (!children) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return children;
|
2016-09-30 18:55:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-07 16:42:39 +00:00
|
|
|
const mapStateToProps = (state, { params }) => {
|
|
|
|
|
const { id: queryID } = params;
|
|
|
|
|
const query = entityGetter(state).get('queries').findBy({ id: queryID });
|
|
|
|
|
|
|
|
|
|
return { query, queryID };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(QueryPageWrapper);
|