From 16fcac673e3f6e620d80a97e17c075bdef0a3564 Mon Sep 17 00:00:00 2001 From: yzamir Date: Wed, 20 Sep 2023 11:57:57 +0300 Subject: [PATCH] Update ovirt URL help text Signed-off-by: yzamir --- .../en/plugin__forklift-console-plugin.json | 3 ++ .../components/OvirtProviderCreateForm.tsx | 45 +++++++++++++++---- 2 files changed, 40 insertions(+), 8 deletions(-) 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 c86cff1f8..4142b53c9 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 @@ -99,6 +99,7 @@ "Edit VDDK init image": "Edit VDDK init image", "Empty": "Empty", "Endpoint": "Endpoint", + "Enter the API engine URL for the Red Hat Virtualization (RHV) provider. Ensure it includes the \"ovirt-engine/api\" path, e.g., https://rhv.com/ovirt-engine/api.": "Enter the API engine URL for the Red Hat Virtualization (RHV) provider. Ensure it includes the \"ovirt-engine/api\" path, e.g., https://rhv.com/ovirt-engine/api.", "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.", @@ -106,6 +107,7 @@ "Error: Name is required and must be a unique within a namespace and valid Kubernetes name (i.e., must contain no more than 253 characters, consists of lower case alphanumeric characters , '-' or '.' and starts and ends with an alphanumeric character).": "Error: Name is required and must be a unique within a namespace and valid Kubernetes name (i.e., must contain no more than 253 characters, consists of lower case alphanumeric characters , '-' or '.' and starts and ends with an alphanumeric character).", "Error: NFS mount end point should be in the form NFS_SERVER:EXPORTED_DIRECTORY, for example: 10.10.0.10:/ova.": "Error: NFS mount end point should be in the form NFS_SERVER:EXPORTED_DIRECTORY, for example: 10.10.0.10:/ova.", "Error: Password is required and must be valid.": "Error: Password is required and must be valid.", + "Error: Please provide a valid URL with a schema, domain, and path. For example: https://rhv.com/ovirt-engine/api.": "Error: Please provide a valid URL with a schema, domain, and path. For example: https://rhv.com/ovirt-engine/api.", "Error: This field must be a boolean.": "Error: This field must be a boolean.", "Error: token is a required field, the token must be a valid kubernetes token.": "Error: token is a required field, the token must be a valid kubernetes token.", "Error: URL is required and must be valid.": "Error: URL is required and must be valid.", @@ -395,6 +397,7 @@ "vSphere product name": "vSphere product name", "vSphere REST API password credentials.": "vSphere REST API password credentials.", "vSphere REST API user name.": "vSphere REST API user name.", + "Warning: The provided URL does not end with \"ovirt-engine/api\". Ensure it includes the correct path, like: https://rhv.com/ovirt-engine/api.": "Warning: The provided URL does not end with \"ovirt-engine/api\". Ensure it includes the correct path, like: https://rhv.com/ovirt-engine/api.", "Welcome": "Welcome", "When a plan is archived, its history, metadata, and logs are deleted. The plan cannot be edited or restarted but it can be viewed.": "When a plan is archived, its history, metadata, and logs are deleted. The plan cannot be edited or restarted but it can be viewed.", "YAML": "YAML", diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/create/components/OvirtProviderCreateForm.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/create/components/OvirtProviderCreateForm.tsx index 8fa868e26..64af01fdf 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/create/components/OvirtProviderCreateForm.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/create/components/OvirtProviderCreateForm.tsx @@ -18,9 +18,19 @@ export const OvirtProviderCreateForm: React.FC = ( const url = provider?.spec?.url || ''; + const helperTextInvalid = { + error: t( + 'Error: Please provide a valid URL with a schema, domain, and path. For example: https://rhv.com/ovirt-engine/api.', + ), + warning: t( + 'Warning: The provided URL does not end with "ovirt-engine/api". Ensure it includes the correct path, like: https://rhv.com/ovirt-engine/api.', + ), + }; + const initialState = { validation: { url: 'default' as Validation, + urlHelperTextInvalid: '', }, }; @@ -43,27 +53,46 @@ export const OvirtProviderCreateForm: React.FC = ( const handleChange = useCallback( (id, value) => { - const trimmedValue = value.trim(); + if (id !== 'url') return; + + const trimmedValue: string = value.trim(); + const validationState = getURLValidationState(trimmedValue); - if (id === 'url') { - const validationState = validateURL(trimmedValue) ? 'success' : 'error'; - dispatch({ type: 'SET_FIELD_VALIDATED', payload: { field: id, validationState } }); + dispatch({ + type: 'SET_FIELD_VALIDATED', + payload: { field: 'url', validationState }, + }); - onChange({ ...provider, spec: { ...provider.spec, url: trimmedValue } }); - } + dispatch({ + type: 'SET_FIELD_VALIDATED', + payload: { + field: 'urlHelperTextInvalid', + validationState: helperTextInvalid[validationState], + }, + }); + + onChange({ ...provider, spec: { ...provider.spec, url: trimmedValue } }); }, [provider], ); + const getURLValidationState = (url: string): Validation => { + if (!validateURL(url)) return 'error'; + if (!url.endsWith('ovirt-engine/api')) return 'warning'; + return 'success'; + }; + return (