Skip to content
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: add FileField definition #53

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://deno.land/x/deno/cli/schemas/config-file.v1.json",
"name": "@byzanteam/taihaku-schemas",
"version": "0.5.3",
"version": "0.5.4",
"exports": "./types/mod.ts",
"license": "UNLICENSED",
"compilerOptions": {
Expand Down
23 changes: 23 additions & 0 deletions types/ui_schema/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum FieldType {
Checkbox = 'Checkbox',
Date = 'Date',
DateTime = 'DateTime',
File = 'File',
HasMany = 'HasMany',
HasOne = 'HasOne',
Numeric = 'Numeric',
Expand All @@ -26,9 +27,30 @@ interface AssocitaionSettings {
associationResource: string
}

interface FileSettings {
/**
* Defines the max size of a file upload in megabytes (MB) (inclusive)
* that can be selected for uploading
* @default Infinity
*/
maxFileItemSizeLimitInMB?: number
/**
* Count limit
* @default Infinity
*/
maxCount?: number
/**
* Allowed mimetype pattern
* @default '*'
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept
*/
accept?: string
}

type SettingsRequiredFieldType =
| FieldType.BelongsTo
| FieldType.Checkbox
| FieldType.File
| FieldType.HasMany
| FieldType.HasOne
| FieldType.RadioButton
Expand All @@ -37,6 +59,7 @@ type SettingsRequiredFieldType =
interface FieldSettingsMap {
[FieldType.BelongsTo]: AssocitaionSettings
[FieldType.Checkbox]: EnumSettings
[FieldType.File]: FileSettings
[FieldType.HasMany]: AssocitaionSettings
[FieldType.HasOne]: AssocitaionSettings
[FieldType.RadioButton]: EnumSettings
Expand Down
14 changes: 10 additions & 4 deletions types/ui_schema/form/example/association.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const MovieFormUISchema: FormUISchema<
id: string // format: 'uuid'
name?: string
}
score: number
poster?: {
id?: string // format: 'uuid'
name: string
Expand All @@ -15,9 +16,8 @@ const MovieFormUISchema: FormUISchema<
},
/** Custom Widget UIOption Map */
{
FileWidget: {
'ui:x-multiple': boolean
'ui:x-accept': string
RatingWidget: {
'ui:x-count'?: number
}
}
> = {
Expand All @@ -33,8 +33,14 @@ const MovieFormUISchema: FormUISchema<
},
poster: {
'ui:widget': 'FileWidget',
'ui:x-multiple': false,
'ui:x-max-file-item-size-limit-in-mb': 20,
'ui:x-capture': 'user',
'ui:x-accept': 'image/*',
'ui:x-max-count': 1,
},
score: {
'ui:widget': 'RatingWidget',
'ui:x-count': 5,
},
actors: {
'ui:widget': 'HasManyWidget',
Expand Down
9 changes: 9 additions & 0 deletions types/ui_schema/form/ui_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,21 @@ type BooleanFieldUIOptions = {
'ui:x-falsy-label'?: string
} & CommonCustomFieldUIOptions

type FileFieldUIOptions = {
'ui:x-max-file-item-size-limit-in-mb'?: number
'ui:x-accept'?: string
/** @link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/capture */
'ui:x-capture'?: 'user' | 'environment'
'ui:x-max-count'?: number
} & CommonCustomFieldUIOptions

export type CustomFieldUIOptionsMap = {
[FieldType.BelongsTo]: AssociationFieldUIOptions
[FieldType.Boolean]: BooleanFieldUIOptions
[FieldType.Checkbox]: CheckBoxFieldUIOptions
[FieldType.Date]: DateFieldUIOptions
[FieldType.DateTime]: DateTimeFieldUIOptions
[FieldType.File]: FileFieldUIOptions
[FieldType.HasMany]: AssociationFieldUIOptions
[FieldType.HasOne]: AssociationFieldUIOptions
[FieldType.Numeric]: NumericFieldUIOptions
Expand Down
17 changes: 10 additions & 7 deletions types/ui_schema/table/example/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ const moviesTableSchema: TableSchema<
},
/** Custom Widget UIOption Map */
{
FileWidget: {
'ui:x-multiple': boolean
'ui:x-accept': string
RatingWidget: {
'ui:x-count'?: number
}
}
> = {
Expand Down Expand Up @@ -93,10 +92,12 @@ const moviesTableSchema: TableSchema<
},
poster: {
name: 'poster',
fieldType: 'HasOneField',
fieldType: 'FileField',
label: '海报',
settings: {
associationResource: 'object',
accept: 'image/*',
maxCount: 1,
maxFileItemSizeLimitInMB: 20,
},
},
actors: {
Expand Down Expand Up @@ -143,13 +144,15 @@ const moviesTableSchema: TableSchema<
},
poster: {
'ui:widget': 'FileWidget',
'ui:x-multiple': false,
'ui:x-accept': 'image/*',
},
actors: {
'ui:widget': 'HasManyWidget',
'ui:x-display-property': 'name',
},
score: {
'ui:widget': 'RatingWidget',
'ui:x-count': 5,
},
},
}

Expand Down
18 changes: 7 additions & 11 deletions types/ui_schema/table/ui_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ type DateTimeFieldUIOptions = CommonCustomFieldUIOptions & {
'ui:x-format'?: string
}

type DateFieldUIOptions = CommonCustomFieldUIOptions & {
'ui:x-format'?: string
}
type DateFieldUIOptions = DateTimeFieldUIOptions

type RadioButtonUIOptions = CommonCustomFieldUIOptions & {
'ui:x-option-fallback-style'?: /** className */ string
Expand All @@ -25,31 +23,29 @@ type RadioButtonUIOptions = CommonCustomFieldUIOptions & {
>
}

type CheckboxUIOptions = CommonCustomFieldUIOptions & {
'ui:x-option-fallback-style'?: /** className */ string
'ui:x-options-style'?: Record<
/** option-value */ string,
/** className */ string
>
}
type CheckboxUIOptions = RadioButtonUIOptions

type AssociationUIOptions = CommonCustomFieldUIOptions & {
/** which property should be shown as current assoication row value */
'ui:x-display-property': string
}

type FileUIOptions = CommonCustomFieldUIOptions & {
'ui:x-capture'?: 'user' | 'environment'
}

type BooleanUIOptions = CommonCustomFieldUIOptions & {
'ui:x-truthy-label'?: string
'ui:x-falsy-label'?: string
}

export type CustomColumnUIOptionsMap = {
// TODO: define Checkbox to Signature's UIOptions
[FieldType.BelongsTo]: AssociationUIOptions
[FieldType.Boolean]: BooleanUIOptions
[FieldType.Checkbox]: CheckboxUIOptions
[FieldType.Date]: DateFieldUIOptions
[FieldType.DateTime]: DateTimeFieldUIOptions
[FieldType.File]: FileUIOptions
[FieldType.HasMany]: AssociationUIOptions
[FieldType.HasOne]: AssociationUIOptions
[FieldType.Numeric]: CommonCustomFieldUIOptions
Expand Down