FIX: admin always see configure default sidebar categories (#20836)

When an admin removes all the categories from their personal sidebar configuration, the section should remain visible to them with the “Configure default categories” prompt.

Similar solution for tags.

/t/95036
This commit is contained in:
Krzysztof Kotlarek 2023-03-27 15:46:39 +11:00 committed by GitHub
parent 1edf7d1b72
commit e0cf2849fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 84 additions and 66 deletions

View File

@ -1,4 +1,4 @@
{{#if this.shouldDisplay}} {{#if (or this.shouldDisplay this.shouldDisplayDefaultConfig)}}
<Sidebar::Section <Sidebar::Section
@sectionName="categories" @sectionName="categories"
@headerLinkText={{i18n "sidebar.sections.categories.header_link_text"}} @headerLinkText={{i18n "sidebar.sections.categories.header_link_text"}}
@ -12,44 +12,48 @@
@collapsable={{@collapsable}} @collapsable={{@collapsable}}
> >
{{#if (gt this.sectionLinks.length 0)}} {{#if this.shouldDisplay}}
{{#each this.sectionLinks as |sectionLink|}} {{#if (gt this.sectionLinks.length 0)}}
{{#each this.sectionLinks as |sectionLink|}}
<Sidebar::SectionLink
@route={{sectionLink.route}}
@query={{sectionLink.query}}
@title={{sectionLink.title}}
@content={{sectionLink.text}}
@currentWhen={{sectionLink.currentWhen}}
@model={{sectionLink.model}}
@badgeText={{sectionLink.badgeText}}
@prefixBadge={{sectionLink.prefixBadge}}
@prefixType={{sectionLink.prefixType}}
@prefixValue={{sectionLink.prefixValue}}
@prefixColor={{sectionLink.prefixColor}}
@prefixElementColors={{sectionLink.prefixElementColors}}
@suffixCSSClass={{sectionLink.suffixCSSClass}}
@suffixValue={{sectionLink.suffixValue}}
@suffixType={{sectionLink.suffixType}}
data-category-id={{sectionLink.category.id}}
/>
{{/each}}
{{else}}
<Sidebar::SectionLink <Sidebar::SectionLink
@route={{sectionLink.route}} @linkName="configure-categories"
@query={{sectionLink.query}} @route="preferences.sidebar"
@title={{sectionLink.title}} @prefixType="icon"
@content={{sectionLink.text}} @prefixValue="pencil-alt"
@currentWhen={{sectionLink.currentWhen}} @model={{this.currentUser}}
@model={{sectionLink.model}} @content={{i18n
@badgeText={{sectionLink.badgeText}} "sidebar.sections.categories.links.add_categories.content"
@prefixBadge={{sectionLink.prefixBadge}} }}
@prefixType={{sectionLink.prefixType}} @title={{i18n
@prefixValue={{sectionLink.prefixValue}} "sidebar.sections.categories.links.add_categories.title"
@prefixColor={{sectionLink.prefixColor}} }}
@prefixElementColors={{sectionLink.prefixElementColors}}
@suffixCSSClass={{sectionLink.suffixCSSClass}}
@suffixValue={{sectionLink.suffixValue}}
@suffixType={{sectionLink.suffixType}}
data-category-id={{sectionLink.category.id}}
/> />
{{/each}} {{/if}}
{{else}}
<Sidebar::SectionLink <Sidebar::Common::AllCategoriesSectionLink />
@linkName="configure-categories"
@route="preferences.sidebar"
@prefixType="icon"
@prefixValue="pencil-alt"
@model={{this.currentUser}}
@content={{i18n
"sidebar.sections.categories.links.add_categories.content"
}}
@title={{i18n "sidebar.sections.categories.links.add_categories.title"}}
/>
{{/if}} {{/if}}
<Sidebar::Common::AllCategoriesSectionLink /> {{#if this.shouldDisplayDefaultConfig}}
{{#if (and this.currentUser.admin (not this.hasDefaultSidebarCategories))}}
<Sidebar::SectionLink <Sidebar::SectionLink
@linkName="configure-default-sidebar-categories" @linkName="configure-default-sidebar-categories"
@content={{i18n "sidebar.sections.categories.configure_defaults"}} @content={{i18n "sidebar.sections.categories.configure_defaults"}}

View File

@ -64,6 +64,10 @@ export default class SidebarUserCategoriesSection extends SidebarCommonCategorie
} }
} }
get shouldDisplayDefaultConfig() {
return this.currentUser.admin && !this.hasDefaultSidebarCategories;
}
get hasDefaultSidebarCategories() { get hasDefaultSidebarCategories() {
return this.siteSettings.default_sidebar_categories.length > 0; return this.siteSettings.default_sidebar_categories.length > 0;
} }

View File

@ -1,4 +1,4 @@
{{#if this.shouldDisplay}} {{#if (or this.shouldDisplay this.shouldDisplayDefaultConfig)}}
<Sidebar::Section <Sidebar::Section
@sectionName="tags" @sectionName="tags"
@headerLinkText={{i18n "sidebar.sections.tags.header_link_text"}} @headerLinkText={{i18n "sidebar.sections.tags.header_link_text"}}
@ -12,38 +12,40 @@
@collapsable={{@collapsable}} @collapsable={{@collapsable}}
> >
{{#if (gt this.sectionLinks.length 0)}} {{#if this.shouldDisplay}}
{{#each this.sectionLinks as |sectionLink|}} {{#if (gt this.sectionLinks.length 0)}}
{{#each this.sectionLinks as |sectionLink|}}
<Sidebar::SectionLink
@route={{sectionLink.route}}
@title={{sectionLink.title}}
@content={{sectionLink.text}}
@currentWhen={{sectionLink.currentWhen}}
@prefixType={{sectionLink.prefixType}}
@prefixValue={{sectionLink.prefixValue}}
@badgeText={{sectionLink.badgeText}}
@models={{sectionLink.models}}
@suffixCSSClass={{sectionLink.suffixCSSClass}}
@suffixValue={{sectionLink.suffixValue}}
@suffixType={{sectionLink.suffixType}}
data-tag-name={{sectionLink.tagName}}
/>
{{/each}}
{{else}}
<Sidebar::SectionLink <Sidebar::SectionLink
@route={{sectionLink.route}} @linkName="configure-tags"
@title={{sectionLink.title}} @route="preferences.sidebar"
@content={{sectionLink.text}} @prefixType="icon"
@currentWhen={{sectionLink.currentWhen}} @prefixValue="pencil-alt"
@prefixType={{sectionLink.prefixType}} @model={{this.currentUser}}
@prefixValue={{sectionLink.prefixValue}} @content={{i18n "sidebar.sections.tags.links.add_tags.content"}}
@badgeText={{sectionLink.badgeText}} @title={{i18n "sidebar.sections.tags.links.add_tags.title"}}
@models={{sectionLink.models}}
@suffixCSSClass={{sectionLink.suffixCSSClass}}
@suffixValue={{sectionLink.suffixValue}}
@suffixType={{sectionLink.suffixType}}
data-tag-name={{sectionLink.tagName}}
/> />
{{/each}} {{/if}}
{{else}}
<Sidebar::SectionLink <Sidebar::Common::AllTagsSectionLink />
@linkName="configure-tags"
@route="preferences.sidebar"
@prefixType="icon"
@prefixValue="pencil-alt"
@model={{this.currentUser}}
@content={{i18n "sidebar.sections.tags.links.add_tags.content"}}
@title={{i18n "sidebar.sections.tags.links.add_tags.title"}}
/>
{{/if}} {{/if}}
<Sidebar::Common::AllTagsSectionLink /> {{#if this.shouldDisplayDefaultConfig}}
{{#if (and this.currentUser.admin (not this.hasDefaultSidebarTags))}}
<Sidebar::SectionLink <Sidebar::SectionLink
@linkName="configure-default-sidebar-tags" @linkName="configure-default-sidebar-tags"
@content={{i18n "sidebar.sections.tags.configure_defaults"}} @content={{i18n "sidebar.sections.tags.configure_defaults"}}

View File

@ -69,6 +69,10 @@ export default class SidebarUserTagsSection extends Component {
} }
} }
get shouldDisplayDefaultConfig() {
return this.currentUser.admin && !this.hasDefaultSidebarTags;
}
get hasDefaultSidebarTags() { get hasDefaultSidebarTags() {
return this.siteSettings.default_sidebar_tags.length > 0; return this.siteSettings.default_sidebar_tags.length > 0;
} }

View File

@ -954,7 +954,6 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) {
}); });
test("section link to admin site settings page when default sidebar categories have not been configured", async function (assert) { test("section link to admin site settings page when default sidebar categories have not been configured", async function (assert) {
setupUserSidebarCategories();
updateCurrentUser({ admin: true }); updateCurrentUser({ admin: true });
await visit("/"); await visit("/");

View File

@ -666,7 +666,11 @@ acceptance("Sidebar - Logged on user - Tags section", function (needs) {
}); });
test("section link to admin site settings page when default sidebar tags have not been configured", async function (assert) { test("section link to admin site settings page when default sidebar tags have not been configured", async function (assert) {
updateCurrentUser({ admin: true }); updateCurrentUser({ admin: true, sidebar_tags: [] });
updateCurrentUser({
sidebar_tags: [],
});
await visit("/"); await visit("/");

View File

@ -109,6 +109,7 @@ acceptance("User Preferences - Sidebar", function (needs) {
}); });
test("user adding categories to sidebar when default sidebar categories have not been configured", async function (assert) { test("user adding categories to sidebar when default sidebar categories have not been configured", async function (assert) {
updateCurrentUser({ admin: false, display_sidebar_tags: false });
await visit("/u/eviltrout/preferences/sidebar"); await visit("/u/eviltrout/preferences/sidebar");
assert.notOk(exists(".sidebar-section[data-section-name='categories']")); assert.notOk(exists(".sidebar-section[data-section-name='categories']"));