From 02c5a4f166484e2b4c4b22c4a8acd83822eeb9af Mon Sep 17 00:00:00 2001 From: Sharon Gratch Date: Sun, 1 Oct 2023 20:03:30 +0300 Subject: [PATCH] Fix vSphere provider url help text field As a followup for https://github.com/kubev2v/forklift-console-plugin/pull/736, fix the vSphere provider's URL help text as follows: 1. Rephrase the error, warning and successful/initial text messages to be aligned with the documnetation, other providers fields and Patternfly error msg recommendations. 2. Set a url input ended with a "/" (i.e. "sdk/") as a valid url since it's a common used case. 3. Fix a bug in which the waring text message string (helperTextMsgs.warning) is never displayed in the UI (the color is set to yellow to indicate the warning field validation state, but the text message was not changed accordingly). Signed-off-by: Sharon Gratch --- .../en/plugin__forklift-console-plugin.json | 6 ++--- .../components/VSphereProviderCreateForm.tsx | 23 ++++++++++--------- 2 files changed, 15 insertions(+), 14 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 3c94c8e42..c11a3f902 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 @@ -101,7 +101,6 @@ "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.", @@ -110,7 +109,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: The provided URL is in an invalid format. Please provide a URL that includes a scheme, a domain name and path. For example: https://vCenter-host-example.com/sdk": "Error: The provided URL is in an invalid format. Please provide a URL that includes a scheme, a domain name and path. For example: https://vCenter-host-example.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.", @@ -391,6 +390,7 @@ "URL must start with https:// or http:// and contain valid hostname and path": "URL must start with https:// or http:// and contain valid hostname and path", "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 vCenter API endpoint. Ensure it includes the \"/sdk\" path, for example: https://vCenter-host-example.com/sdk": "URL of the vCenter API endpoint. Ensure it 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.", "Username": "Username", @@ -412,7 +412,7 @@ "vSphere REST API user name.": "vSphere REST API user name.", "Warning concerns": "Warning concerns", "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.", + "Warning: The provided URL does not end with the API endpoint path: \"sdk\". Ensure it includes the correct path, For example: https://vCenter-host-example.com/sdk": "Warning: The provided URL does not end with the API endpoint path: \"sdk\". Ensure it includes the correct path, For example: https://vCenter-host-example.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 c47222aef..d123e4203 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,19 +19,22 @@ export const VSphereProviderCreateForm: React.FC const url = provider?.spec?.url || ''; const vddkInitImage = provider?.spec?.settings?.['vddkInitImage'] || ''; - const helperTextInvalid = { + const helperTextMsgs = { error: t( - 'Error: Please provide a valid URL with a schema, domain, and path. For example: https://vcenter.com/sdk.', + 'Error: The provided URL is in an invalid format. Please provide a URL that includes a scheme, a domain name and path. For example: https://vCenter-host-example.com/sdk', ), warning: t( - '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 the API endpoint path: "sdk". Ensure it includes the correct path, For example: https://vCenter-host-example.com/sdk', + ), + success: t( + 'URL of the vCenter API endpoint. Ensure it includes the "/sdk" path, for example: https://vCenter-host-example.com/sdk', ), }; const initialState = { validation: { url: 'default' as Validation, - urlHelperTextInvalid: '', + urlHelperText: helperTextMsgs.success, vddkInitImage: 'default' as Validation, }, }; @@ -84,8 +87,8 @@ export const VSphereProviderCreateForm: React.FC dispatch({ type: 'SET_FIELD_VALIDATED', payload: { - field: 'urlHelperTextInvalid', - validationState: helperTextInvalid[validationState], + field: 'urlHelperText', + validationState: helperTextMsgs[validationState], }, }); @@ -97,7 +100,7 @@ export const VSphereProviderCreateForm: React.FC const getURLValidationState = (url: string): Validation => { if (!validateURL(url)) return 'error'; - if (!url.endsWith('sdk')) return 'warning'; + if (!url.endsWith('sdk') && !url.endsWith('sdk/')) return 'warning'; return 'success'; }; @@ -107,11 +110,9 @@ export const VSphereProviderCreateForm: React.FC label={t('URL')} isRequired fieldId="url" - helperText={t( - 'Enter the URL of the SDK endpoint in vCenter. Ensure it includes the "sdk" path, e.g., https://vcenter.com/sdk.', - )} + helperText={state.validation.urlHelperText} validated={state.validation.url} - helperTextInvalid={state.validation.urlHelperTextInvalid} + helperTextInvalid={state.validation.urlHelperText} >