Add category breadcrumbs to edit category page (#13126)

This commit is contained in:
Mark VanLandingham 2021-05-25 13:40:11 -05:00 committed by GitHub
parent 3f5d868219
commit 72950e051c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 83 additions and 17 deletions

View File

@ -7,6 +7,8 @@ import { filter } from "@ember/object/computed";
export default Component.extend({ export default Component.extend({
classNameBindings: ["hidden:hidden", ":category-breadcrumb"], classNameBindings: ["hidden:hidden", ":category-breadcrumb"],
tagName: "ol", tagName: "ol",
editingCategory: false,
editingCategoryTab: null,
@discourseComputed("categories") @discourseComputed("categories")
filteredCategories(categories) { filteredCategories(categories) {
@ -47,6 +49,11 @@ export default Component.extend({
}); });
}, },
@discourseComputed("siteSettings.tagging_enabled", "editingCategory")
showTagsSection(taggingEnabled, editingCategory) {
return taggingEnabled && !editingCategory;
},
@discourseComputed("category") @discourseComputed("category")
parentCategory(category) { parentCategory(category) {
deprecated( deprecated(

View File

@ -1,5 +1,6 @@
import getURL, { withoutPrefix } from "discourse-common/lib/get-url"; import getURL, { withoutPrefix } from "discourse-common/lib/get-url";
import { next, schedule } from "@ember/runloop"; import { next, schedule } from "@ember/runloop";
import Category from "discourse/models/category";
import EmberObject from "@ember/object"; import EmberObject from "@ember/object";
import LockOn from "discourse/lib/lock-on"; import LockOn from "discourse/lib/lock-on";
import Session from "discourse/models/session"; import Session from "discourse/models/session";
@ -515,4 +516,13 @@ export function getCategoryAndTagUrl(category, subcategories, tag) {
return getURL(url || "/"); return getURL(url || "/");
} }
export function getEditCategoryUrl(category, subcategories, tab) {
let url = `/c/${Category.slugFor(category)}/edit`;
if (tab) {
url += `/${tab}`;
}
return getURL(url);
}
export default _urlInstance; export default _urlInstance;

View File

@ -4,6 +4,8 @@
category=breadcrumb.category category=breadcrumb.category
categories=breadcrumb.options categories=breadcrumb.options
tagId=tag.id tagId=tag.id
editingCategory=editingCategory
editingCategoryTab=editingCategoryTab
options=(hash options=(hash
parentCategory=breadcrumb.parentCategory parentCategory=breadcrumb.parentCategory
subCategory=breadcrumb.isSubcategory subCategory=breadcrumb.isSubcategory
@ -14,7 +16,7 @@
{{/if}} {{/if}}
{{/each}} {{/each}}
{{#if siteSettings.tagging_enabled}} {{#if showTagsSection}}
{{#if additionalTags}} {{#if additionalTags}}
{{tags-intersection-chooser {{tags-intersection-chooser
currentCategory=category currentCategory=category

View File

@ -1,6 +1,17 @@
<div class="edit-category {{if expandedMenu "expanded-menu"}}"> <div class="edit-category {{if expandedMenu "expanded-menu"}}">
<div class="edit-category-title-bar">
<div class="edit-category-title"> <div class="edit-category-title">
<h2>{{title}}</h2> <h2>{{title}}</h2>
{{#if model.id}}
{{bread-crumbs
categories=site.categoriesList
category=model
noSubcategories=model.noSubcategories
editingCategory=true
editingCategoryTab=selectedTab
}}
{{/if}}
</div>
{{#unless mobileView}} {{#unless mobileView}}
{{#if model.id}} {{#if model.id}}
{{d-button {{d-button

View File

@ -23,9 +23,19 @@ acceptance("Category Edit", function (needs) {
"it jumps to the correct screen" "it jumps to the correct screen"
); );
assert.equal(queryAll(".badge-category").text(), "bug"); assert.equal(
queryAll(".category-breadcrumb .badge-category").text(),
"bug"
);
assert.equal(
queryAll(".category-color-editor .badge-category").text(),
"bug"
);
await fillIn("input.category-name", "testing"); await fillIn("input.category-name", "testing");
assert.equal(queryAll(".badge-category").text(), "testing"); assert.equal(
queryAll(".category-color-editor .badge-category").text(),
"testing"
);
await fillIn(".edit-text-color input", "ff0000"); await fillIn(".edit-text-color input", "ff0000");

View File

@ -1,4 +1,8 @@
import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers"; import {
acceptance,
exists,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import { click, currentURL, fillIn, visit } from "@ember/test-helpers"; import { click, currentURL, fillIn, visit } from "@ember/test-helpers";
import DiscourseURL from "discourse/lib/url"; import DiscourseURL from "discourse/lib/url";
import I18n from "I18n"; import I18n from "I18n";
@ -10,7 +14,9 @@ acceptance("Category New", function (needs) {
test("Creating a new category", async function (assert) { test("Creating a new category", async function (assert) {
await visit("/new-category"); await visit("/new-category");
assert.ok(queryAll(".badge-category")); assert.ok(queryAll(".badge-category"));
assert.notOk(exists(".category-breadcrumb"));
await fillIn("input.category-name", "testing"); await fillIn("input.category-name", "testing");
assert.equal(queryAll(".badge-category").text(), "testing"); assert.equal(queryAll(".badge-category").text(), "testing");

View File

@ -1,6 +1,9 @@
import Category from "discourse/models/category"; import Category from "discourse/models/category";
import ComboBoxComponent from "select-kit/components/combo-box"; import ComboBoxComponent from "select-kit/components/combo-box";
import DiscourseURL, { getCategoryAndTagUrl } from "discourse/lib/url"; import DiscourseURL, {
getCategoryAndTagUrl,
getEditCategoryUrl,
} from "discourse/lib/url";
import I18n from "I18n"; import I18n from "I18n";
import { categoryBadgeHTML } from "discourse/helpers/category-link"; import { categoryBadgeHTML } from "discourse/helpers/category-link";
import { computed } from "@ember/object"; import { computed } from "@ember/object";
@ -18,6 +21,9 @@ export default ComboBoxComponent.extend({
tagName: "li", tagName: "li",
categoryStyle: readOnly("siteSettings.category_style"), categoryStyle: readOnly("siteSettings.category_style"),
noCategoriesLabel: I18n.t("categories.no_subcategory"), noCategoriesLabel: I18n.t("categories.no_subcategory"),
navigateToEdit: false,
editingCategory: false,
editingCategoryTab: null,
selectKitOptions: { selectKitOptions: {
filterable: true, filterable: true,
@ -57,7 +63,7 @@ export default ComboBoxComponent.extend({
const shortcuts = []; const shortcuts = [];
if ( if (
this.value || (this.value && !this.editingCategory) ||
(this.selectKit.options.noSubcategories && (this.selectKit.options.noSubcategories &&
this.selectKit.options.subCategory) this.selectKit.options.subCategory)
) { ) {
@ -110,6 +116,9 @@ export default ComboBoxComponent.extend({
"parentCategoryName", "parentCategoryName",
"selectKit.options.subCategory", "selectKit.options.subCategory",
function () { function () {
if (this.editingCategory) {
return this.noCategoriesLabel;
}
if (this.selectKit.options.subCategory) { if (this.selectKit.options.subCategory) {
return I18n.t("categories.all_subcategories", { return I18n.t("categories.all_subcategories", {
categoryName: this.parentCategoryName, categoryName: this.parentCategoryName,
@ -145,13 +154,19 @@ export default ComboBoxComponent.extend({
? this.selectKit.options.parentCategory ? this.selectKit.options.parentCategory
: Category.findById(parseInt(categoryId, 10)); : Category.findById(parseInt(categoryId, 10));
DiscourseURL.routeToUrl( const route = this.editingCategory
getCategoryAndTagUrl( ? getEditCategoryUrl(
category,
categoryId !== NO_CATEGORIES_ID,
this.editingCategoryTab
)
: getCategoryAndTagUrl(
category, category,
categoryId !== NO_CATEGORIES_ID, categoryId !== NO_CATEGORIES_ID,
this.tagId this.tagId
)
); );
DiscourseURL.routeToUrl(route);
}, },
}, },

View File

@ -9,7 +9,7 @@ div.edit-category {
grid-column-gap: 1.5em; grid-column-gap: 1.5em;
grid-template-areas: "header header" "sidebar content" "sidebar warning" "sidebar footer"; grid-template-areas: "header header" "sidebar content" "sidebar warning" "sidebar footer";
.edit-category-title { .edit-category-title-bar {
grid-area: header; grid-area: header;
grid-column: 1 / span 2; grid-column: 1 / span 2;
display: flex; display: flex;
@ -17,6 +17,11 @@ div.edit-category {
align-self: start; align-self: start;
background-color: var(--primary-very-low); background-color: var(--primary-very-low);
padding: 20px; padding: 20px;
.category-back {
height: 2em;
align-self: flex-end;
}
} }
.edit-category-nav { .edit-category-nav {

View File

@ -39,7 +39,7 @@ div.edit-category {
} }
} }
.edit-category-title { .edit-category-title-bar {
justify-content: start; justify-content: start;
align-items: center; align-items: center;
padding-bottom: 1em; padding-bottom: 1em;