-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,157 @@ | ||
import type { JsfSchemaType } from '../types' | ||
|
||
/** | ||
* WIP type for UI field output that allows for all `x-jsf-presentation` properties to be splatted | ||
* TODO/QUESTION: what are the required fields for a field? what are the things we want to deprecate, if any? | ||
*/ | ||
export interface Field { | ||
name: string | ||
label?: string | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. todo: Here's my controversial opinion: JSF does not care about So answering @lukad question:
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 commentThe 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 |
||
|
||
interface BaseField { | ||
type: FieldType | ||
inputType: FieldType | ||
name: string | ||
label: string | ||
required: boolean | ||
inputType: FieldType | ||
jsonType: JsfSchemaType | ||
errorMessage: Record<string, string> | ||
schema: any | ||
isVisible: boolean | ||
accept?: string | ||
errorMessage?: Record<string, string> | ||
computedAttributes?: Record<string, unknown> | ||
} | ||
|
||
export interface FieldOption { | ||
label: string | ||
value?: string | number | boolean | Record<string, any> | ||
[key: string]: unknown | ||
} | ||
|
||
export interface FieldSelect extends BaseField { | ||
type: 'select' | ||
options: FieldOption[] | ||
} | ||
|
||
export interface FieldTextarea extends BaseField { | ||
type: 'textarea' | ||
maxLength?: number | ||
minLength?: number | ||
} | ||
|
||
export interface FieldDate extends BaseField { | ||
type: 'date' | ||
format: string | ||
minDate?: string | ||
maxDate?: string | ||
maxLength?: number | ||
maxFileSize?: number | ||
format?: string | ||
anyOf?: unknown[] | ||
options?: unknown[] | ||
const?: unknown | ||
checkboxValue?: unknown | ||
} | ||
|
||
// Allow additional properties from x-jsf-presentation (e.g. meta from oneOf/anyOf) | ||
[key: string]: unknown | ||
export interface FieldText extends BaseField { | ||
type: 'text' | ||
maxLength?: number | ||
maskSecret?: number | ||
pattern?: string | ||
} | ||
|
||
/** | ||
* Field option | ||
* @description | ||
* Represents a key/value pair that is used to populate the options for a field. | ||
* Will be created from the oneOf/anyOf elements in a schema. | ||
*/ | ||
export interface FieldOption { | ||
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 commentThe 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 ( There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 👍 |
||
const?: string | ||
} | ||
|
||
export interface FieldNumber extends BaseField { | ||
type: 'number' | ||
minimum?: number | ||
maximum?: number | ||
} | ||
|
||
export interface FieldMoney extends BaseField { | ||
type: 'money' | ||
|
||
} | ||
|
||
export interface FieldCheckbox extends BaseField { | ||
type: 'checkbox' | ||
options?: FieldOption[] | ||
multiple?: boolean | ||
direction?: 'row' | 'column' | ||
checkboxValue?: string | boolean | ||
const?: string | ||
} | ||
|
||
export interface FieldEmail extends BaseField { | ||
type: 'email' | ||
maxLength?: number | ||
format: 'email' | ||
} | ||
|
||
export interface FieldFile extends BaseField { | ||
type: 'file' | ||
accept: string | ||
multiple?: boolean | ||
fileDownload: string | ||
fileName: string | ||
} | ||
export interface FieldFieldSet extends BaseField { | ||
type: 'fieldset' | ||
valueGroupingDisabled?: boolean | ||
visualGroupingDisabled?: boolean | ||
variant?: 'card' | 'focused' | 'default' | ||
fields: Field[] | ||
} | ||
|
||
export interface GroupArrayField extends BaseField { | ||
type: 'group-array' | ||
name: string | ||
label: string | ||
value: unknown | ||
[key: string]: unknown | ||
description: string | ||
fields: Field[] | ||
addFieldText: string | ||
} | ||
|
||
export type FieldType = 'text' | 'number' | 'select' | 'file' | 'radio' | 'group-array' | 'email' | 'date' | 'checkbox' | 'fieldset' | 'money' | 'country' | 'textarea' | ||
export interface FieldCountry extends BaseField { | ||
type: 'country' | ||
options?: FieldOption[] | ||
} | ||
|
||
export interface Field extends BaseField { | ||
computedAttributes?: Record<string, unknown> | ||
description?: string | ||
|
||
// Select specific properties | ||
options?: FieldOption[] | ||
|
||
// Text specific properties | ||
maxLength?: number | ||
maskSecret?: number | ||
minLength?: number | ||
pattern?: string | ||
|
||
// Date specific properties | ||
format?: string | ||
minDate?: string | ||
maxDate?: string | ||
|
||
// Radio specific properties | ||
const?: string | ||
|
||
// Number specific properties | ||
minimum?: number | ||
maximum?: number | ||
|
||
// Money specific properties | ||
currency?: string | ||
|
||
// Checkbox specific properties | ||
multiple?: boolean | ||
checkboxValue?: string | boolean | ||
|
||
// File specific properties | ||
accept?: string | ||
fileName?: string | ||
|
||
// Fieldset specific properties | ||
valueGroupingDisabled?: boolean | ||
visualGroupingDisabled?: boolean | ||
|
||
fields?: Field[] | ||
|
||
// GroupArray specific properties | ||
addFieldText?: string | ||
|
||
enum?: 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.
Hi @eng-almeida 👋 I'll review it this afternoon around 16:00!