Skip to content

Commit

Permalink
Merge pull request #732 from yaacov/update-ovier-url-help-text
Browse files Browse the repository at this point in the history
Update ovier url help text
  • Loading branch information
yaacov authored Sep 20, 2023
2 parents 50634a6 + 16fcac6 commit 3217dee
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@
"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.",
"Error: Insecure Skip Verify must be a boolean value.": "Error: Insecure Skip Verify must be a boolean value.",
"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.",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@ export const OvirtProviderCreateForm: React.FC<OvirtProviderCreateFormProps> = (

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: '',
},
};

Expand All @@ -43,27 +53,46 @@ export const OvirtProviderCreateForm: React.FC<OvirtProviderCreateFormProps> = (

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 (
<Form isWidthLimited className="forklift-section-provider-edit">
<FormGroup
label={t('URL')}
isRequired
fieldId="url"
helperText={t('URL of the provider')}
helperText={t(
'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.',
)}
validated={state.validation.url}
helperTextInvalid={t('Error: URL is required and must be valid.')}
helperTextInvalid={state.validation.urlHelperTextInvalid}
>
<TextInput
isRequired
Expand Down

0 comments on commit 3217dee

Please sign in to comment.