Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Projects (Budgets) to filtered search #11740

Merged

Conversation

greenwoodt
Copy link
Contributor

@greenwoodt greenwoodt commented Oct 11, 2023

🎩 What? Why?

Upon searching through modules as a user, Projects under Budgets were not searchable or available.

📌 Related Issues

Testing

  1. Head to Decidim
  2. Search by typing a Project name (or just by pressing 'Enter' while in the search)
  3. See the searchable Projects in filters on the left.

RSPEC test added to decidim-core/spec/system/search_spec.rb also.

📷 Screenshots

Before:

image

After:

Screenshot 2023-10-11 at 12 13 14

♥️ Thank you!

@greenwoodt greenwoodt added type: bug Issues that describe a bug module: core labels Oct 11, 2023
@greenwoodt greenwoodt self-assigned this Oct 11, 2023
@greenwoodt
Copy link
Contributor Author

I think you were right about the tests @andreslucena.

I'm having a discussion with @carolromero on what icon to replace Projects with to which we have concluded it would be the same as Budgets "coin-line"in the CONST located in: decidim-core/app/helpers/decidim/icon_helper.rb.

@andreslucena andreslucena changed the title Adding Projects (Budgets) to filtered search Add Projects (Budgets) to filtered search Oct 13, 2023
@greenwoodt
Copy link
Contributor Author

Screenshot 2023-10-13 at 11 59 04

Seems to a recurring theme in the test failures. Possibly to do with seeds..

@andreslucena
Copy link
Member

Seems to a recurring theme in the test failures. Possibly to do with seeds..

I think it's related to this association:

https://github.com/greenwoodt/decidim/blob/85e53e4b491066c2e12a79c46c343fc4c70c73fa/decidim-budgets/app/models/decidim/budgets/project.rb#L26-L27

And this other ActiveRecord method: https://github.com/greenwoodt/decidim/blob/85e53e4b491066c2e12a79c46c343fc4c70c73fa/decidim-core/lib/decidim/has_component.rb#L12-L13

That we're including in the same class. As far as I remember, the problem is that we usually have a simpler relation between the Components and its resources, (like you have a set of Meetings in this Component, and there are Proposals in this other Component). The issue comes that in this case, the relation between the Component and the Projects is done through the Budgets, and adding this concern like that is breaking the Projects creation.

You check it out by creating a new Project in the Admin panel. I see the same exception as the specs.

I think a better approach could be to actually change the code that registers these models in the Search. Let's try this:

  1. Remove the new line from the Project model, including the HasComponent concern
  2. Change the searchable.rb check for ancestors from HasComponent to Searchable, as that's the other concern that all the Resources have in common and semantically sounds right

As we're changing code from lib/, to see that it works you'll need to stop and start again the bin/dev script

This is what I have in mind:

diff --git a/decidim-budgets/app/models/decidim/budgets/project.rb b/decidim-budgets/app/models/decidim/budgets/project.rb
index 545c632cff..508c73bc49 100644
--- a/decidim-budgets/app/models/decidim/budgets/project.rb
+++ b/decidim-budgets/app/models/decidim/budgets/project.rb
@@ -19,7 +19,6 @@ module Decidim
       include Decidim::Searchable
       include Decidim::TranslatableResource
       include Decidim::FilterableResource
-      include Decidim::HasComponent
 
       translatable_fields :title, :description
 
diff --git a/decidim-core/lib/decidim/searchable.rb b/decidim-core/lib/decidim/searchable.rb
index 6da2b23a94..fa132ffbc1 100644
--- a/decidim-core/lib/decidim/searchable.rb
+++ b/decidim-core/lib/decidim/searchable.rb
@@ -35,7 +35,7 @@ module Decidim
     end
 
     def self.searchable_resources_of_type_component
-      searchable_resources.select { |r| r.constantize.ancestors.include?(Decidim::HasComponent) }
+      searchable_resources.select { |r| r.constantize.ancestors.include?(Decidim::Searchable) }
     end
 
     def self.searchable_resources_of_type_comment

Try it out locally and if you see that it works then commit/push and wait for the specs 🤞🏽

@greenwoodt
Copy link
Contributor Author

Seems to a recurring theme in the test failures. Possibly to do with seeds..

I think it's related to this association:

https://github.com/greenwoodt/decidim/blob/85e53e4b491066c2e12a79c46c343fc4c70c73fa/decidim-budgets/app/models/decidim/budgets/project.rb#L26-L27

And this other ActiveRecord method: https://github.com/greenwoodt/decidim/blob/85e53e4b491066c2e12a79c46c343fc4c70c73fa/decidim-core/lib/decidim/has_component.rb#L12-L13

That we're including in the same class. As far as I remember, the problem is that we usually have a simpler relation between the Components and its resources, (like you have a set of Meetings in this Component, and there are Proposals in this other Component). The issue comes that in this case, the relation between the Component and the Projects is done through the Budgets, and adding this concern like that is breaking the Projects creation.

You check it out by creating a new Project in the Admin panel. I see the same exception as the specs.

I think a better approach could be to actually change the code that registers these models in the Search. Let's try this:

1. Remove the new line from the Project model, including the HasComponent concern

2. Change the searchable.rb check for ancestors from HasComponent to Searchable, as that's the other concern that all the Resources have in common and semantically sounds right

As we're changing code from lib/, to see that it works you'll need to stop and start again the bin/dev script

This is what I have in mind:

