Skip to content

check browseable items automatically with "is_folderish" metadata#1499

Merged
petschki merged 2 commits intomasterfrom
contentbrowser-selectable-fix
Oct 2, 2025
Merged

check browseable items automatically with "is_folderish" metadata#1499
petschki merged 2 commits intomasterfrom
contentbrowser-selectable-fix

Conversation

@petschki
Copy link
Copy Markdown
Member

@petschki petschki commented Sep 4, 2025

This tries to fix #1497

How its done:

  1. every item is fetched from each level.
  2. if selectableTypes is configured, only those are shown in the list
  3. also items with is_folderish=True are shown and are browseable (and of course selectable too if configured)

Important:

This has one downside which we have to solve: batching!

If you have a folder with 50 pages and one image at the end and you configure selectableTypes: ["Image"] you see an empty list, because the catalog query only fetches the first 20 items.

I can now remember, that this was the reason why I've implemented "browseableTypes" in order to contrain the catalog query to selectable and browseable types to fix this batching issue.

Now we have to have another strategy when you want to show only the selectable types in a large folder with many other types in it. Ideas welcome

/cc @erral @MrTango @thet @1letter @yurj

@erral
Copy link
Copy Markdown
Member

erral commented Sep 19, 2025

I have tested this PR and it works as expected.

I don't have such large image folders so I don't know how can I test it... I will try to create dummy folders here..

Anyway, perhaps this is another issue, but wouldn't ordering items alphabetically (using sortable_title) make the content browser more usable?

@frapell
Copy link
Copy Markdown
Member

frapell commented Sep 30, 2025

@petschki I haven't tested this, so I might be wrong... but why would you get an empty list? I see in

if (selectableTypes.length) {
vocabQuery.criteria.push({
i: "portal_type",
o: "plone.app.querystring.operation.list.contains",
v: selectableTypes,
})
}
that the catalog query should only search for selectableTypes types, and so in your example where only Image is selectable, you should only get images from the catalog. Am I missing something?

OTOH, I would be -1 on removing the ability to configure browseableTypes and leave it to auto detect as the only option. It is not a weird requirement to have some sort of "special" folder where items can be created but editors shouldn't navigate to when inserting links/images from TinyMCE... What if you leave browseableTypes present so this behavior is configurable, but if empty, then auto detect?

@petschki
Copy link
Copy Markdown
Member Author

@frapell thanks for your suggestions. You're right, browseableTypes make sense in some szenarios. I'll bring it back...

Your code snipped belongs to the "search mode" of contentbrowser, which is a flat list of items without the ability to browse somewhere at all (this is like the "search mode" in the old relateditems pattern) so there, we can simply constrain the catalog query to the selectable types without caring about browseable types ...

@petschki petschki force-pushed the contentbrowser-selectable-fix branch from cf6672b to 4a5beb2 Compare September 30, 2025 13:13
@petschki petschki changed the title Remove "browseableTypes" option and check browseable items automatically with "is_folderish" metadata check browseable items automatically with "is_folderish" metadata Oct 1, 2025
@petschki petschki force-pushed the contentbrowser-selectable-fix branch from 4a5beb2 to 6fffa9c Compare October 1, 2025 08:37
@petschki petschki marked this pull request as ready for review October 1, 2025 08:37
@petschki petschki requested review from MrTango and thet October 1, 2025 08:37
@petschki petschki force-pushed the contentbrowser-selectable-fix branch from 6fffa9c to cacfc36 Compare October 1, 2025 08:46
@MrTango
Copy link
Copy Markdown
Contributor

MrTango commented Oct 1, 2025

I don't understand why we are not filtering for browsableTypes in the query, what is the problem with that? If nothing is set, we skip that filter, even if selectableTypes are given. selectableTypes should only have an affected if we can select them, they should still be visible.

The only problem I see with the current behavior, is that providing selectableTypes, is also activating the filter for browsableTypes.

