Skip to content

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

chore(next): Field types #185

wants to merge 5 commits into from

Conversation

eng-almeida
Copy link
Collaborator

Adds TS types for individual fields.

@eng-almeida eng-almeida self-assigned this May 8, 2025
@eng-almeida eng-almeida marked this pull request as draft May 8, 2025 16:37
@eng-almeida
Copy link
Collaborator Author

eng-almeida commented May 8, 2025

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'
Copy link
Collaborator

@sandrina-p sandrina-p May 9, 2025

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!

Copy link
Collaborator

@lukad lukad left a 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?


export interface FieldTextarea extends BaseField {
type: 'textarea'
maxLength: number
Copy link
Collaborator

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.

Suggested change
maxLength: number
maxLength?: number

export interface FieldOption {
export interface FieldText extends BaseField {
type: 'text'
maxLength: number
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as with FieldTextArea.

inputType: 'statement'
severity: 'warning' | 'error' | 'info'
}
[key: string]: unknown
Copy link
Collaborator Author

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'
Copy link
Collaborator

@sandrina-p sandrina-p May 9, 2025

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?

Copy link
Collaborator

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 😶

export interface FieldOption {
label: string
value: string
description?: string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo:

  1. The FieldOption is a mirror of oneOf, so if the oneOf has, foo inside, then the Type includes foo too.
  2. value is not necessarily a string, can be anything, number, bool, even object. It's a mirror of oneOf.const 🪩
  3. value can be optional too :p Look at this example with pattern

export interface FieldRadio extends BaseField {
type: 'radio'
options: FieldOption[]
direction?: 'row' | 'column'
Copy link
Collaborator

@sandrina-p sandrina-p May 9, 2025

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.

Copy link
Collaborator Author

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 👍

value: unknown
[key: string]: unknown
description: string
fields: () => Field[]
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants