-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a fast Create Plan page - step 3
Changes: 1. split state into slices 2. split reducer.tx - move state helper functions 3. improve typings for multus network type 4. create hooks to retrieve nic profiles and networks from the inventory 5. create a MappingList component for editing mappings 6. re-create state only when input queries are fully loaded 7. display source networks in 2 categories: networks used by the selected VMs and remaining networks on the provider 8. create network mapping based on information in the state Signed-off-by: Radoslaw Szwajkowski <[email protected]>
- Loading branch information
Showing
16 changed files
with
1,416 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,3 +67,5 @@ filesystems | |
bootloader | ||
typeahead | ||
immer | ||
networkattachmentdefinitions | ||
nicprofiles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/forklift-console-plugin/src/modules/Providers/hooks/useNetworks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useMemo } from 'react'; | ||
|
||
import { | ||
OpenShiftNetworkAttachmentDefinition, | ||
OpenstackNetwork, | ||
OVirtNetwork, | ||
ProviderType, | ||
V1beta1Provider, | ||
VSphereNetwork, | ||
} from '@kubev2v/types'; | ||
|
||
import useProviderInventory from './useProviderInventory'; | ||
|
||
export type InventoryNetwork = | ||
| OpenShiftNetworkAttachmentDefinition | ||
| OpenstackNetwork | ||
| OVirtNetwork | ||
| VSphereNetwork; | ||
|
||
export const useSourceNetworks = ( | ||
provider: V1beta1Provider, | ||
): [InventoryNetwork[], boolean, Error] => { | ||
const providerType: ProviderType = provider?.spec?.type as ProviderType; | ||
const { | ||
inventory: networks, | ||
loading, | ||
error, | ||
} = useProviderInventory<InventoryNetwork[]>({ | ||
provider, | ||
subPath: providerType === 'openshift' ? '/networkattachmentdefinitions' : '/networks', | ||
}); | ||
|
||
const typedNetworks = useMemo( | ||
() => | ||
Array.isArray(networks) | ||
? networks.map((net) => ({ ...net, providerType } as InventoryNetwork)) | ||
: [], | ||
[networks], | ||
); | ||
|
||
return [typedNetworks, loading, error]; | ||
}; | ||
|
||
export const useOpenShiftNetworks = ( | ||
provider: V1beta1Provider, | ||
): [OpenShiftNetworkAttachmentDefinition[], boolean, Error] => { | ||
const isOpenShift = provider?.spec?.type === 'openshift'; | ||
const { | ||
inventory: networks, | ||
loading, | ||
error, | ||
} = useProviderInventory<OpenShiftNetworkAttachmentDefinition[]>({ | ||
provider, | ||
subPath: isOpenShift ? '/networkattachmentdefinitions' : '', | ||
}); | ||
|
||
const typedNetworks: OpenShiftNetworkAttachmentDefinition[] = useMemo( | ||
() => | ||
Array.isArray(networks) ? networks.map((net) => ({ ...net, providerType: 'openshift' })) : [], | ||
[networks], | ||
); | ||
|
||
return [typedNetworks, loading, error]; | ||
}; |
29 changes: 29 additions & 0 deletions
29
packages/forklift-console-plugin/src/modules/Providers/hooks/useNicProfiles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useMemo } from 'react'; | ||
|
||
import { OVirtNicProfile, V1beta1Provider } from '@kubev2v/types'; | ||
|
||
import useProviderInventory from './useProviderInventory'; | ||
|
||
/** | ||
* Works only for oVirt | ||
*/ | ||
export const useNicProfiles = (provider: V1beta1Provider): [OVirtNicProfile[], boolean, Error] => { | ||
const isOVirt = provider?.spec?.type === 'ovirt'; | ||
const { | ||
inventory: nicProfiles, | ||
loading, | ||
error, | ||
} = useProviderInventory<OVirtNicProfile[]>({ | ||
provider, | ||
subPath: isOVirt ? '/nicprofiles?detail=1' : '', | ||
}); | ||
|
||
const stable = useMemo(() => { | ||
if (!isOVirt) { | ||
return []; | ||
} | ||
return Array.isArray(nicProfiles) ? nicProfiles : []; | ||
}, [isOVirt, nicProfiles]); | ||
|
||
return [stable, loading, error]; | ||
}; |
2 changes: 2 additions & 0 deletions
2
packages/forklift-console-plugin/src/modules/Providers/views/create/templates/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
// @index(['./*', /style/g], f => `export * from '${f.path}';`) | ||
export * from './networkMapTemplate'; | ||
export * from './planTemplate'; | ||
export * from './providerTemplate'; | ||
export * from './secretTemplate'; | ||
export * from './storageMapTemplate'; | ||
// @endindex |
10 changes: 10 additions & 0 deletions
10
...orklift-console-plugin/src/modules/Providers/views/create/templates/networkMapTemplate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { V1beta1NetworkMap } from '@kubev2v/types'; | ||
|
||
export const networkMapTemplate: V1beta1NetworkMap = { | ||
apiVersion: 'forklift.konveyor.io/v1beta1', | ||
kind: 'NetworkMap', | ||
metadata: { | ||
name: undefined, | ||
namespace: undefined, | ||
}, | ||
}; |
10 changes: 10 additions & 0 deletions
10
...orklift-console-plugin/src/modules/Providers/views/create/templates/storageMapTemplate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { V1beta1StorageMap } from '@kubev2v/types'; | ||
|
||
export const storageMapTemplate: V1beta1StorageMap = { | ||
apiVersion: 'forklift.konveyor.io/v1beta1', | ||
kind: 'StorageMap', | ||
metadata: { | ||
name: undefined, | ||
namespace: undefined, | ||
}, | ||
}; |
Oops, something went wrong.