-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat(types): add types for forms collection #1415
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
599d92a
feat: add types for FF field-wrappers
Birkbjo 827f5e4
feat(types): add types for transformers and validators
Birkbjo a1ee758
fix: mirror folder-structure for types
Birkbjo e3d27f8
fix: remove old-types structure
Birkbjo 392f782
fix(types): cleanup
Birkbjo 4927daf
style: run prettier
Birkbjo 0a3c283
refactor: rename overridden type name to rest
Birkbjo b54551e
style: run prettier
Birkbjo 3b8a539
fix(types): make selected payload always present
Birkbjo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
collections/forms/types/CheckboxFieldFF/CheckboxFieldFF.d.ts
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,16 @@ | ||
import type { FieldRenderProps } from 'react-final-form' | ||
import type { CheckboxFieldProps } from '@dhis2-ui/checkbox' | ||
import React from 'react' | ||
|
||
type CheckBoxValue = CheckboxFieldProps['value'] | ||
type CheckboxRestProps = Omit< | ||
CheckboxFieldProps, | ||
'onChange' | 'value' | 'checked' | 'name' | ||
> | ||
|
||
export type CheckboxFieldFFProps = FieldRenderProps<CheckBoxValue> & | ||
CheckboxRestProps & { | ||
showValidStatus?: boolean | ||
} | ||
|
||
export const CheckboxFieldFF: React.FC<CheckboxFieldFFProps> |
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,9 @@ | ||
import React from 'react' | ||
import type { FieldGroupProps } from '@dhis2-ui/field' | ||
|
||
export type FieldGroupFFProps = Omit< | ||
FieldGroupProps, | ||
'children' | 'label' | 'name' | 'required' | ||
> | ||
|
||
export const FieldGroupFF: React.FC<FieldGroupFFProps> |
18 changes: 18 additions & 0 deletions
18
collections/forms/types/FileInputFieldFF/FileInputFieldFF.d.ts
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,18 @@ | ||
import React from 'react' | ||
import type { FileInputFieldProps } from '@dhis2-ui/file-input' | ||
import type { FieldRenderProps } from 'react-final-form' | ||
|
||
export type FilesValue = File[] | undefined | null | '' | ||
|
||
type FileInputRestProps = Omit< | ||
FileInputFieldProps, | ||
'onChange' | 'multiple' | 'name' | ||
> | ||
|
||
export type FileInputFieldFFProps = FieldRenderProps<FilesValue> & | ||
FileInputRestProps & { | ||
showValidStatus?: boolean | ||
multifile: FileInputFieldProps['multiple'] | ||
} | ||
|
||
export const FileInputFieldFF: React.FC<FileInputFieldFFProps> |
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,15 @@ | ||
import React from 'react' | ||
import type { InputFieldProps } from '@dhis2-ui/input' | ||
import type { FieldRenderProps } from 'react-final-form' | ||
|
||
export type InputValue = InputFieldProps['value'] | ||
|
||
type InputFieldRestProps = Omit<InputFieldProps, 'onChange' | 'value' | 'name'> | ||
|
||
export type InputFieldFFProps = FieldRenderProps<InputValue> & | ||
InputFieldRestProps & { | ||
showLoadingStatus?: boolean | ||
showValidStatus?: boolean | ||
} | ||
|
||
export const InputFieldFF: React.FC<InputFieldFFProps> |
24 changes: 24 additions & 0 deletions
24
collections/forms/types/MultiSelectFieldFF/MutliSelectFieldFF.d.ts
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,24 @@ | ||
import React from 'react' | ||
import type { FieldRenderProps } from 'react-final-form' | ||
import type { | ||
MultiSelectOptionProps, | ||
MultiSelectFieldProps, | ||
} from '@dhis2-ui/select' | ||
|
||
type InputValue = MultiSelectFieldProps['selected'] | '' | ||
|
||
type MultiSelectFieldRestProps = Omit< | ||
MultiSelectFieldProps, | ||
'onChange' | 'value' | ||
> | ||
|
||
type MultiSelectOptions = Array<Pick<MultiSelectOptionProps, 'value' | 'label'>> | ||
|
||
export type MultiSelectFieldFFProps = FieldRenderProps<InputValue> & | ||
MultiSelectFieldRestProps & { | ||
showLoadingStatus?: boolean | ||
showValidStatus?: boolean | ||
options: MultiSelectOptions | ||
} | ||
|
||
export const MultiSelectFieldFF: React.FC<MultiSelectFieldFFProps> |
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,17 @@ | ||
import React from 'react' | ||
import type { FieldRenderProps } from 'react-final-form' | ||
import type { RadioProps } from '@dhis2-ui/radio' | ||
|
||
type InputValue = RadioProps['value'] | ||
|
||
type RadioRestProps = Omit< | ||
RadioProps, | ||
'onChange' | 'value' | 'checked' | 'name' | ||
> | ||
|
||
export type RadioFieldFFProps = FieldRenderProps<InputValue> & | ||
RadioRestProps & { | ||
showValidStatus?: boolean | ||
} | ||
|
||
export const RadioFieldFF: React.FC<RadioFieldFFProps> |
26 changes: 26 additions & 0 deletions
26
collections/forms/types/SingleSelectFieldFF/SingleSelectFieldFF.d.ts
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,26 @@ | ||
import React from 'react' | ||
import type { FieldRenderProps } from 'react-final-form' | ||
import type { | ||
SingleSelectOptionProps, | ||
SingleSelectFieldProps, | ||
} from '@dhis2-ui/select' | ||
|
||
type InputValue = SingleSelectFieldProps['selected'] | ||
|
||
type SingleSelectOptions = Array< | ||
Pick<SingleSelectOptionProps, 'value' | 'label'> | ||
> | ||
|
||
type SingleSelectRestProps = Omit< | ||
SingleSelectFieldProps, | ||
'onChange' | 'value' | 'name' | ||
> | ||
|
||
export type SingleSelectFieldFFProps = FieldRenderProps<InputValue> & | ||
SingleSelectRestProps & { | ||
showLoadingStatus?: boolean | ||
showValidStatus?: boolean | ||
options: SingleSelectOptions | ||
} | ||
|
||
export const SingleSelectFieldFF: React.FC<SingleSelectFieldFFProps> |
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,15 @@ | ||
import React from 'react' | ||
import type { FieldRenderProps } from 'react-final-form' | ||
import type { SwitchFieldProps } from '@dhis2-ui/switch' | ||
|
||
type InputValue = SwitchFieldProps['value'] | ||
|
||
type SwitchFieldRestProps = Omit< | ||
SwitchFieldProps, | ||
'onChange' | 'checked' | 'value' | 'name' | ||
> | ||
|
||
export type SwitchFieldFFProps = FieldRenderProps<InputValue> & | ||
SwitchFieldRestProps | ||
|
||
export const SwitchFieldFF: React.FC<SwitchFieldFFProps> |
15 changes: 15 additions & 0 deletions
15
collections/forms/types/TextAreaFieldFF/TextAreaFieldFF.d.ts
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,15 @@ | ||
import React from 'react' | ||
import type { FieldRenderProps } from 'react-final-form' | ||
import type { TextAreaFieldProps } from '@dhis2-ui/text-area' | ||
|
||
type InputValue = TextAreaFieldProps['value'] | ||
|
||
type TextAreaFieldRestProps = Omit< | ||
TextAreaFieldProps, | ||
'onChange' | 'value' | 'name' | ||
> | ||
|
||
export type TextAreaFieldFFProps = FieldRenderProps<InputValue> & | ||
TextAreaFieldRestProps | ||
|
||
export const TextAreaFieldFF: React.FC<TextAreaFieldFFProps> |
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,28 @@ | ||
import * as FinalForm from 'final-form' | ||
import * as ReactFinalForm from 'react-final-form' | ||
|
||
export { CheckboxFieldFF } from './CheckboxFieldFF/CheckboxFieldFF' | ||
export { FileInputFieldFF } from './FileInputFieldFF/FileInputFieldFF' | ||
export { InputFieldFF } from './InputFieldFF/InputFieldFF' | ||
export { MultiSelectFieldFF } from './MultiSelectFieldFF/MutliSelectFieldFF' | ||
export { SingleSelectFieldFF } from './SingleSelectFieldFF/SingleSelectFieldFF' | ||
export { RadioFieldFF } from './RadioFieldFF/RadioFieldFF' | ||
export { SwitchFieldFF } from './SwitchFieldFF/SwitchFieldFF' | ||
export { TextAreaFieldFF } from './TextAreaFieldFF/TextAreaFieldFF' | ||
export { FieldGroupFF } from './FieldGroupFF/FieldGroupFF' | ||
|
||
export * from './transformers' | ||
export * from './validators' | ||
|
||
/** | ||
* Allows direct access to the FinalForm library. Please note that this is considered advanced | ||
* usage and that you need to stay up to date with breaking changes in the FinalForm library. | ||
*/ | ||
export { FinalForm } | ||
|
||
/** | ||
* Allows direct access to the ReactFinalForm library. Please note that this is considered | ||
* advanced usage and that you need to stay up to date with breaking changes in the FinalForm | ||
* library. | ||
*/ | ||
export { ReactFinalForm } |
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,6 @@ | ||
export type ValuesWithId = Array<{ id: string }> | undefined | ||
|
||
export const arrayWithIdObjects: { | ||
format: (value: ValuesWithId) => string | ||
pars: (value: string) => ValuesWithId | ||
} |
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,31 @@ | ||
export type Validator = (value: unknown) => string | undefined | ||
|
||
export const alphaNumeric: Validator | ||
export const boolean: Validator | ||
export const composeValidators: (...validators: Validator[]) => Validator | ||
|
||
export const createCharacterLengthRange: ( | ||
lowerBound: number, | ||
upperBound: number, | ||
customMessage?: string | ||
) => Validator | ||
export const createEqualTo: (key: string, description?: string) => Validator | ||
export const createMaxCharacterLength: (upperBound: number) => Validator | ||
export const createMaxNumber: (upperBound: number) => Validator | ||
export const createMinCharacterLength: (lowerBound: number) => Validator | ||
export const createMinNumber: (lowerBound: number) => Validator | ||
export const createNumberRange: ( | ||
lowerBound: number, | ||
upperBound: number, | ||
customMessage?: string | ||
) => Validator | ||
export const createPattern: (pattern: RegExp, message?: string) => Validator | ||
export const dhis2Password: Validator | ||
export const dhis2Username: Validator | ||
export const email: Validator | ||
export const hasValue: Validator | ||
export const integer: Validator | ||
export const internationalPhoneNumber: Validator | ||
export const number: Validator | ||
export const string: Validator | ||
export const url: Validator |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should onBlur be omitted too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onChange
is the only handler that won't be called.onBlur
andonFocus
will call both the callback oninput.onBlur
and the passedonBlur
in root-props.onChange
just calls the one oninput
. This seems consistent for all FF components. See here https://github.com/dhis2/ui/blob/feat/types-fieldff/collections/forms/src/CheckboxFieldFF/CheckboxFieldFF.js#L33-L35 .