From 1466de72fa4d7c4b4ffc6ab2d1304ac152258c0a Mon Sep 17 00:00:00 2001 From: yzamir Date: Wed, 20 Sep 2023 14:23:27 +0300 Subject: [PATCH] Update vsphere url help text Signed-off-by: yzamir --- .../en/plugin__forklift-console-plugin.json | 3 ++ .../components/VSphereProviderCreateForm.tsx | 35 ++++++++++++++++--- 2 files changed, 34 insertions(+), 4 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 3db602ca4..cde6e1864 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 @@ "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.", + "Enter the URL of the SDK endpoint in vCenter. Ensure it includes the \"sdk\" path, e.g., https://vcenter.com/sdk.": "Enter the URL of the SDK endpoint in vCenter. Ensure it includes the \"sdk\" path, e.g., https://vcenter.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.", @@ -107,6 +108,7 @@ "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: Please provide a valid URL with a schema, domain, and path. For example: https://vcenter.com/sdk.": "Error: Please provide a valid URL with a schema, domain, and path. For example: https://vcenter.com/sdk.", "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.", @@ -383,6 +385,7 @@ "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.", + "Warning: The provided URL does not end with \"sdk\". Ensure it includes the correct path, like: https://vcenter.com/sdk.": "Warning: The provided URL does not end with \"sdk\". Ensure it includes the correct path, like: https://vcenter.com/sdk.", "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/VSphereProviderCreateForm.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/create/components/VSphereProviderCreateForm.tsx index 97e72f62a..c47222aef 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/create/components/VSphereProviderCreateForm.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/create/components/VSphereProviderCreateForm.tsx @@ -19,9 +19,19 @@ export const VSphereProviderCreateForm: React.FC const url = provider?.spec?.url || ''; const vddkInitImage = provider?.spec?.settings?.['vddkInitImage'] || ''; + const helperTextInvalid = { + error: t( + 'Error: Please provide a valid URL with a schema, domain, and path. For example: https://vcenter.com/sdk.', + ), + warning: t( + 'Warning: The provided URL does not end with "sdk". Ensure it includes the correct path, like: https://vcenter.com/sdk.', + ), + }; + const initialState = { validation: { url: 'default' as Validation, + urlHelperTextInvalid: '', vddkInitImage: 'default' as Validation, }, }; @@ -67,8 +77,17 @@ export const VSphereProviderCreateForm: React.FC } if (id === 'url') { - const validationState = validateURL(trimmedValue) ? 'success' : 'error'; - dispatch({ type: 'SET_FIELD_VALIDATED', payload: { field: id, validationState } }); + const validationState = getURLValidationState(trimmedValue); + + dispatch({ type: 'SET_FIELD_VALIDATED', payload: { field: 'url', validationState } }); + + dispatch({ + type: 'SET_FIELD_VALIDATED', + payload: { + field: 'urlHelperTextInvalid', + validationState: helperTextInvalid[validationState], + }, + }); onChange({ ...provider, spec: { ...provider.spec, url: trimmedValue } }); } @@ -76,15 +95,23 @@ export const VSphereProviderCreateForm: React.FC [provider], ); + const getURLValidationState = (url: string): Validation => { + if (!validateURL(url)) return 'error'; + if (!url.endsWith('sdk')) return 'warning'; + return 'success'; + }; + return (