From fa7bbdb0b3d8e595e2263b597d534023e68044a9 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Mon, 24 Jul 2023 16:43:52 -0700 Subject: [PATCH] feat: Add support for plain design help center layout (#7598) --- .../public/api/v1/portals/base_controller.rb | 5 ++++ app/javascript/portal/portalHelpers.js | 21 ++++++++++++--- app/views/layouts/portal.html.erb | 9 +++++-- .../api/v1/portals/_category-block.html.erb | 2 +- .../public/api/v1/portals/_hero.html.erb | 3 ++- .../portals/articles/_article_header.html.erb | 17 ++++++++++++ .../api/v1/portals/articles/show.html.erb | 26 ++++++------------- .../categories/_category-hero.html.erb | 17 ++++++++++++ .../api/v1/portals/categories/show.html.erb | 23 ++++------------ 9 files changed, 80 insertions(+), 43 deletions(-) create mode 100644 app/views/public/api/v1/portals/articles/_article_header.html.erb create mode 100644 app/views/public/api/v1/portals/categories/_category-hero.html.erb diff --git a/app/controllers/public/api/v1/portals/base_controller.rb b/app/controllers/public/api/v1/portals/base_controller.rb index c5297e6e4..851b8c549 100644 --- a/app/controllers/public/api/v1/portals/base_controller.rb +++ b/app/controllers/public/api/v1/portals/base_controller.rb @@ -1,8 +1,13 @@ class Public::Api::V1::Portals::BaseController < PublicController + before_action :show_plain_layout around_action :set_locale private + def show_plain_layout + @is_plain_layout_enabled = params[:show_plain_layout] == 'true' + end + def set_locale(&) switch_locale_with_portal(&) if params[:locale].present? switch_locale_with_article(&) if params[:article_slug].present? diff --git a/app/javascript/portal/portalHelpers.js b/app/javascript/portal/portalHelpers.js index b5f892398..e0513d339 100644 --- a/app/javascript/portal/portalHelpers.js +++ b/app/javascript/portal/portalHelpers.js @@ -57,10 +57,25 @@ export const InitializationHelpers = { } }, + appendPlainParamToURLs: () => { + document.getElementsByTagName('a').forEach(aTagElement => { + if (aTagElement.href && aTagElement.href.includes('/hc/')) { + aTagElement.setAttribute( + 'href', + aTagElement.href + '?show_plain_layout=true' + ); + } + }); + }, + initialize: () => { - InitializationHelpers.navigateToLocalePage(); - InitializationHelpers.initalizeSearch(); - InitializationHelpers.initializeTableOfContents(); + if (window.portalConfig.isPlainLayoutEnabled === 'true') { + InitializationHelpers.appendPlainParamToURLs(); + } else { + InitializationHelpers.navigateToLocalePage(); + InitializationHelpers.initalizeSearch(); + InitializationHelpers.initializeTableOfContents(); + } }, onLoad: () => { diff --git a/app/views/layouts/portal.html.erb b/app/views/layouts/portal.html.erb index 8f1dda7ae..763222d81 100644 --- a/app/views/layouts/portal.html.erb +++ b/app/views/layouts/portal.html.erb @@ -30,9 +30,13 @@ By default, it renders:
- <%= render "public/api/v1/portals/header", portal: @portal %> + <% if !@is_plain_layout_enabled %> + <%= render "public/api/v1/portals/header", portal: @portal %> + <% end %> <%= yield %> - <%= render "public/api/v1/portals/footer" %> + <% if !@is_plain_layout_enabled %> + <%= render "public/api/v1/portals/footer" %> + <% end %>
@@ -46,6 +50,7 @@ By default, it renders: loadingPlaceholder: '<%= I18n.t('public_portal.search.loading_placeholder') %>', resultsTitle: '<%= I18n.t('public_portal.search.results_title') %>', }, + isPlainLayoutEnabled: '<%= @is_plain_layout_enabled %>', tocHeader: '<%= I18n.t('public_portal.toc_header') %>' }; diff --git a/app/views/public/api/v1/portals/_category-block.html.erb b/app/views/public/api/v1/portals/_category-block.html.erb index aa1fbbd22..c5c8e8e53 100644 --- a/app/views/public/api/v1/portals/_category-block.html.erb +++ b/app/views/public/api/v1/portals/_category-block.html.erb @@ -1,6 +1,6 @@
-

