diff --git a/app/javascript/components/index.js b/app/javascript/components/index.js index 4b63d99620..c2ff8683ed 100644 --- a/app/javascript/components/index.js +++ b/app/javascript/components/index.js @@ -112,7 +112,7 @@ export const coreComponents = [ '&sort_order=desc', fetchClustersUrl: 'api/clusters/' + - '?attributes=ext_management_system.emstype,v_parent_datacenter,ext_management_system.name' + + '?attributes=ext_management_system.emstype,v_parent_datacenter,ext_management_system.name,lans,storages' + '&expand=resources', fetchNetworksUrl: 'api/lans/?expand=resources', fetchDatastoresUrl: 'api/data_stores?expand=resources' diff --git a/app/javascript/react/screens/App/Overview/components/InfrastructureMappingsList/helpers.js b/app/javascript/react/screens/App/Overview/components/InfrastructureMappingsList/helpers.js index c71f13161b..01008f1a30 100644 --- a/app/javascript/react/screens/App/Overview/components/InfrastructureMappingsList/helpers.js +++ b/app/javascript/react/screens/App/Overview/components/InfrastructureMappingsList/helpers.js @@ -1,3 +1,6 @@ +import Immutable from 'seamless-immutable'; +import { networkKey } from '../../../common/networkKey'; + export const mapInfrastructureMappings = (transformation_mapping_items, clusters, datastores, networks) => { /** * map the target source -> destination clusters/networks/datastores for @@ -54,12 +57,6 @@ export const mapInfrastructureMappings = (transformation_mapping_items, clusters item => item.destination_type.toLowerCase() === 'lan' ); - // transform cluster mappings to key/value - const clustersByMappingId = {}; - clusterMappingItems.forEach(cluster => { - clustersByMappingId[cluster.transformation_mapping_id] = cluster; - }); - // create unique cluster mappings by unique target cluster const targetClusters = {}; clusterMappingItems.forEach(clusterMapping => { @@ -76,16 +73,31 @@ export const mapInfrastructureMappings = (transformation_mapping_items, clusters } }); + // transform cluster lans and datastores to key/value lookups for use in datastore/lan mappings + const clusterDatastores = {}; + const clusterLans = {}; + clusters.forEach(cluster => { + if (cluster.storages && cluster.storages.length) { + cluster.storages.forEach(datastore => { + clusterDatastores[datastore.id] = cluster.id; + }); + } + if (cluster.lans && cluster.lans.length) { + cluster.lans.forEach(lan => { + clusterLans[lan.id] = cluster.id; + }); + } + }); + // create unique datastore mappings by unique target datastore const targetDatastores = {}; datastoreMappingItems.forEach(datastoreMapping => { - const clusterMapping = clustersByMappingId[datastoreMapping.transformation_mapping_id]; - const sourceCluster = clusters.find(c => c.id === clusterMapping.source_id); - const targetCluster = clusters.find(c => c.id === clusterMapping.destination_id); + const sourceCluster = clusters.find(c => c.id === clusterDatastores[datastoreMapping.source_id]); + const targetCluster = clusters.find(c => c.id === clusterDatastores[datastoreMapping.destination_id]); const sourceDatastore = datastores.find(d => d.id === datastoreMapping.source_id); const targetDatastore = datastores.find(d => d.id === datastoreMapping.destination_id); - if (clusterMapping && sourceCluster && targetCluster && sourceDatastore && targetDatastore) { + if (sourceCluster && targetCluster && sourceDatastore && targetDatastore) { const source = { sourceDatastore, sourceCluster @@ -105,16 +117,19 @@ export const mapInfrastructureMappings = (transformation_mapping_items, clusters } }); - // create unique networks mappings by unique target network (using ems_uid) + // create unique networks mappings by unique target network const targetNetworks = {}; networkMappingItems.forEach(networkMapping => { - const clusterMapping = clustersByMappingId[networkMapping.transformation_mapping_id]; - const sourceCluster = clusters.find(c => c.id === clusterMapping.source_id); - const targetCluster = clusters.find(c => c.id === clusterMapping.destination_id); - const sourceNetwork = networks.find(d => d.id === networkMapping.source_id); - const targetNetwork = networks.find(d => d.id === networkMapping.destination_id); + const sourceCluster = clusters.find(c => c.id === clusterLans[networkMapping.source_id]); + const targetCluster = clusters.find(c => c.id === clusterLans[networkMapping.destination_id]); - if (clusterMapping && sourceCluster && targetCluster && sourceNetwork && targetNetwork) { + const sn = networks.find(d => d.id === networkMapping.source_id); + const sourceNetwork = Immutable.set(sn, 'clusterId', sourceCluster.id); + + const tn = networks.find(d => d.id === networkMapping.destination_id); + const targetNetwork = Immutable.set(tn, 'clusterId', targetCluster.id); + + if (sourceCluster && targetCluster && sourceNetwork && targetNetwork) { const source = { sourceNetwork, sourceCluster @@ -124,19 +139,19 @@ export const mapInfrastructureMappings = (transformation_mapping_items, clusters targetNetwork, targetCluster }; - // LANs are currently duplicated in the backend database model, so - // we dedupe them using uid_ems attribute for now. - if (targetNetworks[targetNetwork.uid_ems]) { - const duplicatedLanIndex = targetNetworks[targetNetwork.uid_ems].sources.findIndex( - s => s.sourceNetwork.uid_ems === sourceNetwork.uid_ems + + const targetNetworkKey = networkKey(targetNetwork); + if (targetNetworks[targetNetworkKey]) { + const duplicatedLanIndex = targetNetworks[targetNetworkKey].sources.findIndex( + s => networkKey(s.sourceNetwork) === networkKey(sourceNetwork) ); if (duplicatedLanIndex === -1) { - targetNetworks[targetNetwork.uid_ems].sources.push(source); + targetNetworks[targetNetworkKey].sources.push(source); } } else { - targetNetworks[targetNetwork.uid_ems] = {}; - targetNetworks[targetNetwork.uid_ems].target = target; - targetNetworks[targetNetwork.uid_ems].sources = [source]; + targetNetworks[targetNetworkKey] = {}; + targetNetworks[targetNetworkKey].target = target; + targetNetworks[targetNetworkKey].sources = [source]; } } }); diff --git a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/MappingWizardNetworksStepActions.js b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/MappingWizardNetworksStepActions.js index aab9cad498..972ce2d33e 100644 --- a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/MappingWizardNetworksStepActions.js +++ b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/MappingWizardNetworksStepActions.js @@ -7,7 +7,8 @@ const _filterSourceNetworks = response => { if (data.lans) { const sourceNetworks = data.lans.map(lan => ({ ...lan, - providerName: data.ext_management_system.name + providerName: data.ext_management_system.name, + clusterId: data.id })); return { sourceNetworks @@ -45,7 +46,8 @@ const _filterTargetNetworks = response => { if (data.lans) { const targetNetworks = data.lans.map(lan => ({ ...lan, - providerName: data.ext_management_system.name + providerName: data.ext_management_system.name, + clusterId: data.id })); return { targetNetworks diff --git a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/MappingWizardNetworksStepSelectors.js b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/MappingWizardNetworksStepSelectors.js index 42cf3e806f..63dbf8a69c 100644 --- a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/MappingWizardNetworksStepSelectors.js +++ b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/MappingWizardNetworksStepSelectors.js @@ -1,8 +1,12 @@ -export const groupByUidEms = (networks = []) => +import { networkKey } from '../../../../../common/networkKey'; + +export const uniqueNetworks = (networks = []) => networks.reduce( (networksMap, network) => ({ ...networksMap, - [network.uid_ems]: networksMap[network.uid_ems] ? [...networksMap[network.uid_ems], network] : [network] + [networkKey(network)]: networksMap[networkKey(network)] + ? [...networksMap[networkKey(network)], network] + : [network] }), {} ); diff --git a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/__tests__/MappingWizardNetworksStepSelectors.test.js b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/__tests__/MappingWizardNetworksStepSelectors.test.js index e5485f6f1c..576a6c263c 100644 --- a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/__tests__/MappingWizardNetworksStepSelectors.test.js +++ b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/__tests__/MappingWizardNetworksStepSelectors.test.js @@ -1,8 +1,8 @@ import { sourceClusterNetworks } from '../mappingWizardNetworksStep.fixtures'; -import { groupByUidEms } from '../MappingWizardNetworksStepSelectors'; +import { uniqueNetworks } from '../MappingWizardNetworksStepSelectors'; -test('groupByUidEms creates a mapping of networks organized by uid_ems', () => { +test('uniqueNetworks creates a mapping of grouped networks', () => { const sourceNetworks = sourceClusterNetworks[0].lans; - expect(groupByUidEms(sourceNetworks)).toMatchSnapshot(); + expect(uniqueNetworks(sourceNetworks)).toMatchSnapshot(); }); diff --git a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/__tests__/__snapshots__/MappingWizardDatastoresStepReducer.test.js.snap b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/__tests__/__snapshots__/MappingWizardDatastoresStepReducer.test.js.snap index f0f375fa45..cdb740bbb5 100644 --- a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/__tests__/__snapshots__/MappingWizardDatastoresStepReducer.test.js.snap +++ b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/__tests__/__snapshots__/MappingWizardDatastoresStepReducer.test.js.snap @@ -11,6 +11,7 @@ Object { "sourceNetworks": Array [ Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -69,6 +70,7 @@ Object { "targetNetworks": Array [ Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, diff --git a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/__tests__/__snapshots__/MappingWizardNetworksStepSelectors.test.js.snap b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/__tests__/__snapshots__/MappingWizardNetworksStepSelectors.test.js.snap index c98bed0f3d..e753b5e3da 100644 --- a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/__tests__/__snapshots__/MappingWizardNetworksStepSelectors.test.js.snap +++ b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/__tests__/__snapshots__/MappingWizardNetworksStepSelectors.test.js.snap @@ -1,10 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`groupByUidEms creates a mapping of networks organized by uid_ems 1`] = ` +exports[`uniqueNetworks creates a mapping of grouped networks 1`] = ` Object { - "VMWareCluster1-vm_network1": Array [ + "1\\\\VMWareCluster1-vm_network1": Array [ Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -22,6 +23,7 @@ Object { }, Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -38,9 +40,10 @@ Object { "updated_on": "2017-06-01T04:24:18Z", }, ], - "VMWareCluster1-vm_network2": Array [ + "1\\\\VMWareCluster1-vm_network2": Array [ Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -57,9 +60,10 @@ Object { "updated_on": "2017-06-01T04:24:18Z", }, ], - "VMWareCluster1-vm_network3": Array [ + "1\\\\VMWareCluster1-vm_network3": Array [ Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, diff --git a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/NetworksStepForm.js b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/NetworksStepForm.js index 2a8c420625..eb212c272d 100644 --- a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/NetworksStepForm.js +++ b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/NetworksStepForm.js @@ -7,6 +7,7 @@ import DualPaneMapperList from '../../../DualPaneMapper/DualPaneMapperList'; import DualPaneMapperCount from '../../../DualPaneMapper/DualPaneMapperCount'; import DualPaneMapperListItem from '../../../DualPaneMapper/DualPaneMapperListItem'; import MappingWizardTreeView from '../../../MappingWizardTreeView/MappingWizardTreeView'; +import { networkKey } from '../../../../../../../common/networkKey'; import { sourceNetworksFilter, @@ -38,12 +39,12 @@ class NetworksStepForm extends React.Component { selectSourceNetwork = sourceNetwork => { this.setState(prevState => { const isAlreadySelected = prevState.selectedSourceNetworks.some( - selectedSourceNetwork => selectedSourceNetwork.uid_ems === sourceNetwork.uid_ems + selectedSourceNetwork => networkKey(selectedSourceNetwork) === networkKey(sourceNetwork) ); if (isAlreadySelected) { return { selectedSourceNetworks: prevState.selectedSourceNetworks.filter( - selectedSourceNetwork => selectedSourceNetwork.uid_ems !== sourceNetwork.uid_ems + selectedSourceNetwork => networkKey(selectedSourceNetwork) !== networkKey(sourceNetwork) ) }; } @@ -201,7 +202,7 @@ class NetworksStepForm extends React.Component { ...targetNetwork, selected: false, nodes: sourceNetworks.map(sourceNetwork => { - if (sourceNetwork.uid_ems === selectedNode.uid_ems) { + if (networkKey(sourceNetwork) === networkKey(selectedNode)) { return { ...sourceNetwork, selected: !sourceNetwork.selected @@ -309,7 +310,7 @@ class NetworksStepForm extends React.Component { selected={ selectedSourceNetworks && selectedSourceNetworks.some( - selectedSourceNetwork => selectedSourceNetwork.uid_ems === sourceNetwork.uid_ems + selectedSourceNetwork => networkKey(selectedSourceNetwork) === networkKey(sourceNetwork) ) } handleClick={this.selectSourceNetwork} @@ -324,7 +325,7 @@ class NetworksStepForm extends React.Component { item={targetNetwork} text={`${targetNetwork.providerName} \\ ${targetNetwork.name}`} key={targetNetwork.id} - selected={selectedTargetNetwork && selectedTargetNetwork.uid_ems === targetNetwork.uid_ems} + selected={selectedTargetNetwork && networkKey(selectedTargetNetwork) === networkKey(targetNetwork)} handleClick={this.selectTargetNetwork} handleKeyPress={this.selectTargetNetwork} /> diff --git a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/__tests__/NetworksStepForm.test.js b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/__tests__/NetworksStepForm.test.js index 20975a532f..6bc9e48e76 100644 --- a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/__tests__/NetworksStepForm.test.js +++ b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/__tests__/NetworksStepForm.test.js @@ -2,7 +2,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import NetworksStepForm from '../NetworksStepForm'; -import { groupByUidEms } from '../../../MappingWizardNetworksStepSelectors'; +import { uniqueNetworks } from '../../../MappingWizardNetworksStepSelectors'; import { clustersMappingWithTreeViewAttrs, targetNetworkWithTreeViewAttrs, networkGroupingForRep } from '../helpers'; @@ -36,8 +36,8 @@ describe('#addNetworkMapping', () => { ); const [networkGroupRep] = networkGrouping; @@ -58,7 +58,7 @@ describe('#addNetworkMapping', () => { nodes: [ { ...targetNetworkWithTreeViewAttrs(targetNetworkToMap), - nodes: networkGroupingForRep(networkGroupRep, groupByUidEms(networkGrouping), props.selectedCluster) + nodes: networkGroupingForRep(networkGroupRep, uniqueNetworks(networkGrouping), props.selectedCluster) } ] } @@ -69,7 +69,7 @@ describe('#addNetworkMapping', () => { const [mappedTargetNetwork, , targetNetworkToMap] = targetNetworks; const [, , mappedSourceNetwork] = sourceNetworks; const srcNetworks = [...networkGrouping, mappedSourceNetwork]; - const groupedNetworks = groupByUidEms(srcNetworks); + const groupedNetworks = uniqueNetworks(srcNetworks); const networksStepMapping = { ...clustersMappingWithTreeViewAttrs(clustersMapping), nodes: [ @@ -87,8 +87,8 @@ describe('#addNetworkMapping', () => { ); const [networkGroupRep] = networkGrouping; @@ -122,7 +122,7 @@ describe('#addNetworkMapping', () => { const [mappedTargetNetwork] = targetNetworks; const [, , mappedSourceNetwork] = sourceNetworks; const srcNetworks = [...networkGrouping, mappedSourceNetwork]; - const groupedNetworks = groupByUidEms(srcNetworks); + const groupedNetworks = uniqueNetworks(srcNetworks); const networksStepMapping = { ...clustersMappingWithTreeViewAttrs(clustersMapping), nodes: [ @@ -141,8 +141,8 @@ describe('#addNetworkMapping', () => { ); const [networkGroupRep] = networkGrouping; @@ -179,8 +179,8 @@ describe('#removeNode', () => { const [targetNetworkOne, targetNetworkTwo] = targetNetworks; const sourceNetworkGroupOne = sourceNetworks.slice(0, 2); const sourceNetworkGroupTwo = sourceNetworks.slice(2, 3); - const groupedSourceNetworks = groupByUidEms([...sourceNetworkGroupOne, ...sourceNetworkGroupTwo]); - const groupedTargetNetworks = groupByUidEms([targetNetworkOne, targetNetworkTwo]); + const groupedSourceNetworks = uniqueNetworks([...sourceNetworkGroupOne, ...sourceNetworkGroupTwo]); + const groupedTargetNetworks = uniqueNetworks([targetNetworkOne, targetNetworkTwo]); props = { ...props, groupedSourceNetworks, diff --git a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/__tests__/__snapshots__/helpers.test.js.snap b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/__tests__/__snapshots__/helpers.test.js.snap index a6285556fd..386b491605 100644 --- a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/__tests__/__snapshots__/helpers.test.js.snap +++ b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/__tests__/__snapshots__/helpers.test.js.snap @@ -58,6 +58,7 @@ Object { exports[`dedupeMappedSourceNetworks reduces a network mapping's source networks to representatives 1`] = ` Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -70,6 +71,7 @@ Object { "nodes": Array [ Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -98,6 +100,7 @@ exports[`getRepresentatives should return an array with a representative from ea Array [ Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -115,6 +118,7 @@ Array [ }, Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -132,6 +136,7 @@ Array [ }, Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -150,9 +155,10 @@ Array [ ] `; -exports[`mappingWithSourceNetworkRemoved removes all networks whose uid_ems matches that of the specified source network 1`] = ` +exports[`mappingWithSourceNetworkRemoved removes all networks whose network key matches that of the specified source network 1`] = ` Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -165,6 +171,7 @@ Object { "nodes": Array [ Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -212,6 +219,7 @@ Object { "nodes": Array [ Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -224,6 +232,7 @@ Object { "nodes": Array [ Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -277,6 +286,7 @@ Array [ "nodes": Array [ Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -289,6 +299,7 @@ Array [ "nodes": Array [ Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -323,6 +334,7 @@ exports[`networkGroupingForRep returns the network grouping, with TreeView attrs Array [ Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -339,12 +351,13 @@ Array [ "sourceClusterId": "1", "switch_id": "1", "tag": "23", - "text": "VMWareCluster1-vm_network1", + "text": "undefined \\\\ VMWareCluster1-vm_network1", "uid_ems": "VMWareCluster1-vm_network1", "updated_on": "2017-06-01T04:24:18Z", }, Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -361,7 +374,7 @@ Array [ "sourceClusterId": "1", "switch_id": "2", "tag": "24", - "text": "VMWareCluster1-vm_network1", + "text": "undefined \\\\ VMWareCluster1-vm_network1", "uid_ems": "VMWareCluster1-vm_network1", "updated_on": "2017-06-01T04:24:18Z", }, @@ -371,6 +384,7 @@ Array [ exports[`sourceNetworkWithTreeViewAttrs adds extra attributes for display in TreeView 1`] = ` Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -387,7 +401,7 @@ Object { "sourceClusterId": "1", "switch_id": "1", "tag": "23", - "text": "VMWareCluster1-vm_network1", + "text": "undefined \\\\ VMWareCluster1-vm_network1", "uid_ems": "VMWareCluster1-vm_network1", "updated_on": "2017-06-01T04:24:18Z", } @@ -397,6 +411,7 @@ exports[`sourceNetworksFilter should return a representative for each source net Array [ Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -414,6 +429,7 @@ Array [ }, Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -435,6 +451,7 @@ Array [ exports[`targetNetworkWithTreeViewAttrs adds extra attributes for display in TreeView 1`] = ` Object { "allow_promiscuous": null, + "clusterId": "1", "computed_allow_promiscuous": null, "computed_forged_transmits": null, "computed_mac_changes": null, @@ -452,7 +469,7 @@ Object { }, "switch_id": "10000000000000", "tag": null, - "text": "RHV Cluster 1 - ovirtmgmt1", + "text": "undefined \\\\ RHV Cluster 1 - ovirtmgmt1", "uid_ems": "00000000-0000-0000-0000-000000000000", "updated_on": "2017-06-01T04:24:18Z", } diff --git a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/__tests__/helpers.test.js b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/__tests__/helpers.test.js index 092e049f4a..a1b4fc689d 100644 --- a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/__tests__/helpers.test.js +++ b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/__tests__/helpers.test.js @@ -11,7 +11,7 @@ import { mappingWithTargetNetworkRemoved, mappingWithSourceNetworkRemoved } from '../helpers'; -import { groupByUidEms } from '../../../MappingWizardNetworksStepSelectors'; +import { uniqueNetworks } from '../../../MappingWizardNetworksStepSelectors'; import { sourceNetworks, targetNetworks, @@ -22,7 +22,7 @@ import { } from '../networksStepForm.fixtures'; test('getRepresentatives should return an array with a representative from each source network grouping', () => { - expect(getRepresentatives(groupByUidEms(sourceNetworks))).toMatchSnapshot(); + expect(getRepresentatives(uniqueNetworks(sourceNetworks))).toMatchSnapshot(); }); test('sourceNetworksFilter should return a representative for each source network grouping that have not been mapped', () => { @@ -39,7 +39,7 @@ test('sourceNetworksFilter should return a representative for each source networ } ] }; - expect(sourceNetworksFilter(groupByUidEms(sourceNetworks), [networksStepMapping])).toMatchSnapshot(); + expect(sourceNetworksFilter(uniqueNetworks(sourceNetworks), [networksStepMapping])).toMatchSnapshot(); }); test('clustersMappingWithTreeViewAttrs adds extra attributes for display in TreeView', () => { @@ -59,7 +59,7 @@ test('sourceNetworkWithTreeViewAttrs adds extra attributes for display in TreeVi test('networkGroupingForRep returns the network grouping, with TreeView attrs, for a representative', () => { const [sourceNetworkRep] = networkGrouping; - const groupedSourceNetworks = groupByUidEms(networkGrouping); + const groupedSourceNetworks = uniqueNetworks(networkGrouping); const selectedCluster = sourceCluster; expect(networkGroupingForRep(sourceNetworkRep, groupedSourceNetworks, selectedCluster)).toMatchSnapshot(); @@ -134,7 +134,7 @@ describe('mappingWithSourceNetworkRemoved', () => { const [sourceNetworkToRemove] = networkGrouping; const [targetNetwork] = targetNetworks; - test('removes all networks whose uid_ems matches that of the specified source network', () => { + test('removes all networks whose network key matches that of the specified source network', () => { const networksMapping = { ...targetNetwork, nodes: [...networkGrouping, sourceNetworkShouldRemain] diff --git a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/helpers.js b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/helpers.js index 98d8d68e68..19e58b34cf 100644 --- a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/helpers.js +++ b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/components/NetworksStepForm/helpers.js @@ -1,10 +1,11 @@ -import { groupByUidEms } from '../../MappingWizardNetworksStepSelectors'; +import { uniqueNetworks } from '../../MappingWizardNetworksStepSelectors'; +import { networkKey } from '../../../../../../../common/networkKey'; export const getRepresentatives = (groupedNetworks = {}) => { const representatives = []; - for (const uid_ems in groupedNetworks) { - if ({}.hasOwnProperty.call(groupedNetworks, uid_ems)) { - representatives.push(groupedNetworks[uid_ems][0]); + for (const key in groupedNetworks) { + if ({}.hasOwnProperty.call(groupedNetworks, key)) { + representatives.push(groupedNetworks[key][0]); } } return representatives; @@ -20,7 +21,7 @@ export const sourceNetworksFilter = (groupedSourceNetworks, networksStepMappings }, []); return getRepresentatives(groupedSourceNetworks).filter( - network => !mappedNetworks.some(mappedNetwork => mappedNetwork.uid_ems === network.uid_ems) + network => !mappedNetworks.some(mappedNetwork => networkKey(mappedNetwork) === networkKey(network)) ); }; @@ -32,7 +33,7 @@ export const clustersMappingWithTreeViewAttrs = clusterMapping => ({ export const targetNetworkWithTreeViewAttrs = targetNetwork => ({ ...targetNetwork, - text: targetNetwork.name, + text: `${targetNetwork.providerName} \\ ${targetNetwork.name}`, selectable: true, selected: false, state: { @@ -42,7 +43,7 @@ export const targetNetworkWithTreeViewAttrs = targetNetwork => ({ export const sourceNetworkWithTreeViewAttrs = (sourceNetwork, selectedCluster) => ({ ...sourceNetwork, - text: sourceNetwork.name, + text: `${sourceNetwork.providerName} \\ ${sourceNetwork.name}`, icon: 'fa fa-file-o', sourceClusterId: selectedCluster.id, selectable: true, @@ -50,13 +51,13 @@ export const sourceNetworkWithTreeViewAttrs = (sourceNetwork, selectedCluster) = }); export const networkGroupingForRep = (sourceNetworkRep, groupedSourceNetworks, selectedCluster) => { - const sourceNetworks = groupedSourceNetworks[sourceNetworkRep.uid_ems]; + const sourceNetworks = groupedSourceNetworks[networkKey(sourceNetworkRep)]; return sourceNetworks.map(sourceNetwork => sourceNetworkWithTreeViewAttrs(sourceNetwork, selectedCluster)); }; export const dedupeMappedSourceNetworks = networksMapping => { const { nodes: sourceNetworks, ...targetNetwork } = networksMapping; - const groupedNetworks = groupByUidEms(sourceNetworks); + const groupedNetworks = uniqueNetworks(sourceNetworks); return { ...targetNetwork, nodes: getRepresentatives(groupedNetworks) @@ -65,7 +66,7 @@ export const dedupeMappedSourceNetworks = networksMapping => { export const dedupeMappedTargetNetworks = networksStepMapping => { const { nodes: networksMappings, ...targetCluster } = networksStepMapping; - const groupedMappings = groupByUidEms(networksMappings); + const groupedMappings = uniqueNetworks(networksMappings); return { ...targetCluster, nodes: getRepresentatives(groupedMappings) @@ -102,7 +103,7 @@ export const mappingWithTargetNetworkRemoved = (networksStepMapping, targetNetwo export const mappingWithSourceNetworkRemoved = (networksMapping, sourceNetworkToRemove) => { const { nodes: sourceNetworks, ...targetNetwork } = networksMapping; const updatedSourceNetworks = sourceNetworks.filter( - sourceNetwork => sourceNetwork.uid_ems !== sourceNetworkToRemove.uid_ems + sourceNetwork => networkKey(sourceNetwork) !== networkKey(sourceNetworkToRemove) ); return updatedSourceNetworks.length === 0 ? null diff --git a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/index.js b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/index.js index 1a92b99902..959c3cf401 100644 --- a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/index.js +++ b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/index.js @@ -2,7 +2,7 @@ import { connect } from 'react-redux'; import MappingWizardNetworksStep from './MappingWizardNetworksStep'; import * as MappingWizardNetworksStepActions from './MappingWizardNetworksStepActions'; import { showAlertAction } from '../../MappingWizardActions'; -import { groupByUidEms } from './MappingWizardNetworksStepSelectors'; +import { uniqueNetworks } from './MappingWizardNetworksStepSelectors'; import reducer from './MappingWizardNetworksStepReducer'; @@ -12,8 +12,8 @@ const mapStateToProps = ({ mappingWizardNetworksStep, form }, ownProps) => ({ ...mappingWizardNetworksStep, ...ownProps.data, clusterMappings: form.mappingWizardClustersStep.values.clusterMappings, - groupedSourceNetworks: groupByUidEms(mappingWizardNetworksStep.sourceNetworks), - groupedTargetNetworks: groupByUidEms(mappingWizardNetworksStep.targetNetworks) + groupedSourceNetworks: uniqueNetworks(mappingWizardNetworksStep.sourceNetworks), + groupedTargetNetworks: uniqueNetworks(mappingWizardNetworksStep.targetNetworks) }); const actions = { diff --git a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/mappingWizardNetworksStep.fixtures.js b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/mappingWizardNetworksStep.fixtures.js index 8de8583174..1ffd44232e 100644 --- a/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/mappingWizardNetworksStep.fixtures.js +++ b/app/javascript/react/screens/App/Overview/screens/MappingWizard/components/MappingWizardNetworksStep/mappingWizardNetworksStep.fixtures.js @@ -26,6 +26,7 @@ export const sourceClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000007', id: '1-1', + clusterId: '1', switch_id: '1', name: 'VMWareCluster1-vm_network1', tag: '23', @@ -43,6 +44,7 @@ export const sourceClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000008', id: '1-2', + clusterId: '1', switch_id: '2', name: 'VMWareCluster1-vm_network1', tag: '24', @@ -60,6 +62,7 @@ export const sourceClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000009', id: '1-3', + clusterId: '1', switch_id: '1', name: 'VMWareCluster1-vm_network2', tag: '24', @@ -77,6 +80,7 @@ export const sourceClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000010', id: '1-4', + clusterId: '1', switch_id: '1', name: 'VMWareCluster1-vm_network3', tag: '24', @@ -117,6 +121,7 @@ export const sourceClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000011', id: '2-1', + clusterId: '2', switch_id: '1', name: 'VMWareCluster2-vm_network1', tag: '23', @@ -134,6 +139,7 @@ export const sourceClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000012', id: '2-2', + clusterId: '2', switch_id: '1', name: 'VMWareCluster2-vm_network2', tag: '24', @@ -151,6 +157,7 @@ export const sourceClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000013', id: '2-3', + clusterId: '2', switch_id: '1', name: 'VMWareCluster2-vm_network3', tag: '24', @@ -168,6 +175,7 @@ export const sourceClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000014', id: '2-4', + clusterId: '2', switch_id: '2', name: 'VMWareCluster2-vm_network3', tag: '24', @@ -208,6 +216,7 @@ export const sourceClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000015', id: '3-1', + clusterId: '3', switch_id: '1', name: 'VMWareCluster3-vm_network1', tag: '23', @@ -225,6 +234,7 @@ export const sourceClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000016', id: '3-2', + clusterId: '3', switch_id: '2', name: 'VMWareCluster3-vm_network1', tag: '24', @@ -242,6 +252,7 @@ export const sourceClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000017', id: '3-3', + clusterId: '3', switch_id: '3', name: 'VMWareCluster3-vm_network1', tag: '24', @@ -259,6 +270,7 @@ export const sourceClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000018', id: '3-4', + clusterId: '3', switch_id: '1', name: 'VMWareCluster3-vm_network2', tag: '24', @@ -302,6 +314,7 @@ export const targetClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000019', id: '1-1', + clusterId: '1', switch_id: '10000000000000', name: 'RHV Cluster 1 - ovirtmgmt1', tag: null, @@ -319,6 +332,7 @@ export const targetClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000020', id: '1-2', + clusterId: '1', switch_id: '10000000000001', name: 'RHV Cluster 1 - ovirtmgmt1', tag: null, @@ -337,6 +351,7 @@ export const targetClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000021', id: '1-3', + clusterId: '1', switch_id: '10000000000013', name: 'RHV Cluster 1 - ovirtmgmt3', tag: null, @@ -377,6 +392,7 @@ export const targetClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000022', id: '2-1', + clusterId: '2', switch_id: '10000000000008', name: 'RHV Cluster 2 - ovirtmgmt1', tag: null, @@ -394,6 +410,7 @@ export const targetClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000023', id: '2-2', + clusterId: '2', switch_id: '10000000000015', name: 'RHV Cluster 2 - ovirtmgmt2', tag: null, @@ -412,6 +429,7 @@ export const targetClusterNetworks = [ { href: 'http://localhost:3000/api/lans/10000000000024', id: '2-3', + clusterId: '2', switch_id: '10000000000013', name: 'RHV Cluster 2 - ovirtmgmt3', tag: null, diff --git a/app/javascript/react/screens/App/common/networkKey.js b/app/javascript/react/screens/App/common/networkKey.js new file mode 100644 index 0000000000..8f2d18cf13 --- /dev/null +++ b/app/javascript/react/screens/App/common/networkKey.js @@ -0,0 +1,4 @@ +/** + * returns a unique network based on current UI model + */ +export const networkKey = network => `${network.clusterId}\\${network.uid_ems}`;