-
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 providerType property to provider specific Resource types
OpenshiftResource is left unchanged because it's the basis for all Providers. Signed-off-by: Radoslaw Szwajkowski <[email protected]>
- Loading branch information
Showing
8 changed files
with
81 additions
and
31 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
54 changes: 54 additions & 0 deletions
54
...plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/useInventoryVms.tsx
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,54 @@ | ||
import { useProviderInventory, UseProviderInventoryParams } from 'src/modules/Providers/hooks'; | ||
import { ProviderData } from 'src/modules/Providers/utils'; | ||
|
||
import { ProviderVirtualMachine } from '@kubev2v/types'; | ||
|
||
import { VmData } from '../components'; | ||
|
||
import { getHighestPriorityConcern } from './helpers'; | ||
|
||
/** | ||
* A hook for retrieving VMs from the inventory. | ||
* Adds providerType property to each VM. | ||
* | ||
* @param providerData provider that is the source of the data | ||
* @param providerLoaded loading status of the parent provider | ||
* @param providerLoadError load error of the parent provider (if any) | ||
* @returns {Array} tuple containing: the data, loading status and load error (if any) | ||
*/ | ||
export const useInventoryVms = ( | ||
{ provider, inventory }: ProviderData, | ||
providerLoaded: boolean, | ||
providerLoadError: unknown, | ||
): [VmData[], boolean, Error] => { | ||
const largeInventory = inventory?.vmCount > 1000; | ||
const customTimeoutAndInterval = largeInventory ? 250000 : undefined; | ||
const validProvider = providerLoaded && !providerLoadError && provider; | ||
|
||
const inventoryOptions: UseProviderInventoryParams = { | ||
provider: validProvider, | ||
subPath: 'vms?detail=4', | ||
fetchTimeout: customTimeoutAndInterval, | ||
interval: customTimeoutAndInterval, | ||
}; | ||
|
||
const { | ||
inventory: vms, | ||
loading, | ||
error, | ||
} = useProviderInventory<ProviderVirtualMachine[]>(inventoryOptions); | ||
|
||
const vmData: VmData[] = | ||
!loading && !error && Array.isArray(vms) | ||
? vms.map((vm) => ({ | ||
vm: { | ||
...vm, | ||
providerType: provider?.spec?.type, | ||
} as ProviderVirtualMachine, | ||
name: vm.name, | ||
concerns: getHighestPriorityConcern(vm), | ||
})) | ||
: []; | ||
|
||
return [vmData, loading, error]; | ||
}; |
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
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
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
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
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
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