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

Feature/338 form validation library #368

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
69d7aca
feat: Install react-hook-form library
g-saracca Apr 1, 2024
5403001
feat: Add placeholder prop
g-saracca Apr 1, 2024
aeccafa
fix(design system): Remove span from feedback col causing overflow-x
g-saracca Apr 2, 2024
65ac28e
chore: avoid checking voids return on attributes
g-saracca Apr 2, 2024
a7e05fa
feat: forward ref to Fields
g-saracca Apr 2, 2024
4843632
feat(design system): forward refs to form-elements
g-saracca Apr 2, 2024
ae9244e
feat: replicate borders for checkbox group, more forward refs and rem…
g-saracca Apr 2, 2024
7f25f14
chore: comment unused imports temporarily
g-saracca Apr 2, 2024
db641b2
feat: validations in progress
g-saracca Apr 4, 2024
4abfaa7
feat: validations done
g-saracca Apr 4, 2024
fc1f36e
feat: use real endpoint refactor
g-saracca Apr 5, 2024
3b3154b
fix: use items as router Links and add collectionId to route link
g-saracca Apr 5, 2024
62ff552
refactor: collectionId could either be a number or a string
g-saracca Apr 5, 2024
37af53a
feat: change vocabulary multiple to work with checkboxes
g-saracca Apr 6, 2024
c79ad59
feat(design system): forward ref to checkbox input
g-saracca Apr 6, 2024
1ed3a0e
feat: Remove unnecesary props from fields
g-saracca Apr 6, 2024
6fc322a
feat: Use locales for fields validations
g-saracca Apr 6, 2024
5b874e5
feat: Add feedback validation to checkbox group
g-saracca Apr 6, 2024
42378c1
feat: map metadatablock info fields names with dots to slashes to avo…
g-saracca Apr 6, 2024
c386f84
feat: map metadatablock info fields names and viceversa on form submit
g-saracca Apr 8, 2024
d00d4e9
feat: finish formatting form values to DTO
g-saracca Apr 8, 2024
9dde1ec
feat: Add test cases to cover validation rules
g-saracca Apr 10, 2024
acdee29
feat: rename metadaBlockInfo types
g-saracca Apr 10, 2024
26b8c2c
feat: More testings
g-saracca Apr 10, 2024
08dd236
feat: finish with component testing and remove submitting state becau…
g-saracca Apr 10, 2024
599ab9b
chore: use different version of client-js
g-saracca Apr 10, 2024
d6fa9fa
feat: small changes reading submitting state
g-saracca Apr 10, 2024
d3276a5
test: refactor e2e test
g-saracca Apr 11, 2024
2e6e97c
feat: back to original submitting state
g-saracca Apr 11, 2024
cf4ead7
chore: remove comments
g-saracca Apr 11, 2024
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
8 changes: 8 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
"trailingComma": "none",
"bracketSameLine": true
}
],
"@typescript-eslint/no-misused-promises": [
"error",
{
"checksVoidReturn": {
"attributes": false
}
}
]
},
"overrides": [
Expand Down
2 changes: 1 addition & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"selector-pseudo-class-no-unknown": [
true,
{
"ignorePseudoClasses": ["export"]
"ignorePseudoClasses": ["export", "global"]
}
],
"property-no-unknown": [
Expand Down
95 changes: 20 additions & 75 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"@faker-js/faker": "7.6.0",
"@iqss/dataverse-client-javascript": "2.0.0-pr132.dd49caf",
"@iqss/dataverse-client-javascript": "2.0.0-pr141.2d54907",
"@iqss/dataverse-design-system": "*",
"@istanbuljs/nyc-config-typescript": "1.0.2",
"@tanstack/react-table": "8.9.2",
Expand All @@ -33,6 +33,7 @@
"moment-timezone": "0.5.43",
"react-bootstrap": "2.7.2",
"react-bootstrap-icons": "1.10.3",
"react-hook-form": "7.51.2",
"react-i18next": "12.1.5",
"react-infinite-scroll-hook": "4.1.1",
"react-loader-spinner": "5.3.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ interface FormCheckboxProps extends Omit<React.InputHTMLAttributes<HTMLInputElem
validFeedback?: string
}

export function FormCheckbox({
label,
id,
isValid,
isInvalid,
validFeedback,
invalidFeedback,
...props
}: FormCheckboxProps) {
export const FormCheckbox = React.forwardRef(function FormCheckbox(
{ label, id, isValid, isInvalid, validFeedback, invalidFeedback, ...props }: FormCheckboxProps,
ref
) {
return (
<FormBS.Check type="checkbox" id={id}>
<FormBS.Check.Input type="checkbox" isValid={isValid} isInvalid={isInvalid} {...props} />
<FormBS.Check.Input
type="checkbox"
isValid={isValid}
isInvalid={isInvalid}
ref={ref as React.ForwardedRef<HTMLInputElement>}
{...props}
/>
<FormBS.Check.Label>{label}</FormBS.Check.Label>
<FormBS.Control.Feedback type="invalid">{invalidFeedback}</FormBS.Control.Feedback>
<FormBS.Control.Feedback type="valid">{validFeedback}</FormBS.Control.Feedback>
</FormBS.Check>
)
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function FormFeedback({
return withinMultipleFieldsGroup ? (
<FormControl.Feedback type={type}>{children}</FormControl.Feedback>
) : (
<FormControl.Feedback as={Col} sm={{ offset: 3, span: 9 }} type={type}>
<FormControl.Feedback as={Col} sm={{ offset: 3 }} type={type}>
{children}
</FormControl.Feedback>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ interface FormInputProps extends React.HTMLAttributes<FormInputElement> {
disabled?: boolean
}

export function FormInput({
type = 'text',
name,
readOnly,
isValid,
isInvalid,
disabled,
withinMultipleFieldsGroup,
...props
}: FormInputProps) {
export const FormInput = React.forwardRef(function FormInput(
{
type = 'text',
name,
readOnly,
isValid,
isInvalid,
disabled,
withinMultipleFieldsGroup,
...props
}: FormInputProps,
ref
) {
return (
<FormElementLayout
withinMultipleFieldsGroup={withinMultipleFieldsGroup}
Expand All @@ -37,8 +40,9 @@ export function FormInput({
isValid={isValid}
isInvalid={isInvalid}
disabled={disabled}
ref={ref as React.ForwardedRef<HTMLInputElement>}
{...props}
/>
</FormElementLayout>
)
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ interface FormSelectProps extends Omit<React.SelectHTMLAttributes<HTMLSelectElem
withinMultipleFieldsGroup?: boolean
}

export function FormSelect({
withinMultipleFieldsGroup,
children,
...props
}: PropsWithChildren<FormSelectProps>) {
export const FormSelect = React.forwardRef(function FormSelect(
{ withinMultipleFieldsGroup, children, ...props }: PropsWithChildren<FormSelectProps>,
ref
) {
return (
<FormElementLayout withinMultipleFieldsGroup={withinMultipleFieldsGroup}>
<FormBS.Select {...props}>{children}</FormBS.Select>
<FormBS.Select ref={ref as React.ForwardedRef<HTMLSelectElement>} {...props}>
{children}
</FormBS.Select>
</FormElementLayout>
)
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@ interface FormTextAreaProps extends Omit<React.HTMLAttributes<FormInputElement>,
isInvalid?: boolean
}

export function FormTextArea({
name,
disabled,
isValid,
isInvalid,
withinMultipleFieldsGroup,
...props
}: FormTextAreaProps) {
export const FormTextArea = React.forwardRef(function FormTextArea(
{ name, disabled, isValid, isInvalid, withinMultipleFieldsGroup, ...props }: FormTextAreaProps,
ref
) {
return (
<FormElementLayout
withinMultipleFieldsGroup={withinMultipleFieldsGroup}
isInvalid={isInvalid}
isValid={isValid}>
<FormBS.Control as="textarea" rows={5} disabled={disabled} name={name} {...props} />
<FormBS.Control
as="textarea"
rows={5}
disabled={disabled}
name={name}
isValid={isValid}
isInvalid={isInvalid}
ref={ref as React.ForwardedRef<HTMLTextAreaElement>}
{...props}
/>
</FormElementLayout>
)
}
})
33 changes: 8 additions & 25 deletions public/locales/en/createDataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,14 @@
},
"requiredFields": "Asterisks indicate required fields",
"datasetForm": {
"fields": {
"title": {
"label": "Title",
"tooltip": "The main title of the Dataset",
"feedback": "Title is required."
},
"authorName": {
"label": "Author Name",
"tooltip": "The name of the author, such as the person's name or the name of an organization",
"feedback": "Author name is required."
},
"datasetContactEmail": {
"label": "Point of Contact E-mail",
"tooltip": "The point of contact's e-mail address",
"feedback": "Point of Contact E-mail is required."
},
"dsDescriptionValue": {
"label": "Description Text",
"tooltip": "A summary describing the purpose, nature and scope of the Dataset",
"feedback": "Description Text is required."
},
"subject": {
"label": "Subject",
"tooltip": "The area of study relevant to the Dataset",
"feedback": "Subject is required."
"field": {
"required": "{{displayName}} is required",
"invalid": {
"url": "{{displayName}} is not a valid URL",
"email": "{{displayName}} is not a valid email",
"int": "{{displayName}} is not a valid integer",
"float": "{{displayName}} is not a valid float",
"date": "{{displayName}} is not a valid date. Please use the format {{dateFormat}}"
}
},
"status": {
Expand Down
Loading
Loading