Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update vsphere url help text #736

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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.",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@ export const VSphereProviderCreateForm: React.FC<VSphereProviderCreateFormProps>
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,
},
};
Expand Down Expand Up @@ -67,24 +77,41 @@ export const VSphereProviderCreateForm: React.FC<VSphereProviderCreateFormProps>
}

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 } });
}
},
[provider],
);

const getURLValidationState = (url: string): Validation => {
if (!validateURL(url)) return 'error';
if (!url.endsWith('sdk')) return 'warning';
return 'success';
};

return (
<Form isWidthLimited className="forklift-section-provider-edit">
<FormGroup
label={t('URL')}
isRequired
fieldId="url"
helperText={t('URL of the provider')}
helperText={t(
'Enter the URL of the SDK endpoint in vCenter. Ensure it includes the "sdk" path, e.g., https://vcenter.com/sdk.',
)}
validated={state.validation.url}
helperTextInvalid={t('Error: URL is required and must be valid.')}
helperTextInvalid={state.validation.urlHelperTextInvalid}
>
<TextInput
isRequired
Expand Down