Add isParent boolean to tags

This commit is contained in:
2025-12-21 21:57:16 +01:00
parent d1adb07f40
commit 48114f391a
10 changed files with 46 additions and 8 deletions

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "ArtTag" ADD COLUMN "isParent" BOOLEAN NOT NULL DEFAULT false;

View File

@ -103,6 +103,7 @@ model ArtTag {
name String @unique
slug String @unique
isParent Boolean @default(false)
showOnAnimalPage Boolean @default(false)
description String?

View File

@ -22,6 +22,7 @@ export async function createTag(formData: TagFormInput) {
name: data.name,
slug: tagSlug,
description: data.description,
isParent: data.isParent,
showOnAnimalPage: data.showOnAnimalPage,
parentId
},

View File

@ -32,7 +32,8 @@ export async function updateTag(id: string, rawData: TagFormInput) {
data: {
name: data.name,
slug: tagSlug,
description: data.description,
description: data.description,
isParent: data.isParent,
showOnAnimalPage: data.showOnAnimalPage,
parentId,
categories: data.categoryIds

View File

@ -14,7 +14,7 @@ export default async function PortfolioTagsEditPage({ params }: { params: { id:
})
const categories = await prisma.artCategory.findMany({ include: { tags: true }, orderBy: { sortIndex: "asc" } });
const tags = await prisma.artTag.findMany({ orderBy: { sortIndex: "asc" } });
const tags = await prisma.artTag.findMany({ where: { isParent: true }, orderBy: { sortIndex: "asc" } });
return (
<div>

View File

@ -3,7 +3,7 @@ import { prisma } from "@/lib/prisma";
export default async function PortfolioTagsNewPage() {
const categories = await prisma.artCategory.findMany({ include: { tags: true }, orderBy: { sortIndex: "asc" } });
const tags = await prisma.artTag.findMany({ orderBy: { sortIndex: "asc" } });
const tags = await prisma.artTag.findMany({ where: { isParent: true }, orderBy: { sortIndex: "asc" } });
return (
<div>

View File

@ -22,11 +22,7 @@ const artworkItems = [
{
title: "Tags",
href: "/tags",
},
{
title: "Animals",
href: "/animals",
},
}
]
// const portfolioItems = [

View File

@ -25,6 +25,7 @@ export default function EditTagForm({ tag, categories, allTags }: { tag: ArtTag
description: tag.description || "",
categoryIds: tag.categories?.map(cat => cat.id) ?? [],
parentId: (tag as any).parentId ?? null,
isParent: tag.isParent ?? false,
showOnAnimalPage: tag.showOnAnimalPage ?? false,
aliases: tag.aliases?.map(a => a.alias) ?? []
}
@ -149,6 +150,23 @@ export default function EditTagForm({ tag, categories, allTags }: { tag: ArtTag
</FormItem>
)}
/>
<div className="flex">
<FormField
control={form.control}
name="isParent"
render={({ field }) => (
<FormItem className="flex items-center justify-between rounded-lg border p-4">
<div className="space-y-0.5">
<FormLabel>Is parent tag</FormLabel>
<FormDescription></FormDescription>
</div>
<FormControl>
<Switch checked={field.value} onCheckedChange={field.onChange} />
</FormControl>
</FormItem>
)}
/>
</div>
<div className="flex">
<FormField
control={form.control}

View File

@ -26,6 +26,7 @@ export default function NewTagForm({ categories, allTags }: { categories: ArtCat
description: "",
categoryIds: [],
parentId: null,
isParent: false,
showOnAnimalPage: false,
aliases: [],
}
@ -150,6 +151,23 @@ export default function NewTagForm({ categories, allTags }: { categories: ArtCat
</FormItem>
)}
/>
<div className="flex">
<FormField
control={form.control}
name="isParent"
render={({ field }) => (
<FormItem className="flex items-center justify-between rounded-lg border p-4">
<div className="space-y-0.5">
<FormLabel>Is parent tag</FormLabel>
<FormDescription></FormDescription>
</div>
<FormControl>
<Switch checked={field.value} onCheckedChange={field.onChange} />
</FormControl>
</FormItem>
)}
/>
</div>
<div className="flex">
<FormField
control={form.control}

View File

@ -5,6 +5,7 @@ export const tagSchema = z.object({
description: z.string().optional(),
categoryIds: z.array(z.string()).optional(),
parentId: z.string().nullable().optional(),
isParent: z.boolean(),
showOnAnimalPage: z.boolean(),
aliases: z