Skip to content

Commit

Permalink
fix: fix json value display
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Nov 24, 2024
1 parent d27a54e commit 6d1e14e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export let onValueChange: (value: Json) => void
let content: Content = {
text: "{}",
text: JSON.stringify(value ?? {}),
json: value ?? {},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
export let isSelected: boolean
export let field: JsonField
export let recordId: string
export let onValueChange: (value: JsonValue) => void
export let onValueChange: (value: JsonValue | undefined) => void
const updateCell = createMutation({
mutationKey: ["record", tableId, field.id.value, recordId],
Expand All @@ -25,7 +25,7 @@
})
let content: Content = {
text: undefined,
text: JSON.stringify(value ?? {}),
json: value ?? {},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Some } from "@undb/domain"
import { z } from "@undb/zod"
import type { FormFieldVO } from "../../../../forms/form/form-field.vo"
import { FieldConstraintVO, baseFieldConstraint } from "../../field-constraint.vo"
import { jsonSchemaValue } from "./json-field-value.vo"

export const jsonFieldConstraint = z
.object({
Expand All @@ -20,8 +21,7 @@ export class JsonFieldConstraint extends FieldConstraintVO<IJsonFieldConstraint>
})
}
override get schema() {
const literalSchema = z.union([z.string(), z.number(), z.boolean(), z.null()])
let base: z.ZodTypeAny = z.lazy(() => z.union([literalSchema, z.array(base), z.record(base)]))
let base: z.ZodTypeAny = jsonSchemaValue

if (!this.props.required) {
base = base.optional().nullable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import { FieldValueObject } from "../../field-value"

export type { JsonValue } from "type-fest"

const baseSchema = z.union([z.string(), z.number(), z.boolean(), z.null()])
const jsonSchemaValue: z.ZodTypeAny = z.lazy(() =>
z.union([baseSchema, z.array(jsonSchemaValue), z.record(jsonSchemaValue)]),
)
const baseSchema = z.union([
z.string(),
z.number(),
z.boolean(),
z.null(),
z.array(z.any()),
z.record(z.any(), z.any()),
])
export const jsonSchemaValue = baseSchema

export const mutateJsonFieldValueSchema = jsonSchemaValue

Expand Down

0 comments on commit 6d1e14e

Please sign in to comment.