Skip to content

Commit

Permalink
fix(core): allow create nullable select value
Browse files Browse the repository at this point in the history
fix #90
  • Loading branch information
nichenqin committed Jan 1, 2023
1 parent e7c2896 commit cf43602
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/core/field/select-field-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { FieldValue } from './field.type'
import type { ISelectFieldValue } from './select-field.type'

export class SelectFieldValue extends ValueObject<ISelectFieldValue> {
constructor(value: string) {
constructor(value: ISelectFieldValue) {
super({ value })
}

Expand All @@ -16,7 +16,7 @@ export class SelectFieldValue extends ValueObject<ISelectFieldValue> {
return new this(o.id.value)
}

get id(): string {
get id(): ISelectFieldValue {
return this.props.value
}
}
4 changes: 4 additions & 0 deletions packages/core/field/select-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export class SelectField extends BaseField<ISelectField> {
}

createValue(value: ICreateSelectFieldValue): SelectFieldValue {
if (value === null) {
return new SelectFieldValue(null)
}

const option = this.options.getById(value).unwrap()

return SelectFieldValue.fromOption(option)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/field/select-field.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export const selectFieldQuerySchema = baseFieldQuerySchema.merge(selectTypeObjec
}),
)

export const selectFieldValue = optionIdSchema
export const selectFieldValue = optionIdSchema.nullable()
export type ISelectFieldValue = z.infer<typeof selectFieldValue>

export const createSelectFieldValue = optionIdSchema
export const createSelectFieldValue = optionIdSchema.nullable()
export type ICreateSelectFieldValue = z.infer<typeof createSelectFieldValue>

export const createSelectFieldValue_internal = z
Expand Down

0 comments on commit cf43602

Please sign in to comment.