Skip to content

Commit

Permalink
Merge branch 'main' into feature/reorder-key-value-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
enderahmetyurt authored Oct 5, 2024
2 parents a280577 + a53f9a0 commit d103790
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/components/avo/index/resource_table_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/components/avo/modal_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/components/avo/views/resource_index_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions app/controllers/avo/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 6 additions & 10 deletions app/javascript/js/controllers/toggle_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_6.1_ruby_3.1.4.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_6.1_ruby_3.3.0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7.1_ruby_3.1.4.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7.1_ruby_3.3.0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7.2.0.beta2_ruby_3.1.4.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7.2.0.beta2_ruby_3.3.0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_8.0_ruby_3.1.4.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_8.0_ruby_3.3.0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions lib/avo/resources/resource_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
2 changes: 1 addition & 1 deletion lib/avo/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Avo
VERSION = "3.13.0" unless const_defined?(:VERSION)
VERSION = "3.13.3" unless const_defined?(:VERSION)
end

0 comments on commit d103790

Please sign in to comment.