fix(catalog): open visual manager from dedicated button
This commit is contained in:
1 parent
814d8650be
commit
0bedc04692
3 files changed
+14
-91
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"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 { useRouter, useSearchParams } from "next/navigation";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
@@ -23,7 +23,7 @@ export function CatalogViewToggle({
|
|||||||
function setView(view: string) {
|
function setView(view: string) {
|
||||||
if (view === currentView || !requestCatalogNavigation()) return;
|
if (view === currentView || !requestCatalogNavigation()) return;
|
||||||
const params = new URLSearchParams(searchParams.toString());
|
const params = new URLSearchParams(searchParams.toString());
|
||||||
if (view === "manager") {
|
if (view === "tree") {
|
||||||
params.delete("view");
|
params.delete("view");
|
||||||
} else {
|
} else {
|
||||||
params.set("view", view);
|
params.set("view", view);
|
||||||
@@ -76,14 +76,6 @@ export function CatalogViewToggle({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* View mode selector */}
|
{/* 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">
|
<div className="flex items-center rounded-md border bg-card">
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import { CatalogTree } from "@/components/admin/catalog-tree";
|
|||||||
import Link from "@/components/link";
|
import Link from "@/components/link";
|
||||||
import { CatalogSearch } from "@/features/catalog/components/catalog-search";
|
import { CatalogSearch } from "@/features/catalog/components/catalog-search";
|
||||||
import { CatalogSyncStatus } from "@/features/catalog/components/catalog-sync-status";
|
import { CatalogSyncStatus } from "@/features/catalog/components/catalog-sync-status";
|
||||||
import { loadCatalogOverview } from "@/features/catalog/server/overview";
|
|
||||||
import { calcPagination, parseListParams } from "@/lib/admin-helpers";
|
import { calcPagination, parseListParams } from "@/lib/admin-helpers";
|
||||||
import {
|
import {
|
||||||
CatalogItems,
|
CatalogItems,
|
||||||
@@ -31,10 +30,7 @@ import {
|
|||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { getCatalogItemCounts } from "@/lib/services/catalog-tree";
|
import { getCatalogItemCounts } from "@/lib/services/catalog-tree";
|
||||||
import { CatalogActions } from "./catalog-actions";
|
import { CatalogActions } from "./catalog-actions";
|
||||||
import {
|
import { CatalogManagerDialog } from "./catalog-manager-dialog-wrapper";
|
||||||
CatalogManagerDialog,
|
|
||||||
CatalogManagerWorkspace,
|
|
||||||
} from "./catalog-manager-dialog-wrapper";
|
|
||||||
import { CatalogTable } from "./catalog-table";
|
import { CatalogTable } from "./catalog-table";
|
||||||
import { CatalogViewToggle } from "./catalog-view-toggle";
|
import { CatalogViewToggle } from "./catalog-view-toggle";
|
||||||
|
|
||||||
@@ -63,43 +59,8 @@ export default async function CatalogPagesPage({
|
|||||||
const sp = new URLSearchParams(params);
|
const sp = new URLSearchParams(params);
|
||||||
const { search, perPage, page, sort, order } = parseListParams(sp);
|
const { search, perPage, page, sort, order } = parseListParams(sp);
|
||||||
const requestedView = sp.get("view");
|
const requestedView = sp.get("view");
|
||||||
const viewMode =
|
const viewMode = requestedView === "table" ? "table" : "tree";
|
||||||
requestedView === "tree" || requestedView === "table"
|
|
||||||
? requestedView
|
|
||||||
: "manager";
|
|
||||||
const catalogType = sp.get("catalog") === "bc" ? "bc" : "normal";
|
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 = {
|
type TreeNodeShape = {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -300,13 +261,17 @@ export default async function CatalogPagesPage({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<AdminPageShell icon={Store} title={t("title")} subtitle={t("subtitle")}>
|
<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="space-y-6">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<p className="text-muted-foreground">
|
<p className="text-muted-foreground">
|
||||||
{totalBcPages} BC pages ({enabledBcPages} enabled) ·{" "}
|
{totalBcPages} BC pages ({enabledBcPages} enabled) ·{" "}
|
||||||
{totalBcItems} items
|
{totalBcItems} items
|
||||||
</p>
|
</p>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
<CatalogViewToggle currentView={viewMode} catalogType="bc" />
|
<CatalogViewToggle currentView={viewMode} catalogType="bc" />
|
||||||
{canEdit && (
|
{canEdit && (
|
||||||
<CatalogManagerDialog
|
<CatalogManagerDialog
|
||||||
@@ -529,13 +494,17 @@ export default async function CatalogPagesPage({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<AdminPageShell icon={Store} title={t("title")} subtitle={t("subtitle")}>
|
<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="space-y-6">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<p className="text-muted-foreground">
|
<p className="text-muted-foreground">
|
||||||
{totalPages} pages ({enabledPages} enabled) · {totalItems}{" "}
|
{totalPages} pages ({enabledPages} enabled) · {totalItems}{" "}
|
||||||
items
|
items
|
||||||
</p>
|
</p>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
<CatalogViewToggle currentView={viewMode} catalogType="normal" />
|
<CatalogViewToggle currentView={viewMode} catalogType="normal" />
|
||||||
{canEdit && (
|
{canEdit && (
|
||||||
<CatalogManagerDialog
|
<CatalogManagerDialog
|
||||||
|
|||||||
@@ -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),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user