-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Form lib enhancements #78588
Form lib enhancements #78588
Conversation
The typings for the FromSchema was too permissive and did not limit the keys to the form interface provided. Fixes elastic#60602
Pinging @elastic/es-ui (Team:Elasticsearch UI) |
@patrykkopycinski Could you have a look at those 2 files. There are typings issue now that the
|
@elasticmachine merge upstream |
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.
Tested ingest processors pipeline locally, and did not spot any regressions!
Great work @sebelga ! I left non-blocking comments in the code.
readonly isSubmitting: boolean; | ||
/** Flag that indicates if the form is valid. It can have three values: `true | false | undefined`. */ |
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.
nit; I would phrase this as:
/** Flag that indicates if the form is valid. If `undefined` then form validation has not been checked yet. */
I think the TS boolean
value is self-explanatory for the other states.
readonly id: string; | ||
/** | ||
* This handlers submits the form and returns its data and validity. If the form is not valid, the data will be `null` |
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.
typo: handlers -> handler
@@ -18,7 +18,7 @@ import { | |||
import { TextEditor } from '../../field_components'; | |||
import { to, from, EDITOR_PX_HEIGHT } from '../shared'; | |||
|
|||
const ignoreFailureConfig: FieldConfig = { | |||
const ignoreFailureConfig: FieldConfig<any, any> = { |
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.
I know we discussed some of this offline, but seeing it now I am wondering if FieldConfig
could be typed as:
interface FieldConfig<ValueType = unknown, T extends FormData = any> {}
Then when it is used on individual fields we can write:
const ignoreFailureConfig: FieldConfig<boolean> = {
...
}
I'm not certain how often we will set a type for FieldData when using this type directly, I can see it provides types for the validator, but perhaps the helpers/validators we provide cover a large number of cases already?
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.
Yes it makes total sense, I will update it 👍
Thanks for the review @jloleysens ! I made your suggested change to |
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]async chunks size
page load bundle size
History
To update your PR or re-run it, just comment with: |
This PR adds several enhancements to the form lib that I have made while working on the docs. Mainly refactors, TS types, comments.
It is now possible to declare the internal state interface (
I
) when building the form.When providing a schema to a typed form, it validates that fields name are valid. None of the fields are required though.
<UseMultiFields />
componentgetFieldDefaultValue()
)Fixes #60602