1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

wrap edit toggle to make sure it is loaded in store before we enter edit-component

This commit is contained in:
Ivar 2016-11-16 00:15:57 +01:00
parent d3d8591b45
commit f921786850
3 changed files with 44 additions and 12 deletions

View File

@ -7,22 +7,13 @@ import FormComponent from './form';
const ID = 'edit-feature-toggle';
function getId (props) {
return [ID, props.featureToggleName];
return [ID, props.featureToggle.name];
}
// TODO: need to scope to the active featureToggle
// best is to emulate the "input-storage"?
const mapStateToProps = createMapper({
id: getId,
getDefault: (state, ownProps) => {
if (ownProps.featureToggleName) {
const match = state.features.findEntry((entry) => entry.get('name') === ownProps.featureToggleName);
if (match && match[1]) {
return match[1].toJS();
}
}
return {};
},
getDefault: (state, ownProps) => ownProps.featureToggle,
prepare: (props) => {
props.editmode = true;
return props;

View File

@ -0,0 +1,41 @@
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import EditFeatureToggle from './form-edit-container.jsx';
import { fetchFeatureToggles } from '../../store/feature-actions';
class EditFeatureToggleWrapper extends React.Component {
static propTypes () {
return {
featureToggleName: PropTypes.string.isRequired,
features: PropTypes.array.isRequired,
fetchFeatureToggles: PropTypes.array.isRequired,
};
}
componentWillMount () {
if (this.props.features.length === 0) {
this.props.fetchFeatureToggles();
}
}
render () {
const { features, featureToggleName } = this.props;
const featureToggle = features.find(toggle => toggle.name === featureToggleName);
if (featureToggle) {
return <EditFeatureToggle featureToggle={featureToggle} />;
} else if (features.length === 0 ) {
return <span>Loading</span>;
} else {
return <span>Could not find {this.props.featureToggleName}</span>;
}
}
}
export default connect((state) => ({
features: state.features.toJS(),
}), { fetchFeatureToggles })(EditFeatureToggleWrapper);

View File

@ -1,5 +1,5 @@
import React, { Component, PropTypes } from 'react';
import EditFeatureToggleForm from '../../component/feature/form-edit-container';
import EditFeatureToggleForm from '../../component/feature/form-edit-wrap';
export default class Features extends Component {
static propTypes () {