diff --git a/decidim-budgets/app/models/decidim/budgets/project.rb b/decidim-budgets/app/models/decidim/budgets/project.rb
index 545c632cff..508c73bc49 100644
--- a/decidim-budgets/app/models/decidim/budgets/project.rb
+++ b/decidim-budgets/app/models/decidim/budgets/project.rb
@@ -19,7 +19,6 @@ module Decidim
       include Decidim::Searchable
       include Decidim::TranslatableResource
       include Decidim::FilterableResource
-      include Decidim::HasComponent
 
       translatable_fields :title, :description
 
diff --git a/decidim-core/lib/decidim/searchable.rb b/decidim-core/lib/decidim/searchable.rb
index 6da2b23a94..fa132ffbc1 100644
--- a/decidim-core/lib/decidim/searchable.rb
+++ b/decidim-core/lib/decidim/searchable.rb
@@ -35,7 +35,7 @@ module Decidim
     end
 
     def self.searchable_resources_of_type_component
-      searchable_resources.select { |r| r.constantize.ancestors.include?(Decidim::HasComponent) }
+      searchable_resources.select { |r| r.constantize.ancestors.include?(Decidim::Searchable) }
     end
 
     def self.searchable_resources_of_type_comment

Try it out locally and if you see that it works then commit/push and wait for the specs 🤞🏽

Thanks Andres I'll give it a go!

@greenwoodt
Copy link
Contributor Author

@andreslucena looks like your suggestion worked! Thanks very much! I will now open this for a review by the maintainers!

@greenwoodt greenwoodt requested review from a team and removed request for carolromero October 13, 2023 12:26
@greenwoodt greenwoodt marked this pull request as ready for review October 13, 2023 12:26
@andreslucena
Copy link
Member

@andreslucena looks like your suggestion worked! Thanks very much! I will now open this for a review by the maintainers!

Glad to hear that! Lets add an spec here, I think this would be enough:

diff --git a/decidim-core/spec/system/search_spec.rb b/decidim-core/spec/system/search_spec.rb
index 9ccb45e386..8bffc83eca 100644
--- a/decidim-core/spec/system/search_spec.rb
+++ b/decidim-core/spec/system/search_spec.rb
@@ -32,6 +32,13 @@ describe "Search", type: :system do
       expect(page).to have_content(/results for the search: "#{term}"/i)
       expect(page).to have_selector(".filter-search.filter-container")
     end
+
+    it "has all the resources to search" do
+      within ".search__filter" do
+        expect(page).to have_content("All")
+        expect(page).to have_content("Participants")
+        # TODO: all the resources
+    end
   end
 
   context "when the device is a mobile" do

You need to add the list of all the Searchable models, of course. Just having this list would be enough IMO.

@greenwoodt
Copy link
Contributor Author

@andreslucena looks like your suggestion worked! Thanks very much! I will now open this for a review by the maintainers!

Glad to hear that! Lets add an spec here, I think this would be enough:

diff --git a/decidim-core/spec/system/search_spec.rb b/decidim-core/spec/system/search_spec.rb
index 9ccb45e386..8bffc83eca 100644
--- a/decidim-core/spec/system/search_spec.rb
+++ b/decidim-core/spec/system/search_spec.rb
@@ -32,6 +32,13 @@ describe "Search", type: :system do
       expect(page).to have_content(/results for the search: "#{term}"/i)
       expect(page).to have_selector(".filter-search.filter-container")
     end
+
+    it "has all the resources to search" do
+      within ".search__filter" do
+        expect(page).to have_content("All")
+        expect(page).to have_content("Participants")
+        # TODO: all the resources
+    end
   end
 
   context "when the device is a mobile" do

You need to add the list of all the Searchable models, of course. Just having this list would be enough IMO.

Done!

Copy link
Member

@andreslucena andreslucena left a comment

Choose a reason for hiding this comment

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

A change in the spec and this would be good to me

decidim-core/spec/system/search_spec.rb Outdated Show resolved Hide resolved
Copy link
Member

@andreslucena andreslucena left a comment

Choose a reason for hiding this comment

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

LGTM!

I'll not merge until @alecslupu checks this out, as I was involved in the code

Copy link
Contributor

@alecslupu alecslupu left a comment

Choose a reason for hiding this comment

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

Sweet !
LGTM

@alecslupu alecslupu merged commit bc75cd9 into decidim:develop Oct 16, 2023
102 checks passed
entantoencuanto added a commit that referenced this pull request Oct 17, 2023
* develop: (30 commits)
  Add `process-content` to erb-lint's deprecated classes (#11762)
  Add possibility of overriding the tailwind.config.js (#11763)
  Ask old password when changing email or password (#11737)
  Add Projects (Budgets) to filtered search (#11740)
  Fix missing results on Geocoded when search without diacritics (#11761)
  Add robots.txt instructions (#11693)
  Add missing activerecord budget locales for search (#11766)
  Improve design of Admin's Sidebar pages (#11759)
  Show small static map on admin's meetings index with big screens  (#11715)
  Remove "Manage" button when there's a Sidebar (#11717)
  Fix admin breadcrumb in Process (#11757)
  Apply new rubocop rules on erb - Layout/MultilineMethodCallIndentation (#11756)
  Remove xlarge-* references from admin forms (#11712)
  Apply new rubocop rules on erb - Argument identation (#11707)
  Update HERE API autocomplete (#11507)
  Admin redesign proposal issues (#11668)
  Redesign: responsive links on cards (#11538)
  Refactor CI pipelines (#11196)
  Update postcss and graphql to latest versions (#11733)
  Fix develop pipeline (#11750)
  ...
@andreslucena andreslucena added type: fix PRs that implement a fix for a bug and removed type: bug Issues that describe a bug labels Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: core type: fix PRs that implement a fix for a bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Projects not displayed in search filters
3 participants