From be33363f131947ad9e92965fa2d31c859ebe6966 Mon Sep 17 00:00:00 2001 From: Ted Johansson Date: Tue, 17 Sep 2024 14:43:34 +0800 Subject: [PATCH] FEATURE: Add ability to dismiss admin notices (#28916) his is a new feature that lets admins dismiss notices from the dashboard. This helps with self-service in cases where a notice is "stuck", while we work on provisions to prevent "sticking" in the first place. --- .../admin/addon/components/admin-notice.gjs | 25 ++++++++ .../addon/components/dashboard-problems.gjs | 63 ++++++++++--------- .../addon/controllers/admin-dashboard.js | 21 +------ .../admin/addon/templates/dashboard.hbs | 4 +- .../tests/acceptance/dashboard-test.js | 8 --- .../stylesheets/common/admin/dashboard.scss | 15 +++-- .../admin/admin_notices_controller.rb | 10 +++ app/models/problem_check_tracker.rb | 7 ++- app/serializers/admin_notice_serializer.rb | 2 +- app/services/admin_notices/dismiss.rb | 32 ++++++++++ config/locales/client.en.yml | 1 + config/routes.rb | 2 + spec/fabricators/admin_notice_fabricator.rb | 1 + spec/models/problem_check_tracker_spec.rb | 26 ++++++++ spec/services/admin_notices/dismiss_spec.rb | 32 ++++++++++ spec/system/admin_notices_spec.rb | 25 ++++++++ .../page_objects/pages/admin_dashboard.rb | 24 +++++++ 17 files changed, 231 insertions(+), 67 deletions(-) create mode 100644 app/assets/javascripts/admin/addon/components/admin-notice.gjs create mode 100644 app/controllers/admin/admin_notices_controller.rb create mode 100644 app/services/admin_notices/dismiss.rb create mode 100644 spec/services/admin_notices/dismiss_spec.rb create mode 100644 spec/system/admin_notices_spec.rb create mode 100644 spec/system/page_objects/pages/admin_dashboard.rb diff --git a/app/assets/javascripts/admin/addon/components/admin-notice.gjs b/app/assets/javascripts/admin/addon/components/admin-notice.gjs new file mode 100644 index 00000000000..07138307c7d --- /dev/null +++ b/app/assets/javascripts/admin/addon/components/admin-notice.gjs @@ -0,0 +1,25 @@ +import Component from "@glimmer/component"; +import { action } from "@ember/object"; +import { htmlSafe } from "@ember/template"; +import DButton from "discourse/components/d-button"; +import icon from "discourse-common/helpers/d-icon"; + +export default class AdminNotice extends Component { + @action + dismiss() { + this.args.dismissCallback(this.args.problem); + } + + +} diff --git a/app/assets/javascripts/admin/addon/components/dashboard-problems.gjs b/app/assets/javascripts/admin/addon/components/dashboard-problems.gjs index 7f34df878b4..882d65501d6 100644 --- a/app/assets/javascripts/admin/addon/components/dashboard-problems.gjs +++ b/app/assets/javascripts/admin/addon/components/dashboard-problems.gjs @@ -1,15 +1,33 @@ import Component from "@glimmer/component"; -import { htmlSafe } from "@ember/template"; +import { concat } from "@ember/helper"; +import { action } from "@ember/object"; +import { eq } from "truth-helpers"; import ConditionalLoadingSection from "discourse/components/conditional-loading-section"; import DButton from "discourse/components/d-button"; import concatClass from "discourse/helpers/concat-class"; +import { ajax } from "discourse/lib/ajax"; +import { popupAjaxError } from "discourse/lib/ajax-error"; import icon from "discourse-common/helpers/d-icon"; import i18n from "discourse-common/helpers/i18n"; +import AdminNotice from "admin/components/admin-notice"; -// eslint-disable-next-line ember/no-empty-glimmer-component-classes export default class DashboardProblems extends Component { + @action + async dismissProblem(problem) { + try { + await ajax(`/admin/admin_notices/${problem.id}`, { type: "DELETE" }); + this.args.problems.removeObject(problem); + } catch (error) { + popupAjaxError(error); + } + } + + get problems() { + return this.args.problems.sortBy("priority"); + } +