Skip to content

Commit

Permalink
Merge branch 'main' into feature/multiple_select_field_for_products
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob authored Feb 5, 2025
2 parents 9f26661 + 2e99b67 commit 5eded33
Show file tree
Hide file tree
Showing 40 changed files with 843 additions and 65 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/i18n-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ jobs:
id: run_tests
run: bundle exec rspec spec/system/i18n_spec.rb

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: coverage_system_${{ matrix.rails }}_ruby_${{ matrix.ruby }}
path: coverage/.resultset.json

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: always() && steps.run_tests.outcome == 'failure'
with:
name: rspec_failed_screenshots_rails_${{ matrix.rails }}_ruby_${{ matrix.ruby }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/system-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ jobs:
id: run_tests
run: bundle exec rspec spec/system/ --tag=~i18n

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: coverage_system_${{ matrix.rails }}_ruby_${{ matrix.ruby }}
path: coverage/.resultset.json

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: always() && steps.run_tests.outcome == 'failure'
with:
name: rspec_failed_screenshots_rails_${{ matrix.rails }}_ruby_${{ matrix.ruby }}
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
avo (3.16.2)
avo (3.17.2)
actionview (>= 6.1)
active_link_to
activerecord (>= 6.1)
Expand Down
3 changes: 2 additions & 1 deletion app/components/avo/actions_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def action_data_attributes(action)
disabled: action.disabled?,
turbo_prefetch: false,
enabled_classes: "text-black",
disabled_classes: "text-gray-500"
disabled_classes: "text-gray-500",
resource_name: action.resource.model_key
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
<% end %>

<%# This is the last script to run so it can register custom StimulusJS controllers from plugins. %>
<%= javascript_include_tag 'late-registration', "data-turbo-track": "reload", defer: true %>
<% path = Avo::PACKED ? '/avo-assets/late-registration' : 'late-registration' %>
<%= javascript_include_tag path, "data-turbo-track": "reload", defer: true %>
2 changes: 1 addition & 1 deletion app/components/avo/media_library/list_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def controller = Avo::Current.view_context.controller
def query
ActiveStorage::Blob.includes(:attachments)
# ignore blobs who are just a variant to avoid "n+1" blob creation
.where.not(id: ActiveStorage::Attachment.where(record_type: "ActiveStorage::VariantRecord").pluck(:blob_id))
.where.not(id: ActiveStorage::Attachment.where(record_type: "ActiveStorage::VariantRecord").select(:blob_id))
.order(created_at: :desc)
end

Expand Down
3 changes: 2 additions & 1 deletion app/components/avo/media_library/list_item_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def data
component: component_name,
blob_id: blob.id,
media_library_blob_param: blob.as_json,
media_library_path_param: helpers.main_app.url_for(blob),
media_library_path_param: helpers.main_app.rails_blob_path(blob),
media_library_url_param: helpers.main_app.url_for(blob),
media_library_attaching_param: @attaching,
media_library_multiple_param: @multiple,
media_library_selected_item: params[:controller_selector],
Expand Down
3 changes: 2 additions & 1 deletion app/components/avo/resource_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ def render_action(action)
turbo_prefetch: false,
# When action has record present behave as standalone and keep always active.
"actions-picker-target": (action.action.standalone || action.action.record.present?) ? "standaloneAction" : "resourceAction",
disabled: action.action.disabled?
disabled: action.action.disabled?,
resource_name: action.action.resource.model_key
} do
action.label
end
Expand Down
6 changes: 4 additions & 2 deletions app/components/avo/sidebar_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
<div class="space-y-6 mb-4">
<%= render Avo::Sidebar::LinkComponent.new label: 'Get started', path: helpers.avo.root_path, active: :exclusive if Rails.env.development? && Avo.configuration.home_path.nil? %>

<%= render Avo::Sidebar::LinkComponent.new label: 'Media Library', path: helpers.avo.media_library_index_path, active: :exclusive if Avo::MediaLibrary.configuration.visible? %>

<% if Avo.plugin_manager.installed?(:avo_menu) && Avo.has_main_menu? %>
<% Avo.main_menu.items.each do |item| %>
<%= render Avo::Sidebar::ItemSwitcherComponent.new item: item %>
Expand Down Expand Up @@ -53,6 +51,10 @@
</div>
</div>
<% end %>

<% if Avo::MediaLibrary.configuration.visible? %>
<%= render Avo::Sidebar::LinkComponent.new label: 'Media Library', path: helpers.avo.media_library_index_path, active: :exclusive %>
<% end %>
<% end %>

<%= render partial: "/avo/partials/sidebar_extra" %>
Expand Down
5 changes: 5 additions & 0 deletions app/components/avo/tab_content_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="space-y-12">
<% @tab.visible_items.each do |item| %>
<%= render Avo::Items::SwitcherComponent.new item: item, **@kwargs %>
<% end %>
</div>
6 changes: 6 additions & 0 deletions app/components/avo/tab_content_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

