[RFC] Tree View #13982
Replies: 5 comments
-
Absolutely! Very much anticipating that feature. I've built a tree view recently as well but went with a more traditional approach and made it a separate pane between sidebar and list view. One advantage was that it could stay open while editing a single page. On the other hand, on the list view you end up having two views. page.tree.mp4Not sure if there's much inspiration to take from it, but maybe a right click context menu could be interesting, or some other more touch-friendly way for various interactions with items in that tree view. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
> Would you use tree-view as the default navigational structure for certain collections? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for opening this RFC to the community, I think a tree view is an essential feature when using Payload for websites. Regarding the challenge of updating all child documents when a parent changes, I’d like to share an approach that I’ve been using successfully in production almost a year now across multiple websites:
The big advantage is that no cascading updates are required when a parent changes. All paths and breadcrumbs remain correct at all times because they are derived dynamically. By making the parent field polymorphic (allowing parents from different collections), I was also able to build complex hierarchical structures across multiple collections, for example: Pages Collection
Countries Collection
Regions Collection
I’ve encapsulated this logic in a plugin: https://github.com/jhb-software/payload-plugins/tree/main/pages I do have a couple of questions regarding the RFC:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The problem
Managing nested documents of any kind can be a bit tricky. Basically you set relationship field on a collection and call it "docParent". That relationTo on that field is set to the same collection where you added the field. That is all you really need to create a tree like structure in Payload.
Some use cases for this structure normally evolve into:
The first one is probably the hardest one. Documents need to know when their parents change so they can update their slug and title paths, and that has to be done across all documents that rely on the document you are editing. You could be editing a parent document that has children with nested children. If you edit a field that is used to generate the slug, then all of those children need to know that they need to update their slugs and title paths. What if the title path is localized? Then it gets even more complex because now you need to update the localized document values for all those nested children.
Ordering nested documents can be done now that Payload supports ordering documents. However the difficulty comes when you are visually looking at the list view because you must know what order your docs are in when you are moving them around so they all stay in perfect order. It is not ideal for managing nested documents.
Also you might want to organize documents from many collections all based on a hierarchical structure, where you can easily browse through the hierarchy based on a given taxonomy. We have folders, but folders have a very important constraint: a given document can only be in a single folder. Let's say you want to organize by tag, and a document can have many tags. A tag sits in a hierarchy of other tags and you want to be able to easily browse them. We don't have a great UX to browse this type of structure right now.
Current solutions
Today, you might use something like the nested-docs plugin and that would be an "ok" solution.
A couple issues with the plugin:
So what is this RFC for?
We have been working with a few customers in design to implement something along the lines of "Tree View", which would be a new way to view documents that shows hierarchy in a list view. The idea is to make managing nested documents more navigable and easier to understand at a glance.
Here is a simplified example for "nested pages":
And here is a simplified example for "nested tags":
This RFC is for a core feature, something that you could turn on a the collection level and it might look like:
How might it look visually?
Pages Example

Tags Example

Tree View List Search

Ordering & Moving Tree View Documents

Implementing something like Tags w/ join

Questions to the community
Beta Was this translation helpful? Give feedback.
All reactions