From 5935148bd863ea80865cee1049b3a44f3fbf3cc8 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Fri, 16 Feb 2024 14:31:42 +1000 Subject: [PATCH] FIX: Respect homepage prefs on admin sidebar Back to Forum link (#25642) --- .../app/lib/sidebar/admin-sidebar.js | 3 +- app/models/user_option.rb | 39 +++++++------------ .../admin_revamp_sidebar_navigation_spec.rb | 8 ++++ 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js b/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js index 1931c892b1f..5d7a221d047 100644 --- a/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js +++ b/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js @@ -4,6 +4,7 @@ import BaseCustomSidebarPanel from "discourse/lib/sidebar/base-custom-sidebar-pa import BaseCustomSidebarSection from "discourse/lib/sidebar/base-custom-sidebar-section"; import BaseCustomSidebarSectionLink from "discourse/lib/sidebar/base-custom-sidebar-section-link"; import { ADMIN_PANEL } from "discourse/lib/sidebar/panels"; +import { defaultHomepage } from "discourse/lib/utilities"; import { getOwnerWithFallback } from "discourse-common/lib/get-owner"; import I18n from "discourse-i18n"; @@ -109,7 +110,7 @@ export function useAdminNavConfig(navMap) { links: [ { name: "back_to_forum", - route: "discovery.latest", + route: `discovery.${defaultHomepage()}`, label: "admin.back_to_forum", icon: "arrow-left", }, diff --git a/app/models/user_option.rb b/app/models/user_option.rb index b62b2d42431..ef3a9a6a03e 100644 --- a/app/models/user_option.rb +++ b/app/models/user_option.rb @@ -1,6 +1,16 @@ # frozen_string_literal: true class UserOption < ActiveRecord::Base + HOMEPAGES = { + 1 => "latest", + 2 => "categories", + 3 => "unread", + 4 => "new", + 5 => "top", + 6 => "bookmarks", + 7 => "unseen", + } + self.ignored_columns = [ "disable_jump_reply", # Remove once 20210706091905 is promoted from post_deploy to regular migration "sidebar_list_destination", # TODO(osama): Remove in January 2024 @@ -170,30 +180,11 @@ class UserOption < ActiveRecord::Base end def homepage - case homepage_id - when 1 - "latest" - when 2 - "categories" - when 3 - "unread" - when 4 - "new" - when 5 - "top" - when 6 - "bookmarks" - when 7 - "unseen" - when 8 - if SiteSetting.experimental_hot_topics - "hot" - else - SiteSetting.homepage - end - else - SiteSetting.homepage - end + return HOMEPAGES[homepage_id] if HOMEPAGES.keys.include?(homepage_id) + + return SiteSetting.experimental_hot_topics ? "hot" : SiteSetting.homepage if homepage_id == 8 + + SiteSetting.homepage end def text_size diff --git a/spec/system/admin_revamp_sidebar_navigation_spec.rb b/spec/system/admin_revamp_sidebar_navigation_spec.rb index 070c0d0d773..1f4a4ed1964 100644 --- a/spec/system/admin_revamp_sidebar_navigation_spec.rb +++ b/spec/system/admin_revamp_sidebar_navigation_spec.rb @@ -24,6 +24,14 @@ describe "Admin Revamp | Sidebar Navigation", type: :system do expect(sidebar).to have_no_section("admin-nav-section-root") end + it "respects the user homepage preference for the Back to Forum link" do + admin.user_option.update!( + homepage_id: UserOption::HOMEPAGES.find { |id, value| value == "categories" }.first, + ) + visit("/admin") + expect(page).to have_link("Back to Forum", href: "/categories") + end + context "when on mobile" do it "shows the admin sidebar links in the header-dropdown when navigating to an admin route and hides them when leaving", mobile: true do