From a3882597c7963b9ade08c7faaa96b8d0fc2a2ab9 Mon Sep 17 00:00:00 2001 From: Radoslaw Szwajkowski Date: Mon, 30 Oct 2023 19:34:32 +0100 Subject: [PATCH] Render VM name as resource link for local cluster Signed-off-by: Radoslaw Szwajkowski --- .../OpenShiftVirtualMachinesRow.tsx | 5 ++-- .../VirtualMachines/components/VMCellProps.ts | 1 + .../components/VmResourceLinkRenderer.tsx | 25 +++++++++++++++++++ .../VirtualMachines/utils/useInventoryVms.tsx | 2 ++ .../mocks/src/definitions/basic/vms.mock.ts | 5 +++- 5 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/VmResourceLinkRenderer.tsx diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesRow.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesRow.tsx index 6d5a66397..68583bbd9 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesRow.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesRow.tsx @@ -5,11 +5,12 @@ import { ResourceField, RowProps } from '@kubev2v/common'; import { Td, Tr } from '@patternfly/react-table'; import { PowerStateCellRenderer } from './components/PowerStateCellRenderer'; -import { VMCellProps, VmData, VMNameCellRenderer } from './components'; +import { VmResourceLinkRenderer } from './components/VmResourceLinkRenderer'; +import { VMCellProps, VmData } from './components'; import { getVmTemplate } from './utils'; const cellRenderers: Record> = { - name: VMNameCellRenderer, + name: VmResourceLinkRenderer, status: PowerStateCellRenderer, template: ({ data }) => {getVmTemplate(data?.vm)}, }; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/VMCellProps.ts b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/VMCellProps.ts index 3b4c73a10..aec314307 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/VMCellProps.ts +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/VMCellProps.ts @@ -4,6 +4,7 @@ import { ProviderVirtualMachine } from '@kubev2v/types'; export interface VmData { vm: ProviderVirtualMachine; name: string; + isProviderLocalTarget?: boolean; } export interface VMCellProps { diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/VmResourceLinkRenderer.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/VmResourceLinkRenderer.tsx new file mode 100644 index 000000000..8c8729036 --- /dev/null +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/VmResourceLinkRenderer.tsx @@ -0,0 +1,25 @@ +import React from 'react'; +import { TableCell } from 'src/modules/Providers/utils'; +import { groupVersionKindForObj } from 'src/utils/resources'; + +import { ResourceLink } from '@openshift-console/dynamic-plugin-sdk'; + +import { VMCellProps } from './VMCellProps'; +import { VMNameCellRenderer } from './VMNameCellRenderer'; + +export const VmResourceLinkRenderer: React.FC = (props) => { + const { name, isProviderLocalTarget, vm } = props.data; + if (vm.providerType === 'openshift' && isProviderLocalTarget) { + return ( + + + + ); + } + + return ; +}; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/useInventoryVms.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/useInventoryVms.tsx index 978afe1b2..a24f91e03 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/useInventoryVms.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/useInventoryVms.tsx @@ -1,5 +1,6 @@ import { useProviderInventory, UseProviderInventoryParams } from 'src/modules/Providers/hooks'; import { ProviderData } from 'src/modules/Providers/utils'; +import { isProviderLocalTarget } from 'src/utils/resources'; import { ProviderVirtualMachine } from '@kubev2v/types'; @@ -44,6 +45,7 @@ export const useInventoryVms = ( providerType: provider?.spec?.type, } as ProviderVirtualMachine, name: vm.name, + isProviderLocalTarget: isProviderLocalTarget(validProvider), })) : []; diff --git a/packages/mocks/src/definitions/basic/vms.mock.ts b/packages/mocks/src/definitions/basic/vms.mock.ts index 90fac3fce..b2b70acd1 100644 --- a/packages/mocks/src/definitions/basic/vms.mock.ts +++ b/packages/mocks/src/definitions/basic/vms.mock.ts @@ -1,6 +1,8 @@ /* eslint-disable @cspell/spellchecker */ import { OpenshiftVM, OVirtVM, VSphereVM } from '@kubev2v/types'; +import { NAMESPACE_FORKLIFT } from '../utils'; + import { MOCK_DISK_ATTACHMENTS } from './disks.mock'; import { MOCK_NICS } from './nicProfiles.mock'; import { @@ -376,7 +378,7 @@ export const MOCK_OPENSHIFT_VMS: { [uid in OpenshiftProviderIDs]: OpenshiftVM[] // source: https://kubevirt.io/user-guide/virtual_machines/templates/ { name: 'rheltinyvm', - namespace: '', + namespace: NAMESPACE_FORKLIFT, selfLink: `providers/openshift/${OPENSHIFT_HOST_UID}/vms/3dcaf3ec-6b51-4ca0-8345-6d61841731d7`, uid: '', version: '', @@ -404,6 +406,7 @@ export const MOCK_OPENSHIFT_VMS: { [uid in OpenshiftProviderIDs]: OpenshiftVM[] ['vm.kubevirt.io/template.version']: '0.11.3', }, name: 'rheltinyvm', + namespace: NAMESPACE_FORKLIFT, }, spec: { dataVolumeTemplates: [