ckan / ckan

CKAN is an open-source DMS (data management system) for powering data hubs and data portals. CKAN makes it easy to publish, share and use data. It powers catalog.data.gov, open.canada.ca/data, data.humdata.org among many other sites.
https://ckan.org/
Other
4.41k stars 1.98k forks source link

UI Revamp: Displaying facet accordion with active options as expanded by default #8429

Open aleeexgreeen opened 1 week ago

aleeexgreeen commented 1 week ago

Hello! By request of the designers of the UI revamp, they would like the facets to appear as accordions. They have requested by default if there are no active options within a facet, it should be collapsed, otherwise it should be expanded.

Screenshots for context: Default, facets with no active item image

Default, facets with 1 or more active items image

I have a working version of this, that is probably not efficient and uses jinja filters right now. I'm using {% set active_items = items|selectattr('active')|list|length >= 1 %} to see if there are any active items within a facet and if active_items is empty, I'm collapsing that facet accordion. For full code, see facet_list.html

CKAN currently can indicate whether an item in a facet is active (item.active -> happening in {% for item in items %}), but ultimately, I need to indicate whether there are any active items in the facet before the for loop to collapse and expand the accordions accordingly (🤣 ) and I'm wondering what is the best way to do so?

wardi commented 6 days ago

As @amercader suggested it might be easier to modify get_facet_items_dict to return the information you need than to do it in jinja2.

aleeexgreeen commented 3 days ago

@wardi Okay thanks, it was easier than I thought! I just want to confirm that by default the accordions should be expanded and there should add a config option to have the collapsed by default, or does there need to be more discussions about that?