feat: relation field and picker
This commit is contained in:
1 parent
b45c99be3b
commit
37a77c9c22
92 files changed
+6826
-80
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
effectiveDefault,
|
||||
holdsRelation,
|
||||
isUnique,
|
||||
supportsChoices,
|
||||
supportsLimits,
|
||||
@@ -7,6 +8,7 @@ import {
|
||||
type BuilderField,
|
||||
type BuilderForm,
|
||||
} from '@/lib/schemaBuilderModel'
|
||||
import type { RelationDefinition } from '@/lib/relationField'
|
||||
|
||||
export interface PayloadField {
|
||||
key: string
|
||||
@@ -18,6 +20,7 @@ export interface PayloadField {
|
||||
min: number | string | null
|
||||
max: number | string | null
|
||||
options: string[]
|
||||
relation: RelationDefinition | null
|
||||
}
|
||||
|
||||
export interface ContentTypePayload {
|
||||
@@ -50,6 +53,12 @@ export interface UpdatePayload {
|
||||
fields: PayloadField[]
|
||||
}
|
||||
|
||||
function relationFor(field: BuilderField): RelationDefinition | null {
|
||||
return holdsRelation(field.type)
|
||||
? { content_type: field.relationType, kind: field.relationKind }
|
||||
: null
|
||||
}
|
||||
|
||||
export function payloadField(field: BuilderField): PayloadField {
|
||||
return {
|
||||
key: field.key,
|
||||
@@ -61,6 +70,7 @@ export function payloadField(field: BuilderField): PayloadField {
|
||||
min: limit(field, field.min),
|
||||
max: limit(field, field.max),
|
||||
options: supportsChoices(field.type) ? trimmedOptions(field) : [],
|
||||
relation: relationFor(field),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user