DEV: Introduce SiteSetting to enable/disable Sidebar. (#17662)

This commit removes the ability to enable/disable the Sidebar on a per
user basis and introduces a site wide setting. For testing purposes, sidebar can be enabled/disabled via the `enable_sidebar=1` or `enable_sidebar=0` query param.
This commit is contained in:
Alan Guo Xiang Tan 2022-07-27 13:42:26 +08:00 committed by GitHub
parent 83f4e45664
commit 3bd5f2d411
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 274 additions and 285 deletions

View File

@ -368,7 +368,7 @@ const SiteHeaderComponent = MountWidget.extend(
return { return {
topic: this._topic, topic: this._topic,
canSignUp: this.canSignUp, canSignUp: this.canSignUp,
sidebarDocked: this.sidebarDocked, sidebarEnabled: this.sidebarEnabled,
}; };
}, },

View File

@ -5,11 +5,14 @@ import { inject as service } from "@ember/service";
import { action } from "@ember/object"; import { action } from "@ember/object";
export default Controller.extend({ export default Controller.extend({
queryParams: ["enable_sidebar"],
showTop: true, showTop: true,
showFooter: false, showFooter: false,
router: service(), router: service(),
showSidebar: null, showSidebar: null,
hideSidebarKey: "sidebar-hidden", hideSidebarKey: "sidebar-hidden",
enable_sidebar: null,
init() { init() {
this._super(...arguments); this._super(...arguments);
@ -42,6 +45,19 @@ export default Controller.extend({
document.querySelector("body").classList.remove("sidebar-animate"); document.querySelector("body").classList.remove("sidebar-animate");
}, },
@discourseComputed("enable_sidebar", "siteSettings.enable_sidebar")
sidebarEnabled(sidebarQueryParamOverride, enableSidebar) {
if (sidebarQueryParamOverride === "1") {
return true;
}
if (sidebarQueryParamOverride === "0") {
return false;
}
return enableSidebar;
},
@action @action
toggleSidebar() { toggleSidebar() {
// enables CSS transitions, but not on did-insert // enables CSS transitions, but not on did-insert
@ -52,10 +68,6 @@ export default Controller.extend({
this.toggleProperty("showSidebar"); this.toggleProperty("showSidebar");
if (this.site.desktopView) { if (this.site.desktopView) {
this.appEvents.trigger("header:keyboard-trigger", {
type: "hamburger",
});
if (this.showSidebar) { if (this.showSidebar) {
this.keyValueStore.removeItem(this.hideSidebarKey); this.keyValueStore.removeItem(this.hideSidebarKey);
} else { } else {

View File

@ -58,7 +58,6 @@ export default Controller.extend({
"skip_new_user_tips", "skip_new_user_tips",
"color_scheme_id", "color_scheme_id",
"dark_scheme_id", "dark_scheme_id",
"enable_experimental_sidebar",
]; ];
if (makeThemeDefault) { if (makeThemeDefault) {

View File

@ -106,7 +106,6 @@ let userOptionFields = [
"skip_new_user_tips", "skip_new_user_tips",
"default_calendar", "default_calendar",
"bookmark_auto_delete_preference", "bookmark_auto_delete_preference",
"enable_experimental_sidebar",
]; ];
export function addSaveableUserOptionField(fieldName) { export function addSaveableUserOptionField(fieldName) {

View File

@ -11,7 +11,7 @@
@toggleMobileView={{route-action "toggleMobileView"}} @toggleMobileView={{route-action "toggleMobileView"}}
@toggleAnonymous={{route-action "toggleAnonymous"}} @toggleAnonymous={{route-action "toggleAnonymous"}}
@logout={{route-action "logout"}} @logout={{route-action "logout"}}
@sidebarDocked={{and this.currentUser.experimental_sidebar_enabled this.showSidebar this.site.desktopView}} @sidebarEnabled={{this.sidebarEnabled}}
@toggleSidebar={{action "toggleSidebar"}} /> @toggleSidebar={{action "toggleSidebar"}} />
<SoftwareUpdatePrompt /> <SoftwareUpdatePrompt />
@ -22,7 +22,7 @@
<div class="sidebar-wrapper"> <div class="sidebar-wrapper">
{{!-- empty div allows for animation --}} {{!-- empty div allows for animation --}}
{{#if (and this.currentUser.experimental_sidebar_enabled this.showSidebar)}} {{#if (and this.siteSettings.enable_experimental_sidebar_hamburger this.sidebarEnabled this.showSidebar)}}
<Sidebar @toggleSidebar={{action "toggleSidebar"}}/> <Sidebar @toggleSidebar={{action "toggleSidebar"}}/>
{{/if}} {{/if}}
</div> </div>

View File

@ -18,13 +18,6 @@
@title="keyboard_shortcuts_help.title" @title="keyboard_shortcuts_help.title"
@icon="keyboard" @icon="keyboard"
@class="sidebar-footer-actions-button sidebar-footer-actions-keyboard-shortcuts" /> @class="sidebar-footer-actions-button sidebar-footer-actions-keyboard-shortcuts" />
{{#if (and this.site.desktopView (not @sidebarDocked))}}
<DButton
@action={{@toggleSidebar}}
@icon="thumbtack"
@class="sidebar-footer-actions-button sidebar-footer-actions-dock-toggle"/>
{{/if}}
</div> </div>
</div> </div>
</div> </div>

View File

@ -4,7 +4,7 @@
<div class="panel-body-content"> <div class="panel-body-content">
<div class="sidebar-hamburger-dropdown"> <div class="sidebar-hamburger-dropdown">
<Sidebar::Sections @collapsableSections={{false}}/> <Sidebar::Sections @collapsableSections={{false}}/>
<Sidebar::Footer @toggleSidebar={{route-action "toggleSidebar"}} @sidebarDocked={{@sidebarDocked}} @tagName="" /> <Sidebar::Footer @toggleSidebar={{route-action "toggleSidebar"}} @tagName="" />
</div> </div>
</div> </div>
</div> </div>

View File

@ -50,7 +50,7 @@
</LinkTo> </LinkTo>
</li> </li>
{{#if this.siteSettings.enable_experimental_sidebar}} {{#if this.siteSettings.enable_experimental_sidebar_hamburger}}
<li class="indent nav-sidebar"> <li class="indent nav-sidebar">
<LinkTo @route="preferences.sidebar"> <LinkTo @route="preferences.sidebar">
{{i18n "user.preferences_nav.sidebar"}} {{i18n "user.preferences_nav.sidebar"}}

View File

@ -1,49 +1,38 @@
<div class="control-group preferences-sidebar-options"> <div class="control-group preferences-sidebar-categories">
<legend class="control-label">{{i18n "user.experimental_sidebar.options"}}</legend> <legend class="control-label">{{i18n "user.experimental_sidebar.categories_section"}}</legend>
<PreferenceCheckbox <div class="controls">
@labelKey="user.experimental_sidebar.enable" <CategorySelector
@checked={{this.model.user_option.enable_experimental_sidebar}} @categories={{this.selectedSidebarCategories}}
@class="preferences-sidebar-enable-checkbox" /> @onChange={{action (mut this.selectedSidebarCategories)}}
@options={{hash
allowUncategorized=(not this.siteSettings.suppress_uncategorized_badge)
displayCategoryDescription=true
}}
/>
</div>
<div class="instructions">{{i18n "user.experimental_sidebar.categories_section_instruction"}}</div>
</div> </div>
{{#if this.model.experimental_sidebar_enabled}} {{#if this.siteSettings.tagging_enabled}}
<div class="control-group preferences-sidebar-categories"> <div class="control-group preferences-sidebar-tags">
<legend class="control-label">{{i18n "user.experimental_sidebar.categories_section"}}</legend> <legend class="control-label">{{i18n "user.experimental_sidebar.tags_section"}}</legend>
<div class="controls"> <div class="controls">
<CategorySelector <TagChooser
@categories={{this.selectedSidebarCategories}} @tags={{this.selectedSidebarTagNames}}
@onChange={{action (mut this.selectedSidebarCategories)}} @everyTag={{true}}
@options={{hash @unlimitedTagCount={{true}}
allowUncategorized=(not this.siteSettings.suppress_uncategorized_badge) @onChange={{action (mut this.selectedSidebarTagNames)}}
displayCategoryDescription=true @options={{hash
}} allowAny=false
}}
/> />
</div> </div>
<div class="instructions">{{i18n "user.experimental_sidebar.categories_section_instruction"}}</div> <div class="instructions">{{i18n "user.experimental_sidebar.tags_section_instruction"}}</div>
</div> </div>
{{#if this.siteSettings.tagging_enabled}}
<div class="control-group preferences-sidebar-tags">
<legend class="control-label">{{i18n "user.experimental_sidebar.tags_section"}}</legend>
<div class="controls">
<TagChooser
@tags={{this.selectedSidebarTagNames}}
@everyTag={{true}}
@unlimitedTagCount={{true}}
@onChange={{action (mut this.selectedSidebarTagNames)}}
@options={{hash
allowAny=false
}}
/>
</div>
<div class="instructions">{{i18n "user.experimental_sidebar.tags_section_instruction"}}</div>
</div>
{{/if}}
{{/if}} {{/if}}
<SaveControls @model={{this.model}} @action={{action "save"}} @saved={{this.saved}} /> <SaveControls @model={{this.model}} @action={{action "save"}} @saved={{this.saved}} />

View File

@ -337,15 +337,12 @@ createWidget("revamped-hamburger-menu-wrapper", {
return { "data-click-outside": true }; return { "data-click-outside": true };
}, },
html(attrs) { html() {
return [ return [
new RenderGlimmer( new RenderGlimmer(
this, this,
"div.widget-component-connector", "div.widget-component-connector",
hbs`<Sidebar::HamburgerDropdown @sidebarDocked={{@data.sidebarDocked}} />`, hbs`<Sidebar::HamburgerDropdown />`
{
sidebarDocked: attrs.sidebarDocked,
}
), ),
]; ];
}, },
@ -426,12 +423,10 @@ export default createWidget("header", {
}) })
); );
} else if (state.hamburgerVisible) { } else if (state.hamburgerVisible) {
if (this.currentUser?.experimental_sidebar_enabled) { if (this.siteSettings.enable_experimental_sidebar_hamburger) {
panels.push( if (!attrs.sidebarEnabled) {
this.attach("revamped-hamburger-menu-wrapper", { panels.push(this.attach("revamped-hamburger-menu-wrapper", {}));
sidebarDocked: attrs.sidebarDocked, }
})
);
} else { } else {
panels.push(this.attach("hamburger-menu")); panels.push(this.attach("hamburger-menu"));
} }
@ -547,8 +542,8 @@ export default createWidget("header", {
toggleHamburger() { toggleHamburger() {
if ( if (
this.currentUser?.experimental_sidebar_enabled && this.siteSettings.enable_experimental_sidebar_hamburger &&
this.site.mobileView (this.attrs.sidebarEnabled || this.site.mobileView)
) { ) {
this.sendWidgetAction("toggleSidebar"); this.sendWidgetAction("toggleSidebar");
} else { } else {

View File

@ -10,8 +10,6 @@ import {
updateCurrentUser, updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import { undockSidebar } from "discourse/tests/helpers/sidebar-helpers";
import Site from "discourse/models/site"; import Site from "discourse/models/site";
import discoveryFixture from "discourse/tests/fixtures/discovery-fixtures"; import discoveryFixture from "discourse/tests/fixtures/discovery-fixtures";
import categoryFixture from "discourse/tests/fixtures/category-fixtures"; import categoryFixture from "discourse/tests/fixtures/category-fixtures";
@ -22,9 +20,11 @@ acceptance(
function (needs) { function (needs) {
needs.settings({ needs.settings({
suppress_uncategorized_badge: true, suppress_uncategorized_badge: true,
enable_experimental_sidebar_hamburger: true,
enable_sidebar: true,
}); });
needs.user({ experimental_sidebar_enabled: true }); needs.user();
test("uncategorized category is not shown", async function (assert) { test("uncategorized category is not shown", async function (assert) {
const categories = Site.current().categories; const categories = Site.current().categories;
@ -56,12 +56,13 @@ acceptance(
acceptance("Sidebar - Categories Section", function (needs) { acceptance("Sidebar - Categories Section", function (needs) {
needs.user({ needs.user({
experimental_sidebar_enabled: true,
sidebar_category_ids: [], sidebar_category_ids: [],
sidebar_tag_names: [], sidebar_tag_names: [],
}); });
needs.settings({ needs.settings({
enable_experimental_sidebar_hamburger: true,
enable_sidebar: true,
suppress_uncategorized_badge: false, suppress_uncategorized_badge: false,
}); });
@ -397,11 +398,11 @@ acceptance("Sidebar - Categories Section", function (needs) {
topicTrackingState.stateChangeCallbacks topicTrackingState.stateChangeCallbacks
).length; ).length;
await undockSidebar(); await click(".hamburger-dropdown");
assert.strictEqual( assert.ok(
Object.keys(topicTrackingState.stateChangeCallbacks).length, Object.keys(topicTrackingState.stateChangeCallbacks).length <
initialCallbackCount initialCallbackCount
); );
}); });
}); });

View File

@ -9,7 +9,6 @@ import {
publishToMessageBus, publishToMessageBus,
query, query,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import { undockSidebar } from "discourse/tests/helpers/sidebar-helpers";
import topicFixtures from "discourse/tests/fixtures/discovery-fixtures"; import topicFixtures from "discourse/tests/fixtures/discovery-fixtures";
import { cloneJSON } from "discourse-common/lib/object"; import { cloneJSON } from "discourse-common/lib/object";
import { withPluginApi } from "discourse/lib/plugin-api"; import { withPluginApi } from "discourse/lib/plugin-api";
@ -18,12 +17,16 @@ import { NotificationLevels } from "discourse/lib/notification-levels";
acceptance("Sidebar - Community Section", function (needs) { acceptance("Sidebar - Community Section", function (needs) {
needs.user({ needs.user({
experimental_sidebar_enabled: true,
tracked_tags: ["tag1"], tracked_tags: ["tag1"],
watched_tags: ["tag2"], watched_tags: ["tag2"],
watching_first_post_tags: ["tag3"], watching_first_post_tags: ["tag3"],
}); });
needs.settings({
enable_experimental_sidebar_hamburger: true,
enable_sidebar: true,
});
needs.pretender((server, helper) => { needs.pretender((server, helper) => {
server.get("/new.json", () => { server.get("/new.json", () => {
return helper.response(cloneJSON(topicFixtures["/latest.json"])); return helper.response(cloneJSON(topicFixtures["/latest.json"]));
@ -753,11 +756,11 @@ acceptance("Sidebar - Community Section", function (needs) {
topicTrackingState.stateChangeCallbacks topicTrackingState.stateChangeCallbacks
).length; ).length;
await undockSidebar(); await click(".hamburger-dropdown");
assert.strictEqual( assert.ok(
Object.keys(topicTrackingState.stateChangeCallbacks).length, Object.keys(topicTrackingState.stateChangeCallbacks).length <
initialCallbackCount initialCallbackCount
); );
}); });
}); });

View File

@ -14,11 +14,11 @@ import { NotificationLevels } from "discourse/lib/notification-levels";
acceptance( acceptance(
"Sidebar - Messages Section - enable_personal_messages disabled", "Sidebar - Messages Section - enable_personal_messages disabled",
function (needs) { function (needs) {
needs.user({ needs.user();
experimental_sidebar_enabled: true,
});
needs.settings({ needs.settings({
enable_experimental_sidebar_hamburger: true,
enable_sidebar: true,
enable_personal_messages: false, enable_personal_messages: false,
}); });
@ -36,8 +36,11 @@ acceptance(
acceptance( acceptance(
"Sidebar - Messages Section - enable_personal_messages enabled", "Sidebar - Messages Section - enable_personal_messages enabled",
function (needs) { function (needs) {
needs.user({ needs.user();
experimental_sidebar_enabled: true,
needs.settings({
enable_experimental_sidebar_hamburger: true,
enable_sidebar: true,
}); });
needs.pretender((server, helper) => { needs.pretender((server, helper) => {

View File

@ -3,7 +3,13 @@ import { click, visit } from "@ember/test-helpers";
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers"; import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
acceptance("Sidebar - Mobile - User with sidebar enabled", function (needs) { acceptance("Sidebar - Mobile - User with sidebar enabled", function (needs) {
needs.user({ experimental_sidebar_enabled: true }); needs.user();
needs.settings({
enable_experimental_sidebar_hamburger: true,
enable_sidebar: true,
});
needs.mobileView(); needs.mobileView();
test("hidden by default", async function (assert) { test("hidden by default", async function (assert) {
@ -17,11 +23,6 @@ acceptance("Sidebar - Mobile - User with sidebar enabled", function (needs) {
await click(".hamburger-dropdown"); await click(".hamburger-dropdown");
assert.notOk(
exists(".sidebar-footer-actions-dock-toggle"),
"button to dock sidebar is not displayed"
);
assert.ok(exists(".sidebar-container"), "sidebar is displayed"); assert.ok(exists(".sidebar-container"), "sidebar is displayed");
await click("#main-outlet"); await click("#main-outlet");

View File

@ -10,10 +10,14 @@ import {
import { withPluginApi } from "discourse/lib/plugin-api"; import { withPluginApi } from "discourse/lib/plugin-api";
import { resetSidebarSection } from "discourse/lib/sidebar/custom-sections"; import { resetSidebarSection } from "discourse/lib/sidebar/custom-sections";
import { bind } from "discourse-common/utils/decorators"; import { bind } from "discourse-common/utils/decorators";
import { undockSidebar } from "discourse/tests/helpers/sidebar-helpers";
acceptance("Sidebar - Plugin API", function (needs) { acceptance("Sidebar - Plugin API", function (needs) {
needs.user({ experimental_sidebar_enabled: true }); needs.user();
needs.settings({
enable_experimental_sidebar_hamburger: true,
enable_sidebar: true,
});
needs.hooks.afterEach(() => { needs.hooks.afterEach(() => {
resetSidebarSection(); resetSidebarSection();
@ -339,7 +343,7 @@ acceptance("Sidebar - Plugin API", function (needs) {
"displays hover button with correct title" "displays hover button with correct title"
); );
await undockSidebar(); await click(".hamburger-dropdown");
assert.strictEqual( assert.strictEqual(
linkDestroy, linkDestroy,

View File

@ -9,16 +9,17 @@ import {
query, query,
updateCurrentUser, updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import { undockSidebar } from "discourse/tests/helpers/sidebar-helpers";
import discoveryFixture from "discourse/tests/fixtures/discovery-fixtures"; import discoveryFixture from "discourse/tests/fixtures/discovery-fixtures";
import { cloneJSON } from "discourse-common/lib/object"; import { cloneJSON } from "discourse-common/lib/object";
acceptance("Sidebar - Tags section - tagging disabled", function (needs) { acceptance("Sidebar - Tags section - tagging disabled", function (needs) {
needs.settings({ needs.settings({
tagging_enabled: false, tagging_enabled: false,
enable_experimental_sidebar_hamburger: true,
enable_sidebar: true,
}); });
needs.user({ experimental_sidebar_enabled: true }); needs.user();
test("tags section is not shown", async function (assert) { test("tags section is not shown", async function (assert) {
await visit("/"); await visit("/");
@ -33,10 +34,11 @@ acceptance("Sidebar - Tags section - tagging disabled", function (needs) {
acceptance("Sidebar - Tags section", function (needs) { acceptance("Sidebar - Tags section", function (needs) {
needs.settings({ needs.settings({
tagging_enabled: true, tagging_enabled: true,
enable_experimental_sidebar_hamburger: true,
enable_sidebar: true,
}); });
needs.user({ needs.user({
experimental_sidebar_enabled: true,
tracked_tags: ["tag1"], tracked_tags: ["tag1"],
watched_tags: ["tag2", "tag3"], watched_tags: ["tag2", "tag3"],
watching_first_post_tags: [], watching_first_post_tags: [],
@ -324,11 +326,11 @@ acceptance("Sidebar - Tags section", function (needs) {
topicTrackingState.stateChangeCallbacks topicTrackingState.stateChangeCallbacks
).length; ).length;
await undockSidebar(); await click(".hamburger-dropdown");
assert.strictEqual( assert.ok(
Object.keys(topicTrackingState.stateChangeCallbacks).length, Object.keys(topicTrackingState.stateChangeCallbacks).length <
initialCallbackCount initialCallbackCount
); );
}); });
}); });

View File

@ -7,7 +7,6 @@ import {
exists, exists,
updateCurrentUser, updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import { undockSidebar } from "discourse/tests/helpers/sidebar-helpers";
acceptance("Sidebar - Anon User", function () { acceptance("Sidebar - Anon User", function () {
// Don't show sidebar for anon user until we know what we want to display // Don't show sidebar for anon user until we know what we want to display
@ -23,106 +22,163 @@ acceptance("Sidebar - Anon User", function () {
}); });
}); });
acceptance("Sidebar - User with sidebar disabled", function (needs) { acceptance(
needs.user({ experimental_sidebar_enabled: false }); "Sidebar - Experimental sidebar and hamburger setting disabled",
function (needs) {
needs.user();
test("sidebar is not displayed", async function (assert) { needs.settings({
await visit("/"); enable_experimental_sidebar_hamburger: false,
});
assert.ok( test("clicking header hamburger icon displays old hamburger drodown", async function (assert) {
!document.body.classList.contains("has-sidebar-page"), await visit("/");
"does not add sidebar utility class to body" await click(".hamburger-dropdown");
);
assert.ok(!exists(".sidebar-container")); assert.ok(exists(".menu-container-general-links"));
}); });
}); }
);
acceptance("Sidebar - User with sidebar enabled", function (needs) { acceptance(
needs.user({ experimental_sidebar_enabled: true }); "Sidebar - Experimental sidebar and hamburger setting enabled - Sidebar disabled",
function (needs) {
needs.user();
test("navigating to about route using sidebar", async function (assert) { needs.settings({
await visit("/"); enable_experimental_sidebar_hamburger: true,
await click(".sidebar-footer-link-about"); enable_sidebar: false,
});
assert.strictEqual(currentRouteName(), "about"); test("showing and hiding sidebar", async function (assert) {
}); await visit("/");
await click(".hamburger-dropdown");
test("viewing keyboard shortcuts using sidebar", async function (assert) { assert.ok(
await visit("/"); exists(".sidebar-hamburger-dropdown"),
await click( "displays the sidebar dropdown"
`.sidebar-footer-actions-keyboard-shortcuts[title="${I18n.t( );
"keyboard_shortcuts_help.title"
)}"]`
);
assert.ok( await click(".hamburger-dropdown");
exists("#keyboard-shortcuts-help"),
"keyboard shortcuts help is displayed"
);
});
test("navigating to admin route using sidebar", async function (assert) { assert.notOk(
await visit("/"); exists(".sidebar-hamburger-dropdown"),
await click(".sidebar-footer-link-admin"); "hides the sidebar dropdown"
);
});
assert.strictEqual(currentRouteName(), "admin.dashboard.general"); test("'enable_sidebar' query param override to enable sidebar", async function (assert) {
}); await visit("/?enable_sidebar=1");
test("admin link is not shown in sidebar for non-admin user", async function (assert) { assert.ok(exists(".sidebar-container"), "sidebar is displayed");
updateCurrentUser({ admin: false, moderator: false });
await visit("/"); await click(".hamburger-dropdown");
assert.notOk(exists(".sidebar-footer-link-admin")); assert.notOk(
}); exists(".sidebar-hamburger-dropdown"),
"does not display the sidebar dropdown"
);
test("undocking and docking sidebar", async function (assert) { assert.notOk(exists(".sidebar-container"), "sidebar is hidden");
await visit("/");
assert.ok( await click(".hamburger-dropdown");
document.body.classList.contains("has-sidebar-page"),
"adds sidebar utility class to body"
);
assert.ok(exists(".sidebar-container"), "displays the sidebar by default"); assert.ok(exists(".sidebar-container"), "sidebar is displayed");
});
}
);
await undockSidebar(); acceptance(
"Sidebar - Experimental sidebar and hamburger setting enabled - Sidebar enabled",
function (needs) {
needs.user();
assert.ok( needs.settings({
!document.body.classList.contains("has-sidebar-page"), enable_experimental_sidebar_hamburger: true,
"removes sidebar utility class from body" enable_sidebar: true,
); });
assert.ok(!exists(".sidebar-container"), "hides the sidebar"); test("navigating to about route using sidebar", async function (assert) {
await visit("/");
await click(".sidebar-footer-link-about");
assert.ok( assert.strictEqual(currentRouteName(), "about");
exists(".sidebar-hamburger-dropdown"), });
"displays the sidebar in hamburger dropdown automatically after undocking"
);
await click("button.sidebar-footer-actions-dock-toggle"); test("viewing keyboard shortcuts using sidebar", async function (assert) {
await visit("/");
await click(
`.sidebar-footer-actions-keyboard-shortcuts[title="${I18n.t(
"keyboard_shortcuts_help.title"
)}"]`
);
assert.ok( assert.ok(
exists(".sidebar-container"), exists("#keyboard-shortcuts-help"),
"displays the sidebar after docking" "keyboard shortcuts help is displayed"
); );
});
assert.notOk( test("navigating to admin route using sidebar", async function (assert) {
exists(".sidebar-hamburger-dropdown"), await visit("/");
"hides the sidebar in hamburger dropdown automatically after docking" await click(".sidebar-footer-link-admin");
);
await click(".hamburger-dropdown"); assert.strictEqual(currentRouteName(), "admin.dashboard.general");
});
assert.ok( test("admin link is not shown in sidebar for non-admin user", async function (assert) {
exists(".sidebar-hamburger-dropdown"), updateCurrentUser({ admin: false, moderator: false });
"displays the sidebar in hamburger dropdown even when sidebar is docked"
);
assert.notOk( await visit("/");
exists(".sidebar-hamburger-dropdown .sidebar-footer-actions-dock-toggle"),
"does not display sidebar dock toggle in hamburger dropdown when sidebar is docked" assert.notOk(exists(".sidebar-footer-link-admin"));
); });
});
}); test("showing and hiding sidebar", async function (assert) {
await visit("/");
assert.ok(
document.body.classList.contains("has-sidebar-page"),
"adds sidebar utility class to body"
);
assert.ok(
exists(".sidebar-container"),
"displays the sidebar by default"
);
await click(".hamburger-dropdown");
assert.ok(
!document.body.classList.contains("has-sidebar-page"),
"removes sidebar utility class from body"
);
assert.ok(!exists(".sidebar-container"), "hides the sidebar");
await click(".hamburger-dropdown");
assert.ok(exists(".sidebar-container"), "displays the sidebar");
});
test("'enable_sidebar' query param override to disable sidebar", async function (assert) {
await visit("/?enable_sidebar=0");
assert.notOk(exists(".sidebar-container"), "sidebar is not displayed");
await click(".hamburger-dropdown");
assert.ok(
exists(".sidebar-hamburger-dropdown"),
"displays the sidebar dropdown"
);
await click(".hamburger-dropdown");
assert.notOk(
exists(".sidebar-hamburger-dropdown"),
"hides the sidebar dropdown"
);
});
}
);

View File

@ -9,31 +9,15 @@ import {
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
acceptance("User Preferences - Sidebar - Tagging Disabled", function (needs) {
needs.settings({
tagging_enabled: false,
});
needs.user({
experimental_sidebar_enabled: true,
sidebar_category_ids: [],
});
test("user should not see tag chooser", async function (assert) {
await visit("/u/eviltrout/preferences/sidebar");
assert.ok(!exists(".tag-chooser"), "tag chooser is not displayed");
});
});
acceptance("User Preferences - Sidebar", function (needs) { acceptance("User Preferences - Sidebar", function (needs) {
needs.user({ needs.user({
experimental_sidebar_enabled: true,
sidebar_category_ids: [], sidebar_category_ids: [],
sidebar_tag_names: [], sidebar_tag_names: [],
}); });
needs.settings({ needs.settings({
enable_experimental_sidebar_hamburger: true,
enable_sidebar: true,
tagging_enabled: true, tagging_enabled: true,
}); });
@ -60,6 +44,14 @@ acceptance("User Preferences - Sidebar", function (needs) {
}); });
}); });
test("user should not see tag chooser when tagging is disabled", async function (assert) {
this.siteSettings.tagging_enabled = false;
await visit("/u/eviltrout/preferences/sidebar");
assert.ok(!exists(".tag-chooser"), "tag chooser is not displayed");
});
test("user encountering error when adding categories to sidebar", async function (assert) { test("user encountering error when adding categories to sidebar", async function (assert) {
updateCurrentUser({ sidebar_category_ids: [6] }); updateCurrentUser({ sidebar_category_ids: [6] });

View File

@ -1,5 +0,0 @@
import { click } from "@ember/test-helpers";
export async function undockSidebar() {
await click("button.sidebar-footer-actions-dock-toggle");
}

View File

@ -53,15 +53,6 @@
} }
} }
.has-sidebar-page {
.sidebar-footer-actions-dock-toggle {
.d-icon {
transform: rotate(180deg);
top: -0.1em; // optical alignment
}
}
}
.sidebar-footer-wrapper { .sidebar-footer-wrapper {
background: var(--primary-very-low); background: var(--primary-very-low);
.desktop-view & { .desktop-view & {

View File

@ -1824,7 +1824,7 @@ class UsersController < ApplicationController
permitted.concat UserUpdater::TAG_NAMES.keys permitted.concat UserUpdater::TAG_NAMES.keys
permitted << UserUpdater::NOTIFICATION_SCHEDULE_ATTRS permitted << UserUpdater::NOTIFICATION_SCHEDULE_ATTRS
if current_user&.user_option&.enable_experimental_sidebar if SiteSetting.enable_experimental_sidebar_hamburger
if params.has_key?(:sidebar_category_ids) && params[:sidebar_category_ids].blank? if params.has_key?(:sidebar_category_ids) && params[:sidebar_category_ids].blank?
params[:sidebar_category_ids] = [] params[:sidebar_category_ids] = []
end end

View File

@ -277,7 +277,7 @@ class TopicTrackingState
end end
def self.include_tags_in_report? def self.include_tags_in_report?
SiteSetting.tagging_enabled && (@include_tags_in_report || SiteSetting.enable_experimental_sidebar) SiteSetting.tagging_enabled && (@include_tags_in_report || SiteSetting.enable_experimental_sidebar_hamburger)
end end
def self.include_tags_in_report=(v) def self.include_tags_in_report=(v)

View File

@ -71,7 +71,6 @@ class CurrentUserSerializer < BasicUserSerializer
:default_calendar, :default_calendar,
:bookmark_auto_delete_preference, :bookmark_auto_delete_preference,
:pending_posts_count, :pending_posts_count,
:experimental_sidebar_enabled,
:status, :status,
:sidebar_category_ids, :sidebar_category_ids,
:sidebar_tag_names, :sidebar_tag_names,
@ -309,20 +308,12 @@ class CurrentUserSerializer < BasicUserSerializer
Draft.has_topic_draft(object) Draft.has_topic_draft(object)
end end
def experimental_sidebar_enabled
object.user_option.enable_experimental_sidebar
end
def include_experimental_sidebar_enabled?
SiteSetting.enable_experimental_sidebar
end
def sidebar_category_ids def sidebar_category_ids
object.category_sidebar_section_links.pluck(:linkable_id) object.category_sidebar_section_links.pluck(:linkable_id)
end end
def include_sidebar_category_ids? def include_sidebar_category_ids?
include_experimental_sidebar_enabled? && object.user_option.enable_experimental_sidebar SiteSetting.enable_experimental_sidebar_hamburger
end end
def sidebar_tag_names def sidebar_tag_names

View File

@ -34,8 +34,7 @@ class UserOptionSerializer < ApplicationSerializer
:timezone, :timezone,
:skip_new_user_tips, :skip_new_user_tips,
:default_calendar, :default_calendar,
:oldest_search_log_date, :oldest_search_log_date
:enable_experimental_sidebar
def auto_track_topics_after_msecs def auto_track_topics_after_msecs
object.auto_track_topics_after_msecs || SiteSetting.default_other_auto_track_topics_after_msecs object.auto_track_topics_after_msecs || SiteSetting.default_other_auto_track_topics_after_msecs
@ -52,9 +51,4 @@ class UserOptionSerializer < ApplicationSerializer
def theme_ids def theme_ids
object.theme_ids.presence || [SiteSetting.default_theme_id] object.theme_ids.presence || [SiteSetting.default_theme_id]
end end
def include_enable_experimental_sidebar?
SiteSetting.enable_experimental_sidebar
end
end end

View File

@ -47,8 +47,7 @@ class UserUpdater
:title_count_mode, :title_count_mode,
:timezone, :timezone,
:skip_new_user_tips, :skip_new_user_tips,
:default_calendar, :default_calendar
:enable_experimental_sidebar
] ]
NOTIFICATION_SCHEDULE_ATTRS = -> { NOTIFICATION_SCHEDULE_ATTRS = -> {

View File

@ -1985,7 +1985,11 @@ developer:
enable_safe_mode: enable_safe_mode:
default: true default: true
client: true client: true
enable_experimental_sidebar: enable_experimental_sidebar_hamburger:
default: false
client: true
hidden: true
enable_sidebar:
default: false default: false
client: true client: true
hidden: true hidden: true

View File

@ -593,13 +593,13 @@ describe TopicTrackingState do
) )
end end
it "includes tags when SiteSetting.enable_experimental_sidebar is true" do it "includes tags when SiteSetting.enable_experimental_sidebar_hamburger is true" do
report = TopicTrackingState.report(user) report = TopicTrackingState.report(user)
expect(report.length).to eq(1) expect(report.length).to eq(1)
row = report[0] row = report[0]
expect(row.respond_to?(:tags)).to eq(false) expect(row.respond_to?(:tags)).to eq(false)
SiteSetting.enable_experimental_sidebar = true SiteSetting.enable_experimental_sidebar_hamburger = true
report = TopicTrackingState.report(user) report = TopicTrackingState.report(user)
expect(report.length).to eq(1) expect(report.length).to eq(1)

View File

@ -2300,20 +2300,7 @@ describe UsersController do
context 'experimental sidebar' do context 'experimental sidebar' do
before do before do
SiteSetting.enable_experimental_sidebar = true SiteSetting.enable_experimental_sidebar_hamburger = true
user.user_option.update!(enable_experimental_sidebar: true)
end
it "should allow user to update UserOption#enable_experimental_sidebar" do
put "/u/#{user.username}.json", params: { enable_experimental_sidebar: 'false' }
expect(response.status).to eq(200)
expect(user.reload.user_option.enable_experimental_sidebar).to eq(false)
put "/u/#{user.username}.json", params: { enable_experimental_sidebar: 'true' }
expect(response.status).to eq(200)
expect(user.reload.user_option.enable_experimental_sidebar).to eq(true)
end end
it 'does not remove category or tag sidebar section links when params are not present' do it 'does not remove category or tag sidebar section links when params are not present' do
@ -3979,23 +3966,6 @@ describe UsersController do
expect(topic_post_count[topic.id.to_s]).to eq(2) expect(topic_post_count[topic.id.to_s]).to eq(2)
end end
end end
it "includes UserOption#enable_experimental_sidebar when SiteSetting.enable_experimental_sidebar is true" do
SiteSetting.enable_experimental_sidebar = true
user1.user_option.update!(enable_experimental_sidebar: true)
get "/u/#{user1.username}.json"
expect(response.status).to eq(200)
expect(response.parsed_body["user"]["user_option"]["enable_experimental_sidebar"]).to eq(true)
end
it "does not include UserOption#enable_experimental_sidebar when SiteSetting.enable_experimental_sidebar is false" do
get "/u/#{user1.username}.json"
expect(response.status).to eq(200)
expect(response.parsed_body["user"]["user_option"]["enable_experimental_sidebar"]).to eq(nil)
end
end end
it "should be able to view a user" do it "should be able to view a user" do

View File

@ -224,8 +224,8 @@ RSpec.describe CurrentUserSerializer do
fab!(:tag_sidebar_section_link) { Fabricate(:tag_sidebar_section_link, user: user) } fab!(:tag_sidebar_section_link) { Fabricate(:tag_sidebar_section_link, user: user) }
fab!(:tag_sidebar_section_link_2) { Fabricate(:tag_sidebar_section_link, user: user) } fab!(:tag_sidebar_section_link_2) { Fabricate(:tag_sidebar_section_link, user: user) }
it "is not included when SiteSeting.enable_experimental_sidebar is false" do it "is not included when SiteSeting.enable_experimental_sidebar_hamburger is false" do
SiteSetting.enable_experimental_sidebar = false SiteSetting.enable_experimental_sidebar_hamburger = false
json = serializer.as_json json = serializer.as_json
@ -233,7 +233,7 @@ RSpec.describe CurrentUserSerializer do
end end
it "is not included when SiteSeting.tagging_enabled is false" do it "is not included when SiteSeting.tagging_enabled is false" do
SiteSetting.enable_experimental_sidebar = true SiteSetting.enable_experimental_sidebar_hamburger = true
SiteSetting.tagging_enabled = false SiteSetting.tagging_enabled = false
json = serializer.as_json json = serializer.as_json
@ -241,20 +241,18 @@ RSpec.describe CurrentUserSerializer do
expect(json[:sidebar_tag_names]).to eq(nil) expect(json[:sidebar_tag_names]).to eq(nil)
end end
it "is not included when experimental sidebar has not been enabled by user" do it "is not included when experimental sidebar has not been enabled" do
SiteSetting.enable_experimental_sidebar = true SiteSetting.enable_experimental_sidebar_hamburger = false
SiteSetting.tagging_enabled = true SiteSetting.tagging_enabled = true
user.user_option.update!(enable_experimental_sidebar: false)
json = serializer.as_json json = serializer.as_json
expect(json[:sidebar_tag_names]).to eq(nil) expect(json[:sidebar_tag_names]).to eq(nil)
end end
it "is present when experimental sidebar has been enabled by user" do it "is present when experimental sidebar has been enabled" do
SiteSetting.enable_experimental_sidebar = true SiteSetting.enable_experimental_sidebar_hamburger = true
SiteSetting.tagging_enabled = true SiteSetting.tagging_enabled = true
user.user_option.update!(enable_experimental_sidebar: true)
json = serializer.as_json json = serializer.as_json
@ -269,26 +267,24 @@ RSpec.describe CurrentUserSerializer do
fab!(:category_sidebar_section_link) { Fabricate(:category_sidebar_section_link, user: user) } fab!(:category_sidebar_section_link) { Fabricate(:category_sidebar_section_link, user: user) }
fab!(:category_sidebar_section_link_2) { Fabricate(:category_sidebar_section_link, user: user) } fab!(:category_sidebar_section_link_2) { Fabricate(:category_sidebar_section_link, user: user) }
it "is not included when SiteSeting.enable_experimental_sidebar is false" do it "is not included when SiteSeting.enable_experimental_sidebar_hamburger is false" do
SiteSetting.enable_experimental_sidebar = false SiteSetting.enable_experimental_sidebar_hamburger = false
json = serializer.as_json json = serializer.as_json
expect(json[:sidebar_category_ids]).to eq(nil) expect(json[:sidebar_category_ids]).to eq(nil)
end end
it "is not included when experimental sidebar has not been enabled by user" do it "is not included when experimental sidebar has not been enabled" do
SiteSetting.enable_experimental_sidebar = true SiteSetting.enable_experimental_sidebar_hamburger = false
user.user_option.update!(enable_experimental_sidebar: false)
json = serializer.as_json json = serializer.as_json
expect(json[:sidebar_category_ids]).to eq(nil) expect(json[:sidebar_category_ids]).to eq(nil)
end end
it "is present when experimental sidebar has been enabled by user" do it "is present when experimental sidebar has been enabled" do
SiteSetting.enable_experimental_sidebar = true SiteSetting.enable_experimental_sidebar_hamburger = true
user.user_option.update!(enable_experimental_sidebar: true)
json = serializer.as_json json = serializer.as_json