Add taxonomy filters for components and resources#13296
Merged
Conversation
Contributor
Author
|
the followup PR is this: #13584 |
Co-authored-by: Alexandru Emil Lupu <contact@alecslupu.ro>
Contributor
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

🎩 What? Why?
This is a big PR that covers the substitution of the current, participatory spaces dependent, categories and (global) scopes and areas for a generic tree of items called taxonomies. Taxonomies are not meant to be used directly by different participatory spaces or components but instead, using an intermediate filter that allows to choose specifically which taxonomies are used in each place.
Architecture:

Creation of a filter for a type of participatory space:

List of filters for a type of participatory space:

Usage of filters in participatory spaces:

After creating some filters for type of participatory space (for instance, an Assembly), all these filter will be available in the participatory space configuration (info):
In the public web side, filters are used instead of the old scope/areas search:

Usage of filters in components

Filters can also be assigned in the component's configuration page:
Usage of these filters depend on the component intention but, in general, are used to allow users and admins to assign one of the taxonomies that the filter provides (all other taxonomies will be hidden).

Also used in the frontend for filtering:

Or in the admin side:

Note that, in both cases, resources are linked to taxonomies, never to filters. So removing a filter does not breaks any association between an existing resource an a taxonomy.
Technical implementation
DATABASE:
taxonomy_filter_items, which in turn are associated to a specific taxonomy. The final tree of taxonomies is built in the frontend using the specified items only.NOTE: An alternative to this design could've been just a JSONB column in the filters table storing all the category ids for that filter. I decided to go with the traditional approach to favor integrity and cascade destroys.
Note that filters use the same name as the parent taxonomy, in the future we might want to add a column to change the name of the filter so it can be distinct if several filters are associated to the same root taxonomy.
REUSABLE PARTS:
taxonomy_filtersSettings type (defined in filesdecidim-admin/app/helpers/decidim/admin/settings_helper.rbanddecidim-core/lib/decidim/settings_manifest.rb). It is a new type of form field for components to allow specify the ids of the taxonomy filters that going to be used in that component. Uses a lateral drawer to choose from the available ones. This is used by specifying something like this in the components definition:decidim-core/lib/decidim/has_taxonomy_settings.rb: Provides with methods to extract available taxonomies and filters according to the components settings configuration. This are intended to be used in parts where the user has to assign taxonomies to a resource. Added to the Component model.decidim-admin/app/forms/concerns/decidim/has_taxonomy_form_attributes.rb: Provides with attribute definitions for adding multiple taxonomies in aDecidim::Formobject. It only requires for the implementing class to return the manifest of the participatory space (which is used to obtain the list of filters available). Used in every resource form that needs to include taxonomies (ie:AssemblyForm,ProposalForm, etc...).A related file is
decidim-core/app/helpers/decidim/taxonomies_helper.rbwhich defines the methodtaxonomy_items_options_for_filterthat is used in the form views as:decidim-admin/app/controllers/concerns/decidim/admin/filterable.rb: Provides with methods to obtain taxonomies and defines ransack attributes for searching resources using taxonomies. Added in every controller that need to deal with searching by taxonomy (public or admin side).Related to using filters, the
decidim-core/app/helpers/decidim/check_boxes_tree_helper.rband other related files have been modified to allow sending matrix-like id definitions. This is because, now in the sidebar, we list every root taxonomy (enabled by a filter) as it was a main item (for instance in a proposal index page you can search by author, state and every taxonomy as it was an independent filter). To handle this in ransack, the scopewith_any_taxonomieshave been defined that can deal with a tree of taxonomies (see thedecidim-core/lib/decidim/taxonomizable.rbconcern). Now, to show the taxonomies in the sidebar usually you just need it to add to thefilter_sectionsmethod like this:This applies to all components currently using categories or scopes.
In addition theses component have further changes as they where using categories in other ways:
The Accountability component: This component uses categories to generate a 2 level tree and display in each of them the projects assigned to that category. This has been changed to use taxonomies allowed by the taxonomy filter enabled in settings. Note that editing/removing a filter from the settings will effectively hide all the related projects from the public web frontend.
The Sortitions component: Sortitions used categories to filter the proposals to be randomized. This has been change also to use the available taxonomies allowed by filters. Past sortitions are not affected by changes in the filters/taxonomies.
Additional changes included in this PR:
Further work for future PRs
📌 Related Issues
Link your PR to an issue
Testing
📷 Screenshots
Edit component filters:
Screencast from 22-08-24 17:40:56.webm
Tasks:
taxonomy_filtersGraphql: taxonomy input filterThis would be great to filter in the API by taxonomies all the Taxonomizable elements.When doing that, the current query_extensions could be improved by unlinking from the core the participatory process filter.
InititativesHandle metrics calculationHandle imports with categories/scopesHandler participatory space serializers (add taxonomies)