mirror of https://github.com/embarklabs/embark.git
Adding selector
This commit is contained in:
parent
a61f499abb
commit
9aac039e7e
|
@ -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
|
||||||
};
|
};
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue