Replace usages of _.pluck by _.map

In order to make possible an upgrade of Lodash package
to the latest 4.x version, usages of _.pluck should be replaced by _.map.
_.pluck is deprecated in the 4.x Lodash.

Change-Id: I080ff817049d69f4cd4365c42f5a171da74125aa
This commit is contained in:
Julia Aranovich 2016-04-20 16:28:35 +03:00 committed by Nikolay Bogdanov
parent 91c152bfa6
commit ebb7c12015
17 changed files with 49 additions and 51 deletions

View File

@ -187,7 +187,7 @@ gulp.task('license', function(cb) {
_.each(data, function(moduleInfo) {
var name = moduleInfo.name;
var version = moduleInfo.version;
var license = _.pluck(moduleInfo.licenseSources.package.sources, 'license').join(', ') ||
var license = _.map(moduleInfo.licenseSources.package.sources, 'license').join(', ') ||
'unknown';
var licenseOk = license.match(licenseRegexp);
if (!licenseOk) errors.push({libraryName: name, license: license});

View File

@ -116,7 +116,7 @@ class Router extends Backbone.Router {
}
showCluster(clusterId, tab) {
var tabs = _.pluck(ClusterPage.getTabs(), 'url');
var tabs = _.map(ClusterPage.getTabs(), 'url');
if (!tab || !_.contains(tabs, tab)) {
this.navigate('cluster/' + clusterId + '/' + tabs[0], {trigger: true, replace: true});
} else {

View File

@ -122,7 +122,7 @@ var restrictionMixin = models.restrictionMixin = {
);
return {
result: !!satisfiedRestrictions.length,
message: _.compact(_.pluck(satisfiedRestrictions, 'message')).join(' ')
message: _.compact(_.map(satisfiedRestrictions, 'message')).join(' ')
};
},
expandLimits(limits) {
@ -428,7 +428,7 @@ models.Node = BaseModel.extend({
} else if (resourceName === 'ram') {
resource = this.get('meta').memory.total;
} else if (resourceName === 'disks') {
resource = _.pluck(this.get('meta').disks, 'size').sort((a, b) => a - b);
resource = _.map(this.get('meta').disks, 'size').sort((a, b) => a - b);
} else if (resourceName === 'disks_amount') {
resource = this.get('meta').disks.length;
} else if (resourceName === 'interfaces') {
@ -483,9 +483,9 @@ models.Node = BaseModel.extend({
return status === 'discover' || status === 'error';
},
getRolesSummary(releaseRoles) {
return _.map(this.sortedRoles(releaseRoles.pluck('name')), (role) => {
return releaseRoles.find({name: role}).get('label');
}).join(', ');
return _.map(this.sortedRoles(releaseRoles.pluck('name')),
(role) => releaseRoles.find({name: role}).get('label')
).join(', ');
},
getStatusSummary() {
// 'offline' status has higher priority
@ -941,7 +941,7 @@ models.Interface = Backbone.DeepModel
},
getSlaveInterfaces() {
if (!this.isBond()) return [this];
var slaveNames = _.pluck(this.get('slaves'), 'name');
var slaveNames = _.map(this.get('slaves'), 'name');
return this.collection.filter((ifc) => _.contains(slaveNames, ifc.get('name')));
},
validate(attrs, options) {

View File

@ -151,7 +151,7 @@ var NovaComputes = BaseCollection.extend({
this.invoke('checkDuplicates', keys);
this.invoke('checkEmptyTargetNode');
var errors = _.compact(_.pluck(this.models, 'validationError'));
var errors = _.compact(this.map('validationError'));
return _.isEmpty(errors) ? null : errors;
}
});

View File

@ -289,7 +289,7 @@ var ClusterPage = React.createClass({
render() {
var cluster = this.props.cluster;
var availableTabs = this.getAvailableTabs(cluster);
var tabUrls = _.pluck(availableTabs, 'url');
var tabUrls = _.map(availableTabs, 'url');
var subroutes = {
settings: this.state.activeSettingsSectionName,
network: this.state.activeNetworkSectionName,

View File

@ -835,7 +835,7 @@ var ClusterActionButton = React.createClass({
getInitialState() {
return {
// offline nodes should not be selected for the task
selectedNodeIds: _.pluck(this.props.nodes.filter({online: true}), 'id')
selectedNodeIds: _.map(this.props.nodes.filter({online: true}), 'id')
};
},
getDefaultProps() {

View File

@ -139,7 +139,7 @@ var HealthcheckTabContent = React.createClass({
var testsetIds = this.props.testsets.pluck('id');
this.setState({actionInProgress: true});
_.each(testsetIds, (testsetId) => {
var testsToRun = _.pluck(this.props.tests.filter({
var testsToRun = _.map(this.props.tests.filter({
testset: testsetId,
checked: true
}), 'id');

View File

@ -1296,7 +1296,7 @@ var NodeNetworkGroup = React.createClass({
disabled={locked}
configurationTemplateExists={configurationTemplateExists}
verificationErrorField={
_.pluck(_.filter(verificationErrors, {network: network.id}), 'field')
_.map(_.filter(verificationErrors, {network: network.id}), 'field')
}
currentNodeNetworkGroup={nodeNetworkGroup}
/>

View File

@ -70,8 +70,8 @@ var EditNodeDisksScreen = React.createClass({
},
hasChanges() {
return !this.isLocked() && !_.isEqual(
_.pluck(this.props.disks.toJSON(), 'volumes'),
_.pluck(this.state.initialDisks, 'volumes')
_.map(this.props.disks.toJSON(), 'volumes'),
_.map(this.state.initialDisks, 'volumes')
);
},
loadDefaults() {

View File

@ -369,8 +369,8 @@ var EditNodeInterfacesScreen = React.createClass({
findOffloadingModesIntersection(set1, set2) {
return _.map(
_.intersection(
_.pluck(set1, 'name'),
_.pluck(set2, 'name')
_.map(set1, 'name'),
_.map(set2, 'name')
),
(name) => {
return {
@ -401,7 +401,7 @@ var EditNodeInterfacesScreen = React.createClass({
if (!bond) {
// if no bond selected - create new one
var bondMode = _.flatten(
_.pluck(this.props.bondingConfig.properties[bondType].mode, 'values')
_.map(this.props.bondingConfig.properties[bondType].mode, 'values')
)[0];
bondName = this.props.interfaces.generateBondName('bond');
@ -494,7 +494,7 @@ var EditNodeInterfacesScreen = React.createClass({
var bondHasUnmovableNetwork = bond.get('assigned_networks').any((interfaceNetwork) => {
return interfaceNetwork.getFullNetwork(networks).get('meta').unmovable;
});
var slaveInterfaceNames = _.pluck(slaves, 'name');
var slaveInterfaceNames = _.map(slaves, 'name');
var targetInterface = bond;
// if PXE interface is being removed - place networks there
@ -510,7 +510,7 @@ var EditNodeInterfacesScreen = React.createClass({
// if slaveInterfaceName is set - remove it from slaves, otherwise remove all
if (slaveInterfaceName) {
var slavesUpdated = _.reject(slaves, {name: slaveInterfaceName});
var names = _.pluck(slavesUpdated, 'name');
var names = _.map(slavesUpdated, 'name');
var bondSlaveInterfaces = this.props.interfaces.filter(
(ifc) => _.contains(names, ifc.get('name'))
);
@ -549,7 +549,7 @@ var EditNodeInterfacesScreen = React.createClass({
var networkConfiguration = cluster.get('networkConfiguration');
var networkingParameters = networkConfiguration.get('networking_parameters');
var networks = networkConfiguration.get('networks');
var slaveInterfaceNames = _.pluck(_.flatten(_.filter(interfaces.pluck('slaves'))), 'name');
var slaveInterfaceNames = _.map(_.flatten(_.filter(interfaces.pluck('slaves'))), 'name');
interfaces.each((ifc) => {
if (!_.contains(slaveInterfaceNames, ifc.get('name'))) {
@ -643,7 +643,7 @@ var EditNodeInterfacesScreen = React.createClass({
var unbondingPossible = !checkedInterfaces.length && !!checkedBonds.length;
var hasChanges = this.hasChanges();
var slaveInterfaceNames = _.pluck(_.flatten(_.filter(interfaces.pluck('slaves'))), 'name');
var slaveInterfaceNames = _.map(_.flatten(_.filter(interfaces.pluck('slaves'))), 'name');
var loadDefaultsEnabled = !this.state.actionInProgress;
var revertChangesEnabled = !this.state.actionInProgress && hasChanges;
@ -862,7 +862,7 @@ var NodeInterface = React.createClass({
},
getBondPropertyValues(propertyName, value) {
var bondType = this.props.interface.get('bond_properties').type__;
return _.flatten(_.pluck(this.props.bondingProperties[bondType][propertyName], value));
return _.flatten(_.map(this.props.bondingProperties[bondType][propertyName], value));
},
updateBondProperties(options) {
var bondProperties = _.cloneDeep(this.props.interface.get('bond_properties')) || {};
@ -916,7 +916,7 @@ var NodeInterface = React.createClass({
if (!ifcModes.length) {
return states[!this.props.interface.get('interface_properties').disable_offloading];
}
if (_.uniq(_.pluck(ifcModes, 'state')).length === 1) {
if (_.uniq(_.map(ifcModes, 'state')).length === 1) {
return states[ifcModes[0].state];
}
@ -1103,7 +1103,7 @@ var NodeInterface = React.createClass({
changeBondType(newType) {
this.props.interface.set('bond_properties.type__', newType);
var newMode = _.flatten(
_.pluck(this.props.bondingProperties[newType].mode, 'values')
_.map(this.props.bondingProperties[newType].mode, 'values')
)[0];
this.bondingModeChanged(null, newMode);
},

View File

@ -227,8 +227,8 @@ NodeListScreen = React.createClass({
});
if (
!_.isEqual(
_.pluck(normalizedFilters, 'values'),
_.pluck(this.state.activeFilters, 'values')
_.map(normalizedFilters, 'values'),
_.map(this.state.activeFilters, 'values')
)
) {
this.updateFilters(normalizedFilters);
@ -378,7 +378,7 @@ NodeListScreen = React.createClass({
});
break;
case 'manufacturer':
options = _.uniq(this.props.nodes.pluck('manufacturer')).map((manufacturer) => {
options = _.uniq(this.props.nodes.map('manufacturer')).map((manufacturer) => {
manufacturer = manufacturer || '';
return {
name: manufacturer.replace(/\s/g, '_'),
@ -627,7 +627,7 @@ MultiSelectControl = React.createClass({
onChange(name, checked, isLabel) {
if (!this.props.dynamicValues) {
var values = name === 'all' ?
checked ? _.pluck(this.props.options, 'name') : []
checked ? _.map(this.props.options, 'name') : []
:
checked ? _.union(this.props.values, [name]) : _.difference(this.props.values, [name]);
this.props.onChange(values);
@ -840,10 +840,10 @@ ManagementPanel = React.createClass({
this.changeScreen(action, true);
},
showDeleteNodesDialog() {
DeleteNodesDialog.show({nodes: this.props.nodes, cluster: this.props.cluster})
.done(_.partial(this.props.selectNodes,
_.pluck(this.props.nodes.filter({status: 'ready'}), 'id'), null, true)
);
var {cluster, nodes, selectNodes} = this.props;
DeleteNodesDialog
.show({nodes, cluster})
.done(_.partial(selectNodes, _.map(nodes.filter({status: 'ready'}), 'id'), null, true));
},
hasChanges() {
return this.props.hasChanges;
@ -1406,10 +1406,8 @@ ManagementPanel = React.createClass({
{filter.isNumberRange ?
_.uniq(filter.values).join(' - ')
:
_.pluck(
_.filter(options, (option) => {
return _.contains(filter.values, option.name);
})
_.map(
_.filter(options, ({name}) => _.contains(filter.values, name))
, 'label').join(', ')
}
</span>
@ -1548,7 +1546,7 @@ NodeLabelsPanel = React.createClass({
},
isSavingPossible() {
return !this.state.actionInProgress && this.hasChanges() &&
_.all(_.pluck(this.state.labels, 'error'), _.isNull);
_.all(_.map(this.state.labels, 'error'), _.isNull);
},
revertChanges() {
return this.props.toggleLabelsPanel();
@ -1930,7 +1928,7 @@ SelectAllMixin = {
}
label={i18n('common.select_all')}
wrapperClassName='select-all pull-right'
onChange={_.partial(selectNodes, _.pluck(nodesToSelect, 'id'))}
onChange={_.partial(selectNodes, _.map(nodesToSelect, 'id'))}
/>
);
}
@ -2151,7 +2149,7 @@ NodeGroup = React.createClass({
mixins: [SelectAllMixin],
render() {
var availableNodes = this.props.nodes.filter((node) => node.isSelectable());
var nodesWithRestrictionsIds = _.pluck(_.filter(availableNodes, (node) => {
var nodesWithRestrictionsIds = _.map(_.filter(availableNodes, (node) => {
return _.any(this.props.rolesWithLimitReached, (role) => !node.hasRole(role));
}), 'id');
return (

View File

@ -112,7 +112,7 @@ var OffloadingModesControl = React.createClass({
if (ifcModes) {
modes.push({
name: i18n(ns + 'all_modes'),
state: _.uniq(_.pluck(ifcModes, 'state')).length === 1 ? ifcModes[0].state : undefined,
state: _.uniq(_.map(ifcModes, 'state')).length === 1 ? ifcModes[0].state : undefined,
sub: ifcModes
});
}

View File

@ -73,7 +73,7 @@ var SettingSection = React.createClass({
return setting.toggleable || _.contains(['checkbox', 'radio'], setting.type);
},
getValuesToCheck(setting, valueAttribute) {
return setting.values ? _.without(_.pluck(setting.values, 'data'), setting[valueAttribute]) :
return setting.values ? _.without(_.map(setting.values, 'data'), setting[valueAttribute]) :
[!setting[valueAttribute]];
},
checkValues(values, path, currentValue, restriction) {

View File

@ -244,7 +244,7 @@ var SettingsTab = React.createClass({
// Settings like 'Common' can be splitted to different groups
var settingGroups = _.chain(section)
.omit('metadata')
.pluck('group')
.map('group')
.unique()
.without('network')
.value();
@ -381,7 +381,7 @@ var SettingSubtabs = React.createClass({
this.props.settingsGroupList.map((groupName) => {
if (!this.props.groupedSettings[groupName]) return null;
var hasErrors = _.any(_.pluck(this.props.groupedSettings[groupName], 'invalid'));
var hasErrors = _.any(_.map(this.props.groupedSettings[groupName], 'invalid'));
return (
<li
key={groupName}

View File

@ -1060,7 +1060,7 @@ export var ShowNodeInfoDialog = React.createClass({
(
_.isArray(meta.memory.devices) ?
summaryToString(
_.countBy(_.pluck(meta.memory.devices, 'size'), (value) => utils.showSize(value))
_.countBy(_.map(meta.memory.devices, 'size'), (value) => utils.showSize(value))
)
:
[]
@ -1069,13 +1069,13 @@ export var ShowNodeInfoDialog = React.createClass({
.join(', '),
disks: () => meta.disks.length + ' ' +
i18n('dialog.show_node.drive', {count: meta.disks.length}) + ', ' +
utils.showSize(_.reduce(_.pluck(meta.disks, 'size'), (sum, n) => sum + n, 0)) + ' ' +
utils.showSize(_.reduce(_.map(meta.disks, 'size'), (sum, n) => sum + n, 0)) + ' ' +
i18n('dialog.show_node.total'),
cpu: () => summaryToString(
_.countBy(_.pluck(meta.cpu.spec, 'frequency'), utils.showFrequency)
_.countBy(_.map(meta.cpu.spec, 'frequency'), utils.showFrequency)
).join(', '),
interfaces: () => summaryToString(
_.countBy(_.pluck(meta.interfaces, 'current_speed'), utils.showBandwidth)
_.countBy(_.map(meta.interfaces, 'current_speed'), utils.showBandwidth)
).join(', '),
numa_topology: () => i18n('dialog.show_node.numa_nodes', {
count: meta.numa_topology.numa_nodes.length

View File

@ -72,7 +72,7 @@ var PluginsPage = React.createClass({
return _.map(_.groupBy(data, 'os'), (osReleases, osName) =>
<div key={osName}>
{i18n('plugins_page.' + osName) + ': '}
{_.pluck(osReleases, 'version').join(', ')}
{_.map(osReleases, 'version').join(', ')}
</div>
);
}

View File

@ -125,8 +125,8 @@ var ClusterWizardPanesMixin = {
return false;
}
var allComponentsExclusive = _.all(components, (component) => {
var peerIds = _.pluck(_.reject(components, {id: component.id}), 'id');
var incompatibleIds = _.pluck(_.pluck(component.get('incompatible'), 'component'), 'id');
var peerIds = _.map(_.reject(components, {id: component.id}), 'id');
var incompatibleIds = _.map(_.map(component.get('incompatible'), 'component'), 'id');
// peerIds should be subset of incompatibleIds to have exclusiveness property
return peerIds.length === _.intersection(peerIds, incompatibleIds).length;
});