Commit 00d7bf01 authored by Jaden DIEFENBAUGH's avatar Jaden DIEFENBAUGH
Browse files

refactor - continue to separate container vs component

parent 08be3e57
......@@ -45,23 +45,6 @@ type State = {
activeTab: Tab,
};
const mapStateToProps: MapStateToProps<*,*,*> = (state, ownProps) => {
const entity = ownProps.match.params.entity;
const name = ownProps.match.params.name;
const obj = {
getEntityObject: (): BeatObject => Selectors[`${ entity }Get`](state).find(o => o.name === name) || {name: '', contents: {}},
};
return obj;
};
const mapDispatchToProps: MapDispatchToProps<*,*,*> = (dispatch, ownProps) => ({
updateFunc: (obj) => {
dispatch(Actions[`${ ownProps.match.params.entity }Update`](ownProps.match.params.name, obj));
ownProps.history.push(`/${ ownProps.match.params.entity }/${ obj.name }`);
},
});
class EntityDetail extends React.Component<Props, State> {
constructor(props: Props){
super(props);
......@@ -175,4 +158,21 @@ class EntityDetail extends React.Component<Props, State> {
}
}
const mapStateToProps: MapStateToProps<*,*,*> = (state, ownProps) => {
const entity = ownProps.match.params.entity;
const name = ownProps.match.params.name;
const obj = {
getEntityObject: (): BeatObject => Selectors[`${ entity }Get`](state).find(o => o.name === name) || {name: '', contents: {}},
};
return obj;
};
const mapDispatchToProps: MapDispatchToProps<*,*,*> = (dispatch, ownProps) => ({
updateFunc: (obj) => {
dispatch(Actions[`${ ownProps.match.params.entity }Update`](ownProps.match.params.name, obj));
ownProps.history.push(`/${ ownProps.match.params.entity }/${ obj.name }`);
},
});
export default connect(mapStateToProps, mapDispatchToProps)(EntityDetail);
......@@ -26,13 +26,12 @@ import * as Selectors from '@store/selectors.js';
import * as Actions from '@store/actions.js';
import { BEAT_ENTITIES } from '@helpers/beat.js';
import type { BeatEntity, BeatObject } from '@helpers/beat';
import ValidSchemaBadge from './ValidSchemaBadge.jsx';
import NewEntityModal from './NewEntityModal.jsx';
import type { BeatEntity, BeatObject } from '@helpers/beat';
const El = ({ data, entity, copyFunc, deleteFunc }: any) => (
<ListGroupItem className='d-flex align-items-center'>
<span>
......@@ -61,14 +60,6 @@ type State = {
copyObj: {},
};
const mapStateToProps: MapStateToProps<*,*,*> = (state, ownProps) => ({
data: Selectors[`${ ownProps.entity }Get`](state),
});
const mapDispatchToProps: MapDispatchToProps<*,*,*> = (dispatch, ownProps) => ({
deleteFunc: (obj) => dispatch(Actions[`${ ownProps.entity }Delete`](obj)),
});
class EntityList extends React.Component<Props, State> {
constructor (props: Props) {
super(props);
......@@ -106,4 +97,12 @@ class EntityList extends React.Component<Props, State> {
}
}
const mapStateToProps: MapStateToProps<*,*,*> = (state, ownProps) => ({
data: Selectors[`${ ownProps.entity }Get`](state),
});
const mapDispatchToProps: MapDispatchToProps<*,*,*> = (dispatch, ownProps) => ({
deleteFunc: (obj) => dispatch(Actions[`${ ownProps.entity }Delete`](obj)),
});
export default connect(mapStateToProps, mapDispatchToProps)(EntityList);
......@@ -17,12 +17,13 @@ import {
import { connect } from 'react-redux';
import type { MapStateToProps } from 'react-redux';
import * as Selectors from '@store/selectors';
import Settings from './Settings.jsx';
import { BEAT_ENTITIES } from '@helpers/beat';
import { genModuleApiFuncs } from '@helpers/api';
import { BEAT_ENTITIES } from '@helpers/beat.js';
import { genModuleApiFuncs } from '@helpers/api.js';
import Settings from './Settings.jsx';
type Props = {
database: any[],
......@@ -49,16 +50,6 @@ const saveAll = (allLists: Props) => {
);
};
const mapStateToProps: MapStateToProps<*,*,*> = state => ({
database: Selectors.databaseGet(state),
library: Selectors.libraryGet(state),
dataformat: Selectors.dataformatGet(state),
algorithm: Selectors.algorithmGet(state),
toolchain: Selectors.toolchainGet(state),
experiment: Selectors.experimentGet(state),
});
class MainNav extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
......@@ -124,4 +115,13 @@ class MainNav extends React.Component<Props, State> {
}
}
const mapStateToProps: MapStateToProps<*,*,*> = state => ({
database: Selectors.databaseGet(state),
library: Selectors.libraryGet(state),
dataformat: Selectors.dataformatGet(state),
algorithm: Selectors.algorithmGet(state),
toolchain: Selectors.toolchainGet(state),
experiment: Selectors.experimentGet(state),
});
export default connect(mapStateToProps)(MainNav);
......@@ -10,9 +10,10 @@ import {
import { connect } from 'react-redux';
import { BEAT_ENTITIES, nameValidator } from '@helpers/beat';
import * as Actions from '@store/actions';
import type { BeatEntity, BeatObject } from '@helpers/beat';
import * as Actions from '@store/actions';
type Props = {
isOpen: boolean,
toggle: () => mixed,
......@@ -25,10 +26,6 @@ type State = {
name: string,
};
const mapDispatchToProps = (dispatch, ownProps) => ({
create: (name: string, copyObj?: {} = {}) => dispatch(Actions[`${ ownProps.entity }Add`]({ contents: {}, ...copyObj, name }))
});
class NewEntityModal extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
......@@ -85,4 +82,8 @@ class NewEntityModal extends React.Component<Props, State> {
}
}
const mapDispatchToProps = (dispatch, ownProps) => ({
create: (name: string, copyObj?: {} = {}) => dispatch(Actions[`${ ownProps.entity }Add`]({ contents: {}, ...copyObj, name }))
});
export default connect(undefined, mapDispatchToProps)(NewEntityModal);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment