From a432234cab48ac0dfc3771070f28ee01711673ef Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Tue, 4 Feb 2025 15:02:15 +0100 Subject: [PATCH] Feature: disable eager loading in production and load the sections only if visited (#912) * make the ontology viewer load the sections only if visited * update the ontology viewer to lazy the section that are not data --- app/assets/stylesheets/application.css.scss.erb | 2 +- app/helpers/ontologies_helper.rb | 9 +++++++-- app/views/layouts/_ontology_viewer.html.haml | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/application.css.scss.erb b/app/assets/stylesheets/application.css.scss.erb index 5f86b2214..d177de86a 100755 --- a/app/assets/stylesheets/application.css.scss.erb +++ b/app/assets/stylesheets/application.css.scss.erb @@ -66,6 +66,6 @@ @import "bootstrap_overrides"; -<% if (ui_theme = $UI_THEME.to_s.parameterize).present? && File.exists?(Rails.root.join('app', 'assets', 'stylesheets', 'themes', ui_theme)) %> +<% if (ui_theme = $UI_THEME.to_s.parameterize).present? && File.exist?(Rails.root.join('app', 'assets', 'stylesheets', 'themes', ui_theme)) %> @import "themes/<%= ui_theme %>/main"; <% end %> diff --git a/app/helpers/ontologies_helper.rb b/app/helpers/ontologies_helper.rb index c16e053b4..545a6255b 100644 --- a/app/helpers/ontologies_helper.rb +++ b/app/helpers/ontologies_helper.rb @@ -394,6 +394,10 @@ def ontology_data_section?(section_title = current_section) ontology_data_sections.include?(section_title) end + def lazy_load_section?(section_title) + !(ontology_data_section?(section_title) || section_title.eql?('summary')) + end + def section_data(section_title) if ontology_data_section?(section_title) url_value = selected_section?(section_title) ? request.fullpath : "/ontologies/#{@ontology.acronym}?p=#{section_title}" @@ -403,12 +407,13 @@ def section_data(section_title) end end - def lazy_load_section(section_title, &block) + def lazy_load_section(section_title, lazy_load: true, &block) if current_section.eql?(section_title) block.call else render TurboFrameComponent.new(id: section_title, src: "/ontologies/#{@ontology.acronym}?p=#{section_title}", - loading: Rails.env.development? ? "lazy" : "eager", + + loading: Rails.env.development? || lazy_load ? "lazy" : "eager", target: '_top', data: { "turbo-frame-target": "frame" }) end end diff --git a/app/views/layouts/_ontology_viewer.html.haml b/app/views/layouts/_ontology_viewer.html.haml index 95fe55300..023a64e5e 100644 --- a/app/views/layouts/_ontology_viewer.html.haml +++ b/app/views/layouts/_ontology_viewer.html.haml @@ -32,7 +32,7 @@ - t.item_content do %div.p-1{data: section_data(section_title)} = language_selector_hidden_tag(section_title) if ontology_data_section?(section_title) - = lazy_load_section(section_title) { yield } + = lazy_load_section(section_title, lazy_load: lazy_load_section?(section_title)) { yield } = render partial: "layouts/footer"