import React, { Component } from 'react';
import { connect } from 'react-redux'
import { push } from 'connected-react-router';

import { selectors } from '@openchemistry/redux'
import { calculations, molecules } from '@openchemistry/redux'

import { isNil } from 'lodash-es';

import Calculations from '../components/calculations';

class CalculationsContainer extends Component {

  componentDidMount() {
    this.props.dispatch(molecules.loadMolecules());
    this.props.dispatch(calculations.loadCalculations());
  }

  onOpen = (id) => {
    this.props.dispatch(push(`/calculations/${id}?mo=homo`));
  }

  render() {
    const { calculations, molecules } = this.props;
    if (isNil(calculations)) {
      return null;
    }
    return (
      <Calculations calculations={calculations} molecules={molecules} onOpen={this.onOpen} />
    );
  }
}

CalculationsContainer.propTypes = {
}

CalculationsContainer.defaultProps = {
}

function mapStateToProps(state, ownProps) {
  let calculations = selectors.calculations.getCalculations(state);
  let molecules = selectors.molecules.getMoleculesById(state);
  return { calculations, molecules };
}

export default connect(mapStateToProps)(CalculationsContainer)

import React, { Component } from 'react';
import { connect } from 'react-redux'
import { push } from 'connected-react-router';

import { selectors } from '@openchemistry/redux'
import { calculations, molecules } from '@openchemistry/redux'

import { isNil } from 'lodash-es';

import Calculations from '../components/calculations';

class CalculationsContainer extends Component {

  componentDidMount() {
    const options = { limit: 25, offset: 0, sort: '_id', sortdir: -1 }
    this.props.dispatch(molecules.loadMolecules(options));
    this.props.dispatch(calculations.loadCalculations(options));
  }

  onOpen = (id) => {
    this.props.dispatch(push(`/calculations/${id}?mo=homo`));
  }

  render() {
    const { calculations, molecules } = this.props;
    if (isNil(calculations)) {
      return null;
    }
    return (
      <Calculations calculations={calculations} molecules={molecules} onOpen={this.onOpen} />
    );
  }
}

CalculationsContainer.propTypes = {
}

CalculationsContainer.defaultProps = {
}

function mapStateToProps(state, ownProps) {
  let calculations = selectors.calculations.getCalculations(state);
  let molecules = selectors.molecules.getMoleculesById(state);
  return { calculations, molecules };
}

export default connect(mapStateToProps)(CalculationsContainer)

Add example of using sorting options for calcs
Add example of using sorting options for calcs

Signed-off-by: Patrick Avery <743342299f279e7a8c3ff5eb40671fce3e95f13a@kitware.com>
