Add isParent boolean to tags
This commit is contained in:
2
prisma/migrations/20251221205656_artwork_7/migration.sql
Normal file
2
prisma/migrations/20251221205656_artwork_7/migration.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "ArtTag" ADD COLUMN "isParent" BOOLEAN NOT NULL DEFAULT false;
|
||||||
@ -103,6 +103,7 @@ model ArtTag {
|
|||||||
|
|
||||||
name String @unique
|
name String @unique
|
||||||
slug String @unique
|
slug String @unique
|
||||||
|
isParent Boolean @default(false)
|
||||||
showOnAnimalPage Boolean @default(false)
|
showOnAnimalPage Boolean @default(false)
|
||||||
|
|
||||||
description String?
|
description String?
|
||||||
|
|||||||
@ -22,6 +22,7 @@ export async function createTag(formData: TagFormInput) {
|
|||||||
name: data.name,
|
name: data.name,
|
||||||
slug: tagSlug,
|
slug: tagSlug,
|
||||||
description: data.description,
|
description: data.description,
|
||||||
|
isParent: data.isParent,
|
||||||
showOnAnimalPage: data.showOnAnimalPage,
|
showOnAnimalPage: data.showOnAnimalPage,
|
||||||
parentId
|
parentId
|
||||||
},
|
},
|
||||||
|
|||||||
@ -33,6 +33,7 @@ export async function updateTag(id: string, rawData: TagFormInput) {
|
|||||||
name: data.name,
|
name: data.name,
|
||||||
slug: tagSlug,
|
slug: tagSlug,
|
||||||
description: data.description,
|
description: data.description,
|
||||||
|
isParent: data.isParent,
|
||||||
showOnAnimalPage: data.showOnAnimalPage,
|
showOnAnimalPage: data.showOnAnimalPage,
|
||||||
parentId,
|
parentId,
|
||||||
categories: data.categoryIds
|
categories: data.categoryIds
|
||||||
|
|||||||
@ -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 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 (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { prisma } from "@/lib/prisma";
|
|||||||
|
|
||||||
export default async function PortfolioTagsNewPage() {
|
export default async function PortfolioTagsNewPage() {
|
||||||
const categories = await prisma.artCategory.findMany({ include: { tags: true }, orderBy: { sortIndex: "asc" } });
|
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 (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@ -22,11 +22,7 @@ const artworkItems = [
|
|||||||
{
|
{
|
||||||
title: "Tags",
|
title: "Tags",
|
||||||
href: "/tags",
|
href: "/tags",
|
||||||
},
|
}
|
||||||
{
|
|
||||||
title: "Animals",
|
|
||||||
href: "/animals",
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
|
|
||||||
// const portfolioItems = [
|
// const portfolioItems = [
|
||||||
|
|||||||
@ -25,6 +25,7 @@ export default function EditTagForm({ tag, categories, allTags }: { tag: ArtTag
|
|||||||
description: tag.description || "",
|
description: tag.description || "",
|
||||||
categoryIds: tag.categories?.map(cat => cat.id) ?? [],
|
categoryIds: tag.categories?.map(cat => cat.id) ?? [],
|
||||||
parentId: (tag as any).parentId ?? null,
|
parentId: (tag as any).parentId ?? null,
|
||||||
|
isParent: tag.isParent ?? false,
|
||||||
showOnAnimalPage: tag.showOnAnimalPage ?? false,
|
showOnAnimalPage: tag.showOnAnimalPage ?? false,
|
||||||
aliases: tag.aliases?.map(a => a.alias) ?? []
|
aliases: tag.aliases?.map(a => a.alias) ?? []
|
||||||
}
|
}
|
||||||
@ -149,6 +150,23 @@ export default function EditTagForm({ tag, categories, allTags }: { tag: ArtTag
|
|||||||
</FormItem>
|
</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">
|
<div className="flex">
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
|
|||||||
@ -26,6 +26,7 @@ export default function NewTagForm({ categories, allTags }: { categories: ArtCat
|
|||||||
description: "",
|
description: "",
|
||||||
categoryIds: [],
|
categoryIds: [],
|
||||||
parentId: null,
|
parentId: null,
|
||||||
|
isParent: false,
|
||||||
showOnAnimalPage: false,
|
showOnAnimalPage: false,
|
||||||
aliases: [],
|
aliases: [],
|
||||||
}
|
}
|
||||||
@ -150,6 +151,23 @@ export default function NewTagForm({ categories, allTags }: { categories: ArtCat
|
|||||||
</FormItem>
|
</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">
|
<div className="flex">
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ export const tagSchema = z.object({
|
|||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
categoryIds: z.array(z.string()).optional(),
|
categoryIds: z.array(z.string()).optional(),
|
||||||
parentId: z.string().nullable().optional(),
|
parentId: z.string().nullable().optional(),
|
||||||
|
isParent: z.boolean(),
|
||||||
showOnAnimalPage: z.boolean(),
|
showOnAnimalPage: z.boolean(),
|
||||||
|
|
||||||
aliases: z
|
aliases: z
|
||||||
|
|||||||
Reference in New Issue
Block a user