When i provide browsableTypes, then i have to put all my folderish types. I could live with that.

I honestly rarely use the browsableTypes filter. But selectableTypes all the time.

Maybe instead of browsableTypes, a browsableTypesBlacklist does more sense if at all.

@petschki
Copy link
Copy Markdown
Member Author

petschki commented Oct 1, 2025

I've made some progress here:

  1. browseableTypes and selectableTypes are now completely independent of each other
  2. the default detection of browseable items is checking is_folderish metadata

(possible) downsides:

Since we cannot make OR concated catalog queries like "item_type=selectableTypes OR is_folderish=True" we have to load the complete level list when we have defined selectabledTypes. This can be slow if there are many items inside a folder.

@petschki
Copy link
Copy Markdown
Member Author

petschki commented Oct 1, 2025

I don't understand why we are not filtering for browsableTypes in the query, what is the problem with that? If nothing is set, we skip that filter, even if selectableTypes are given. selectableTypes should only have an affected if we can select them, they should still be visible.

The only problem I see with the current behavior, is that providing selectableTypes, is also activating the filter for browsableTypes.

When i provide browsableTypes, then i have to put all my folderish types. I could live with that.

I honestly rarely use the browsableTypes filter. But selectableTypes all the time.

Maybe instead of browsableTypes, a browsableTypesBlacklist does more sense if at all.

I think the "browseableTypes" problem is solved here since we're autodetecting if not defined.

Once again: defining selectableTypes has the problem, that you also have to provide the "unselectable but browseable" items... that would be easily solvable with a catalog query like "portal_type=selectableTypes OR is_folderish=True" but zcatalog does not provide OR concatenation of search indexes ...

Comment thread src/pat/contentbrowser/src/ContentBrowser.svelte Outdated
@petschki petschki force-pushed the contentbrowser-selectable-fix branch from 1ecba82 to f22c1af Compare October 1, 2025 11:47
@petschki
Copy link
Copy Markdown
Member Author

petschki commented Oct 1, 2025

UPDATE

After talking to @MrTango we came to the following conclusion:

Loading the unbatched and filtered "selectableTypes" list would potentially lead to long loading time for large folders and especially in slow network conditions.

That's why we are now loading the batched level items as usual and in case of defined selectableTypes we "visually deactivate" the unselectable items.

A folder with many images and files where only images are defined as selectable types (in tinymce for example) looks like the following screenshot:

Bildschirmfoto 2025-10-01 um 13 55 29

this loads even faster, because we can get rid of the extra iteration and filtering process.

Copy link
Copy Markdown
Member

@mauritsvanrees mauritsvanrees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes lots of sense. Works for me when I try it in coredev 6.1. Tested in a multilingual site by editing plone/app/relationfield/behavior.py and adding these pattern options to the related items field:

            "browseableTypes": ["Plone Site", "LRF"],
            "selectableTypes": ["Document"],

I wonder if someone will want the old way back, so that non-selectable/non-browsable items are not shown. If you have a folder with 5000 pages and 5 Images and you only allow selecting images, the previous behaviour is nicer. Theoretically I guess we could add a pattern option showNonMatchingItems or something like that, default True. If people prefer the old way, then they could set it to False in their pattern options. Or would that slow down the page again because filtering is needed?

If such an option is easy to add, it would be nice to have. I myself likely won't need it though.

For me this is approved. Thanks!

I won't merge though, I try not to interfere too much in the true ClassicUI parts of Plone. ;-) Best to have another approval.

Copy link
Copy Markdown
Contributor

@MrTango MrTango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@petschki petschki force-pushed the contentbrowser-selectable-fix branch from f22c1af to f297360 Compare October 2, 2025 06:09
@petschki petschki merged commit 06506a8 into master Oct 2, 2025
3 checks passed
@petschki petschki deleted the contentbrowser-selectable-fix branch October 2, 2025 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't add an image that is in a custom folderish content type in a multilingual site

5 participants