webpack/components/ExistingHostSelection/ExistingHostSelection.js in foreman_acd-0.9.7 vs webpack/components/ExistingHostSelection/ExistingHostSelection.js in foreman_acd-0.10.0
- old
+ new
@@ -1,104 +1,83 @@
import React from 'react';
import PropTypes from 'prop-types';
-import { orderBy } from 'lodash';
+import { cloneDeep } from 'lodash';
+import { DualListControlled } from 'patternfly-react';
+import { translate as __ } from 'foremanReact/common/I18n';
import ServiceSelector from './components/ServiceSelector';
import { arrayToObject } from '../../helper';
-import {
- cloneDeep,
-} from 'lodash';
-
-import {
- Icon,
- Button,
- DualListControlled,
-} from 'patternfly-react';
-
class ExistingHostSelection extends React.Component {
-
- constructor(props) {
- super(props);
- }
-
componentDidMount() {
- const {
- location,
- organization,
- services,
- initExistingHostSelection,
- allHosts,
- } = this.props;
+ const { allHosts, initExistingHostSelection } = this.props;
initExistingHostSelection(allHosts);
}
render() {
const {
- location,
- organization,
services,
serviceId,
availableHosts,
alreadyUsedHosts,
loadHostsOfHostgroup,
hostSelectionChanged,
} = this.props;
- const serviceList = arrayToObject(services, "id", "name");
- const load_hostgroup_url = "/api/v2/hostgroups/__hostgroup_id__/hosts"
+ const serviceList = arrayToObject(services, 'id', 'name');
+ const loadHostgroupUrl = '/api/v2/hostgroups/__hostgroup_id__/hosts';
- return(
+ return (
<div>
<div className="row">
<ServiceSelector
label="Service"
- hidden={ false }
- selectValue={ this.props.serviceId ? this.props.serviceId.toString() : '0'}
- options={ serviceList }
- onChange={ loadHostsOfHostgroup }
- additionalData={{ url: load_hostgroup_url, services: services }} />
+ hidden={false}
+ selectValue={serviceId ? serviceId.toString() : '0'}
+ options={serviceList}
+ onChange={loadHostsOfHostgroup}
+ additionalData={{ url: loadHostgroupUrl, services }}
+ />
</div>
<div className="row">
- <label className="col-md-2 control-label">{ __("Hosts") }</label>
- {this.props.serviceId != undefined ? (
- <div className="col-md-6">
- <DualListControlled
- onChange={ hostSelectionChanged }
- left={{
- items: cloneDeep(availableHosts),
- }}
- right={{
- items: cloneDeep(alreadyUsedHosts),
- }}
- allowHiddenInputs={false}
- />
- </div>) : (<span>{ __("Please select service first.") }</span>)}
+ <label className="col-md-2 control-label">{__('Hosts')}</label>
+ {serviceId !== undefined ? (
+ <div className="col-md-6">
+ <DualListControlled
+ onChange={hostSelectionChanged}
+ left={{
+ items: cloneDeep(availableHosts),
+ }}
+ right={{
+ items: cloneDeep(alreadyUsedHosts),
+ }}
+ allowHiddenInputs={false}
+ />
+ </div>
+ ) : (
+ <span>{__('Please select service first.')}</span>
+ )}
</div>
</div>
);
}
}
ExistingHostSelection.defaultProps = {
+ allHosts: [],
serviceId: undefined,
- hostsInHostgroup: {},
availableHosts: [],
alreadyUsedHosts: [],
- selectedHosts: [],
};
ExistingHostSelection.propTypes = {
- location: PropTypes.string.isRequired,
- organization: PropTypes.string.isRequired,
+ allHosts: PropTypes.array,
services: PropTypes.array.isRequired,
- initExistingHostSelection: PropTypes.func,
+ initExistingHostSelection: PropTypes.func.isRequired,
serviceId: PropTypes.number,
- hostsInHostgroup: PropTypes.object,
availableHosts: PropTypes.array,
alreadyUsedHosts: PropTypes.array,
- selectedHosts: PropTypes.array,
- loadHostsOfHostgroup: PropTypes.func,
- hostSelectionChanged: PropTypes.func,
+ loadHostsOfHostgroup: PropTypes.func.isRequired,
+ hostSelectionChanged: PropTypes.func.isRequired,
};
export default ExistingHostSelection;