From fb01444a8836594bf35aa257e8615fadd1cd97aa Mon Sep 17 00:00:00 2001 From: Jason Zimdars Date: Thu, 20 Feb 2025 16:07:07 -0600 Subject: [PATCH 1/2] =?UTF-8?q?"Added=20by=E2=80=A6"=20is=20a=20more=20use?= =?UTF-8?q?ful=20filter=20than=20"Assigned=20by=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/filters_helper.rb | 2 +- app/models/filter.rb | 2 +- app/models/filter/params.rb | 4 +-- app/models/filter/resources.rb | 2 +- app/models/filter/summarized.rb | 14 ++++---- ..._assigners.html.erb => _creators.html.erb} | 32 ++++++++++--------- app/views/filters/_dialog.html.erb | 14 ++++---- app/views/filters/_settings.html.erb | 2 +- ...0416_create_creators_filters_join_table.rb | 11 +++++++ ...20424_drop_assigners_filters_join_table.rb | 7 ++++ db/schema.rb | 16 +++++----- 11 files changed, 63 insertions(+), 43 deletions(-) rename app/views/filters/{_assigners.html.erb => _creators.html.erb} (57%) create mode 100644 db/migrate/20250220220416_create_creators_filters_join_table.rb create mode 100644 db/migrate/20250220220424_drop_assigners_filters_join_table.rb diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb index b185233f4..d8a57dfc1 100644 --- a/app/helpers/filters_helper.rb +++ b/app/helpers/filters_helper.rb @@ -12,7 +12,7 @@ module FiltersHelper end def any_filters?(filter) - filter.tags.any? || filter.assignees.any? || filter.assigners.any? || + filter.tags.any? || filter.assignees.any? || filter.creators.any? || filter.stages.any? || filter.terms.any? || filter.assignment_status.unassigned? || !filter.default_indexed_by? end diff --git a/app/models/filter.rb b/app/models/filter.rb index 1fc09f68b..809e781a2 100644 --- a/app/models/filter.rb +++ b/app/models/filter.rb @@ -22,7 +22,7 @@ class Filter < ApplicationRecord result = result.active unless indexed_by.popped? result = result.unassigned if assignment_status.unassigned? result = result.assigned_to(assignees.ids) if assignees.present? - result = result.assigned_by(assigners.ids) if assigners.present? + result = result.where(creator_id: creators.ids) if creators.present? result = result.in_bucket(buckets.ids) if buckets.present? result = result.in_stage(stages.ids) if stages.present? result = result.tagged_with(tags.ids) if tags.present? diff --git a/app/models/filter/params.rb b/app/models/filter/params.rb index bc617a17a..c09edb074 100644 --- a/app/models/filter/params.rb +++ b/app/models/filter/params.rb @@ -5,7 +5,7 @@ module Filter::Params :assignment_status, :indexed_by, assignee_ids: [], - assigner_ids: [], + creator_ids: [], bucket_ids: [], stage_ids: [], tag_ids: [], @@ -41,7 +41,7 @@ module Filter::Params params[:bucket_ids] = buckets.ids params[:stage_ids] = stages.ids params[:assignee_ids] = assignees.ids - params[:assigner_ids] = assigners.ids + params[:creator_ids] = creators.ids end.compact_blank.reject(&method(:default_value?)) end diff --git a/app/models/filter/resources.rb b/app/models/filter/resources.rb index dabeac4f7..a7df5ab69 100644 --- a/app/models/filter/resources.rb +++ b/app/models/filter/resources.rb @@ -6,7 +6,7 @@ module Filter::Resources has_and_belongs_to_many :buckets has_and_belongs_to_many :stages, class_name: "Workflow::Stage", join_table: "filters_stages" has_and_belongs_to_many :assignees, class_name: "User", join_table: "assignees_filters", association_foreign_key: "assignee_id" - has_and_belongs_to_many :assigners, class_name: "User", join_table: "assigners_filters", association_foreign_key: "assigner_id" + has_and_belongs_to_many :creators, class_name: "User", join_table: "creators_filters", association_foreign_key: "creator_id" end def resource_removed(resource) diff --git a/app/models/filter/summarized.rb b/app/models/filter/summarized.rb index 3e954e51c..559b3bc6b 100644 --- a/app/models/filter/summarized.rb +++ b/app/models/filter/summarized.rb @@ -1,6 +1,6 @@ module Filter::Summarized def summary - [ index_summary, tag_summary, assignee_summary, assigner_summary, stage_summary, terms_summary ].compact.to_sentence + " #{bucket_summary}" + [ index_summary, tag_summary, assignee_summary, creator_summary, stage_summary, terms_summary ].compact.to_sentence + " #{bucket_summary}" end private @@ -22,12 +22,6 @@ module Filter::Summarized end end - def assigner_summary - if assigners.any? - "assigned by #{assigners.pluck(:name).to_choice_sentence}" - end - end - def stage_summary if stages.any? "staged in #{stages.pluck(:name).to_choice_sentence}" @@ -45,4 +39,10 @@ module Filter::Summarized "matching #{terms.map { |term| %Q("#{term}") }.to_sentence}" end end + + def creator_summary + if creators.any? + "added by #{creators.pluck(:name).to_choice_sentence}" + end + end end diff --git a/app/views/filters/_assigners.html.erb b/app/views/filters/_creators.html.erb similarity index 57% rename from app/views/filters/_assigners.html.erb rename to app/views/filters/_creators.html.erb index 8c03625b1..aa8befe24 100644 --- a/app/views/filters/_assigners.html.erb +++ b/app/views/filters/_creators.html.erb @@ -1,47 +1,49 @@ -<% if filter.assigners.any? %> -
+<% if filter.creators.any? %> +
- - Assigned by… + + Added by… <%= form_with url: bubbles_path, method: :get, class: "flex flex-column full-width popup__list", data: { controller: "form" } do |form| %> - <% filter.as_params.except(:assigner_ids).each do |key, value| %> + <% filter.as_params.except(:creator_ids).each do |key, value| %> <%= filter_hidden_field_tag key, value %> <% end %> - <%= link_to bubbles_path(filter.as_params.except(:assigner_ids)), class: "btn popup__item" do %> + <%= link_to bubbles_path(filter.as_params.except(:creator_ids)), class: "btn popup__item" do %> Clear all <% end %> <% Current.account.users.active.without(Current.user).order(:name).each do |user| %> <% end %> diff --git a/app/views/filters/_dialog.html.erb b/app/views/filters/_dialog.html.erb index c3f72b621..73e764c79 100644 --- a/app/views/filters/_dialog.html.erb +++ b/app/views/filters/_dialog.html.erb @@ -121,20 +121,20 @@ -
  • Assigned by…
  • +
  • Added by…
  • - <%= label_tag "assigner_ids_me", class: "btn filter__button" do %> - <%= check_box_tag "assigner_ids[]", Current.user.id, filter.assigners.include?(Current.user), id: "assigner_ids_me", - hidden: true, data: { action: "filter-form#clearCategory", filter_form_name_param: "assignment_status" } %> + <%= label_tag "creator_ids_me", class: "btn filter__button" do %> + <%= check_box_tag "creator_ids[]", Current.user.id, filter.creators.include?(Current.user), id: "creator_ids_me", + hidden: true %> Me <%= image_tag "close.svg", aria: { hidden: true }, size: 24 %> <% end %>
  • <% Current.account.users.active.without(Current.user).order(:name).each do |user| %>
  • - <%= label_tag "assigner_ids_#{user.id}", class: "btn filter__button" do %> - <%= check_box_tag "assigner_ids[]", user.id, filter.assigners.include?(user), id: "assigner_ids_#{user.id}", - hidden: true, data: { action: "filter-form#clearCategory", filter_form_name_param: "assignment_status" } %> + <%= label_tag "creator_ids_#{user.id}", class: "btn filter__button" do %> + <%= check_box_tag "creator_ids[]", user.id, filter.creators.include?(user), id: "creator_ids_#{user.id}", + hidden: true %> <%= user.name %> <%= image_tag "close.svg", aria: { hidden: true }, size: 24 %> <% end %> diff --git a/app/views/filters/_settings.html.erb b/app/views/filters/_settings.html.erb index e172aa880..445f97ab6 100644 --- a/app/views/filters/_settings.html.erb +++ b/app/views/filters/_settings.html.erb @@ -9,7 +9,7 @@ <%= render "filters/buckets", filter: filter %> <%= render "filters/tags", filter: filter %> <%= render "filters/assignees", filter: filter %> - <%= render "filters/assigners", filter: filter %> + <%= render "filters/creators", filter: filter %> <%= render "filters/stages", filter: filter %> <% filter.terms.each do |term| %> diff --git a/db/migrate/20250220220416_create_creators_filters_join_table.rb b/db/migrate/20250220220416_create_creators_filters_join_table.rb new file mode 100644 index 000000000..be26b71fe --- /dev/null +++ b/db/migrate/20250220220416_create_creators_filters_join_table.rb @@ -0,0 +1,11 @@ +class CreateCreatorsFiltersJoinTable < ActiveRecord::Migration[8.1] + def change + create_table :creators_filters, id: false do |t| + t.integer :filter_id, null: false + t.integer :creator_id, null: false + end + + add_index :creators_filters, :filter_id + add_index :creators_filters, :creator_id + end +end diff --git a/db/migrate/20250220220424_drop_assigners_filters_join_table.rb b/db/migrate/20250220220424_drop_assigners_filters_join_table.rb new file mode 100644 index 000000000..8db27a724 --- /dev/null +++ b/db/migrate/20250220220424_drop_assigners_filters_join_table.rb @@ -0,0 +1,7 @@ +class DropAssignersFiltersJoinTable < ActiveRecord::Migration[8.1] + class DropAssignersFiltersJoinTable < ActiveRecord::Migration[7.1] + def change + drop_table :assigners_filters if table_exists?(:assigners_filters) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 060fcdd95..68105ff5e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2025_02_14_222911) do +ActiveRecord::Schema[8.1].define(version: 2025_02_20_220424) do create_table "accesses", force: :cascade do |t| t.integer "bucket_id", null: false t.integer "user_id", null: false @@ -77,13 +77,6 @@ ActiveRecord::Schema[8.1].define(version: 2025_02_14_222911) do t.index ["filter_id"], name: "index_assignees_filters_on_filter_id" end - create_table "assigners_filters", id: false, force: :cascade do |t| - t.integer "filter_id", null: false - t.integer "assigner_id", null: false - t.index ["assigner_id"], name: "index_assigners_filters_on_assigner_id" - t.index ["filter_id"], name: "index_assigners_filters_on_filter_id" - end - create_table "assignments", force: :cascade do |t| t.integer "assignee_id", null: false t.integer "bubble_id", null: false @@ -137,6 +130,13 @@ ActiveRecord::Schema[8.1].define(version: 2025_02_14_222911) do t.datetime "updated_at", null: false end + create_table "creators_filters", id: false, force: :cascade do |t| + t.integer "filter_id", null: false + t.integer "creator_id", null: false + t.index ["creator_id"], name: "index_creators_filters_on_creator_id" + t.index ["filter_id"], name: "index_creators_filters_on_filter_id" + end + create_table "event_summaries", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false From f8209a15e32032317e29248a57fceef37a75522d Mon Sep 17 00:00:00 2001 From: Jason Zimdars Date: Thu, 20 Feb 2025 16:13:27 -0600 Subject: [PATCH 2/2] Update test --- test/models/filter_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/models/filter_test.rb b/test/models/filter_test.rb index 9c5ef0d9a..e31794b52 100644 --- a/test/models/filter_test.rb +++ b/test/models/filter_test.rb @@ -16,7 +16,7 @@ class FilterTest < ActiveSupport::TestCase filter = users(:david).filters.new indexed_by: "most_discussed", assignee_ids: [ users(:jz).id ], tag_ids: [ tags(:mobile).id ] assert_equal [ bubbles(:layout) ], filter.bubbles - filter = users(:david).filters.new assigner_ids: [ users(:david).id ], tag_ids: [ tags(:mobile).id ] + filter = users(:david).filters.new creator_ids: [ users(:david).id ], tag_ids: [ tags(:mobile).id ] assert_equal [ bubbles(:layout) ], filter.bubbles filter = users(:david).filters.new stage_ids: [ workflow_stages(:qa_triage).id ]