fix(catalog): open visual manager from dedicated button

This commit is contained in:
Simo committed 2026-09-06 19:58:10 +02:00
1 parent 814d8650be
commit 0bedc04692
3 files changed
+14 -91

No files matched your search

+2 -10
View File
@@ -1,6 +1,6 @@
"use client";
import { FolderTree, HardHat, LayoutGrid, List, Package } from "lucide-react";
import { FolderTree, HardHat, List, Package } from "lucide-react";
import { useRouter, useSearchParams } from "next/navigation";
import { useTranslations } from "next-intl";
import { Button } from "@/components/ui/button";
@@ -23,7 +23,7 @@ export function CatalogViewToggle({
function setView(view: string) {
if (view === currentView || !requestCatalogNavigation()) return;
const params = new URLSearchParams(searchParams.toString());
if (view === "manager") {
if (view === "tree") {
params.delete("view");
} else {
params.set("view", view);
@@ -76,14 +76,6 @@ export function CatalogViewToggle({
</div>
{/* View mode selector */}
<Button
variant={currentView === "manager" ? "default" : "ghost"}
size="sm"
onClick={() => setView("manager")}
>
<LayoutGrid className="mr-1.5 h-4 w-4" />
{t("editor")}
</Button>
<div className="flex items-center rounded-md border bg-card">
<Button
variant="ghost"
+12 -43
View File
@@ -19,7 +19,6 @@ import { CatalogTree } from "@/components/admin/catalog-tree";
import Link from "@/components/link";
import { CatalogSearch } from "@/features/catalog/components/catalog-search";
import { CatalogSyncStatus } from "@/features/catalog/components/catalog-sync-status";
import { loadCatalogOverview } from "@/features/catalog/server/overview";
import { calcPagination, parseListParams } from "@/lib/admin-helpers";
import {
CatalogItems,
@@ -31,10 +30,7 @@ import {
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
import { getCatalogItemCounts } from "@/lib/services/catalog-tree";
import { CatalogActions } from "./catalog-actions";
import {
CatalogManagerDialog,
CatalogManagerWorkspace,
} from "./catalog-manager-dialog-wrapper";
import { CatalogManagerDialog } from "./catalog-manager-dialog-wrapper";
import { CatalogTable } from "./catalog-table";
import { CatalogViewToggle } from "./catalog-view-toggle";
@@ -63,43 +59,8 @@ export default async function CatalogPagesPage({
const sp = new URLSearchParams(params);
const { search, perPage, page, sort, order } = parseListParams(sp);
const requestedView = sp.get("view");
const viewMode =
requestedView === "tree" || requestedView === "table"
? requestedView
: "manager";
const viewMode = requestedView === "table" ? "table" : "tree";
const catalogType = sp.get("catalog") === "bc" ? "bc" : "normal";
if (viewMode === "manager") {
const overview = await loadCatalogOverview(catalogType);
return (
<AdminPageShell icon={Store} title={t("title")} subtitle={t("subtitle")}>
<div className="flex flex-wrap items-center justify-between gap-3 mb-4">
<CatalogViewToggle currentView={viewMode} catalogType={catalogType} />
<div className="flex flex-wrap items-center gap-2">
<Link className="btn btn-outline" href="/admin/catalog/maintenance">
{t("workspace.diagnostics")}
</Link>
{canEdit && (
<CatalogActions
catalogType={catalogType}
initialParentId={sp.get("newPageParent")}
/>
)}
</div>
</div>
<div className="mb-3">
<CatalogSyncStatus canEdit={canEdit} />
<CatalogSearch catalogType={catalogType} />
</div>
<CatalogManagerWorkspace
key={catalogType}
catalogType={catalogType}
canEdit={canEdit}
initialRoots={overview.roots}
totals={overview.totals}
/>
</AdminPageShell>
);
}
type TreeNodeShape = {
id: number;
@@ -300,13 +261,17 @@ export default async function CatalogPagesPage({
return (
<AdminPageShell icon={Store} title={t("title")} subtitle={t("subtitle")}>
<div className="mb-4 space-y-3">
<CatalogSyncStatus canEdit={canEdit} />
<CatalogSearch catalogType={catalogType} />
</div>
<div className="space-y-6">
<div className="flex items-center justify-between">
<p className="text-muted-foreground">
{totalBcPages} BC pages ({enabledBcPages} enabled) &middot;{" "}
{totalBcItems} items
</p>
<div className="flex items-center gap-2">
<div className="flex flex-wrap items-center gap-2">
<CatalogViewToggle currentView={viewMode} catalogType="bc" />
{canEdit && (
<CatalogManagerDialog
@@ -529,13 +494,17 @@ export default async function CatalogPagesPage({
return (
<AdminPageShell icon={Store} title={t("title")} subtitle={t("subtitle")}>
<div className="mb-4 space-y-3">
<CatalogSyncStatus canEdit={canEdit} />
<CatalogSearch catalogType={catalogType} />
</div>
<div className="space-y-6">
<div className="flex items-center justify-between">
<p className="text-muted-foreground">
{totalPages} pages ({enabledPages} enabled) &middot; {totalItems}{" "}
items
</p>
<div className="flex items-center gap-2">
<div className="flex flex-wrap items-center gap-2">
<CatalogViewToggle currentView={viewMode} catalogType="normal" />
{canEdit && (
<CatalogManagerDialog
-38
View File
@@ -1,38 +0,0 @@
import "server-only";
import { asc, count, eq, or } from "drizzle-orm";
import {
CatalogItems,
CatalogItemsBc,
CatalogPages,
CatalogPagesBc,
db,
} from "@/lib/db";
import type { CatalogKind } from "./page-commands";
export async function loadCatalogOverview(kind: CatalogKind) {
const pages = kind === "bc" ? CatalogPagesBc : CatalogPages;
const items = kind === "bc" ? CatalogItemsBc : CatalogItems;
const [roots, pageCount, itemCount, enabledCount] = await Promise.all([
db
.select({
id: pages.id,
caption: pages.caption,
iconImage: pages.iconImage,
enabled: pages.enabled,
orderNum: pages.orderNum,
})
.from(pages)
.where(or(eq(pages.parentId, -1), eq(pages.parentId, 0)))
.orderBy(asc(pages.orderNum), asc(pages.id)),
db.select({ total: count() }).from(pages),
db.select({ total: count() }).from(items),
db.select({ total: count() }).from(pages).where(eq(pages.enabled, "1")),
]);
return {
roots,
totals: {
totalPages: Number(pageCount[0]?.total ?? 0),
totalItems: Number(itemCount[0]?.total ?? 0),
enabledPages: Number(enabledCount[0]?.total ?? 0),
},
};
}