From 3e2b6f33c0190148851ef14f0559ebd10d2014de Mon Sep 17 00:00:00 2001 From: yaacov Date: Fri, 17 May 2024 17:29:48 +0300 Subject: [PATCH] Add link to vmware ui Signed-off-by: yaacov --- .../en/plugin__forklift-console-plugin.json | 3 ++- .../EditProviderUI/EditProviderUIModal.tsx | 2 +- .../EditProviderUI/OvirtEditUIModal.tsx | 15 +++-------- .../DetailsSection/VSphereDetailsSection.tsx | 16 +++++++++--- .../utils/getOvirtProviderWebUILink.ts | 2 +- .../utils/getVSphereProviderWebUILink.ts | 26 +++++++++++++++++++ .../components/DetailsSection/utils/index.ts | 1 + 7 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 packages/forklift-console-plugin/src/modules/Providers/views/details/components/DetailsSection/utils/getVSphereProviderWebUILink.ts diff --git a/packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json b/packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json index 7c0bc71a3..52c9b7804 100644 --- a/packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json +++ b/packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json @@ -200,7 +200,7 @@ "Issuer": "Issuer", "Kubernetes name of the new migration Plan resource": "Kubernetes name of the new migration Plan resource", "Label": "Label", - "Link for the Red Hat Virtualization Manager (RHVM) landing page. For example, https://rhv-host-example.com/ovirt-engine.": "Link for the Red Hat Virtualization Manager (RHVM) landing page. For example, https://rhv-host-example.com/ovirt-engine.", + "Link for the provider Virtualization Manager landing page. For example, https://rhv-host-example.com/ovirt-engine.": "Link for the provider Virtualization Manager landing page. For example, https://rhv-host-example.com/ovirt-engine.", "List of objects depended by this object. If ALL objects in the list have been deleted,\n this object will be garbage collected. If this object is managed by a controller,\n then an entry in this list will point to this controller, with the controller field set to true.\n There cannot be more than one managing controller.": "List of objects depended by this object. If ALL objects in the list have been deleted,\n this object will be garbage collected. If this object is managed by a controller,\n then an entry in this list will point to this controller, with the controller field set to true.\n There cannot be more than one managing controller.", "Loading": "Loading", "Loading...": "Loading...", @@ -506,6 +506,7 @@ "VM(s) with NICs that are not linked with a NIC profile were detected.": "VM(s) with NICs that are not linked with a NIC profile were detected.", "VMs": "VMs", "VMware only: vSphere product name.": "VMware only: vSphere product name.", + "VMware UI": "VMware UI", "VMware Virtual Disk Development Kit (VDDK) image, for example: quay.io/kubev2v/vddk:latest .": "VMware Virtual Disk Development Kit (VDDK) image, for example: quay.io/kubev2v/vddk:latest .", "Volume Types": "Volume Types", "Volumes": "Volumes", diff --git a/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderUI/EditProviderUIModal.tsx b/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderUI/EditProviderUIModal.tsx index 3bfaec0de..cb0012e8d 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderUI/EditProviderUIModal.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderUI/EditProviderUIModal.tsx @@ -21,11 +21,11 @@ export type EditProviderUIModalProps = Modify< export const EditProviderUIModal: React.FC = (props) => { switch (props.resource?.spec?.type) { + case 'vsphere': case 'ovirt': return ; case 'openshift': case 'openstack': - case 'vsphere': default: return <>; } diff --git a/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderUI/OvirtEditUIModal.tsx b/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderUI/OvirtEditUIModal.tsx index fe8d898ac..487238a9a 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderUI/OvirtEditUIModal.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderUI/OvirtEditUIModal.tsx @@ -15,17 +15,8 @@ export const OvirtEditUIModal: React.FC = (props) => { const ModalBody = ( -

Link for the Red Hat Virtualization Manager (RHVM) landing page.

-
-

Use this link to access the RHVM user interface for RHV VMs management.

-
-

- The format of the provided link for the Red Hat Virtualization Manager (RHVM) landing page - should include a scheme, a domain name, path, and optionally a port. Usually the path will - end with /ovirt-engine, for example:{' '} - https://rhv-host-example.com/ovirt-engine. -

-
+

Link for the Provider Virtualization Manager landing page.

+

Use this link to access the user interface for the providers virtualization management.

If no link value is specify then a default auto calculated or an empty value is set.

); @@ -40,7 +31,7 @@ export const OvirtEditUIModal: React.FC = (props) => { variant={ModalVariant.large} body={ModalBody} helperText={t( - 'Link for the Red Hat Virtualization Manager (RHVM) landing page. For example, https://rhv-host-example.com/ovirt-engine.', + 'Link for the provider Virtualization Manager landing page. For example, https://rhv-host-example.com/ovirt-engine.', )} onConfirmHook={patchProviderUI} validationHook={validateOvirtUILink} diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/components/DetailsSection/VSphereDetailsSection.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/components/DetailsSection/VSphereDetailsSection.tsx index f21aa1707..8681a66e0 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/components/DetailsSection/VSphereDetailsSection.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/components/DetailsSection/VSphereDetailsSection.tsx @@ -8,6 +8,7 @@ import { DetailsItem } from '../../../../utils'; import { CreatedAtDetailsItem, CredentialsDetailsItem, + ExternalManagementLinkDetailsItem, NameDetailsItem, NamespaceDetailsItem, OwnerDetailsItem, @@ -16,11 +17,13 @@ import { VDDKDetailsItem, } from './components'; import { DetailsSectionProps } from './DetailsSection'; +import { getVSphereProviderWebUILink } from './utils'; export const VSphereDetailsSection: React.FC = ({ data }) => { const { t } = useForkliftTranslation(); const { provider, permissions } = data; + const webUILink = getVSphereProviderWebUILink(provider); return ( = ({ data }) = - + = ({ data }) = } /> - + - + + + ); }; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/components/DetailsSection/utils/getOvirtProviderWebUILink.ts b/packages/forklift-console-plugin/src/modules/Providers/views/details/components/DetailsSection/utils/getOvirtProviderWebUILink.ts index 3cec06f50..5a857d215 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/components/DetailsSection/utils/getOvirtProviderWebUILink.ts +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/components/DetailsSection/utils/getOvirtProviderWebUILink.ts @@ -16,7 +16,7 @@ export const getOvirtProviderWebUILink = (provider: V1beta1Provider): string => } // Calculate link using API URL - const uiLinkRegexp = new RegExp('(?<=ovirt-engine)\\/api(\\/)*$', 'g'); + const uiLinkRegexp = new RegExp('(?<=ovirt-engine)/api(/)?$', 'g'); const regexpResult = uiLinkRegexp.exec(provider?.spec?.url); return provider?.spec?.url && regexpResult diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/components/DetailsSection/utils/getVSphereProviderWebUILink.ts b/packages/forklift-console-plugin/src/modules/Providers/views/details/components/DetailsSection/utils/getVSphereProviderWebUILink.ts new file mode 100644 index 000000000..fe31c7e6c --- /dev/null +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/components/DetailsSection/utils/getVSphereProviderWebUILink.ts @@ -0,0 +1,26 @@ +import { V1beta1Provider } from '@kubev2v/types'; + +import { getProviderUIAnnotation } from './getProviderUIAnnotation'; + +/** + * A function for auto calculating the vSphere UI link. + * It extracts the provider's vSphere UI link from the vSphere URL by searching for the URL's + */ +export const getVSphereProviderWebUILink = (provider: V1beta1Provider): string => { + // Check for custom link + const customLink = getProviderUIAnnotation(provider); + if (customLink) { + return customLink; + } + + // Calculate link using API URL + const url = provider?.spec?.url || ''; + const suffix = '/sdk'; + const newSuffix = '/ui'; + + if (url.endsWith(suffix)) { + return url.slice(0, -suffix.length) + newSuffix; + } else { + return url; + } +}; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/components/DetailsSection/utils/index.ts b/packages/forklift-console-plugin/src/modules/Providers/views/details/components/DetailsSection/utils/index.ts index b08f80cf1..ad045a711 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/components/DetailsSection/utils/index.ts +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/components/DetailsSection/utils/index.ts @@ -1,4 +1,5 @@ // @index(['./*', /style/g], f => `export * from '${f.path}';`) export * from './getOvirtProviderWebUILink'; export * from './getProviderUIAnnotation'; +export * from './getVSphereProviderWebUILink'; // @endindex