diff --git a/Gemfile.lock b/Gemfile.lock index 0105bec49..a058686b2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -107,7 +107,7 @@ GIT PATH remote: . specs: - avo (3.13.0) + avo (3.13.3) actionview (>= 6.1) active_link_to activerecord (>= 6.1) diff --git a/app/components/avo/index/resource_table_component.rb b/app/components/avo/index/resource_table_component.rb index 01d33279c..a434a69c3 100644 --- a/app/components/avo/index/resource_table_component.rb +++ b/app/components/avo/index/resource_table_component.rb @@ -14,7 +14,7 @@ def before_render prop :parent_record, _Nilable(_Any) prop :parent_resource, _Nilable(Avo::BaseResource) prop :pagy, _Nilable(Pagy) - prop :query, _Nilable(ActiveRecord::Relation) + prop :query, _Nilable(_Any) prop :actions, _Nilable(_Array(Avo::BaseAction)) def encrypted_query diff --git a/app/components/avo/modal_component.rb b/app/components/avo/modal_component.rb index 2814c2ea8..8a55a587d 100644 --- a/app/components/avo/modal_component.rb +++ b/app/components/avo/modal_component.rb @@ -6,7 +6,7 @@ class Avo::ModalComponent < Avo::BaseComponent prop :width, Symbol, default: :md prop :body_class, _Nilable(String) - prop :overflow, Symbol, default: :auto + prop :overflow, _Nilable(Symbol), default: :auto def width_classes case @width.to_sym diff --git a/app/components/avo/views/resource_index_component.rb b/app/components/avo/views/resource_index_component.rb index 92779c8c7..c70805a66 100644 --- a/app/components/avo/views/resource_index_component.rb +++ b/app/components/avo/views/resource_index_component.rb @@ -17,7 +17,7 @@ class Avo::Views::ResourceIndexComponent < Avo::ResourceComponent prop :parent_record, _Nilable(_Any) prop :parent_resource, _Nilable(Avo::BaseResource) prop :applied_filters, Hash, default: {}.freeze - prop :query, _Nilable(ActiveRecord::Relation), reader: :public + prop :query, _Nilable(_Any), reader: :public # This should be # prop :scopes, _Nilable(_Array(Avo::Advanced::Scopes::BaseScope)), reader: :public # However, Avo::Advanced::Scopes::BaseScope raises an error because diff --git a/app/controllers/avo/search_controller.rb b/app/controllers/avo/search_controller.rb index d36f56fee..1aa284050 100644 --- a/app/controllers/avo/search_controller.rb +++ b/app/controllers/avo/search_controller.rb @@ -9,14 +9,22 @@ class SearchController < ApplicationController before_action :set_resource, only: :show def show - render json: search_resources([resource]) + render json: search_resources([resource], request:) rescue => error render_error _label: error.message end + def process_results(results, request:) + results + end + private - def search_resources(resources) + def search_resources(resources, request: nil) + process_results search_results(resources, request:), request: + end + + def search_results(resources, request: nil) resources .map do |resource| # Apply authorization diff --git a/app/javascript/js/controllers/toggle_controller.js b/app/javascript/js/controllers/toggle_controller.js index 01b4dff9b..1041e783f 100644 --- a/app/javascript/js/controllers/toggle_controller.js +++ b/app/javascript/js/controllers/toggle_controller.js @@ -6,12 +6,12 @@ export default class extends Controller { static targets = ['panel'] static values = { - // One may want to have an element that is exempt from triggerring the click outside event - exemptionContainer: String, + // One may want to have elements that are exempt from triggering the click outside event + exemptionContainers: Array, } - get exemptionContainerTarget() { - return document.querySelector(this.exemptionContainerValue) + get exemptionContainerTargets() { + return this.exemptionContainersValue.map((selector) => document.querySelector(selector)).filter(Boolean) } connect() { @@ -20,13 +20,9 @@ export default class extends Controller { clickOutside(e) { if (this.hasPanelTarget) { - if (this.hasExemptionContainerValue && this.exemptionContainerTarget) { - const inExemptionContainer = this.exemptionContainerTarget.contains(e.target) + const isInExemptionContainer = this.hasExemptionContainersValue && this.exemptionContainerTargets.some((container) => container.contains(e.target)) - if (!inExemptionContainer) { - leave(this.panelTarget) - } - } else { + if (!isInExemptionContainer) { leave(this.panelTarget) } } diff --git a/gemfiles/rails_6.1_ruby_3.1.4.gemfile.lock b/gemfiles/rails_6.1_ruby_3.1.4.gemfile.lock index 30028d401..4e6a63dcd 100644 --- a/gemfiles/rails_6.1_ruby_3.1.4.gemfile.lock +++ b/gemfiles/rails_6.1_ruby_3.1.4.gemfile.lock @@ -13,7 +13,7 @@ PATH PATH remote: .. specs: - avo (3.13.0) + avo (3.13.3) actionview (>= 6.1) active_link_to activerecord (>= 6.1) diff --git a/gemfiles/rails_6.1_ruby_3.3.0.gemfile.lock b/gemfiles/rails_6.1_ruby_3.3.0.gemfile.lock index 0f653adb1..76f868fc9 100644 --- a/gemfiles/rails_6.1_ruby_3.3.0.gemfile.lock +++ b/gemfiles/rails_6.1_ruby_3.3.0.gemfile.lock @@ -13,7 +13,7 @@ PATH PATH remote: .. specs: - avo (3.13.0) + avo (3.13.3) actionview (>= 6.1) active_link_to activerecord (>= 6.1) diff --git a/gemfiles/rails_7.1_ruby_3.1.4.gemfile.lock b/gemfiles/rails_7.1_ruby_3.1.4.gemfile.lock index 37b7de06e..f0e9b1a7a 100644 --- a/gemfiles/rails_7.1_ruby_3.1.4.gemfile.lock +++ b/gemfiles/rails_7.1_ruby_3.1.4.gemfile.lock @@ -13,7 +13,7 @@ PATH PATH remote: .. specs: - avo (3.13.0) + avo (3.13.3) actionview (>= 6.1) active_link_to activerecord (>= 6.1) diff --git a/gemfiles/rails_7.1_ruby_3.3.0.gemfile.lock b/gemfiles/rails_7.1_ruby_3.3.0.gemfile.lock index fd88bbdb2..36b407e43 100644 --- a/gemfiles/rails_7.1_ruby_3.3.0.gemfile.lock +++ b/gemfiles/rails_7.1_ruby_3.3.0.gemfile.lock @@ -13,7 +13,7 @@ PATH PATH remote: .. specs: - avo (3.13.0) + avo (3.13.3) actionview (>= 6.1) active_link_to activerecord (>= 6.1) diff --git a/gemfiles/rails_7.2.0.beta2_ruby_3.1.4.gemfile.lock b/gemfiles/rails_7.2.0.beta2_ruby_3.1.4.gemfile.lock index 3eb47874a..7a68e3525 100644 --- a/gemfiles/rails_7.2.0.beta2_ruby_3.1.4.gemfile.lock +++ b/gemfiles/rails_7.2.0.beta2_ruby_3.1.4.gemfile.lock @@ -13,7 +13,7 @@ PATH PATH remote: .. specs: - avo (3.13.0) + avo (3.13.3) actionview (>= 6.1) active_link_to activerecord (>= 6.1) diff --git a/gemfiles/rails_7.2.0.beta2_ruby_3.3.0.gemfile.lock b/gemfiles/rails_7.2.0.beta2_ruby_3.3.0.gemfile.lock index 3eb47874a..7a68e3525 100644 --- a/gemfiles/rails_7.2.0.beta2_ruby_3.3.0.gemfile.lock +++ b/gemfiles/rails_7.2.0.beta2_ruby_3.3.0.gemfile.lock @@ -13,7 +13,7 @@ PATH PATH remote: .. specs: - avo (3.13.0) + avo (3.13.3) actionview (>= 6.1) active_link_to activerecord (>= 6.1) diff --git a/gemfiles/rails_8.0_ruby_3.1.4.gemfile.lock b/gemfiles/rails_8.0_ruby_3.1.4.gemfile.lock index 89af58c7f..d66e88005 100644 --- a/gemfiles/rails_8.0_ruby_3.1.4.gemfile.lock +++ b/gemfiles/rails_8.0_ruby_3.1.4.gemfile.lock @@ -112,7 +112,7 @@ PATH PATH remote: .. specs: - avo (3.13.0) + avo (3.13.3) actionview (>= 6.1) active_link_to activerecord (>= 6.1) diff --git a/gemfiles/rails_8.0_ruby_3.3.0.gemfile.lock b/gemfiles/rails_8.0_ruby_3.3.0.gemfile.lock index 89af58c7f..d66e88005 100644 --- a/gemfiles/rails_8.0_ruby_3.3.0.gemfile.lock +++ b/gemfiles/rails_8.0_ruby_3.3.0.gemfile.lock @@ -112,7 +112,7 @@ PATH PATH remote: .. specs: - avo (3.13.0) + avo (3.13.3) actionview (>= 6.1) active_link_to activerecord (>= 6.1) diff --git a/lib/avo/resources/resource_manager.rb b/lib/avo/resources/resource_manager.rb index 48b9eb037..8eada1bd1 100644 --- a/lib/avo/resources/resource_manager.rb +++ b/lib/avo/resources/resource_manager.rb @@ -100,6 +100,15 @@ def get_resource_by_name(name) get_resource name.singularize.camelize end + # Returns the Avo resource by singular snake_cased name + # + # get_resource_by_name('z posts') => instance of Avo::Resources::ZPost + def get_resource_by_plural_name(name) + resources.find do |resource| + resource.plural_name == name + end + end + # Returns the Avo resource by singular snake_cased name # From all the resources that use the same model_class, it will fetch the first one in alphabetical order # diff --git a/lib/avo/version.rb b/lib/avo/version.rb index 8bf29b418..4d39a0b84 100644 --- a/lib/avo/version.rb +++ b/lib/avo/version.rb @@ -1,3 +1,3 @@ module Avo - VERSION = "3.13.0" unless const_defined?(:VERSION) + VERSION = "3.13.3" unless const_defined?(:VERSION) end