From 4b4aedb50f7d0a3e2ee06c4781e7b52fceeba121 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Fri, 19 Jan 2024 13:27:33 +0100 Subject: [PATCH] DEV: Use the new controller/period component for the dashboard (#435) --- .discourse-compatibility | 1 + .../controllers/admin-dashboard-sentiment.js | 41 +++---------------- .../templates/admin-dashboard-sentiment.hbs | 22 ++++------ .../modules/sentiment/common/dashboard.scss | 4 -- spec/system/admin_dashboard_spec.rb | 15 +++++++ 5 files changed, 30 insertions(+), 53 deletions(-) create mode 100644 spec/system/admin_dashboard_spec.rb diff --git a/.discourse-compatibility b/.discourse-compatibility index 7ff13486..e8e40b3c 100644 --- a/.discourse-compatibility +++ b/.discourse-compatibility @@ -1,3 +1,4 @@ +< 3.2.0.beta5-dev: c70f43f130fb98e4a1adb1afd9b621aaa49088e3 < 3.2.0.beta4-dev: 493b48477a9288f2f1b6f021954088705a6673d6 < 3.2.0.beta2-dev: 3bced1c6f525553fe2b5b79d29bd66c1cf2a47d5 3.1.999: c0415bb7eb878b1b7abf112d65cba981030df8df diff --git a/assets/javascripts/discourse/controllers/admin-dashboard-sentiment.js b/assets/javascripts/discourse/controllers/admin-dashboard-sentiment.js index 75d12e54..6de5b249 100644 --- a/assets/javascripts/discourse/controllers/admin-dashboard-sentiment.js +++ b/assets/javascripts/discourse/controllers/admin-dashboard-sentiment.js @@ -1,38 +1,9 @@ -import Controller from "@ember/controller"; -import { action } from "@ember/object"; -import { inject as service } from "@ember/service"; -import getURL from "discourse-common/lib/get-url"; -import discourseComputed from "discourse-common/utils/decorators"; -import CustomDateRangeModal from "admin/components/modal/custom-date-range"; -import PeriodComputationMixin from "admin/mixins/period-computation"; +import { computed } from "@ember/object"; +import AdminDashboardTabController from "admin/controllers/admin-dashboard-tab"; -export default class AdminDashboardSentiment extends Controller.extend( - PeriodComputationMixin -) { - @service modal; - - @discourseComputed("startDate", "endDate") - filters(startDate, endDate) { - return { startDate, endDate }; - } - - _reportsForPeriodURL(period) { - return getURL(`/admin/dashboard/sentiment?period=${period}`); - } - - @action - setCustomDateRange(startDate, endDate) { - this.setProperties({ startDate, endDate }); - } - - @action - openCustomDateRangeModal() { - this.modal.show(CustomDateRangeModal, { - model: { - startDate: this.startDate, - endDate: this.endDate, - setCustomDateRange: this.setCustomDateRange, - }, - }); +export default class AdminDashboardSentiment extends AdminDashboardTabController { + @computed("startDate", "endDate") + get filters() { + return { startDate: this.startDate, endDate: this.endDate }; } } diff --git a/assets/javascripts/discourse/templates/admin-dashboard-sentiment.hbs b/assets/javascripts/discourse/templates/admin-dashboard-sentiment.hbs index 7cfb8495..bdbf3a29 100644 --- a/assets/javascripts/discourse/templates/admin-dashboard-sentiment.hbs +++ b/assets/javascripts/discourse/templates/admin-dashboard-sentiment.hbs @@ -4,20 +4,14 @@

{{i18n "discourse_ai.sentiments.dashboard.title"}}

- - - - + + diff --git a/assets/stylesheets/modules/sentiment/common/dashboard.scss b/assets/stylesheets/modules/sentiment/common/dashboard.scss index 56ba6e54..6e2058aa 100644 --- a/assets/stylesheets/modules/sentiment/common/dashboard.scss +++ b/assets/stylesheets/modules/sentiment/common/dashboard.scss @@ -1,8 +1,4 @@ .dashboard.dashboard-sentiment { - .sentiment { - margin-bottom: 1em; - } - .navigation-item.sentiment { border-bottom: 0.4em solid var(--tertiary); } diff --git a/spec/system/admin_dashboard_spec.rb b/spec/system/admin_dashboard_spec.rb new file mode 100644 index 00000000..0931dc3d --- /dev/null +++ b/spec/system/admin_dashboard_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +RSpec.describe "Admin dashboard", type: :system do + fab!(:admin) + + it "displays the sentiment dashboard" do + SiteSetting.ai_sentiment_enabled = true + sign_in(admin) + + visit "/admin" + find(".navigation-item.sentiment").click() + + expect(page).to have_css(".section.sentiment") + end +end