Adding selector

This commit is contained in:
Anthony Laibe 2018-10-12 09:58:13 +01:00 committed by Pascal Precht
parent a61f499abb
commit 9aac039e7e
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
2 changed files with 9 additions and 8 deletions

View File

@ -1,11 +1,10 @@
import React, {Component} from 'react'; import React, {Component} from 'react';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import {withRouter} from 'react-router-dom';
import {contract as contractAction} from '../actions'; import {contract as contractAction} from '../actions';
import ContractLayout from '../components/ContractLayout'; import ContractLayout from '../components/ContractLayout';
import {getContractsByFilename} from "../reducers/selectors"; import {getContractsByPath} from "../reducers/selectors";
class FileContractsContainer extends Component { class FileContractsContainer extends Component {
componentDidMount() { componentDidMount() {
@ -13,17 +12,15 @@ class FileContractsContainer extends Component {
} }
render() { render() {
if (this.props.contract){ return (
return <ContractLayout contractIsFiddle={this.props.contract.isFiddle} />; this.props.contracts.map(contract => <ContractLayout contract={contract} />)
} else { )
return <React.Fragment />;
}
} }
} }
function mapStateToProps(state, props) { function mapStateToProps(state, props) {
return { return {
contracts: getContractsByFilename(state, props.currentFile.name), contracts: getContractsByPath(state, props.currentFile.path),
error: state.errorMessage, error: state.errorMessage,
loading: state.loading loading: state.loading
}; };

View File

@ -68,6 +68,10 @@ export function getContract(state, contractName) {
return state.entities.contracts.find((contract => contract.className === contractName)); return state.entities.contracts.find((contract => contract.className === contractName));
} }
export function getContractsByPath(state, path) {
return state.entities.contracts.filter((contract => contract.path === path));
}
export function getContractProfile(state, contractName) { export function getContractProfile(state, contractName) {
return state.entities.contractProfiles.find((contractProfile => contractProfile.name === contractName)); return state.entities.contractProfiles.find((contractProfile => contractProfile.name === contractName));
} }