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

Embedded form #421

Draft
wants to merge 10 commits into
base: feat/generator-custom
Choose a base branch
from
Draft
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
18 changes: 17 additions & 1 deletion apps/example/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const options: NextAdminOptions = {
} as const,
"email",
"posts",
"coPosts",
"role",
"birthDate",
"avatar",
Expand Down Expand Up @@ -121,6 +122,9 @@ export const options: NextAdminOptions = {
display: "list",
orderField: "order",
},
role: {
//disabled: true,
},
avatar: {
format: "file",
handler: {
Expand Down Expand Up @@ -157,7 +161,7 @@ export const options: NextAdminOptions = {
},
hooks: {
beforeDb: async (data, mode, request) => {
const newPassword = data.newPassword;
const newPassword = data.password;
if (newPassword) {
data.hashedPassword = `hashed-${newPassword}`;
}
Expand Down Expand Up @@ -277,6 +281,17 @@ export const options: NextAdminOptions = {
},
},
edit: {
styles: {
_form: "grid-cols-3 gap-4 md:grid-cols-4",
id: "col-span-2 row-start-1",
title: "col-span-2 row-start-1",
content: "col-span-4 row-start-2",
published: "col-span-4 md:col-span-2 row-start-3",
categories: "col-span-4 md:col-span-2 row-start-4",
author: "col-span-4 md:col-span-3 row-start-5",
rate: "col-span-3 row-start-6",
tags: "col-span-4 row-start-7",
},
fields: {
content: {
format: "richtext-html",
Expand All @@ -297,6 +312,7 @@ export const options: NextAdminOptions = {
"published",
"categories",
"author",
"coAuthors",
"rate",
"tags",
],
Expand Down
250 changes: 250 additions & 0 deletions apps/example/prisma/json-schema/json-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"User": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"email": {
"type": "string"
},
"hashedPassword": {
"type": [
"string",
"null"
]
},
"name": {
"type": [
"string",
"null"
]
},
"posts": {
"type": "array",
"items": {
"$ref": "#/definitions/Post"
}
},
"coPosts": {
"type": "array",
"items": {
"$ref": "#/definitions/Post"
}
},
"profile": {
"anyOf": [
{
"$ref": "#/definitions/Profile"
},
{
"type": "null"
}
]
},
"birthDate": {
"type": [
"string",
"null"
],
"format": "date-time"
},
"createdAt": {
"type": "string",
"format": "date-time"
},
"updatedAt": {
"type": "string",
"format": "date-time"
},
"role": {
"type": "string",
"default": "USER",
"enum": [
"USER",
"ADMIN"
]
},
"avatar": {
"type": [
"string",
"null"
]
},
"metadata": {
"type": [
"number",
"string",
"boolean",
"object",
"array",
"null"
]
}
},
"required": [
"email"
]
},
"Post": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"title": {
"type": "string"
},
"content": {
"type": [
"string",
"null"
]
},
"published": {
"type": "boolean",
"default": false
},
"author": {
"$ref": "#/definitions/User"
},
"coAuthors": {
"type": "array",
"items": {
"$ref": "#/definitions/User"
}
},
"categories": {
"type": "array",
"items": {
"$ref": "#/definitions/CategoriesOnPosts"
}
},
"rate": {
"type": [
"number",
"null"
]
},
"order": {
"type": "integer",
"default": 0
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"title",
"authorId",
"tags"
]
},
"Profile": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"bio": {
"type": [
"string",
"null"
]
},
"user": {
"anyOf": [
{
"$ref": "#/definitions/User"
},
{
"type": "null"
}
]
},
"createdAt": {
"type": "string",
"format": "date-time"
},
"updatedAt": {
"type": "string",
"format": "date-time"
}
},
"required": []
},
"Category": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"posts": {
"type": "array",
"items": {
"$ref": "#/definitions/CategoriesOnPosts"
}
},
"createdAt": {
"type": "string",
"format": "date-time"
},
"updatedAt": {
"type": "string",
"format": "date-time"
}
},
"required": [
"name"
]
},
"CategoriesOnPosts": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"post": {
"$ref": "#/definitions/Post"
},
"category": {
"$ref": "#/definitions/Category"
},
"order": {
"type": "integer",
"default": 0
}
},
"required": [
"postId",
"categoryId"
]
}
},
"type": "object",
"properties": {
"user": {
"$ref": "#/definitions/User"
},
"post": {
"$ref": "#/definitions/Post"
},
"profile": {
"$ref": "#/definitions/Profile"
},
"category": {
"$ref": "#/definitions/Category"
},
"categoriesOnPosts": {
"$ref": "#/definitions/CategoriesOnPosts"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- CreateTable
CREATE TABLE "_coAuthors" (
"A" INTEGER NOT NULL,
"B" INTEGER NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "_coAuthors_AB_unique" ON "_coAuthors"("A", "B");

-- CreateIndex
CREATE INDEX "_coAuthors_B_index" ON "_coAuthors"("B");

-- AddForeignKey
ALTER TABLE "_coAuthors" ADD CONSTRAINT "_coAuthors_A_fkey" FOREIGN KEY ("A") REFERENCES "Post"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_coAuthors" ADD CONSTRAINT "_coAuthors_B_fkey" FOREIGN KEY ("B") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
2 changes: 2 additions & 0 deletions apps/example/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ model User {
hashedPassword String?
name String?
posts Post[] @relation("author") // One-to-many relation
coPosts Post[] @relation("coAuthors") // Many-to-many relation
profile Profile? @relation("profile") // One-to-one relation
birthDate DateTime?
createdAt DateTime @default(now())
Expand All @@ -43,6 +44,7 @@ model Post {
published Boolean @default(false)
author User @relation("author", fields: [authorId], references: [id]) // Many-to-one relation
authorId Int
coAuthors User[] @relation("coAuthors") // Many-to-many relation
categories CategoriesOnPosts[]
rate Decimal? @db.Decimal(5, 2)
order Int @default(0)
Expand Down
Loading
Loading