Add an option to group collections by directory (/api/{group}/{collection}) #16404
llaz00
started this conversation in
Feature Requests & Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The problem
Let's say you have an ecommerce with Payload CMS and you have product categories and blog post categories. Currently, you would need to name your collections as BlogCategories or ProductCategories, and so on. Then imagine you have multiple collections related to blog (categories, posts, authors) and others related for products (categories, products). Many of them can collision so you are always repeating the "BlogCollection" and "ProductCollection" on every collection you are creating. However, the logical way of organizing this information would be putting blog things in blog directory and products in product directory. Then you would be able to use /api/blog/categories and /api/products/categories, so you don't need to repeat the group name on every collection.
At this moment PayloadCMS can't handle subdirectories in categories slugs, so there is no option to group them except in the UI where you can use
admin.groupoption.The solution
There are multiple ways of implementation. For example, there could be a new type of collection that is a "GroupCollection" with its own slug and an array of other collections. For the previous example, we would import a BlogCollection in payload.config.ts which would contain an array of collections related to blog.
Another way of implementation (I personally don't like this one, as you wouldn't be able to check how the collections are grouped at first glance) would be supporting the slash (/) symbol in current collection slugs.
Other things to consider
It would be great to also consider how this affects to UI. Currently, there is an option to group collections visually by
admin.group. Maybe we could consider that, by default, all collections under the same group would also be displayed accordingly, even if they don't have anadmin.groupset.Beta Was this translation helpful? Give feedback.
All reactions