class Avo::TabContentComponent < Avo::BaseComponent
prop :tab
prop :kwargs, kind: :**
end
14 changes: 10 additions & 4 deletions app/components/avo/tab_group_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@
<div class="border rounded-lg p-2 -mx-2 -my-2 lg:p-4 lg:-mx-4 lg:-my-3 space-y-4">
<%= render Avo::TabSwitcherComponent.new resource: resource, current_tab: visible_tabs.first, group: group, active_tab_name: tab.name, view: view %>
<% if !tab.is_empty? %>
<div class="space-y-12">
<% tab.visible_items.each do |item| %>
<%= render Avo::Items::SwitcherComponent.new resource: resource, item: item, index: index, form: form, view: @view %>
<% if tab.lazy_load && view.display? %>
<%= turbo_frame_tag tab.turbo_frame_id(parent: @group), **frame_args(tab) do %>
<% if is_not_loaded?(tab) %>
<%= render Avo::LoadingComponent.new(title: tab.name) %>
<% else %>
<%= render Avo::TabContentComponent.new tab:, resource:, index:, form:, view:%>
<% end %>
<% end %>
</div>
<% else %>
<%= render Avo::TabContentComponent.new tab:, resource:, index:, form:, view:%>
<% end %>
<% end %>
</div>
<% end %>
Expand Down
24 changes: 24 additions & 0 deletions app/components/avo/tab_group_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ def render?
tabs_have_content? && visible_tabs.present?
end

def frame_args(tab)
args = {
target: :_top,
class: "block"
}

if is_not_loaded?(tab)
args[:loading] = :lazy
args[:src] = helpers.resource_path(
resource: @resource,
record: @resource.record,
keep_query_params: true,
active_tab_name: tab.name,
tab_turbo_frame: tab.turbo_frame_id(parent: @group)
)
end

args
end

def is_not_loaded?(tab)
params[:tab_turbo_frame] != tab.turbo_frame_id(parent: @group)
end

def tabs_have_content?
visible_tabs.present?
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/avo/media_library_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def blob_params
end

