From 2585b4fd7c42303410c81125ccc09479e9501041 Mon Sep 17 00:00:00 2001 From: Paul Bob <69730720+Paul-Bob@users.noreply.github.com> Date: Mon, 16 Dec 2024 03:31:00 +0200 Subject: [PATCH 01/14] fix: Pagy::OverflowError (#3528) * fix: pagy overflow when reset filters * fix: Pagy::OverflowError * revert page 1 on filters reset --- lib/avo/concerns/pagination.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/avo/concerns/pagination.rb b/lib/avo/concerns/pagination.rb index 33b48ac06..784ac8a1f 100644 --- a/lib/avo/concerns/pagination.rb +++ b/lib/avo/concerns/pagination.rb @@ -37,6 +37,18 @@ def apply_pagination(index_params:, query:, **args) data_turbo_frame = "data-turbo-frame=\"#{CGI.escapeHTML(params[:turbo_frame]) if params[:turbo_frame]}\"" + # Perform pagination and fallback to first page on Pagy::OverflowError + begin + perform_pagination(index_params:, query:, data_turbo_frame:, extra_pagy_params:, **args) + rescue Pagy::OverflowError + index_params[:page] = 1 + perform_pagination(index_params:, query:, data_turbo_frame:, extra_pagy_params:, **args) + end + end + + private + + def perform_pagination(index_params:, query:, data_turbo_frame:, extra_pagy_params:, **args) send PAGINATION_METHOD[pagination_type.to_sym], query, **args, @@ -49,8 +61,6 @@ def apply_pagination(index_params:, query:, **args) size: pagination_hash[:size] end - private - def pagination_hash @pagination ||= PAGINATION_DEFAULTS.merge(Avo.configuration.pagination).merge Avo::ExecutionContext.new( target: pagination, From 77b412b9b1366ddec058581a892230de9ff1828a Mon Sep 17 00:00:00 2001 From: Adrian Marin Date: Mon, 16 Dec 2024 04:04:33 +0200 Subject: [PATCH 02/14] feature: cmd+return to submit form (#3532) * feature: cmd+return to submit form * add spec * lint * fix test --------- Co-authored-by: Paul Bob --- .../avo/views/resource_edit_component.html.erb | 6 +++++- app/javascript/js/controllers.js | 2 ++ app/javascript/js/controllers/form_controller.js | 8 ++++++++ spec/system/avo/avo_cmd_return_to_submits_spec.rb | 11 +++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 app/javascript/js/controllers/form_controller.js create mode 100644 spec/system/avo/avo_cmd_return_to_submits_spec.rb diff --git a/app/components/avo/views/resource_edit_component.html.erb b/app/components/avo/views/resource_edit_component.html.erb index 950e2b331..2836f1d24 100644 --- a/app/components/avo/views/resource_edit_component.html.erb +++ b/app/components/avo/views/resource_edit_component.html.erb @@ -15,7 +15,11 @@ method: form_method, local: true, html: { - novalidate: true + novalidate: true, + data: { + controller: "form", + action: "keydown.ctrl+enter->form#submit keydown.meta+enter->form#submit" + } }, multipart: true do |form| %> <%= render Avo::ReferrerParamsComponent.new back_path: back_path %> diff --git a/app/javascript/js/controllers.js b/app/javascript/js/controllers.js index de91a986b..f9113b0c1 100644 --- a/app/javascript/js/controllers.js +++ b/app/javascript/js/controllers.js @@ -15,6 +15,7 @@ import DateFieldController from './controllers/fields/date_field_controller' import DateTimeFilterController from './controllers/date_time_filter_controller' import EasyMdeController from './controllers/fields/easy_mde_controller' import FilterController from './controllers/filter_controller' +import FormController from './controllers/form_controller' import HiddenInputController from './controllers/hidden_input_controller' import InputAutofocusController from './controllers/input_autofocus_controller' import ItemSelectAllController from './controllers/item_select_all_controller' @@ -59,6 +60,7 @@ application.register('copy-to-clipboard', CopyToClipboardController) application.register('dashboard-card', DashboardCardController) application.register('date-time-filter', DateTimeFilterController) application.register('filter', FilterController) +application.register('form', FormController) application.register('panel-refresh', PanelRefreshController) application.register('hidden-input', HiddenInputController) application.register('input-autofocus', InputAutofocusController) diff --git a/app/javascript/js/controllers/form_controller.js b/app/javascript/js/controllers/form_controller.js new file mode 100644 index 000000000..c1024dc61 --- /dev/null +++ b/app/javascript/js/controllers/form_controller.js @@ -0,0 +1,8 @@ +import { Controller } from '@hotwired/stimulus' + +// Connects to data-controller="form" +export default class extends Controller { + submit() { + this.element.requestSubmit() + } +} diff --git a/spec/system/avo/avo_cmd_return_to_submits_spec.rb b/spec/system/avo/avo_cmd_return_to_submits_spec.rb new file mode 100644 index 000000000..c4e5e5cb0 --- /dev/null +++ b/spec/system/avo/avo_cmd_return_to_submits_spec.rb @@ -0,0 +1,11 @@ +require "rails_helper" + +RSpec.describe "CmdReturnToSubmits", type: :system do + let(:project) { create :project } + + it "submits form when cmd+enter is pressed" do + visit "/admin/resources/projects/#{project.id}/edit" + find("input[name='project[name]']").send_keys [:control, :enter] + expect(page).to have_text "Project was successfully updated" + end +end From e46909cd4be4098b53e7aa32f077a50b57b32226 Mon Sep 17 00:00:00 2001 From: Paul Bob <69730720+Paul-Bob@users.noreply.github.com> Date: Mon, 16 Dec 2024 15:18:35 +0200 Subject: [PATCH 03/14] enhancement: `cache_associations_pagination` option (#3534) * enhancement: `cache_associations_pagination` option * fix complexity and tests * test * template * Update spec/system/avo/tabs_spec.rb --- .../avo/associations_controller.rb | 25 +++++++++++++++---- lib/avo/configuration.rb | 2 ++ .../avo/templates/initializer/avo.tt | 2 ++ spec/dummy/config/initializers/avo.rb | 1 + spec/system/avo/tabs_spec.rb | 9 +++++++ 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/app/controllers/avo/associations_controller.rb b/app/controllers/avo/associations_controller.rb index 7ba0bc9ca..ce05ebdde 100644 --- a/app/controllers/avo/associations_controller.rb +++ b/app/controllers/avo/associations_controller.rb @@ -291,20 +291,35 @@ def select_options(query) end end + def pagination_key + @pagination_key ||= "#{@parent_resource.class.to_s.parameterize}.has_many.#{@related_resource.class.to_s.parameterize}" + end + def set_pagination_params - pagination_key = "#{@parent_resource.class.to_s.parameterize}.has_many.#{@related_resource.class.to_s.parameterize}" + set_page_param + set_per_page_param + end + def set_page_param # avo-resources-project.has_many.avo-resources-user.page page_key = "#{pagination_key}.page" - session[page_key] = params[:page] || session[page_key] || 1 - @index_params[:page] = session[page_key] + @index_params[:page] = if Avo.configuration.cache_associations_pagination + session[page_key] = params[:page] || session[page_key] || 1 + else + params[:page] || 1 + end + end + def set_per_page_param # avo-resources-project.has_many.avo-resources-user.per_page per_page_key = "#{pagination_key}.per_page" - session[per_page_key] = params[:per_page] || session[per_page_key] || Avo.configuration.via_per_page - @index_params[:per_page] = session[per_page_key] + @index_params[:per_page] = if Avo.configuration.cache_associations_pagination + session[per_page_key] = params[:per_page] || session[per_page_key] || Avo.configuration.via_per_page + else + params[:per_page] || Avo.configuration.via_per_page + end end end end diff --git a/lib/avo/configuration.rb b/lib/avo/configuration.rb index 5155957bb..c89123749 100644 --- a/lib/avo/configuration.rb +++ b/lib/avo/configuration.rb @@ -27,6 +27,7 @@ class Configuration attr_accessor :full_width_index_view attr_accessor :cache_resources_on_index_view attr_accessor :cache_resource_filters + attr_accessor :cache_associations_pagination attr_accessor :context attr_accessor :display_breadcrumbs attr_accessor :hide_layout_when_printing @@ -87,6 +88,7 @@ def initialize @full_width_index_view = false @cache_resources_on_index_view = Avo::PACKED @cache_resource_filters = false + @cache_associations_pagination = false @context = proc {} @initial_breadcrumbs = proc { add_breadcrumb I18n.t("avo.home").humanize, avo.root_path diff --git a/lib/generators/avo/templates/initializer/avo.tt b/lib/generators/avo/templates/initializer/avo.tt index 75c7021ee..7e5b56b11 100644 --- a/lib/generators/avo/templates/initializer/avo.tt +++ b/lib/generators/avo/templates/initializer/avo.tt @@ -82,6 +82,8 @@ Avo.configure do |config| # config.cache_resource_filters = false ## provide a lambda to enable or disable cache_resource_filters per user/resource. # config.cache_resource_filters = -> { current_user.cache_resource_filters? } + ## Control persistence for the page and per-page options in association tables. + # config.cache_associations_pagination = false ## == Turbo options == # config.turbo = -> do diff --git a/spec/dummy/config/initializers/avo.rb b/spec/dummy/config/initializers/avo.rb index f9bd5c637..efb3b1a5f 100644 --- a/spec/dummy/config/initializers/avo.rb +++ b/spec/dummy/config/initializers/avo.rb @@ -45,6 +45,7 @@ config.search_debounce = 300 # config.field_wrapper_layout = :stacked config.cache_resource_filters = false + config.cache_associations_pagination = false config.click_row_to_view_record = true config.turbo = { diff --git a/spec/system/avo/tabs_spec.rb b/spec/system/avo/tabs_spec.rb index 9803a8ce5..0e37e5d51 100644 --- a/spec/system/avo/tabs_spec.rb +++ b/spec/system/avo/tabs_spec.rb @@ -181,6 +181,9 @@ end it "keeps the pagination on tab when back is used" do + default_cache_associations_pagination_value = Avo.configuration.cache_associations_pagination + Avo.configuration.cache_associations_pagination = true + visit avo.resources_user_path user find('a[data-selected="false"][data-tabs-tab-name-param="Projects"]').click @@ -199,9 +202,13 @@ expect(page).to have_css('a.current[role="link"][aria-disabled="true"][aria-current="page"]', text: "2") expect(page).to have_text "Displaying items 9-9 of 9 in total" + + Avo.configuration.cache_associations_pagination = default_cache_associations_pagination_value end it "keeps the per_page on association when back is used" do + default_cache_associations_pagination_value = Avo.configuration.cache_associations_pagination + Avo.configuration.cache_associations_pagination = true visit avo.resources_user_path user find('a[data-selected="false"][data-tabs-tab-name-param="Projects"]').click @@ -221,5 +228,7 @@ expect(page).to have_text "Displaying 9 items" expect(find("select#per_page.appearance-none").find("option[selected]").text).to eq("24") + + Avo.configuration.cache_associations_pagination = default_cache_associations_pagination_value end end From f35feeb5db2da46413c7139394bad1e3330d8068 Mon Sep 17 00:00:00 2001 From: Paul Bob <69730720+Paul-Bob@users.noreply.github.com> Date: Tue, 17 Dec 2024 19:36:09 +0200 Subject: [PATCH 04/14] enhancement: persistence setting (#3540) * enhancement: persistence setting * fix tests --- app/controllers/avo/associations_controller.rb | 4 ++-- lib/avo/concerns/filters_session_handler.rb | 12 ++---------- lib/avo/configuration.rb | 16 ++++++++++++---- lib/generators/avo/templates/initializer/avo.tt | 6 ------ spec/dummy/config/initializers/avo.rb | 2 -- spec/system/avo/filters/persist_filters_spec.rb | 14 ++------------ spec/system/avo/tabs_spec.rb | 11 +++++------ 7 files changed, 23 insertions(+), 42 deletions(-) diff --git a/app/controllers/avo/associations_controller.rb b/app/controllers/avo/associations_controller.rb index ce05ebdde..3dd24b317 100644 --- a/app/controllers/avo/associations_controller.rb +++ b/app/controllers/avo/associations_controller.rb @@ -304,7 +304,7 @@ def set_page_param # avo-resources-project.has_many.avo-resources-user.page page_key = "#{pagination_key}.page" - @index_params[:page] = if Avo.configuration.cache_associations_pagination + @index_params[:page] = if Avo.configuration.session_persistence_enabled? session[page_key] = params[:page] || session[page_key] || 1 else params[:page] || 1 @@ -315,7 +315,7 @@ def set_per_page_param # avo-resources-project.has_many.avo-resources-user.per_page per_page_key = "#{pagination_key}.per_page" - @index_params[:per_page] = if Avo.configuration.cache_associations_pagination + @index_params[:per_page] = if Avo.configuration.session_persistence_enabled? session[per_page_key] = params[:per_page] || session[per_page_key] || Avo.configuration.via_per_page else params[:per_page] || Avo.configuration.via_per_page diff --git a/lib/avo/concerns/filters_session_handler.rb b/lib/avo/concerns/filters_session_handler.rb index cd93f93ff..abca060fc 100644 --- a/lib/avo/concerns/filters_session_handler.rb +++ b/lib/avo/concerns/filters_session_handler.rb @@ -2,13 +2,13 @@ module Avo module Concerns module FiltersSessionHandler def reset_filters - return unless cache_resource_filters? + return unless Avo.configuration.session_persistence_enabled? session.delete(filters_session_key) end def fetch_filters - return filters_from_params unless cache_resource_filters? + return filters_from_params unless Avo.configuration.session_persistence_enabled? (filters_from_params && save_filters_to_session) || filters_from_session end @@ -31,14 +31,6 @@ def filters_session_key action id ].map { |key| params[key] }.compact.join("/") end - - def cache_resource_filters? - Avo::ExecutionContext.new( - target: Avo.configuration.cache_resource_filters, - current_user: _current_user, - resource: @resource - ).handle - end end end end diff --git a/lib/avo/configuration.rb b/lib/avo/configuration.rb index c89123749..6176103d8 100644 --- a/lib/avo/configuration.rb +++ b/lib/avo/configuration.rb @@ -11,6 +11,7 @@ class Configuration attr_writer :pagination attr_writer :explicit_authorization attr_writer :exclude_from_status + attr_writer :persistence attr_accessor :timezone attr_accessor :per_page attr_accessor :per_page_steps @@ -26,8 +27,6 @@ class Configuration attr_accessor :full_width_container attr_accessor :full_width_index_view attr_accessor :cache_resources_on_index_view - attr_accessor :cache_resource_filters - attr_accessor :cache_associations_pagination attr_accessor :context attr_accessor :display_breadcrumbs attr_accessor :hide_layout_when_printing @@ -87,8 +86,9 @@ def initialize @full_width_container = false @full_width_index_view = false @cache_resources_on_index_view = Avo::PACKED - @cache_resource_filters = false - @cache_associations_pagination = false + @persistence = { + driver: nil + } @context = proc {} @initial_breadcrumbs = proc { add_breadcrumb I18n.t("avo.home").humanize, avo.root_path @@ -278,6 +278,14 @@ def default_locale def explicit_authorization Avo::ExecutionContext.new(target: @explicit_authorization).handle end + + def persistence + Avo::ExecutionContext.new(target: @persistence).handle + end + + def session_persistence_enabled? + persistence[:driver] == :session + end end def self.configuration diff --git a/lib/generators/avo/templates/initializer/avo.tt b/lib/generators/avo/templates/initializer/avo.tt index 7e5b56b11..dfe93766d 100644 --- a/lib/generators/avo/templates/initializer/avo.tt +++ b/lib/generators/avo/templates/initializer/avo.tt @@ -78,12 +78,6 @@ Avo.configure do |config| # ActiveSupport::Cache.lookup_store(:solid_cache_store) # } # config.cache_resources_on_index_view = true - ## permanent enable or disable cache_resource_filters, default value is false - # config.cache_resource_filters = false - ## provide a lambda to enable or disable cache_resource_filters per user/resource. - # config.cache_resource_filters = -> { current_user.cache_resource_filters? } - ## Control persistence for the page and per-page options in association tables. - # config.cache_associations_pagination = false ## == Turbo options == # config.turbo = -> do diff --git a/spec/dummy/config/initializers/avo.rb b/spec/dummy/config/initializers/avo.rb index efb3b1a5f..0823ef04b 100644 --- a/spec/dummy/config/initializers/avo.rb +++ b/spec/dummy/config/initializers/avo.rb @@ -44,8 +44,6 @@ config.resource_default_view = :show config.search_debounce = 300 # config.field_wrapper_layout = :stacked - config.cache_resource_filters = false - config.cache_associations_pagination = false config.click_row_to_view_record = true config.turbo = { diff --git a/spec/system/avo/filters/persist_filters_spec.rb b/spec/system/avo/filters/persist_filters_spec.rb index b6bceb128..d3a31a7e6 100644 --- a/spec/system/avo/filters/persist_filters_spec.rb +++ b/spec/system/avo/filters/persist_filters_spec.rb @@ -18,12 +18,9 @@ context "cache resource filter enabled" do around(:each) do |it| - saved_value = Avo.configuration.cache_resource_filters - Avo.configuration.cache_resource_filters = lambda { - true - } + Avo.configuration.persistence = {driver: :session} it.run - Avo.configuration.cache_resource_filters = saved_value + Avo.configuration.persistence = {driver: nil} end it "persist filters by name" do @@ -53,13 +50,6 @@ end context "cache resource filter disabled" do - around(:each) do |it| - saved_value = Avo.configuration.cache_resource_filters - Avo.configuration.cache_resource_filters = false - it.run - Avo.configuration.cache_resource_filters = saved_value - end - it "doesn't persist filters by name" do visit url expect(page).to have_text("Displaying 2 item") diff --git a/spec/system/avo/tabs_spec.rb b/spec/system/avo/tabs_spec.rb index 0e37e5d51..a684e3f12 100644 --- a/spec/system/avo/tabs_spec.rb +++ b/spec/system/avo/tabs_spec.rb @@ -181,8 +181,7 @@ end it "keeps the pagination on tab when back is used" do - default_cache_associations_pagination_value = Avo.configuration.cache_associations_pagination - Avo.configuration.cache_associations_pagination = true + Avo.configuration.persistence = {driver: :session} visit avo.resources_user_path user @@ -203,12 +202,12 @@ expect(page).to have_css('a.current[role="link"][aria-disabled="true"][aria-current="page"]', text: "2") expect(page).to have_text "Displaying items 9-9 of 9 in total" - Avo.configuration.cache_associations_pagination = default_cache_associations_pagination_value + Avo.configuration.persistence = {driver: nil} end it "keeps the per_page on association when back is used" do - default_cache_associations_pagination_value = Avo.configuration.cache_associations_pagination - Avo.configuration.cache_associations_pagination = true + Avo.configuration.persistence = {driver: :session} + visit avo.resources_user_path user find('a[data-selected="false"][data-tabs-tab-name-param="Projects"]').click @@ -229,6 +228,6 @@ expect(page).to have_text "Displaying 9 items" expect(find("select#per_page.appearance-none").find("option[selected]").text).to eq("24") - Avo.configuration.cache_associations_pagination = default_cache_associations_pagination_value + Avo.configuration.persistence = {driver: nil} end end From 2b99dc1554eaca5eb5a44ff17600e90a9ee5cfa5 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Wed, 18 Dec 2024 12:15:39 +0200 Subject: [PATCH 05/14] Bumped avo to 3.15.4 --- Gemfile.lock | 2 +- gemfiles/rails_6.1_ruby_3.1.4.gemfile.lock | 2 +- gemfiles/rails_6.1_ruby_3.3.0.gemfile.lock | 2 +- gemfiles/rails_7.1_ruby_3.1.4.gemfile.lock | 2 +- gemfiles/rails_7.1_ruby_3.3.0.gemfile.lock | 2 +- gemfiles/rails_8.0_ruby_3.3.0.gemfile.lock | 2 +- lib/avo/version.rb | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b218ad315..c69e8d410 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - avo (3.15.3) + avo (3.15.4) actionview (>= 6.1) active_link_to activerecord (>= 6.1) 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 69c223683..ccfa5f726 100644 --- a/gemfiles/rails_6.1_ruby_3.1.4.gemfile.lock +++ b/gemfiles/rails_6.1_ruby_3.1.4.gemfile.lock @@ -6,7 +6,7 @@ PATH PATH remote: .. specs: - avo (3.15.3) + avo (3.15.4) 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 1d810c781..0a31c3a95 100644 --- a/gemfiles/rails_6.1_ruby_3.3.0.gemfile.lock +++ b/gemfiles/rails_6.1_ruby_3.3.0.gemfile.lock @@ -6,7 +6,7 @@ PATH PATH remote: .. specs: - avo (3.15.3) + avo (3.15.4) 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 dc810900e..efc554be8 100644 --- a/gemfiles/rails_7.1_ruby_3.1.4.gemfile.lock +++ b/gemfiles/rails_7.1_ruby_3.1.4.gemfile.lock @@ -6,7 +6,7 @@ PATH PATH remote: .. specs: - avo (3.15.3) + avo (3.15.4) 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 8a3b1e62f..12cf1613b 100644 --- a/gemfiles/rails_7.1_ruby_3.3.0.gemfile.lock +++ b/gemfiles/rails_7.1_ruby_3.3.0.gemfile.lock @@ -6,7 +6,7 @@ PATH PATH remote: .. specs: - avo (3.15.3) + avo (3.15.4) 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 98cdddd9c..f9792e836 100644 --- a/gemfiles/rails_8.0_ruby_3.3.0.gemfile.lock +++ b/gemfiles/rails_8.0_ruby_3.3.0.gemfile.lock @@ -6,7 +6,7 @@ PATH PATH remote: .. specs: - avo (3.15.3) + avo (3.15.4) actionview (>= 6.1) active_link_to activerecord (>= 6.1) diff --git a/lib/avo/version.rb b/lib/avo/version.rb index 65780e905..4e9e0e0ca 100644 --- a/lib/avo/version.rb +++ b/lib/avo/version.rb @@ -1,3 +1,3 @@ module Avo - VERSION = "3.15.3" unless const_defined?(:VERSION) + VERSION = "3.15.4" unless const_defined?(:VERSION) end From 10f1a54f7d0ae1a9d41174d8c7c07b1ecc9fc839 Mon Sep 17 00:00:00 2001 From: Paul Bob <69730720+Paul-Bob@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:18:24 +0200 Subject: [PATCH 06/14] fix: `break-words` on show content (#3542) --- app/components/avo/field_wrapper_component.html.erb | 4 ++-- spec/dummy/app/avo/resources/user.rb | 3 +++ spec/dummy/app/models/user.rb | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/components/avo/field_wrapper_component.html.erb b/app/components/avo/field_wrapper_component.html.erb index e0eedd610..45c0a8ebd 100644 --- a/app/components/avo/field_wrapper_component.html.erb +++ b/app/components/avo/field_wrapper_component.html.erb @@ -17,14 +17,14 @@ <% end %> <% if on_edit? && @field.is_required? %> * <% end %> <% end %> - <%= content_tag :div, class: class_names("flex-1 flex flex-row md:min-h-inherit px-6", + <%= content_tag :div, class: class_names("flex-1 flex flex-row md:min-h-inherit px-6 overflow-x-auto", @field.get_html(:classes, view: @view, element: :content), { "pb-4": stacked?, "py-2": !compact?, "py-1": compact?, }), data: {slot: "value"} do %> -
+
<% if on_show? %> <% if render_dash? %> — diff --git a/spec/dummy/app/avo/resources/user.rb b/spec/dummy/app/avo/resources/user.rb index 81636ac29..1e790dd3f 100644 --- a/spec/dummy/app/avo/resources/user.rb +++ b/spec/dummy/app/avo/resources/user.rb @@ -120,6 +120,8 @@ def main_panel_fields required: true, only_on: [:index] + field :some_token, only_on: :show + field :is_writer, as: :text, sortable: -> { # Order by something else completely, just to make a test case that clearly and reliably does what we want. @@ -154,6 +156,7 @@ def test_sidebar def main_panel_sidebar sidebar do + field :some_token, only_on: :show test_field("Inside main_panel_sidebar") with_options only_on: :show do field :email, as: :gravatar, link_to_record: true, as_avatar: :circle diff --git a/spec/dummy/app/models/user.rb b/spec/dummy/app/models/user.rb index f57b85937..55595f362 100644 --- a/spec/dummy/app/models/user.rb +++ b/spec/dummy/app/models/user.rb @@ -104,4 +104,6 @@ def permissions delete: true, } end + + def some_token = @some_token ||= SecureRandom.hex(64) end From e9792ca332cefda026222c282e22d541ed95c1ed Mon Sep 17 00:00:00 2001 From: "depfu[bot]" <23717796+depfu[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 10:03:19 +0200 Subject: [PATCH 07/14] Update all Yarn dependencies (2024-12-19) (#3543) Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index e91245342..c875e1b6f 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "stimulus-rails-nested-form": "^4.1.0", "stimulus-textarea-autogrow": "^4.1.0", "stimulus-use": "^0.50.0", - "tailwindcss": "^3.4.16", + "tailwindcss": "^3.4.17", "tailwindcss-stimulus-components": "^3.0.4", "tippy.js": "^6.3.7", "trix": "^2.1.10", diff --git a/yarn.lock b/yarn.lock index 976ebb436..37567a53c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5263,10 +5263,10 @@ tailwindcss-stimulus-components@^3.0.4: dependencies: "@hotwired/stimulus" ">=3.0.0" -tailwindcss@^3.4.16: - version "3.4.16" - resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.4.16.tgz#35a7c3030844d6000fc271878db4096b6a8d2ec9" - integrity sha512-TI4Cyx7gDiZ6r44ewaJmt0o6BrMCT5aK5e0rmJ/G9Xq3w7CX/5VXl/zIPEJZFUK5VEqwByyhqNPycPlvcK4ZNw== +tailwindcss@^3.4.17: + version "3.4.17" + resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.4.17.tgz#ae8406c0f96696a631c790768ff319d46d5e5a63" + integrity sha512-w33E2aCvSDP0tW9RZuNXadXlkHXqFzSkQew/aIa2i/Sj8fThxwovwlXHSPXTbAHwEIhBFXAedUhP2tueAKP8Og== dependencies: "@alloc/quick-lru" "^5.2.0" arg "^5.0.2" From d8e7728067ea03aa286c3ec4cab95c1a9066cb1e Mon Sep 17 00:00:00 2001 From: Paul Bob <69730720+Paul-Bob@users.noreply.github.com> Date: Thu, 19 Dec 2024 12:02:05 +0200 Subject: [PATCH 08/14] fix: action redirect loop (#3545) * fix: action redirect loop * test * comment --- app/controllers/avo/actions_controller.rb | 22 ++++++++++++++----- .../test/no_confirmation_posts_redirect.rb | 9 ++++++++ spec/dummy/app/avo/resources/user.rb | 1 + spec/system/avo/actions_spec.rb | 16 ++++++++++++++ 4 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 spec/dummy/app/avo/actions/test/no_confirmation_posts_redirect.rb diff --git a/app/controllers/avo/actions_controller.rb b/app/controllers/avo/actions_controller.rb index a8ebd870c..71389fe74 100644 --- a/app/controllers/avo/actions_controller.rb +++ b/app/controllers/avo/actions_controller.rb @@ -99,6 +99,10 @@ def respond # Flash the messages collected from the action flash_messages + # Always execute turbo_stream.avo_close_modal on all responses, including redirects + # Exclude response types intended to keep the modal open + # This ensures the modal frame refreshes, preventing it from retaining the SRC of the previous action + # and avoids re-triggering that SRC during back navigation respond_to do |format| format.turbo_stream do turbo_response = case @response[:type] @@ -117,11 +121,14 @@ def respond turbo_stream.turbo_frame_set_src(Avo::MODAL_FRAME_ID, src) when :redirect - turbo_stream.redirect_to( - Avo::ExecutionContext.new(target: @response[:path]).handle, - turbo_frame: @response[:redirect_args][:turbo_frame], - **@response[:redirect_args].except(:turbo_frame) - ) + [ + turbo_stream.avo_close_modal, + turbo_stream.redirect_to( + Avo::ExecutionContext.new(target: @response[:path]).handle, + turbo_frame: @response[:redirect_args][:turbo_frame], + **@response[:redirect_args].except(:turbo_frame) + ) + ] when :close_modal # Close the modal and flash the messages [ @@ -132,7 +139,10 @@ def respond # Reload the page back_path = request.referer || params[:referrer].presence || resources_path(resource: @resource) - turbo_stream.redirect_to(back_path) + [ + turbo_stream.avo_close_modal, + turbo_stream.redirect_to(back_path) + ] end responses = if @action.appended_turbo_streams.present? diff --git a/spec/dummy/app/avo/actions/test/no_confirmation_posts_redirect.rb b/spec/dummy/app/avo/actions/test/no_confirmation_posts_redirect.rb new file mode 100644 index 000000000..4874e9645 --- /dev/null +++ b/spec/dummy/app/avo/actions/test/no_confirmation_posts_redirect.rb @@ -0,0 +1,9 @@ +class Avo::Actions::Test::NoConfirmationPostsRedirect < Avo::BaseAction + self.name = "Redirect to Posts" + self.no_confirmation = true + self.standalone = true + + def handle(**args) + redirect_to avo.resources_posts_path + end +end diff --git a/spec/dummy/app/avo/resources/user.rb b/spec/dummy/app/avo/resources/user.rb index 1e790dd3f..cc4beaa5e 100644 --- a/spec/dummy/app/avo/resources/user.rb +++ b/spec/dummy/app/avo/resources/user.rb @@ -72,6 +72,7 @@ def actions action Avo::Actions::Sub::DummyAction action Avo::Actions::DownloadFile, icon: "heroicons/outline/arrow-left" divider + action Avo::Actions::Test::NoConfirmationPostsRedirect action Avo::Actions::Test::NoConfirmationRedirect action Avo::Actions::Test::CloseModal action Avo::Actions::Test::DoNothing diff --git a/spec/system/avo/actions_spec.rb b/spec/system/avo/actions_spec.rb index 3f5e75ae3..6c82a53ea 100644 --- a/spec/system/avo/actions_spec.rb +++ b/spec/system/avo/actions_spec.rb @@ -206,6 +206,22 @@ expect(page).to have_text "hey en" end + + it "redirects to posts and don't redirect when navigating back" do + visit avo.resources_users_path + + click_on "Actions" + click_on "Redirect to Posts" + + wait_for_loaded + + expect(current_path).to eq avo.resources_posts_path + + page.go_back + wait_for_loaded + + expect(current_path).to eq avo.resources_users_path + end end From 5a5127a382b9c905ac3cb26a3ed30eff1d3d9f09 Mon Sep 17 00:00:00 2001 From: Shubham Vishwakarma Date: Thu, 19 Dec 2024 15:32:53 +0530 Subject: [PATCH 09/14] UI Fix: Tables become horizontally scrollable after clicking "Select All" (#3537) * UI Fix: Tables become horizontally scrollable after clicking 'Select All' #3509 * fix with padding * alternative approach This approach removes the margin size from the full width --------- Co-authored-by: Paul Bob Co-authored-by: Paul Bob <69730720+Paul-Bob@users.noreply.github.com> --- app/components/avo/index/resource_table_component.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/avo/index/resource_table_component.html.erb b/app/components/avo/index/resource_table_component.html.erb index ff97ebfe8..dae15b321 100644 --- a/app/components/avo/index/resource_table_component.html.erb +++ b/app/components/avo/index/resource_table_component.html.erb @@ -10,7 +10,7 @@ data-selected-resources="[]" > <% if @pagy.pages > 1 %> -