From dffeaf6a69746b944bf36bd172da3cc19fa025a0 Mon Sep 17 00:00:00 2001 From: Dan Ribbens Date: Sat, 10 Sep 2022 10:00:08 -0400 Subject: [PATCH] feat: collection groups --- docs/configuration/collections.mdx | 3 +- src/admin/components/elements/Nav/index.tsx | 66 ++++++++++----- .../components/elements/NavGroup/index.scss | 32 +++++++ .../components/elements/NavGroup/index.tsx | 83 +++++++++++++++++++ src/collections/config/schema.ts | 1 + src/collections/config/types.ts | 4 + test/admin/config.ts | 48 +++++++++++ test/admin/e2e.spec.ts | 27 ++++++ 8 files changed, 242 insertions(+), 22 deletions(-) create mode 100644 src/admin/components/elements/NavGroup/index.scss create mode 100644 src/admin/components/elements/NavGroup/index.tsx diff --git a/docs/configuration/collections.mdx b/docs/configuration/collections.mdx index 76376a0752..2a64d9c8b3 100644 --- a/docs/configuration/collections.mdx +++ b/docs/configuration/collections.mdx @@ -61,6 +61,7 @@ You can customize the way that the Admin panel behaves on a collection-by-collec | Option | Description | | ---------------------------- | -------------| +| `group` | Text used as a label for grouping collection links together in the navigation. | | `useAsTitle` | Specify a top-level field to use for a document title throughout the Admin panel. If no field is defined, the ID of the document is used as the title. | | `description` | Text or React component to display below the Collection label in the List view to give editors more information. | | `defaultColumns` | Array of field names that correspond to which columns to show by default in this collection's List view. | @@ -78,7 +79,7 @@ If the function is specified, a Preview button will automatically appear in the **The preview function accepts two arguments:** 1. The document being edited -1. An `options` object, containing `locale` and `token` properties. The `token` is the currently logged in user's JWT. +1. An `options` object, containing `locale` and `token` properties. The `token` is the currently logged-in user's JWT. **Example collection with preview function:** diff --git a/src/admin/components/elements/Nav/index.tsx b/src/admin/components/elements/Nav/index.tsx index 6a22e7fed7..1eb3276311 100644 --- a/src/admin/components/elements/Nav/index.tsx +++ b/src/admin/components/elements/Nav/index.tsx @@ -10,6 +10,8 @@ import CloseMenu from '../../icons/CloseMenu'; import Icon from '../../graphics/Icon'; import Account from '../../graphics/Account'; import Localizer from '../Localizer'; +import NavGroup from '../NavGroup'; +import { SanitizedCollectionConfig } from '../../../../collections/config/types'; import './index.scss'; @@ -36,7 +38,21 @@ const DefaultNav = () => { const classes = [ baseClass, menuActive && `${baseClass}--menu-active`, - ].filter(Boolean).join(' '); + ].filter(Boolean) + .join(' '); + + const groupedCollections: Record = collections.reduce((acc, currentValue) => { + if (currentValue.admin.group) { + if (acc[currentValue.admin.group]) { + acc[currentValue.admin.group].push(currentValue); + } else { + acc[currentValue.admin.group] = [currentValue]; + } + } else { + acc[''].push(currentValue); + } + return acc; + }, { '': [] }); useEffect(() => history.listen(() => { setMenuActive(false); @@ -68,31 +84,39 @@ const DefaultNav = () => {
{Array.isArray(beforeNavLinks) && beforeNavLinks.map((Component, i) => )} Collections -