Moving the arttags table to tags table part 1
This commit is contained in:
@ -3,23 +3,43 @@ import { prisma } from "@/lib/prisma";
|
||||
|
||||
export default async function PortfolioTagsEditPage({ params }: { params: { id: string } }) {
|
||||
const { id } = await params;
|
||||
const tag = await prisma.artTag.findUnique({
|
||||
const tag = await prisma.tag.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
include: {
|
||||
categories: true,
|
||||
categoryLinks: {
|
||||
include: {
|
||||
category: true,
|
||||
parentTag: { select: { id: true, name: true } },
|
||||
},
|
||||
},
|
||||
aliases: true
|
||||
}
|
||||
})
|
||||
|
||||
const categories = await prisma.artCategory.findMany({ include: { tags: true }, orderBy: { sortIndex: "asc" } });
|
||||
const tags = await prisma.artTag.findMany({ where: { isParent: true }, orderBy: { sortIndex: "asc" } });
|
||||
const categories = await prisma.artCategory.findMany({
|
||||
include: { tagLinks: true },
|
||||
orderBy: { sortIndex: "asc" },
|
||||
});
|
||||
const tags = await prisma.tag.findMany({ orderBy: { sortIndex: "asc" } });
|
||||
|
||||
const animalLink =
|
||||
tag?.categoryLinks.find((link) => link.category.name === "Animal Studies") ??
|
||||
null;
|
||||
const tagWithMeta = tag
|
||||
? {
|
||||
...tag,
|
||||
parentId: animalLink?.parentTagId ?? null,
|
||||
isParent: animalLink?.isParent ?? false,
|
||||
showOnAnimalPage: animalLink?.showOnAnimalPage ?? false,
|
||||
}
|
||||
: null;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold mb-4">Edit Tag</h1>
|
||||
{tag && <EditTagForm tag={tag} categories={categories} allTags={tags} />}
|
||||
{tagWithMeta && <EditTagForm tag={tagWithMeta} categories={categories} allTags={tags} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,8 +2,11 @@ import NewTagForm from "@/components/tags/NewTagForm";
|
||||
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({ where: { isParent: true }, orderBy: { sortIndex: "asc" } });
|
||||
const categories = await prisma.artCategory.findMany({
|
||||
include: { tagLinks: true },
|
||||
orderBy: { sortIndex: "asc" },
|
||||
});
|
||||
const tags = await prisma.tag.findMany({ orderBy: { sortIndex: "asc" } });
|
||||
|
||||
return (
|
||||
<div>
|
||||
@ -11,4 +14,4 @@ export default async function PortfolioTagsNewPage() {
|
||||
<NewTagForm categories={categories} allTags={tags} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,40 +3,71 @@ import { Button } from "@/components/ui/button";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { PlusCircleIcon } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { migrateArtTags } from "@/actions/tags/migrateArtTags";
|
||||
|
||||
export default async function ArtTagsPage() {
|
||||
const items = await prisma.artTag.findMany({
|
||||
const items = await prisma.tag.findMany({
|
||||
include: {
|
||||
parent: { select: { id: true, name: true } },
|
||||
aliases: { select: { alias: true } },
|
||||
categories: { select: { id: true, name: true } },
|
||||
categoryLinks: {
|
||||
include: {
|
||||
category: { select: { id: true, name: true } },
|
||||
parentTag: { select: { id: true, name: true } },
|
||||
},
|
||||
},
|
||||
_count: { select: { artworks: true } },
|
||||
},
|
||||
orderBy: [{ sortIndex: "asc" }, { name: "asc" }],
|
||||
});
|
||||
|
||||
const rows = items.map((tag) => {
|
||||
const categories = tag.categoryLinks.map((link) => link.category);
|
||||
const animalLink = tag.categoryLinks.find(
|
||||
(link) => link.category.name === "Animal Studies",
|
||||
);
|
||||
|
||||
return {
|
||||
id: tag.id,
|
||||
name: tag.name,
|
||||
slug: tag.slug,
|
||||
parent: animalLink?.parentTag ?? null,
|
||||
isParent: animalLink?.isParent ?? false,
|
||||
showOnAnimalPage: animalLink?.showOnAnimalPage ?? false,
|
||||
aliases: tag.aliases,
|
||||
categories,
|
||||
_count: tag._count,
|
||||
};
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="mx-auto w-full max-w-7xl px-4 py-6">
|
||||
<header className="mb-6 flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between">
|
||||
<div className="space-y-1">
|
||||
<h1 className="text-2xl font-semibold tracking-tight sm:text-3xl">
|
||||
Art Tags
|
||||
Tags
|
||||
</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Manage tags, aliases, categories, and usage across artworks.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Button asChild className="h-11 gap-2">
|
||||
<Link href="/tags/new">
|
||||
<PlusCircleIcon className="h-4 w-4" />
|
||||
Add new tag
|
||||
</Link>
|
||||
</Button>
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-center">
|
||||
<form action={migrateArtTags}>
|
||||
<Button type="submit" variant="secondary" className="h-11">
|
||||
Migrate old tags
|
||||
</Button>
|
||||
</form>
|
||||
<Button asChild className="h-11 gap-2">
|
||||
<Link href="/tags/new">
|
||||
<PlusCircleIcon className="h-4 w-4" />
|
||||
Add new tag
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{items.length > 0 ? (
|
||||
<TagTabs tags={items} />
|
||||
{rows.length > 0 ? (
|
||||
<TagTabs tags={rows} />
|
||||
) : (
|
||||
<p className="text-muted-foreground">
|
||||
There are no tags yet. Consider adding some!
|
||||
@ -44,4 +75,4 @@ export default async function ArtTagsPage() {
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user