Skip to content

Commit

Permalink
Merge pull request #774 from sgratch/fix-edit-vsphere-url-help-text
Browse files Browse the repository at this point in the history
Fix the Edit URL modal text for the vSphere provider
  • Loading branch information
yaacov authored Nov 8, 2023
2 parents 0faeeeb + baadc04 commit 22ade32
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"Edit VDDK init image": "Edit VDDK init image",
"Empty": "Empty",
"Endpoint": "Endpoint",
"Ensure the URL includes the \"/sdk\" path. For example: https://vCenter-host-example.com/sdk": "Ensure the URL includes the \"/sdk\" path. For example: https://vCenter-host-example.com/sdk",
"Error": "Error",
"Error: CA Certificate must be valid.": "Error: CA Certificate must be valid.",
"Error: Fingerprint is required and must be valid.": "Error: Fingerprint is required and must be valid.",
Expand Down Expand Up @@ -273,7 +274,6 @@
"Please enter the URL for RHV engine server.": "Please enter the URL for RHV engine server.",
"Please enter URL for OpenStack services REST APIs.": "Please enter URL for OpenStack services REST APIs.",
"Please enter URL for the kubernetes API server, if empty URL default to this cluster.": "Please enter URL for the kubernetes API server, if empty URL default to this cluster.",
"Please enter URL for vSphere REST APIs server.": "Please enter URL for vSphere REST APIs server.",
"Pod network": "Pod network",
"Power state": "Power state",
"Powered off": "Powered off",
Expand Down Expand Up @@ -334,7 +334,6 @@
"Specify the type of source provider. Allowed values are ova, ovirt, vsphere, and openstack. This label is needed to verify the credentials are correct when the remote system is accessible and, for RHV, to retrieve the Manager CA certificate when a third-party certificate is specified.": "Specify the type of source provider. Allowed values are ova, ovirt, vsphere, and openstack. This label is needed to verify the credentials are correct when the remote system is accessible and, for RHV, to retrieve the Manager CA certificate when a third-party certificate is specified.",
"Specify the VDDK image that you created.": "Specify the VDDK image that you created.",
"Specify the VDDK image that you created. VDDK accelerates migrations significantly.": "Specify the VDDK image that you created. VDDK accelerates migrations significantly.",
"Specify vCenter host name or IP address - if a certificate for FQDN is specified, the value of this field needs to match the FQDN in the certificate.": "Specify vCenter host name or IP address - if a certificate for FQDN is specified, the value of this field needs to match the FQDN in the certificate.",
"SSHA-1 fingerprint": "SSHA-1 fingerprint",
"Staging": "Staging",
"Status": "Status",
Expand Down Expand Up @@ -393,6 +392,7 @@
"URL of the provider": "URL of the provider",
"URL of the provider, leave empty to use this providers URL": "URL of the provider, leave empty to use this providers URL",
"URL of the Red Hat Virtualization Manager (RHVM) API endpoint. Ensure the URL includes the \"/ovirt-engine/api\" path. For example: https://rhv-host-example.com/ovirt-engine/api": "URL of the Red Hat Virtualization Manager (RHVM) API endpoint. Ensure the URL includes the \"/ovirt-engine/api\" path. For example: https://rhv-host-example.com/ovirt-engine/api",
"URL of the vCenter SDK endpoint.": "URL of the vCenter SDK endpoint.",
"URL of the vCenter SDK endpoint. Ensure the URL includes the \"/sdk\" path. For example: https://vCenter-host-example.com/sdk": "URL of the vCenter SDK endpoint. Ensure the URL includes the \"/sdk\" path. For example: https://vCenter-host-example.com/sdk",
"User ID": "User ID",
"User or service account bearer token for service accounts or user authentication.": "User or service account bearer token for service accounts or user authentication.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,41 @@ import { EditProviderURLModalProps } from './EditProviderURLModal';
export const VSphereEditURLModal: React.FC<EditProviderURLModalProps> = (props) => {
const { t } = useForkliftTranslation();

const helperTextMsgs = {
error: t(
'Error: The format of the provided URL is invalid. Ensure the URL includes a scheme, a domain name, and a path. For example: https://vCenter-host-example.com/sdk',
),
warning: t(
'Warning: The provided URL does not end with the SDK endpoint path: "/sdk". Ensure the URL includes the correct path. For example: https://vCenter-host-example.com/sdk',
),
success: t(
'Ensure the URL includes the "/sdk" path. For example: https://vCenter-host-example.com/sdk',
),
};

const urlValidationHook: ValidationHookType = (value) => {
const isValidURL = validateURL(value.toString().trim());

return isValidURL
? {
validationHelpText: undefined,
validated: 'success',
}
: {
validationHelpText: t(
'URL must start with https:// or http:// and contain valid hostname and path',
),
validated: 'error',
};
const trimmedUrl: string = value.toString().trim();
const isValidURL = validateURL(trimmedUrl);

// error
if (!isValidURL)
return {
validationHelpText: helperTextMsgs.error,
validated: 'error',
};

// warning
if (!trimmedUrl.endsWith('sdk') && !trimmedUrl.endsWith('sdk/'))
return {
validationHelpText: helperTextMsgs.warning,
validated: 'warning',
};

// success
return {
validationHelpText: helperTextMsgs.success,
validated: 'success',
};
};

return (
Expand All @@ -37,10 +58,8 @@ export const VSphereEditURLModal: React.FC<EditProviderURLModalProps> = (props)
label={props?.label || t('URL')}
model={ProviderModel}
variant={ModalVariant.large}
body={t(
'Specify vCenter host name or IP address - if a certificate for FQDN is specified, the value of this field needs to match the FQDN in the certificate.',
)}
helperText={t('Please enter URL for vSphere REST APIs server.')}
body={t('URL of the vCenter SDK endpoint.')}
helperText={helperTextMsgs.success}
onConfirmHook={patchProviderURL}
validationHook={urlValidationHook}
/>
Expand Down

0 comments on commit 22ade32

Please sign in to comment.