From 3219142f884a22dee516424a3ee4d84f205aa539 Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Mon, 12 Oct 2026 13:20:50 -0400 Subject: [PATCH] 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) --- src/app/(payload)/admin/importMap.js | 2 + src/components/admin/collection-icons.ts | 286 ++++++++++++++++++ .../admin/dashboard/CollectionCards.tsx | 161 ++++++++++ .../admin/tech-tree/TechTreeNavClient.tsx | 8 + src/payload.config.ts | 12 + 5 files changed, 469 insertions(+) create mode 100644 src/components/admin/collection-icons.ts create mode 100644 src/components/admin/dashboard/CollectionCards.tsx diff --git a/src/app/(payload)/admin/importMap.js b/src/app/(payload)/admin/importMap.js index 822a0acb..b4561a93 100644 --- a/src/app/(payload)/admin/importMap.js +++ b/src/app/(payload)/admin/importMap.js @@ -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 } diff --git a/src/components/admin/collection-icons.ts b/src/components/admin/collection-icons.ts new file mode 100644 index 00000000..11818a86 --- /dev/null +++ b/src/components/admin/collection-icons.ts @@ -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 = { + // 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 = { + 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; +} diff --git a/src/components/admin/dashboard/CollectionCards.tsx b/src/components/admin/dashboard/CollectionCards.tsx new file mode 100644 index 00000000..fa1737ed --- /dev/null +++ b/src/components/admin/dashboard/CollectionCards.tsx @@ -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 ( +
+ {navGroups.map(({ entities, label }, groupIndex) => { + const GroupIcon = getGroupIcon(label); + return ( +
+

+ + {label} +

+
    + {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 ( +
  • + + + + +

    + {title} +

    +
    + {showLocked && userEditing ? ( + + + + ) : null} + {!showLocked && hasCreatePermission && createHREF ? ( + + + + + ) : null} +
  • + ); + })} +
+
+ ); + })} +
+ ); +}; + +export default PolarisCollectionCards; diff --git a/src/components/admin/tech-tree/TechTreeNavClient.tsx b/src/components/admin/tech-tree/TechTreeNavClient.tsx index 2a7ba5f0..c0c30b2a 100644 --- a/src/components/admin/tech-tree/TechTreeNavClient.tsx +++ b/src/components/admin/tech-tree/TechTreeNavClient.tsx @@ -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 = ( {isActive &&
} + {typeof entityLabel === "string" ? entityLabel : String(entityLabel)} diff --git a/src/payload.config.ts b/src/payload.config.ts index b00586ec..af61c4c4 100644 --- a/src/payload.config.ts +++ b/src/payload.config.ts @@ -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"],