-
Notifications
You must be signed in to change notification settings - Fork 13
chore(next): Field types #185
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
base: main
Are you sure you want to change the base?
Conversation
Hi folks! I've started adding TS types to fields, but I'll need your help to confirm what properties I'm missing, identify common properties that I might be missing as well, what properties and optional/mandatory etc. This is why the PR is still in draft 🙂 EDIT: I'm seeing that the CI is failing, so I guess I'll start with that 😅 |
@@ -1,47 +1,123 @@ | |||
import type { JsfSchemaType } from '../types' |
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.
Hi @eng-almeida 👋 I'll review it this afternoon around 16:00!
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.
Hey @eng-almeida, I added comments in two places regarding non-optional properties but this basically applies to all non-optional properties on those field types.
We don't actually have any sort of validation that checks that when for example 'x-js-presentation': { 'inputType': 'money'}
is given there is also 'x-js-presentation': { 'currency': 'EUR'}
.
@sandrina-p, is that something we do in v0?
next/src/field/type.ts
Outdated
|
||
export interface FieldTextarea extends BaseField { | ||
type: 'textarea' | ||
maxLength: number |
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.
maxLength
ia not mandatory in a JsonSchema and if not provided it won't be in the field.
maxLength: number | |
maxLength?: number |
next/src/field/type.ts
Outdated
export interface FieldOption { | ||
export interface FieldText extends BaseField { | ||
type: 'text' | ||
maxLength: number |
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.
Same as with FieldTextArea
.
next/src/field/type.ts
Outdated
inputType: 'statement' | ||
severity: 'warning' | 'error' | 'info' | ||
} | ||
[key: string]: unknown |
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.
This line hides a lot of TS errors that are hard to address without it. I'll keep investigating...
description?: string | ||
fields?: Field[] | ||
// @deprecated in favor of inputType, | ||
export type FieldType = 'text' | 'number' | 'select' | 'file' | 'radio' | 'group-array' | 'email' | 'date' | 'checkbox' | 'fieldset' | 'money' | 'country' | 'textarea' |
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.
todo: Here's my controversial opinion: JSF does not care about FieldType
, it's whatever comes from JSON schema x-jsf-presentation.inputType
. We do not provide any extra logic/validation just based on it, right? (right? 👀)
So answering @lukad question:
We don't actually have any sort of validation that checks that when for example 'x-js-presentation': { 'inputType': 'money'} is given there is also 'x-js-presentation': { 'currency': 'EUR'}. @sandrina-p, is that something we do in v0?
We don't and we shouldn't. That logic is a concern of Remote internals, not JSF as headless generator/validator. If we ever validate that, it's another layer on top of JSON-SCHEMA-FORM
Does it make sense to you both?
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.
P.S. I know, this kind affects most of your MR, as the field types should be based on the json schema type
, not the inputType
😶
next/src/field/type.ts
Outdated
export interface FieldOption { | ||
label: string | ||
value: string | ||
description?: string |
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.
todo:
- The
FieldOption
is a mirror ofoneOf
, so if theoneOf
has,foo
inside, then the Type includesfoo
too. value
is not necessarily a string, can be anything, number, bool, even object. It's a mirror ofoneOf.const
🪩value
can be optional too :p Look at this example withpattern
export interface FieldRadio extends BaseField { | ||
type: 'radio' | ||
options: FieldOption[] | ||
direction?: 'row' | 'column' |
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.
todo: Here's another example. This is Remote internal need, not a JSF concern. A few other examples down the line (currency
, fileDownload
, statement
, etc... All of those Types can exist, but not at JSF.
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.
You're right 💯 ! Probably the right move is to extend these types on Remote SDK project which uses Remote JSON Schemas 👍
next/src/field/type.ts
Outdated
value: unknown | ||
[key: string]: unknown | ||
description: string | ||
fields: () => Field[] |
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.
bug: This is v0, in v1 is fields: Field[]
(Once #177 is merged)) :D
Adds TS types for individual fields.