A platform for community discussion. Free, open, simple.
UI: Show categories in selector and icons in table for engagement in dashboard (#40516)
Natalie Tayd5066ecac357
diff --git a/frontend/discourse/admin/components/dashboard/engagement/activity-by-category.gjs b/frontend/discourse/admin/components/dashboard/engagement/activity-by-category.gjsindex 44bf7dc7070..8f5a1b2c2eb 100644--- a/frontend/discourse/admin/components/dashboard/engagement/activity-by-category.gjs+++ b/frontend/discourse/admin/components/dashboard/engagement/activity-by-category.gjs@@ -8,8 +8,10 @@ import { trustHTML } from "@ember/template";import { ajax } from "discourse/lib/ajax";import { popupAjaxError } from "discourse/lib/ajax-error";import { number } from "discourse/lib/formatter";+import Category from "discourse/models/category";import CategorySelector from "discourse/select-kit/components/category-selector";import { eq } from "discourse/truth-helpers";+import dCategoryBadge from "discourse/ui-kit/helpers/d-category-badge";import I18n, { i18n } from "discourse-i18n";export default class ActivityByCategory extends Component {@@ -19,6 +21,14 @@ export default class ActivityByCategory extends Component {@tracked sortBy = "share";@tracked sortDir = "desc";+ constructor() {+ super(...arguments);++ this.selectedCategories = (this.args.activity?.rows ?? [])+ .map((row) => Category.findById(row.category_id))+ .filter(Boolean);+ }+get activity() {return this.overrideActivity ?? this.args.activity;}@@ -27,6 +37,7 @@ export default class ActivityByCategory extends Component {const rows = this.activity?.rows ?? [];const decorated = rows.map((row) => ({...row,+ category: Category.findById(row.category_id),topicsFormatted: I18n.toNumber(row.topics, { precision: 0 }),postsFormatted: I18n.toNumber(row.posts, { precision: 0 }),pageViewsFormatted: number(row.page_views),@@ -184,12 +195,16 @@ export default class ActivityByCategory extends Component {{{#each this.rows as |row|}}<tr><td class="db-activity-table__cell-category">- <span- class="db-activity-table__swatch"- style={{row.swatchStyle}}- aria-hidden="true"- ></span>- {{row.name}}+ {{#if row.category}}+ {{dCategoryBadge row.category}}+ {{else}}+ <span+ class="db-activity-table__swatch"+ style={{row.swatchStyle}}+ aria-hidden="true"+ ></span>+ {{row.name}}+ {{/if}}</td><tdclass="db-activity-table__cell-number"diff --git a/frontend/discourse/tests/integration/components/dashboard/activity-by-category-test.gjs b/frontend/discourse/tests/integration/components/dashboard/activity-by-category-test.gjsindex 6e21c300b22..dc783500d6e 100644--- a/frontend/discourse/tests/integration/components/dashboard/activity-by-category-test.gjs+++ b/frontend/discourse/tests/integration/components/dashboard/activity-by-category-test.gjs@@ -2,6 +2,7 @@ import { render } from "@ember/test-helpers";import { module, test } from "qunit";import ActivityByCategory from "discourse/admin/components/dashboard/engagement/activity-by-category";import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import selectKit from "discourse/tests/helpers/select-kit-helper";module("Integration | Component | Dashboard | ActivityByCategory",@@ -149,5 +150,39 @@ module(assert.dom(".category-selector").exists();});++ test("prefills the selector with the categories shown by default", async function (assert) {+ await render(+ <template>+ <ActivityByCategory+ @activity={{activity}}+ @startDate={{start}}+ @endDate={{end}}+ />+ </template>+ );++ assert.strictEqual(+ selectKit(".category-selector").header().value(),+ "1,2,3"+ );+ });++ test("renders a category badge for each row instead of a bare swatch", async function (assert) {+ await render(+ <template>+ <ActivityByCategory+ @activity={{activity}}+ @startDate={{start}}+ @endDate={{end}}+ />+ </template>+ );++ assert+ .dom(".db-activity-table__cell-category .badge-category")+ .exists({ count: 3 });+ assert.dom(".db-activity-table__swatch").doesNotExist();+ });});