forked from openshift/console
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OCPBUGS-29616 OCPBUGS-31613 Add validation for vSphere fields
Handle submit errors correctly
- Loading branch information
Showing
16 changed files
with
549 additions
and
462 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 0 additions & 64 deletions
64
frontend/packages/vsphere-plugin/src/components/ConnectionFormContext.tsx
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
frontend/packages/vsphere-plugin/src/components/TextField.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import * as React from 'react'; | ||
import { | ||
FormGroup, | ||
FormHelperText, | ||
HelperText, | ||
HelperTextItem, | ||
TextInput, | ||
TextInputProps, | ||
} from '@patternfly/react-core'; | ||
import { ExclamationCircleIcon } from '@patternfly/react-icons'; | ||
import { useField } from 'formik'; | ||
|
||
interface TextFieldProps extends TextInputProps { | ||
name: string; | ||
helperText?: React.ReactNode; | ||
} | ||
|
||
const TextField = React.forwardRef( | ||
( | ||
{ helperText, onChange: onParentChange, ...props }: TextFieldProps, | ||
ref: React.Ref<HTMLInputElement>, | ||
) => { | ||
const [field, meta, { setValue }] = useField({ | ||
name: props.name, | ||
}); | ||
|
||
const onChange = (_ev, value: string) => { | ||
setValue(value); | ||
onParentChange?.(_ev, value); | ||
}; | ||
|
||
const fieldId = `textfield-${props.name}`; | ||
const hasError = meta.touched && !!meta.error; | ||
|
||
return ( | ||
<FormGroup id={`form-control__${fieldId}`} fieldId={fieldId}> | ||
<TextInput | ||
{...field} | ||
{...props} | ||
ref={ref} | ||
id={fieldId} | ||
onChange={onChange} | ||
validated={hasError ? 'error' : 'default'} | ||
/> | ||
|
||
{helperText && ( | ||
<FormHelperText> | ||
<HelperText> | ||
<HelperTextItem variant={'default'}>{helperText}</HelperTextItem> | ||
</HelperText> | ||
</FormHelperText> | ||
)} | ||
{hasError && ( | ||
<FormHelperText> | ||
<HelperText> | ||
<HelperTextItem icon={<ExclamationCircleIcon />} variant={'error'}> | ||
{meta.error} | ||
</HelperTextItem> | ||
</HelperText> | ||
</FormHelperText> | ||
)} | ||
</FormGroup> | ||
); | ||
}, | ||
); | ||
|
||
TextField.displayName = 'TextField'; | ||
|
||
export default TextField; |
Oops, something went wrong.