feat(admin): add icons to sidebar nav and dashboard collections grid
- New shared slug-to-icon map (collection-icons.ts) covering all collections, globals, plugin collections, and the custom tech-tree entry, with fallbacks - TechTreeNavClient renders a lucide icon before every nav link label - Custom 'collections' dashboard widget replaces Payload's stock CollectionCards grid with an icon-bearing variant (same permission filtering, group headers, create shortcuts, and global lock indicators)
This commit is contained in:
parent
93af541f24
commit
3219142f88
5 changed files with 469 additions and 0 deletions
|
|
@ -47,6 +47,7 @@ import { default as default_05548cb43495e62d80b80ec4d9f0f7e9 } from '@/component
|
|||
import { default as default_459d6b6f5ead73c736013da63a5ace3f } from '@/components/static/GoToFrontendLink'
|
||||
import { InstructionsProvider as InstructionsProvider_4490b89d4413c1ffaecdacfe72efaf73 } from '@ai-stack/payloadcms/client'
|
||||
import { default as default_2b34d0df0cf91f4442ca2cd62ae7cd94 } from '@/components/admin/tech-tree/TechTreeView'
|
||||
import { default as default_f3a799acf91e60a0d7a8ec121a8f5690 } from '@/components/admin/dashboard/CollectionCards'
|
||||
import { CollectionCards as CollectionCards_f9c02e79a4aed9a3924487c0cd4cafb1 } from '@payloadcms/next/rsc'
|
||||
|
||||
/** @type import('payload').ImportMap */
|
||||
|
|
@ -100,5 +101,6 @@ export const importMap = {
|
|||
"@/components/static/GoToFrontendLink#default": default_459d6b6f5ead73c736013da63a5ace3f,
|
||||
"@ai-stack/payloadcms/client#InstructionsProvider": InstructionsProvider_4490b89d4413c1ffaecdacfe72efaf73,
|
||||
"@/components/admin/tech-tree/TechTreeView#default": default_2b34d0df0cf91f4442ca2cd62ae7cd94,
|
||||
"@/components/admin/dashboard/CollectionCards#default": default_f3a799acf91e60a0d7a8ec121a8f5690,
|
||||
"@payloadcms/next/rsc#CollectionCards": CollectionCards_f9c02e79a4aed9a3924487c0cd4cafb1
|
||||
}
|
||||
|
|
|
|||
286
src/components/admin/collection-icons.ts
Normal file
286
src/components/admin/collection-icons.ts
Normal file
|
|
@ -0,0 +1,286 @@
|
|||
import type { LucideIcon } from "lucide-react";
|
||||
import {
|
||||
Activity,
|
||||
Archive,
|
||||
ArrowLeftRight,
|
||||
AudioWaveform,
|
||||
Award,
|
||||
Backpack,
|
||||
BadgeCheck,
|
||||
Bell,
|
||||
BookOpen,
|
||||
BookOpenText,
|
||||
Bomb,
|
||||
BookmarkCheck,
|
||||
Bot,
|
||||
Boxes,
|
||||
Brain,
|
||||
Building2,
|
||||
CalendarCheck,
|
||||
CalendarClock,
|
||||
CalendarDays,
|
||||
Car,
|
||||
CarFront,
|
||||
FastForward,
|
||||
ClipboardCheck,
|
||||
ClipboardList,
|
||||
Crosshair,
|
||||
Cpu,
|
||||
Dices,
|
||||
FileAudio,
|
||||
FileText,
|
||||
Filter,
|
||||
Flag,
|
||||
Flame,
|
||||
Folder,
|
||||
FolderTree,
|
||||
FormInput,
|
||||
Gamepad2,
|
||||
Gauge,
|
||||
Gem,
|
||||
GitCompare,
|
||||
Globe,
|
||||
Handshake,
|
||||
HardHat,
|
||||
History,
|
||||
Hexagon,
|
||||
Image as ImageIcon,
|
||||
Inbox,
|
||||
Joystick,
|
||||
Kanban,
|
||||
KeyRound,
|
||||
Landmark,
|
||||
LayoutGrid,
|
||||
LayoutTemplate,
|
||||
LifeBuoy,
|
||||
LineChart,
|
||||
ListChecks,
|
||||
ListOrdered,
|
||||
Map as MapIcon,
|
||||
MapPin,
|
||||
Medal,
|
||||
Megaphone,
|
||||
MessageSquareText,
|
||||
Mic,
|
||||
Mountain,
|
||||
Network,
|
||||
NotebookText,
|
||||
Package,
|
||||
PackageOpen,
|
||||
Radio,
|
||||
RadioTower,
|
||||
Radar,
|
||||
Receipt,
|
||||
Ribbon,
|
||||
Rocket,
|
||||
Route,
|
||||
Scale,
|
||||
ScrollText,
|
||||
Server,
|
||||
Settings2,
|
||||
ShieldCheck,
|
||||
ShieldHalf,
|
||||
ShoppingBag,
|
||||
ShoppingCart,
|
||||
SlidersHorizontal,
|
||||
Sparkles,
|
||||
Star,
|
||||
Swords,
|
||||
Tags,
|
||||
Target,
|
||||
Terminal,
|
||||
ThumbsUp,
|
||||
Ticket,
|
||||
TrendingUp,
|
||||
Trophy,
|
||||
Truck,
|
||||
UserCheck,
|
||||
UserCog,
|
||||
UserRound,
|
||||
Users,
|
||||
UsersRound,
|
||||
WandSparkles,
|
||||
Warehouse,
|
||||
Workflow,
|
||||
Zap,
|
||||
} from "lucide-react";
|
||||
|
||||
/**
|
||||
* Single source of truth for admin-panel icons, keyed by collection/global
|
||||
* slug (plus the custom `tech-tree` nav entry). Consumed by the admin sidebar
|
||||
* (TechTreeNavClient) and the dashboard collections grid widget so both
|
||||
* surfaces always agree. New collections fall back to `fallbackCollectionIcon`
|
||||
* until they are added here.
|
||||
*/
|
||||
export const collectionIcons: Record<string, LucideIcon> = {
|
||||
// Announcements
|
||||
announcements: Megaphone,
|
||||
|
||||
// Media
|
||||
media: ImageIcon,
|
||||
|
||||
// Game
|
||||
"game-event-logs": History,
|
||||
"game-hard-resources": Gem,
|
||||
"game-npcs": Bot,
|
||||
"game-structures": Building2,
|
||||
"game-vehicles": Car,
|
||||
"labor-classifications": HardHat,
|
||||
"npc-dialogues": MessageSquareText,
|
||||
"npc-staffing": UserCog,
|
||||
"player-flags": Flag,
|
||||
"reinforcement-pools": UsersRound,
|
||||
|
||||
// Users
|
||||
"assignment-transfers": ArrowLeftRight,
|
||||
assignments: Network,
|
||||
awards: Award,
|
||||
"contribution-entries": Sparkles,
|
||||
evaluations: ClipboardCheck,
|
||||
experience: Star,
|
||||
"leadership-transfers": Handshake,
|
||||
profiles: UserRound,
|
||||
"promotion-nominations": TrendingUp,
|
||||
qualifications: BadgeCheck,
|
||||
ranks: Medal,
|
||||
roles: ShieldCheck,
|
||||
"user-notifications": Bell,
|
||||
users: Users,
|
||||
|
||||
// Intelligence
|
||||
campaigns: Swords,
|
||||
factions: ShieldHalf,
|
||||
"mission-attendances": ClipboardList,
|
||||
"mission-map-markers": MapPin,
|
||||
"mission-role-signups": UserCheck,
|
||||
missions: Crosshair,
|
||||
"tech-categories": FolderTree,
|
||||
technologies: Cpu,
|
||||
|
||||
// Logistics
|
||||
assets: Boxes,
|
||||
resources: Package,
|
||||
shipments: Truck,
|
||||
structures: Warehouse,
|
||||
vehicles: CarFront,
|
||||
|
||||
// Banking
|
||||
"bank-accounts": Landmark,
|
||||
"bank-transactions": Receipt,
|
||||
"ledger-entries": NotebookText,
|
||||
|
||||
// Locker
|
||||
loadouts: Backpack,
|
||||
"locker-storages": Archive,
|
||||
|
||||
// Market
|
||||
"market-listings": ShoppingBag,
|
||||
"market-negotiations": Scale,
|
||||
"market-state": LineChart,
|
||||
|
||||
// Voiceover
|
||||
"voice-scripts": FileAudio,
|
||||
"voice-submissions": AudioWaveform,
|
||||
|
||||
// Helpdesk
|
||||
"ticket-votes": ThumbsUp,
|
||||
tickets: LifeBuoy,
|
||||
|
||||
// Wiki
|
||||
"wiki-pages": BookOpen,
|
||||
"wiki-revisions": GitCompare,
|
||||
"wiki-templates": LayoutTemplate,
|
||||
|
||||
// Projects
|
||||
labels: Tags,
|
||||
projects: Kanban,
|
||||
releases: Rocket,
|
||||
sprints: FastForward,
|
||||
|
||||
// World
|
||||
"map-roads": Route,
|
||||
"map-zones": Hexagon,
|
||||
maps: MapIcon,
|
||||
"narrative-events": BookOpenText,
|
||||
"resource-nodes": Mountain,
|
||||
|
||||
// Story (Chronicle)
|
||||
"story-beat-states": BookmarkCheck,
|
||||
"story-beats": ScrollText,
|
||||
"story-voiceovers": Mic,
|
||||
|
||||
// Server
|
||||
"arma-commands": Terminal,
|
||||
"arma-sync-events": RadioTower,
|
||||
"game-servers": Server,
|
||||
"mission-files": FileText,
|
||||
"mod-lists": ListChecks,
|
||||
"respawn-tickets": Ticket,
|
||||
"supply-boxes": PackageOpen,
|
||||
|
||||
// Operations
|
||||
"operation-effects": Zap,
|
||||
"operation-events": CalendarDays,
|
||||
"operation-readiness": Gauge,
|
||||
"operation-reservations": CalendarCheck,
|
||||
"zone-pressure": Flame,
|
||||
|
||||
// Minigames
|
||||
achievements: Trophy,
|
||||
"custom-minefield-scores": Target,
|
||||
"custom-minefields": Bomb,
|
||||
"custom-radio-test-scores": ListOrdered,
|
||||
"custom-radio-tests": Radio,
|
||||
"minigame-entries": Gamepad2,
|
||||
"minigame-periods": CalendarClock,
|
||||
minigames: Dices,
|
||||
|
||||
// Globals
|
||||
"discord-presence": Activity,
|
||||
"game-rules": Settings2,
|
||||
"minigame-rules": SlidersHorizontal,
|
||||
shims: Filter,
|
||||
|
||||
// Custom admin views (nav entries that are not Payload entities)
|
||||
"tech-tree": Workflow,
|
||||
|
||||
// Plugin collections
|
||||
forms: FormInput,
|
||||
"form-submissions": Inbox,
|
||||
"payload-mcp-api-keys": KeyRound,
|
||||
"plugin-ai-instructions": WandSparkles,
|
||||
};
|
||||
|
||||
/** Icons for the admin nav/dashboard groups, keyed by group label. */
|
||||
export const groupIcons: Record<string, LucideIcon> = {
|
||||
Announcements: Megaphone,
|
||||
Awards: Medal,
|
||||
Banking: Landmark,
|
||||
Chronicle: ScrollText,
|
||||
Contributions: Sparkles,
|
||||
Game: Joystick,
|
||||
Helpdesk: LifeBuoy,
|
||||
Intelligence: Brain,
|
||||
Locker: Backpack,
|
||||
Logistics: Truck,
|
||||
Market: ShoppingCart,
|
||||
Minigames: Gamepad2,
|
||||
Operations: Radar,
|
||||
Projects: Kanban,
|
||||
Server: Server,
|
||||
Users: Users,
|
||||
Voiceover: Mic,
|
||||
Wiki: BookOpenText,
|
||||
World: Globe,
|
||||
};
|
||||
|
||||
export const fallbackCollectionIcon: LucideIcon = LayoutGrid;
|
||||
export const fallbackGroupIcon: LucideIcon = Folder;
|
||||
|
||||
export function getCollectionIcon(slug: string): LucideIcon {
|
||||
return collectionIcons[slug] ?? fallbackCollectionIcon;
|
||||
}
|
||||
|
||||
export function getGroupIcon(label: string): LucideIcon {
|
||||
return groupIcons[label] ?? fallbackGroupIcon;
|
||||
}
|
||||
161
src/components/admin/dashboard/CollectionCards.tsx
Normal file
161
src/components/admin/dashboard/CollectionCards.tsx
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
import { Locked } from "@payloadcms/ui/elements/Locked";
|
||||
import { EntityType, groupNavItems } from "@payloadcms/ui/shared";
|
||||
import { getGlobalData } from "@payloadcms/ui/utilities/getGlobalData";
|
||||
import { getVisibleEntities } from "@payloadcms/ui/utilities/getVisibleEntities";
|
||||
import { getAccessResults } from "payload";
|
||||
import { formatAdminURL } from "payload/shared";
|
||||
import type { EntityToGroup } from "@payloadcms/ui/shared";
|
||||
import type { ClientUser, PayloadRequest, SanitizedPermissions } from "payload";
|
||||
import React from "react";
|
||||
|
||||
import { getCollectionIcon, getGroupIcon } from "@/components/admin/collection-icons";
|
||||
|
||||
/**
|
||||
* Replacement for Payload's built-in `collections` dashboard widget
|
||||
* (`@payloadcms/next/rsc#CollectionCards`), registered under the same slug in
|
||||
* `payload.config.ts` (admin.dashboard.widgets). Payload appends its default
|
||||
* widget AFTER user widgets, and the dashboard resolves widgets by first
|
||||
* match, so this component takes over the grid.
|
||||
*
|
||||
* Behavior mirrors the stock widget: entities are filtered by read permission
|
||||
* and visibility, grouped by admin group, globals show their document lock,
|
||||
* and collections with create permission get a "+" shortcut. Adds lucide
|
||||
* icons per entity and per group from the shared collection-icons map.
|
||||
*/
|
||||
|
||||
type WidgetProps = {
|
||||
permissions?: SanitizedPermissions;
|
||||
req: PayloadRequest;
|
||||
};
|
||||
|
||||
function asLabel(label: unknown): string {
|
||||
return typeof label === "string" ? label : String(label);
|
||||
}
|
||||
|
||||
export const PolarisCollectionCards = async ({ permissions, req }: WidgetProps) => {
|
||||
if (!req?.payload?.config) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { i18n, payload, user } = req;
|
||||
const { admin: adminRoute } = payload.config.routes;
|
||||
|
||||
// The dashboard passes resolved permissions; recompute only when a render
|
||||
// path did not provide them.
|
||||
const resolvedPermissions = permissions ?? ((await getAccessResults({ req })) as SanitizedPermissions);
|
||||
|
||||
const visibleEntities = getVisibleEntities({ req });
|
||||
const globalData = await getGlobalData(req);
|
||||
|
||||
const collections = payload.config.collections.filter(
|
||||
(collection) =>
|
||||
resolvedPermissions?.collections?.[collection.slug]?.read &&
|
||||
visibleEntities.collections.includes(collection.slug),
|
||||
);
|
||||
const globals = payload.config.globals.filter(
|
||||
(global) =>
|
||||
resolvedPermissions?.globals?.[global.slug]?.read &&
|
||||
visibleEntities.globals.includes(global.slug),
|
||||
);
|
||||
|
||||
const navGroups = groupNavItems(
|
||||
[
|
||||
...collections.map(
|
||||
(collection): EntityToGroup => ({ type: EntityType.collection, entity: collection }),
|
||||
),
|
||||
...globals.map((global): EntityToGroup => ({ type: EntityType.global, entity: global })),
|
||||
],
|
||||
resolvedPermissions,
|
||||
i18n,
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 py-2">
|
||||
{navGroups.map(({ entities, label }, groupIndex) => {
|
||||
const GroupIcon = getGroupIcon(label);
|
||||
return (
|
||||
<section className="flex flex-col gap-3" key={groupIndex}>
|
||||
<h2 className="m-0 flex items-center gap-2 text-sm font-semibold text-[var(--theme-text-color)]">
|
||||
<GroupIcon aria-hidden className="size-4 shrink-0 opacity-60" />
|
||||
{label}
|
||||
</h2>
|
||||
<ul className="m-0 grid list-none grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-3 p-0">
|
||||
{entities.map(({ slug, type }, entityIndex) => {
|
||||
let title: string;
|
||||
let href: string;
|
||||
let createHREF: string | undefined;
|
||||
let hasCreatePermission = false;
|
||||
let isLocked = false;
|
||||
let userEditing: ClientUser | null = null;
|
||||
|
||||
if (type === EntityType.collection) {
|
||||
const collection = payload.config.collections.find((c) => c.slug === slug)!;
|
||||
title = asLabel(collection.labels.plural);
|
||||
href = formatAdminURL({ adminRoute, path: `/collections/${slug}` });
|
||||
createHREF = formatAdminURL({ adminRoute, path: `/collections/${slug}/create` });
|
||||
hasCreatePermission = Boolean(resolvedPermissions?.collections?.[slug]?.create);
|
||||
} else {
|
||||
const global = payload.config.globals.find((g) => g.slug === slug)!;
|
||||
title = asLabel(global.label);
|
||||
href = formatAdminURL({ adminRoute, path: `/globals/${slug}` });
|
||||
|
||||
const globalLockData = globalData.find((g) => g.slug === slug);
|
||||
if (globalLockData) {
|
||||
isLocked = Boolean(globalLockData.data._isLocked);
|
||||
userEditing =
|
||||
typeof globalLockData.data._userEditing === "object"
|
||||
? (globalLockData.data._userEditing as ClientUser)
|
||||
: null;
|
||||
const lockDuration = globalLockData.lockDuration ?? 0;
|
||||
const lastEditedAt = new Date(globalLockData.data._lastEditedAt).getTime();
|
||||
if (Date.now() > lastEditedAt + lockDuration * 1000) {
|
||||
isLocked = false;
|
||||
userEditing = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const Icon = getCollectionIcon(slug);
|
||||
const showLocked = isLocked && user?.id !== userEditing?.id;
|
||||
|
||||
return (
|
||||
<li className="relative" key={entityIndex}>
|
||||
<a
|
||||
aria-label={`Show all ${title}`}
|
||||
className="group flex h-full items-center gap-3 rounded-lg border border-[var(--theme-border-color)] bg-[var(--theme-input-bg)] p-4 no-underline transition-[border-color,box-shadow] hover:border-[var(--theme-success)] hover:shadow-[inset_0_0_0_1px_var(--theme-success)]"
|
||||
href={href}
|
||||
id={`card-${slug}`}
|
||||
>
|
||||
<span className="flex size-9 shrink-0 items-center justify-center rounded-md border border-[var(--theme-border-color)] bg-[var(--theme-elevation-50)] text-[var(--theme-elevation-700)]">
|
||||
<Icon aria-hidden className="size-4" />
|
||||
</span>
|
||||
<h3 className="m-0 min-w-0 flex-1 truncate text-sm font-medium text-[var(--theme-text-color)]">
|
||||
{title}
|
||||
</h3>
|
||||
</a>
|
||||
{showLocked && userEditing ? (
|
||||
<span className="absolute right-3 top-1/2 -translate-y-1/2">
|
||||
<Locked user={userEditing} />
|
||||
</span>
|
||||
) : null}
|
||||
{!showLocked && hasCreatePermission && createHREF ? (
|
||||
<a
|
||||
aria-label={`Create new ${title}`}
|
||||
className="absolute right-3 top-1/2 z-10 flex size-7 -translate-y-1/2 items-center justify-center rounded-full border border-[var(--theme-border-color)] bg-[var(--theme-bg)] text-lg leading-none text-[var(--theme-elevation-600)] opacity-70 transition-opacity hover:opacity-100"
|
||||
href={createHREF}
|
||||
>
|
||||
+
|
||||
</a>
|
||||
) : null}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</section>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PolarisCollectionCards;
|
||||
|
|
@ -6,6 +6,8 @@ import { usePathname } from "next/navigation.js";
|
|||
import { formatAdminURL } from "payload/shared";
|
||||
import React, { Fragment } from "react";
|
||||
|
||||
import { getCollectionIcon } from "@/components/admin/collection-icons";
|
||||
|
||||
/**
|
||||
* A nav entity: either a standard Payload entity (collection/global) or a
|
||||
* custom view entry injected by TechTreeNav (type "custom", href given).
|
||||
|
|
@ -72,9 +74,15 @@ export const TechTreeNavClient = ({ groups, navPreferences }: Props) => {
|
|||
pathname === href ||
|
||||
(pathname.startsWith(href) && ["/", undefined].includes(pathname[href.length]));
|
||||
|
||||
const Icon = getCollectionIcon(slug);
|
||||
|
||||
const Label = (
|
||||
<Fragment>
|
||||
{isActive && <div className={`${baseClass}__link-indicator`} />}
|
||||
<Icon
|
||||
aria-hidden
|
||||
className={`me-2 size-3.5 shrink-0 ${isActive ? "opacity-100" : "opacity-60"}`}
|
||||
/>
|
||||
<span className={`${baseClass}__link-label`}>
|
||||
{typeof entityLabel === "string" ? entityLabel : String(entityLabel)}
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -445,6 +445,18 @@ export default buildConfig({
|
|||
],
|
||||
},
|
||||
|
||||
// Overrides the built-in collection-cards grid on the admin dashboard
|
||||
// (Payload appends its default `collections` widget after user widgets and
|
||||
// resolves by first match). Same grid + permissions, plus lucide icons.
|
||||
dashboard: {
|
||||
widgets: [
|
||||
{
|
||||
slug: "collections",
|
||||
Component: "@/components/admin/dashboard/CollectionCards",
|
||||
minWidth: "full",
|
||||
},
|
||||
],
|
||||
},
|
||||
components: {
|
||||
beforeDashboard: ["@/components/static/BeforeDashboardText"],
|
||||
header: ["@/components/static/VersionOverlay"],
|
||||
|
|
|
|||
Loading…
Reference in a new issue