webpack/components/WithOrganization/withOrganization.js in katello-3.11.0 vs webpack/components/WithOrganization/withOrganization.js in katello-3.11.1
- old
+ new
@@ -1,12 +1,22 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
+import { bindActionCreators } from 'redux';
+import { connect } from 'react-redux';
+
import { translate as __ } from 'foremanReact/common/I18n';
import { get } from 'lodash';
import SetOrganization from '../SelectOrg/SetOrganization';
import Header from '../../containers/Application/Headers';
+import * as organizationActions from '../../scenes/Organizations/OrganizationActions';
+const mapStateToProps = state => ({
+ organization: state.katello.organization,
+});
+
+const mapDispatchToProps = dispatch => bindActionCreators({ ...organizationActions }, dispatch);
+
function withOrganization(WrappedComponent, redirectPath) {
class CheckOrg extends Component {
constructor(props) {
super(props);
this.state = { orgId: null };
@@ -29,14 +39,16 @@
window.tfm.nav.changeOrganization(orgTitle);
}
}
render() {
- const { location } = this.props;
+ const { organization, location } = this.props;
const newOrgSelected = get(location, 'state.orgChanged');
if (newOrgSelected) {
+ if (!organization.label && !organization.loading) { this.props.loadOrganization(); }
+
return <WrappedComponent {...this.props} />;
} else if (this.state.orgId === '') {
return (
<React.Fragment>
<Header title={__('Select Organization')} />
@@ -47,14 +59,17 @@
}
}
CheckOrg.propTypes = {
location: PropTypes.shape({}),
+ loadOrganization: PropTypes.func.isRequired,
+ organization: PropTypes.shape({}).isRequired,
};
CheckOrg.defaultProps = {
location: undefined,
};
- return CheckOrg;
+
+ return connect(mapStateToProps, mapDispatchToProps)(CheckOrg);
}
export default withOrganization;