+

<%= category.name %> diff --git a/app/views/public/api/v1/portals/_hero.html.erb b/app/views/public/api/v1/portals/_hero.html.erb index c4ec18e2b..599f88ccd 100644 --- a/app/views/public/api/v1/portals/_hero.html.erb +++ b/app/views/public/api/v1/portals/_hero.html.erb @@ -1,4 +1,4 @@ - +<% if !@is_plain_layout_enabled %>

@@ -8,3 +8,4 @@

+<% end %> diff --git a/app/views/public/api/v1/portals/articles/_article_header.html.erb b/app/views/public/api/v1/portals/articles/_article_header.html.erb new file mode 100644 index 000000000..80dc2036e --- /dev/null +++ b/app/views/public/api/v1/portals/articles/_article_header.html.erb @@ -0,0 +1,17 @@ +

+ <%= article.title %> +

+
+
+ <% if article.author&.avatar_url&.present? %> +
+ <%= article.author.display_name %> +
+ <% end %> +
+
<%= article.author.available_name %>
+

+ <%= I18n.t('public_portal.common.last_updated_on', last_updated_on: article.updated_at.strftime("%b %d, %Y")) %> +

+
+
diff --git a/app/views/public/api/v1/portals/articles/show.html.erb b/app/views/public/api/v1/portals/articles/show.html.erb index bc108901d..62e05a900 100644 --- a/app/views/public/api/v1/portals/articles/show.html.erb +++ b/app/views/public/api/v1/portals/articles/show.html.erb @@ -11,7 +11,7 @@ <% end %> <% end %> - +<% if !@is_plain_layout_enabled %>
@@ -33,25 +33,15 @@ Uncategorized <% end %>
-

- <%= @article.title %> -

-
-
- <% if @article.author&.avatar_url&.present? %> -
- <%= @article.author.display_name %> -
- <% end %> -
-
<%= @article.author.available_name %>
-

- <%= I18n.t('public_portal.common.last_updated_on', last_updated_on: @article.updated_at.strftime("%b %d, %Y")) %> -

-
-
+ <%= render "public/api/v1/portals/articles/article_header", article: @article %>
+<% else %> +
+ <%= render "public/api/v1/portals/articles/article_header", article: @article %> +
+<% end %> +
<%= @parsed_content %> diff --git a/app/views/public/api/v1/portals/categories/_category-hero.html.erb b/app/views/public/api/v1/portals/categories/_category-hero.html.erb new file mode 100644 index 000000000..9ca272aa8 --- /dev/null +++ b/app/views/public/api/v1/portals/categories/_category-hero.html.erb @@ -0,0 +1,17 @@ +
+ + <%= I18n.t('public_portal.common.home') %> + + / +
+

+ <%= category.name %> +

+
+ <%= render 'public/api/v1/portals/article_count', article_count: category.articles.published.size %> +
+
+
diff --git a/app/views/public/api/v1/portals/categories/show.html.erb b/app/views/public/api/v1/portals/categories/show.html.erb index 0a30f44d9..651db645b 100644 --- a/app/views/public/api/v1/portals/categories/show.html.erb +++ b/app/views/public/api/v1/portals/categories/show.html.erb @@ -5,26 +5,13 @@ <% end %> <% end %> +<% if !@is_plain_layout_enabled %>
-
- - <%= I18n.t('public_portal.common.home') %> - - / -
-

- <%= @category.name %> -

-
- <%= render 'public/api/v1/portals/article_count', article_count: @category.articles.published.size %> -
-
-
+ <%= render 'public/api/v1/portals/categories/category-hero', category: @category, portal: @portal %>
- +<% else %> + <%= render 'public/api/v1/portals/categories/category-hero', category: @category, portal: @portal %> +<% end %>
<% if @category.articles.published.size == 0 %>