From 67a56c540aff22e01c76a42dbb5c71ba6f414ee6 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 4 Mar 2024 17:45:16 -0300 Subject: [PATCH] feat: no mostrar opciones que no se pueden ejecutar con el filtro actual --- app/models/concerns/aasm_events_concern.rb | 10 ++++++++++ app/views/components/_comments_checked_submenu.haml | 8 ++++++-- app/views/components/_comments_filters.haml | 7 +++++-- app/views/components/_instances_checked_submenu.haml | 2 +- app/views/components/_instances_filters.haml | 7 +++++-- app/views/components/_profiles_checked_submenu.haml | 2 +- app/views/components/_profiles_filters.haml | 7 +++++-- app/views/moderation_queue/_comments.haml | 2 +- 8 files changed, 34 insertions(+), 11 deletions(-) diff --git a/app/models/concerns/aasm_events_concern.rb b/app/models/concerns/aasm_events_concern.rb index 59ea243f..418368d8 100644 --- a/app/models/concerns/aasm_events_concern.rb +++ b/app/models/concerns/aasm_events_concern.rb @@ -11,6 +11,16 @@ module AasmEventsConcern aasm.events.map(&:name) - self::IGNORED_EVENTS end + # Encuentra todos los eventos que se pueden ejecutar con el filtro + # actual. + # + # @return [Array] + def self.transitionable_events(current_state) + self.events.select do |event| + aasm.events.find { |x| x.name == event }.transitions_from_state? current_state + end + end + # Todos los estados de la máquina de estados # # @return [Array] diff --git a/app/views/components/_comments_checked_submenu.haml b/app/views/components/_comments_checked_submenu.haml index fa3d7612..a09da426 100644 --- a/app/views/components/_comments_checked_submenu.haml +++ b/app/views/components/_comments_checked_submenu.haml @@ -1,2 +1,6 @@ -- ActivityPub.events.each do |event| - = render 'components/dropdown_button', form_id: form_id, text: t(".submenu_#{event}"), name: 'activity_pub_action', value: event +- current_state = params[:activity_pub_state]&.to_sym || ActivityPub.states.first + +- ActivityPub.aasm.events.each do |event| + - next if ActivityPub::IGNORED_EVENTS.include? event.name + - next unless event.transitions_from_state?(current_state) + = render 'components/dropdown_button', form_id: form_id, text: t(".submenu_#{event.name}"), name: 'activity_pub_action', value: event.name diff --git a/app/views/components/_comments_filters.haml b/app/views/components/_comments_filters.haml index 15f5173d..35cd5dda 100644 --- a/app/views/components/_comments_filters.haml +++ b/app/views/components/_comments_filters.haml @@ -1,6 +1,9 @@ +- current_state = params[:activity_pub_state]&.to_sym || ActivityPub.states.first + .d-flex.py-2 - = render 'components/dropdown', text: t('.text_checked') do - = render 'components/comments_checked_submenu', form_id: form_id + - if ActivityPub.transitionable_events(current_state).present? + = render 'components/dropdown', text: t('.text_checked') do + = render 'components/comments_checked_submenu', form_id: form_id = render 'components/dropdown', text: t('.text_show') do = render 'components/comments_show_submenu', activity_pubs: activity_pubs diff --git a/app/views/components/_instances_checked_submenu.haml b/app/views/components/_instances_checked_submenu.haml index 2d28fb1c..4c45b7ab 100644 --- a/app/views/components/_instances_checked_submenu.haml +++ b/app/views/components/_instances_checked_submenu.haml @@ -1,2 +1,2 @@ -- InstanceModeration.events.each do |event| +- InstanceModeration.transitionable_events(current_state).each do |event| = render 'components/dropdown_button', text: t(".submenu_#{event}"), name: 'instance_moderation_action', value: event, form_id: form_id diff --git a/app/views/components/_instances_filters.haml b/app/views/components/_instances_filters.haml index 2c05693a..9e8509c4 100644 --- a/app/views/components/_instances_filters.haml +++ b/app/views/components/_instances_filters.haml @@ -1,6 +1,9 @@ +- current_state = params[:state]&.to_sym || InstanceModeration.states.first + .d-flex.py-2 - = render 'components/dropdown', text: t('.text_checked') do - = render 'components/instances_checked_submenu', form_id: form_id + - if InstanceModeration.transitionable_events(current_state).present? + = render 'components/dropdown', text: t('.text_checked') do + = render 'components/instances_checked_submenu', form_id: form_id, current_state: current_state = render 'components/dropdown', text: t('.text_show') do = render 'components/instances_show_submenu', site: site diff --git a/app/views/components/_profiles_checked_submenu.haml b/app/views/components/_profiles_checked_submenu.haml index 13e016ca..66a0fa78 100644 --- a/app/views/components/_profiles_checked_submenu.haml +++ b/app/views/components/_profiles_checked_submenu.haml @@ -1,2 +1,2 @@ -- ActorModeration.events.each do |actor_event| +- ActorModeration.transitionable_events(current_state).each do |actor_event| = render 'components/dropdown_button', text: t(".submenu_#{actor_event}"), name: 'actor_moderation_action', value: actor_event, form_id: form_id diff --git a/app/views/components/_profiles_filters.haml b/app/views/components/_profiles_filters.haml index a2593f4c..bf7fb48a 100644 --- a/app/views/components/_profiles_filters.haml +++ b/app/views/components/_profiles_filters.haml @@ -1,6 +1,9 @@ +- current_state = params[:actor_state]&.to_sym || ActorModeration.states.first + .d-flex.py-2 - = render 'components/dropdown', text: t('.text_checked') do - = render 'components/profiles_checked_submenu', form_id: form_id + - if ActorModeration.transitionable_events(current_state).present? + = render 'components/dropdown', text: t('.text_checked') do + = render 'components/profiles_checked_submenu', form_id: form_id, current_state: current_state = render 'components/dropdown', text: t('.text_show') do = render 'components/profiles_show_submenu', actor_moderations: actor_moderations diff --git a/app/views/moderation_queue/_comments.haml b/app/views/moderation_queue/_comments.haml index bf1e94a0..436777db 100644 --- a/app/views/moderation_queue/_comments.haml +++ b/app/views/moderation_queue/_comments.haml @@ -5,7 +5,7 @@ .row.no-gutters.pt-2{ data: { controller: 'select-all' } } .col-1.d-flex.align-items-center = render 'components/select_all', id: 'select-all-comments', form_id: form_id - .col-md-9 + .col-11 -# Filtros = render 'components/comments_filters', activity_pubs: moderation_queue, form_id: form_id .col-12