def authorize_access!
raise_404 unless Avo::MediaLibrary.configuration.visible?
raise_404 if Avo::MediaLibrary.configuration.disabled?
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@ export default class extends Controller {

const mediaLibraryPath = new URI(`${this.rootPath.path()}/attach-media`)
mediaLibraryPath.addSearch(params)
const mediaLibraryVisible = window.Avo.configuration.media_library.visible && window.Avo.configuration.media_library.enabled

// Add the gallery button to the toolbar
// const buttonHTML = `<button type="button" data-trix-action="gallery" class="trix-button trix-button--icon">${galleryButtonSVG}</button>`
const buttonHTML = `<a href="${mediaLibraryPath}" data-turbo-frame="${window.Avo.configuration.modal_frame_id}" class="trix-button trix-button--icon">${galleryButtonSVG}</a>`
if (mediaLibraryVisible && event.target.toolbarElement && event.target.toolbarElement.querySelector('.trix-button-group--file-tools')) {
if (window.Avo.configuration.media_library.visible && event.target.toolbarElement && event.target.toolbarElement.querySelector('.trix-button-group--file-tools')) {
event.target.toolbarElement
.querySelector('.trix-button-group--file-tools')
.insertAdjacentHTML('beforeend', buttonHTML)
Expand Down
24 changes: 16 additions & 8 deletions app/javascript/js/controllers/item_selector_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,27 @@ export default class extends Controller {

enableResourceActions() {
this.actionLinks.forEach((link) => {
link.classList.add(link.dataset.enabledClasses)
link.classList.remove(link.dataset.disabledClasses)
link.setAttribute('data-href', link.getAttribute('href'))
link.dataset.disabled = false
// Enable only if is on the same resource context
// Avoiding to enable unrelated actions when selecting items on a has many table
if (link.dataset.resourceName === this.resourceName) {
link.classList.add(link.dataset.enabledClasses)
link.classList.remove(link.dataset.disabledClasses)
link.setAttribute('data-href', link.getAttribute('href'))
link.dataset.disabled = false
}
})
}

disableResourceActions() {
this.actionLinks.forEach((link) => {
link.classList.remove(link.dataset.enabledClasses)
link.classList.add(link.dataset.disabledClasses)
link.setAttribute('href', link.getAttribute('data-href'))
link.dataset.disabled = true
// Disable only if is on the same resource context
// Avoiding to disable unrelated actions when selecting items on a has many table
if (link.dataset.resourceName === this.resourceName) {
link.classList.remove(link.dataset.enabledClasses)
link.classList.add(link.dataset.disabledClasses)
link.setAttribute('href', link.getAttribute('data-href'))
link.dataset.disabled = true
}
})
}
}
5 changes: 3 additions & 2 deletions app/javascript/js/controllers/media_library_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class extends Controller {
insertAttachments(attachments, event) {
// show an error if the controller is not found
if (!this.otherController) {
console.error('[Avo->] The Media Library failed to find any field outlets to inject the asset.')
console.error(`[Avo->] The Media Library failed to find any field outlets to inject the asset. Tried selector: ${this.controllerSelectorValue} and name: ${this.controllerNameValue}`)

return
}
Expand All @@ -82,7 +82,8 @@ export default class extends Controller {
#extractMetadataFromItem(item) {
const blob = JSON.parse(item.dataset.mediaLibraryBlobParam)
const path = item.dataset.mediaLibraryPathParam
const url = item.dataset.mediaLibraryUrlParam

return { blob, path }
return { blob, path, url }
}
}
2 changes: 1 addition & 1 deletion app/views/avo/partials/_javascript.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Avo.configuration.modal_frame_id = '<%= ::Avo::MODAL_FRAME_ID %>'
Avo.configuration.stimulus_controllers = []
Avo.configuration.media_library = {
enabled: <%= Avo::MediaLibrary.configuration.enabled %>,
enabled: <%= Avo::MediaLibrary.configuration.enabled? %>,
visible: <%= Avo::MediaLibrary.configuration.visible? %>
}
<% end %>
16 changes: 8 additions & 8 deletions app/views/layouts/avo/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
<%= render partial: "avo/partials/branding" %>
<%= render partial: "avo/partials/pre_head" %>
<%= render Avo::AssetManager::StylesheetComponent.new asset_manager: Avo.asset_manager %>
<%= stylesheet_link_tag @stylesheet_assets_path, "data-turbo-track": "reload", defer: true, as: "style" %>
<% if Avo::PACKED %>
<%= javascript_include_tag "/avo-assets/avo.base", "data-turbo-track": "reload", defer: true %>
<% else %>
<%= javascript_include_tag "avo.base", "data-turbo-track": "reload", defer: true %>
<% if Rails.env.development? && defined?(Hotwire::Livereload) %>
<%= javascript_include_tag "hotwire-livereload", defer: true %>
<% end %>
<%= stylesheet_link_tag @stylesheet_assets_path, "data-turbo-track": "reload", as: "style" %>

<% path = Avo::PACKED ? "/avo-assets/avo.base" : "avo.base" %>
<%= javascript_include_tag path, "data-turbo-track": "reload", defer: true %>

<% if !Avo::PACKED && defined?(Hotwire::Livereload) %>
<%= javascript_include_tag "hotwire-livereload", defer: true %>
<% end %>

<%= render Avo::AssetManager::JavascriptComponent.new asset_manager: Avo.asset_manager %>
<%= render partial: "avo/partials/head" %>
<%= content_for :head %>
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 @@ -6,7 +6,7 @@ PATH
PATH
remote: ..
specs:
avo (3.16.2)
avo (3.17.2)
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 @@ -6,7 +6,7 @@ PATH
PATH
remote: ..
specs:
avo (3.16.2)
avo (3.17.2)
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 @@ -6,7 +6,7 @@ PATH
PATH
remote: ..
specs:
avo (3.16.2)
avo (3.17.2)
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 @@ -6,7 +6,7 @@ PATH
PATH
remote: ..
specs:
avo (3.16.2)
avo (3.17.2)
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 @@ -6,7 +6,7 @@ PATH
PATH
remote: ..
specs:
avo (3.16.2)
avo (3.17.2)
actionview (>= 6.1)
active_link_to
activerecord (>= 6.1)
Expand Down
21 changes: 8 additions & 13 deletions lib/avo/base_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ class BaseAction
class_attribute :cancel_button_label
class_attribute :no_confirmation, default: false
class_attribute :standalone, default: false
class_attribute :visible
class_attribute :visible, default: -> {
# Hide on the :new view by default
return false if view.new?

# Show on all other views
true
}
class_attribute :may_download_file
class_attribute :turbo
class_attribute :authorize, default: true
Expand Down Expand Up @@ -207,25 +213,14 @@ def handle_action(**args)
end

def visible_in_view(parent_resource: nil)
return false unless authorized?

if visible.blank?
# Hide on the :new view by default
return false if view.new?

# Show on all other views
return true
end

# Run the visible block if available
Avo::ExecutionContext.new(
target: visible,
params: params,
parent_resource: parent_resource,
resource: @resource,
view: @view,
arguments: arguments
).handle
).handle && authorized?
end

def succeed(text)
Expand Down
Loading

0 comments on commit 5eded33

Please sign in to comment.