Skip to content

A platform for community discussion. Free, open, simple.

UX: refactor User Visit report and layout for all reports (#37627)

chapoic682292a4cfd
diff --git a/app/assets/stylesheets/admin/admin_report.scss b/app/assets/stylesheets/admin/admin_report.scss
index 910bc79cfc9..7b0d857cb4d 100644
--- a/app/assets/stylesheets/admin/admin_report.scss
+++ b/app/assets/stylesheets/admin/admin_report.scss
@@ -1,6 +1,17 @@
@use "lib/viewport";
.admin-report {
+ .select-kit {
+ @include viewport.from(sm) {
+ width: auto;
+ max-width: 250px;
+ }
+
+ @include viewport.until(sm) {
+ width: 100% !important;
+ }
+ }
+
.conditional-loading-section {
&.is-loading {
margin: 0;
@@ -10,9 +21,7 @@
.header {
display: flex;
align-items: center;
- border-bottom: 1px solid var(--content-border-color);
margin-bottom: 0.5em;
- padding-bottom: 0.5em;
}
.header .breadcrumb {
@@ -79,17 +88,11 @@
}
}
- .body {
- display: flex;
- flex-direction: row;
- }
-
- .main {
- flex: 1;
- min-width: 0; // allow chart.js to shrink below intrinsic width
+ .d-page-subheader__title a {
+ color: var(--primary);
}
- .main .report-alert {
+ .report-alert {
margin: 0;
text-align: center;
padding: 3em;
@@ -123,6 +126,18 @@
color: var(--danger);
}
}
+}
+
+body:not(.uc-reporting-improvements) .admin-report {
+ .body {
+ display: flex;
+ flex-direction: row;
+ }
+
+ .main {
+ flex: 1;
+ min-width: 0; // allow chart.js to shrink below intrinsic width
+ }
.average-chart {
font-style: italic;
@@ -187,10 +202,6 @@
}
}
}
-
- .d-page-subheader__title a {
- color: var(--primary);
- }
}
.rtl .admin-report {
diff --git a/app/assets/stylesheets/admin/admin_report_chart.scss b/app/assets/stylesheets/admin/admin_report_chart.scss
index f39e2f9aa69..0f7598f302f 100644
--- a/app/assets/stylesheets/admin/admin_report_chart.scss
+++ b/app/assets/stylesheets/admin/admin_report_chart.scss
@@ -1,3 +1,5 @@
+@use "lib/viewport";
+
.admin-report-chart {
animation: fadein 2s;
@@ -5,3 +7,151 @@
animation-duration: 0s;
}
}
+
+body.uc-reporting-improvements .admin-contents:not(.dashboard) .chart {
+ &__wrapper {
+ display: flex;
+ flex-direction: column;
+ }
+
+ &__body {
+ margin-block: var(--space-4);
+ flex: 1;
+ min-width: 0; // allow chart.js to shrink below intrinsic width
+
+ .report-alert {
+ margin: 0;
+ text-align: center;
+ padding: 3em;
+ border: 1px solid transparent;
+
+ a {
+ color: var(--primary-high);
+ }
+
+ .d-icon {
+ color: var(--primary-medium);
+ font-size: var(--font-up-5);
+ display: block;
+ margin: 0.25em auto;
+ }
+
+ &.no-data,
+ &.rate-limited {
+ background: var(--secondary);
+ border-color: var(--primary-low);
+ color: var(--primary);
+ }
+
+ &.rate-limited .d-icon {
+ color: var(--danger);
+ }
+
+ &.timeout,
+ &.exception {
+ border-color: var(--danger-low);
+ color: var(--danger);
+ }
+ }
+
+ .average-chart {
+ font-style: italic;
+ color: var(--primary-high);
+ text-align: right;
+ }
+ }
+
+ &__filters {
+ display: flex;
+ align-items: flex-start; // aligned to top to provide alignment when subcat checkbox is in play
+ gap: var(--space-2);
+ margin-bottom: var(--space-4);
+
+ @include viewport.until(sm) {
+ flex-direction: column;
+ align-items: stretch;
+ }
+
+ .chart-groupings {
+ display: flex;
+ gap: var(--space-2);
+ background-color: var(--primary-very-low);
+ border-radius: var(--d-border-radius-large);
+ padding: var(--space-1) var(--space-2);
+
+ @include viewport.from(sm) {
+ margin-right: auto;
+ }
+
+ .chart-grouping {
+ border-radius: var(--d-border-radius-large);
+ background: transparent;
+
+ @include viewport.until(sm) {
+ flex-grow: 1;
+ }
+
+ &:hover {
+ background: transparent;
+ color: var(--primary);
+ }
+
+ &.active {
+ background: var(--secondary);
+ box-shadow: var(--shadow-card);
+ }
+ }
+ }
+ }
+
+ &__filter-label {
+ margin-top: var(--space-1);
+ }
+
+ &__additional-filters {
+ display: flex;
+ gap: var(--space-2);
+
+ @include viewport.until(sm) {
+ flex-direction: column;
+ }
+ }
+
+ &__dates {
+ .d-date-time-input-range {
+ display: flex;
+ gap: var(--space-2);
+
+ > * {
+ margin: 0;
+ }
+ }
+
+ .d-date-time-input {
+ @include viewport.until(sm) {
+ flex-grow: 1;
+ }
+ }
+ }
+
+ &__actions {
+ display: flex;
+ gap: var(--space-4);
+ justify-content: flex-end;
+ margin-top: var(--space-4);
+ }
+
+ &__modes {
+ list-style: none;
+ margin-right: auto;
+
+ .mode {
+ display: inline-flex;
+ flex: 1 0 0px;
+
+ .mode-btn.is-current {
+ color: var(--tertiary);
+ }
+ }
+ }
+}
diff --git a/app/assets/stylesheets/admin/admin_report_stacked_chart.scss b/app/assets/stylesheets/admin/admin_report_stacked_chart.scss
index e6e0267ac01..55a26ec4b23 100644
--- a/app/assets/stylesheets/admin/admin_report_stacked_chart.scss
+++ b/app/assets/stylesheets/admin/admin_report_stacked_chart.scss
@@ -1,4 +1,4 @@
-.admin-report-stacked-chart {
+body:not(.uc-reporting-improvements) .admin-report-stacked-chart {
.chart-canvas-container {
height: 250px;
}
diff --git a/app/assets/stylesheets/admin/admin_reports.scss b/app/assets/stylesheets/admin/admin_reports.scss
index 6e2f7a31da7..83fd5878edf 100644
--- a/app/assets/stylesheets/admin/admin_reports.scss
+++ b/app/assets/stylesheets/admin/admin_reports.scss
@@ -9,8 +9,8 @@
}
}
- .admin-report-chart .chart-canvas-container .chart-canvas {
- height: 400px;
+ .admin-report-chart .chart-canvas-container {
+ height: clamp(200px, 50vh, 350px);
}
}
diff --git a/app/assets/stylesheets/admin/dashboard.scss b/app/assets/stylesheets/admin/dashboard.scss
index 2804b0525c4..da9b66564ca 100644
--- a/app/assets/stylesheets/admin/dashboard.scss
+++ b/app/assets/stylesheets/admin/dashboard.scss
@@ -210,6 +210,10 @@
margin-left: -5px;
}
+ .site-traffic .chart-canvas-container {
+ height: 250px;
+ }
+
.chart-canvas {
width: 100%;
height: 100%;
@@ -352,7 +356,9 @@
padding: 0.65em 0.25em;
}
- .admin-report .main {
+ .admin-report .main,
+ //temp fix for reporting upcoming changes
+ .admin-report .chart__body {
border: 1px solid var(--content-border-color);
&:hover {
@@ -360,6 +366,13 @@
}
}
+ // temp fix for reporting upcoming changes
+ .alert {
+ .uc-reporting-improvements & {
+ margin-bottom: 0;
+ }
+ }
+
.admin-report:not(:last-child) {
.main {
border-bottom: 0;
diff --git a/app/assets/stylesheets/common/components/buttons.scss b/app/assets/stylesheets/common/components/buttons.scss
index 8e5dee77f8a..95257ceb6c8 100644
--- a/app/assets/stylesheets/common/components/buttons.scss
+++ b/app/assets/stylesheets/common/components/buttons.scss
@@ -516,7 +516,7 @@
}
}
- /* The full classname is the old way of combining transparent buttons with colours – no longer use like this
+ /* The full classname is the old way of combining transparent buttons with colours – no longer use like this
Use the --modifiers approach instead
*/
diff --git a/app/jobs/regular/export_csv_file.rb b/app/jobs/regular/export_csv_file.rb
index 20bca4d3e23..739e21ed0d3 100644
--- a/app/jobs/regular/export_csv_file.rb
+++ b/app/jobs/regular/export_csv_file.rb
@@ -221,10 +221,13 @@ module Jobs
end
if report.modes == [Report::MODES[:stacked_chart]]
+ hidden_labels = @extra[:hidden_labels].to_s.split(",").map(&:strip)
+
header = [:x]
data = {}
- report.data.map do |series|
+ report.data.each do |series|
+ next if hidden_labels.include?(series[:req])
header << series[:label]
series[:data].each do |datapoint|
data[datapoint[:x]] ||= { x: datapoint[:x] }
diff --git a/app/models/concerns/reports/visits.rb b/app/models/concerns/reports/visits.rb
index 7878d0a3b7d..e62af800454 100644
--- a/app/models/concerns/reports/visits.rb
+++ b/app/models/concerns/reports/visits.rb
@@ -10,20 +10,77 @@ module Reports::Visits
report.icon = "user"
- basic_report_about report,
- UserVisit,
- :by_day,
- report.start_date,
- report.end_date,
- group_filter
- add_counts report, UserVisit, "visited_at"
-
- report.prev30Days =
- UserVisit.where(
- "visited_at >= ? and visited_at < ?",
- report.start_date - 30.days,
+ if SiteSetting.reporting_improvements
+ report_visits_stacked(report, group_filter)
+ else
+ basic_report_about report,
+ UserVisit,
+ :by_day,
+ report.start_date,
+ report.end_date,
+ group_filter
+ add_counts report, UserVisit, "visited_at"
+
+ if report.facets.include?(:prev30Days)
+ report.prev30Days =
+ UserVisit.where(
+ "visited_at >= ? AND visited_at < ?",
+ report.start_date - 30.days,
+ report.start_date,
+ ).count
+ end
+ end
+ end
+
+ private
+
+ def report_visits_stacked(report, group_filter)
+ report.modes = [Report::MODES[:stacked_chart]]
+ report.default_group_by = "weekly"
+
+ results =
+ UserVisit.counts_by_day_and_mobile(
report.start_date,
- ).count
+ report.end_date,
+ group_id: group_filter,
+ )
+
+ desktop_data = []
+ mobile_data = []
+
+ results.each do |row|
+ if row.mobile
+ mobile_data << { x: row.visited_at.to_s, y: row.visit_count }
+ else
+ desktop_data << { x: row.visited_at.to_s, y: row.visit_count }
+ end
+ end
+
+ report.data = [
+ {
+ req: "desktop",
+ label: I18n.t("reports.visits.xaxis.desktop"),
+ color: report.colors[:turquoise],
+ data: desktop_data,
+ },
+ {
+ req: "mobile",
+ label: I18n.t("reports.visits.xaxis.mobile"),
+ color: report.colors[:lime],
+ data: mobile_data,
+ },
+ ]
+
+ report.total = results.first&.total || 0
+
+ if report.facets.include?(:prev30Days)
+ report.prev30Days =
+ UserVisit.where(
+ "visited_at >= ? AND visited_at < ?",
+ report.start_date - 30.days,
+ report.start_date,
+ ).count
+ end
end
end
end
diff --git a/app/models/report.rb b/app/models/report.rb
index 0cafd36d414..03f9df789b4 100644
--- a/app/models/report.rb
+++ b/app/models/report.rb
@@ -14,6 +14,7 @@ class Report
trust_level
file_extension
include_subcategories
+ hidden_labels
]
MODES = {
@@ -65,6 +66,7 @@ class Report
top_users_by_likes_received_from_inferior_trust_level
top_users_by_likes_received_from_a_variety_of_people
user_to_user_private_messages
+ mobile_visits
]
include Reports::AssociatedAccountsByProvider
@@ -139,6 +141,7 @@ class Report
:filters,
:available_filters,
:legacy,
+ :default_group_by,
:y_axis_title
def self.default_days
@@ -267,6 +270,7 @@ class Report
json[:prev_period] = self.prev_period if self.prev_period
json[:prev30Days] = self.prev30Days if self.prev30Days
json[:limit] = self.limit if self.limit
+ json[:default_group_by] = self.default_group_by if self.default_group_by
json[:y_axis_title] = self.y_axis_title if self.y_axis_title
if type == "page_view_crawler_reqs"
diff --git a/app/models/user_visit.rb b/app/models/user_visit.rb
index 57353a91a9d..6b21f4b71e2 100644
--- a/app/models/user_visit.rb
+++ b/app/models/user_visit.rb
@@ -43,6 +43,27 @@ class UserVisit < ActiveRecord::Base
counts_by_day_query(start_date, end_date, group_id).where(mobile: true).count
end
+ def self.counts_by_day_and_mobile(start_date, end_date, group_id: nil)
+ sql = <<~SQL
+ SELECT
+ visited_at,
+ mobile,
+ COUNT(*) AS visit_count,
+ SUM(COUNT(*)) OVER () AS total
+ FROM user_visits
+ #{"INNER JOIN group_users ON group_users.user_id = user_visits.user_id" if group_id}
+ WHERE visited_at >= :start_date AND visited_at <= :end_date
+ #{"AND group_users.group_id = :group_id" if group_id}
+ GROUP BY visited_at, mobile
+ ORDER BY visited_at
+ SQL
+
+ params = { start_date: start_date, end_date: end_date, prev_start: start_date - 30.days }
+ params[:group_id] = group_id.to_i if group_id
+
+ DB.query(sql, **params)
+ end
+
def self.ensure_consistency!
DB.exec <<~SQL
UPDATE user_stats u set days_visited =
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 4ea2d04308e..9de4df26e26 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -6574,10 +6574,11 @@ en:
all: "All"
view_table: "table"
view_graph: "graph"
- refresh_report: "Refresh Report"
+ refresh_report: "Refresh"
daily: Daily
monthly: Monthly
weekly: Weekly
+ chart_group_period: "Select a period"
value_so_far: "%{value} (so far)"
dates: "Dates (UTC)"
groups: "All groups"
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 74ecc6e4307..ae0cabad7e7 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1334,9 +1334,11 @@ en:
description: "List of flags' statuses including type of flag, poster, flagger, and time to resolution."
visits:
title: "User Visits"
- xaxis: "Day"
+ xaxis:
+ desktop: "Desktop"
+ mobile: "Mobile"
yaxis: "Number of visits"
- description: "Number of signed-in user visits."
+ description: "Number of signed-in user visits by device type."
signups:
title: "Signups"
xaxis: "Day"
@@ -1400,10 +1402,10 @@ en:
description: "Pageviews for logged in users, anonymous users, known crawlers and other traffic."
description_link: "https://meta.discourse.org/t/understanding-pageviews-and-the-site-traffic-report/324062"
dau_by_mau:
- title: "DAU/MAU"
+ title: "DAU / MAU"
xaxis: "Day"
yaxis: "DAU/MAU"
- description: "Number of members that logged in in the last day divided by number of members that logged in in the last month – returns a % which indicates community 'stickiness'. Aim for >20%."
+ description: "The share of monthly active members who returned in the last day. This percentage shows how regularly people come back; also called the community 'stickiness'. Aim for > 20%."
daily_engaged_users:
title: "Daily Engaged Users"
xaxis: "Day"
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 69b5c7fc0cd..46c68afc3f2 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -4227,6 +4227,7 @@ experimental:
status: "experimental"
impact: "feature,staff"
learn_more_url: "https://meta.discourse.org/t/-/395768"
+ disallow_enabled_for_groups: true
enable_auto_grid_images:
default: false
client: true
diff --git a/frontend/discourse/admin/components/admin-report-chart.gjs b/frontend/discourse/admin/components/admin-report-chart.gjs
index dfcb25d22fe..ad9fba817d4 100644
--- a/frontend/discourse/admin/components/admin-report-chart.gjs
+++ b/frontend/discourse/admin/components/admin-report-chart.gjs
@@ -170,7 +170,9 @@ export default class AdminReportChart extends Component {
ticks: {
callback: (label) => number(label),
sampleSize: 5,
+ maxRotation: 25,
minRotation: 0,
+ stepSize: 1,
precision: 0,
},
},
diff --git a/frontend/discourse/admin/components/admin-report-legacy.gjs b/frontend/discourse/admin/components/admin-report-legacy.gjs
new file mode 100644
index 00000000000..80608c7af9f
--- /dev/null
+++ b/frontend/discourse/admin/components/admin-report-legacy.gjs
@@ -0,0 +1,259 @@
+import { concat, fn } from "@ember/helper";
+import didUpdate from "@ember/render-modifiers/modifiers/did-update";
+import AdminReport from "discourse/admin/components/admin-report";
+import ConditionalLoadingSection from "discourse/components/conditional-loading-section";
+import DButton from "discourse/components/d-button";
+import DPageSubheader from "discourse/components/d-page-subheader";
+import DateTimeInputRange from "discourse/components/date-time-input-range";
+import DTooltip from "discourse/float-kit/components/d-tooltip";
+import concatClass from "discourse/helpers/concat-class";
+import icon from "discourse/helpers/d-icon";
+import number from "discourse/helpers/number";
+import { and } from "discourse/truth-helpers";
+import { i18n } from "discourse-i18n";
+
+<template>
+ <div
+ class={{concatClass "admin-report" @report.reportClasses}}
+ {{didUpdate @report.fetchOrRender @filters.startDate @filters.endDate}}
+ >
+ {{#unless @report.isHidden}}
+ <ConditionalLoadingSection @isLoading={{@report.isLoading}}>
+ {{#if
+ (and @report.siteSettings.reporting_improvements @report.model.legacy)
+ }}
+ <div class="alert alert-info">
+ {{icon "triangle-exclamation"}}
+ <span>{{i18n "admin.reports.legacy_warning"}}</span>
+ </div>
+ {{/if}}
+ {{#if @report.showHeader}}
+ <div class="header">
+ {{#unless @report.showNotFoundError}}
+ <DPageSubheader
+ @titleLabel={{@report.model.title}}
+ @titleUrl={{@report.model.reportUrl}}
+ @descriptionLabel={{unless
+ @report.showDescriptionInTooltip
+ @report.model.description
+ }}
+ @learnMoreUrl={{@report.model.description_link}}
+ />
+
+ {{#if @report.showDescriptionInTooltip}}
+ {{#if @report.model.description}}
+ <DTooltip
+ @interactive={{@report.model.description_link.length}}
+ >
+ <:trigger>
+ {{icon "circle-question"}}
+ </:trigger>
+ <:content>
+ {{#if @report.model.description_link}}
+ <a
+ target="_blank"
+ rel="noopener noreferrer"
+ href={{@report.model.description_link}}
+ class="info"
+ >
+ {{@report.model.description}}
+ </a>
+ {{else}}
+ <span>{{@report.model.description}}</span>
+ {{/if}}
+ </:content>
+ </DTooltip>
+ {{/if}}
+ {{/if}}
+ {{/unless}}
+
+ {{#if @report.shouldDisplayTrend}}
+ <div class="trend {{@report.model.trend}}">
+ <span class="value" title={{@report.model.trendTitle}}>
+ {{#if @report.model.average}}
+ {{number @report.model.currentAverage}}{{#if
+ @report.model.percent
+ }}%{{/if}}
+ {{else}}
+ {{number @report.model.currentTotal noTitle="true"}}{{#if
+ @report.model.percent
+ }}%{{/if}}
+ {{/if}}
+
+ {{#if @report.model.trendIcon}}
+ {{icon @report.model.trendIcon class="icon"}}
+ {{/if}}
+ </span>
+ </div>
+ {{/if}}
+ </div>
+ {{/if}}
+
+ <div class="body">
+ <div class="main">
+ {{#if @report.showError}}
+ {{#if @report.showTimeoutError}}
+ <div class="alert alert-error report-alert timeout">
+ {{icon "triangle-exclamation"}}
+ <span>{{i18n "admin.dashboard.timeout_error"}}</span>
+ </div>
+ {{/if}}
+
+ {{#if @report.showExceptionError}}
+ <div class="alert alert-error report-alert exception">
+ {{icon "triangle-exclamation"}}
+ <span>{{i18n "admin.dashboard.exception_error"}}</span>
+ </div>
+ {{/if}}
+
+ {{#if @report.showNotFoundError}}
+ <div class="alert alert-error report-alert not-found">
+ {{icon "triangle-exclamation"}}
+ <span>{{i18n "admin.dashboard.not_found_error"}}</span>
+ </div>
+ {{/if}}
+ {{else}}
+ {{#if @report.hasData}}
+ {{#if @report.currentMode}}
+ {{component
+ @report.modeComponent
+ }}
+
+ {{#if @report.model.relatedReport}}
+ <AdminReport
+ @showFilteringUI={{false}}
+ @dataSourceName={{@report.model.relatedReport.type}}
+ />
+ {{/if}}
+ {{/if}}
+ {{else}}
+ {{#if @report.rateLimitationString}}
+ <div class="alert alert-error report-alert rate-limited">
+ {{icon "temperature-three-quarters"}}
+ <span>{{@report.rateLimitationString}}</span>
+ </div>
+ {{else}}
+ <div class="alert alert-info report-alert no-data">
+ {{icon "chart-pie"}}
+ {{#if @report.model.reportUrl}}
+ <a href={{@report.model.reportUrl}} class="report-url">
+ <span>
+ {{#if @report.model.title}}
+ {{@report.model.title}}
+ —
+ {{/if}}
+ {{i18n "admin.dashboard.reports.no_data"}}
+ </span>
+ </a>
+ {{else}}
+ <span>{{i18n "admin.dashboard.reports.no_data"}}</span>
+ {{/if}}
+ </div>
+ {{/if}}
+ {{/if}}
+ {{/if}}
+ </div>
+
+ {{#if @report.showFilteringUI}}
+ <div class="filters">
+ {{#if @report.showModes}}
+ <div class="modes">
+ {{#each @report.displayedModes as |displayedMode|}}
+ <DButton
+ @action={{fn @report.onChangeMode displayedMode.mode}}
+ @icon={{displayedMode.icon}}
+ class={{displayedMode.cssClass}}
+ />
+ {{/each}}
+ </div>
+ {{/if}}
+
+ {{#if @report.isChartMode}}
+ {{#if @report.model.average}}
+ <span class="average-chart">
+ {{i18n "admin.dashboard.reports.average_chart_label"}}
+ </span>
+ {{/if}}
+ <div class="chart-groupings">
+ {{#each @report.chartGroupings as |chartGrouping|}}
+ <DButton
+ @label={{chartGrouping.label}}
+ @action={{fn @report.changeGrouping chartGrouping.id}}
+ @disabled={{chartGrouping.disabled}}
+ class={{chartGrouping.class}}
+ />
+ {{/each}}
+ </div>
+ {{/if}}
+
+ {{#if @report.showDatesOptions}}
+ <div class="control">
+ <span class="label">
+ {{i18n "admin.dashboard.reports.dates"}}
+ </span>
+
+ <div class="input">
+ <DateTimeInputRange
+ @from={{@report.startDate}}
+ @to={{@report.endDate}}
+ @onChange={{@report.onChangeDateRange}}
+ @showFromTime={{false}}
+ @showToTime={{false}}
+ />
+ </div>
+ </div>
+ {{/if}}
+
+ {{#each @report.model.available_filters as |filter|}}
+ <div class="control">
+ <span class="label">
+ {{i18n
+ (concat
+ "admin.dashboard.reports.filters." filter.id ".label"
+ )
+ }}
+ </span>
+
+ <div class="input">
+ {{component
+ (@report.reportFilterComponent filter)
+ filter=filter
+ }}
+ </div>
+ </div>
+ {{/each}}
+
+ <div class="control">
+ <div class="input">
+ <DButton
+ @action={{@report.exportCsv}}
+ @label="admin.export_csv.button_text"
+ @icon="download"
+ class="btn-default export-csv-btn"
+ />
+ </div>
+ </div>
+
+ {{#if @report.showRefresh}}
+ <div class="control">
+ <div class="input">
+ <DButton
+ @action={{@report.refreshReport}}
+ @label="admin.dashboard.reports.refresh_report"
+ @icon="arrows-rotate"
+ class="refresh-report-btn btn-primary"
+ />
+ </div>
+ </div>
+ {{/if}}
+ </div>
+ {{/if}}
+ </div>
+ </ConditionalLoadingSection>
+ {{/unless}}
+ </div>
+</template>
diff --git a/frontend/discourse/admin/components/admin-report-new.gjs b/frontend/discourse/admin/components/admin-report-new.gjs
new file mode 100644
index 00000000000..f971b86b805
--- /dev/null
+++ b/frontend/discourse/admin/components/admin-report-new.gjs
@@ -0,0 +1,258 @@
+import { concat, fn } from "@ember/helper";
+import didUpdate from "@ember/render-modifiers/modifiers/did-update";
+import AdminReport from "discourse/admin/components/admin-report";
+import ConditionalLoadingSection from "discourse/components/conditional-loading-section";
+import DButton from "discourse/components/d-button";
+import DPageSubheader from "discourse/components/d-page-subheader";
+import DateTimeInputRange from "discourse/components/date-time-input-range";
+import DTooltip from "discourse/float-kit/components/d-tooltip";
+import concatClass from "discourse/helpers/concat-class";
+import icon from "discourse/helpers/d-icon";
+import number from "discourse/helpers/number";
+import { and } from "discourse/truth-helpers";
+import { i18n } from "discourse-i18n";
+
+<template>
+ <div
+ class={{concatClass "admin-report" @report.reportClasses}}
+ {{didUpdate @report.fetchOrRender @filters.startDate @filters.endDate}}
+ >
+ {{#unless @report.isHidden}}
+ <ConditionalLoadingSection @isLoading={{@report.isLoading}}>
+ {{#if
+ (and @report.siteSettings.reporting_improvements @report.model.legacy)
+ }}
+ <div class="alert alert-info">
+ {{icon "triangle-exclamation"}}
+ <span>{{i18n "admin.reports.legacy_warning"}}</span>
+ </div>
+ {{/if}}
+ {{#if @report.showHeader}}
+ <div class="header">
+ {{#unless @report.showNotFoundError}}
+ <DPageSubheader
+ @titleLabel={{@report.model.title}}
+ @titleUrl={{@report.model.reportUrl}}
+ @learnMoreUrl={{@report.model.description_link}}
+ />
+
+ {{#if @report.showDescriptionInTooltip}}
+ {{#if @report.model.description}}
+ <DTooltip
+ @interactive={{@report.model.description_link.length}}
+ >
+ <:trigger>
+ {{icon "circle-question"}}
+ </:trigger>
+ <:content>
+ {{#if @report.model.description_link}}
+ <a
+ target="_blank"
+ rel="noopener noreferrer"
+ href={{@report.model.description_link}}
+ class="info"
+ >
+ {{@report.model.description}}
+ </a>
+ {{else}}
+ <span>{{@report.model.description}}</span>
+ {{/if}}
+ </:content>
+ </DTooltip>
+ {{/if}}
+ {{/if}}
+ {{/unless}}
+
+ {{#if @report.shouldDisplayTrend}}
+ <div class="trend {{@report.model.trend}}">
+ <span class="value" title={{@report.model.trendTitle}}>
+ {{#if @report.model.average}}
+ {{number @report.model.currentAverage}}{{#if
+ @report.model.percent
+ }}%{{/if}}
+ {{else}}
+ {{number @report.model.currentTotal noTitle="true"}}{{#if
+ @report.model.percent
+ }}%{{/if}}
+ {{/if}}
+
+ {{#if @report.model.trendIcon}}
+ {{icon @report.model.trendIcon class="icon"}}
+ {{/if}}
+ </span>
+ </div>
+ {{/if}}
+ </div>
+ {{/if}}
+
+ <div class="chart__wrapper">
+ {{#if @report.showFilteringUI}}
+ <div class="chart__filters">
+ {{#if @report.isChartMode}}
+
+ <div
+ class="chart-groupings"
+ role="tablist"
+ aria-label={{i18n
+ "admin.dashboard.reports.chart_group_period"
+ }}
+ >
+ {{#each @report.chartGroupings as |chartGrouping|}}
+ <DButton
+ @label={{chartGrouping.label}}
+ @action={{fn @report.changeGrouping chartGrouping.id}}
+ @disabled={{chartGrouping.disabled}}
+ class={{chartGrouping.class}}
+ role="tab"
+ />
+ {{/each}}
+ </div>
+ {{/if}}
+
+ {{#if @report.showDatesOptions}}
+ <div class="chart__dates">
+ <DateTimeInputRange
+ @from={{@report.startDate}}
+ @to={{@report.endDate}}
+ @onChange={{@report.onChangeDateRange}}
+ @showFromTime={{false}}
+ @showToTime={{false}}
+ />
+ </div>
+ {{/if}}
+
+ <div class="chart__additional-filters">
+ {{#each @report.model.available_filters as |filter|}}
+ <div
+ class={{concatClass
+ "chart__filter"
+ (concat "--" filter.id)
+ }}
+ >
+ <div class="input">
+ {{component
+ (@report.reportFilterComponent filter)
+ filter=filter
+ }}
+ </div>
+ </div>
+ {{/each}}
+ </div>
+
+ </div>
+ {{/if}}
+ <div class="chart__body">
+ {{#if (and @report.model.average @report.showFilteringUI)}}
+ <div class="average-chart">
+ {{i18n "admin.dashboard.reports.average_chart_label"}}
+ </div>
+ {{/if}}
+ {{#if @report.showError}}
+ {{#if @report.showTimeoutError}}
+ <div class="alert alert-error report-alert timeout">
+ {{icon "triangle-exclamation"}}
+ <span>{{i18n "admin.dashboard.timeout_error"}}</span>
+ </div>
+ {{/if}}
+
+ {{#if @report.showExceptionError}}
+ <div class="alert alert-error report-alert exception">
+ {{icon "triangle-exclamation"}}
+ <span>{{i18n "admin.dashboard.exception_error"}}</span>
+ </div>
+ {{/if}}
+
+ {{#if @report.showNotFoundError}}
+ <div class="alert alert-error report-alert not-found">
+ {{icon "triangle-exclamation"}}
+ <span>{{i18n "admin.dashboard.not_found_error"}}</span>
+ </div>
+ {{/if}}
+ {{else}}
+ {{#if @report.hasData}}
+ {{#if @report.currentMode}}
+ {{component
+ @report.modeComponent
+ }}
+
+ {{#if @report.model.relatedReport}}
+ <AdminReport
+ @showFilteringUI={{false}}
+ @dataSourceName={{@report.model.relatedReport.type}}
+ />
+ {{/if}}
+ {{/if}}
+ {{else}}
+ {{#if @report.rateLimitationString}}
+ <div class="alert alert-error report-alert rate-limited">
+ {{icon "temperature-three-quarters"}}
+ <span>{{@report.rateLimitationString}}</span>
+ </div>
+ {{else}}
+ <div class="alert alert-info report-alert no-data">
+ {{icon "chart-pie"}}
+ {{#if @report.model.reportUrl}}
+ <a href={{@report.model.reportUrl}} class="report-url">
+ <span>
+ {{#if @report.model.title}}
+ {{@report.model.title}}
+ —
+ {{/if}}
+ {{i18n "admin.dashboard.reports.no_data"}}
+ </span>
+ </a>
+ {{else}}
+ <span>{{i18n "admin.dashboard.reports.no_data"}}</span>
+ {{/if}}
+ </div>
+ {{/if}}
+ {{/if}}
+ {{/if}}
+ </div>
+ {{#if @report.showFilteringUI}}
+ <div class="chart__actions">
+ {{#if @report.showModes}}
+ <div class="chart__modes">
+ {{#each @report.displayedModes as |displayedMode|}}
+ <DButton
+ @action={{fn @report.onChangeMode displayedMode.mode}}
+ @icon={{displayedMode.icon}}
+ class={{displayedMode.cssClass}}
+ />
+ {{/each}}
+ </div>
+ {{/if}}
+ <div class="control">
+ <div class="input">
+ <DButton
+ @action={{@report.exportCsv}}
+ @label="admin.export_csv.button_text"
+ @icon="download"
+ class="btn-default export-csv-btn"
+ />
+ </div>
+ </div>
+
+ {{#if @report.showRefresh}}
+ <div class="control">
+ <div class="input">
+ <DButton
+ @action={{@report.refreshReport}}
+ @label="admin.dashboard.reports.refresh_report"
+ @icon="arrows-rotate"
+ class="refresh-report-btn btn-default"
+ />
+ </div>
+ </div>
+ {{/if}}
+ </div>
+ {{/if}}
+ </div>
+ </ConditionalLoadingSection>
+ {{/unless}}
+ </div>
+</template>
diff --git a/frontend/discourse/admin/components/admin-report-stacked-chart.gjs b/frontend/discourse/admin/components/admin-report-stacked-chart.gjs
index dcc8dbfd4e6..c8e8bea73a8 100644
--- a/frontend/discourse/admin/components/admin-report-stacked-chart.gjs
+++ b/frontend/discourse/admin/components/admin-report-stacked-chart.gjs
@@ -4,18 +4,82 @@ import { number } from "discourse/lib/formatter";
import { makeArray } from "discourse/lib/helpers";
import Chart from "./chart";
+function getCSSColor(varName) {
+ return getComputedStyle(document.documentElement)
+ .getPropertyValue(varName)
+ .trim();
+}
+
+function hexToRgba(hex, alpha) {
+ const r = parseInt(hex.slice(1, 3), 16);
+ const g = parseInt(hex.slice(3, 5), 16);
+ const b = parseInt(hex.slice(5, 7), 16);
+ return `rgba(${r}, ${g}, ${b}, ${alpha})`;
+}
+
+const emptyTooltipPlugin = {
+ id: "emptyTooltipPlugin",
+ beforeDraw(chart) {
+ const tooltip = chart.tooltip;
+ if (!tooltip || tooltip.opacity === 0) {
+ return;
+ }
+ const allZero = tooltip.dataPoints?.every((dp) => !dp.parsed.y);
+ if (allZero) {
+ tooltip.opacity = 0;
+ }
+ },
+};
+
+const gradientPlugin = {
+ id: "gradientPlugin",
+ beforeDatasetsDraw(chart) {
+ const { ctx } = chart;
+ chart.data.datasets.forEach((dataset, datasetIndex) => {
+ if (!dataset._baseColor) {
+ return;
+ }
+ const meta = chart.getDatasetMeta(datasetIndex);
+ if (!meta.data.length) {
+ return;
+ }
+
+ const gradients = meta.data.map((bar) => {
+ const { x, y, width, base } = bar.getProps(
+ ["x", "y", "width", "base"],
+ true
+ );
+ if (!x || !y || !width || !base) {
+ return;
+ }
+ const gradient = ctx.createLinearGradient(
+ x - width / 2,
+ y,
+ x + width / 2,
+ base
+ );
+ gradient.addColorStop(0, dataset._baseColor);
+ gradient.addColorStop(1, hexToRgba(dataset._baseColor, 0.7));
+ return gradient;
+ });
+
+ dataset.backgroundColor = gradients;
+ });
+ },
+};
+
export default class AdminReportStackedChart extends Component {
get chartConfig() {
- const { model } = this.args;
+ const { model, options } = this.args;
- const options = this.args.options || {};
- options.hiddenLabels ??= [];
+ const chartOptions = options || {};
+ chartOptions.hiddenLabels ??= [];
const chartData = makeArray(model.chartData || model.data).map(
(series) => ({
label: series.label,
color: series.color,
- data: Report.collapse(model, series.data),
+ data: Report.collapse(model, series.data, chartOptions.chartGrouping),
req: series.req,
})
);
@@ -27,32 +91,106 @@ export default class AdminReportStackedChart extends Component {
stack: "pageviews-stack",
data: series.data,
backgroundColor: series.color,
- hidden: options.hiddenLabels.includes(series.req),
+ _baseColor: series.color, // Store for gradient plugin
+ hidden: chartOptions.hiddenLabels.includes(series.req),
+ borderRadius: 2,
+ maxBarThickness: 30,
})),
};
+ // max Y value so chart remains constant when data changes
+ const stackedTotals = [];
+ for (let i = 0; i < chartData[0].data.length; i++) {
+ let total = 0;
+ for (const value of chartData) {
+ total += value.data[i]?.y || 0;
+ }
+ stackedTotals.push(total);
+ }
+ const maxStackedValue = Math.max(...stackedTotals);
+
+ const prefersReducedMotion = window.matchMedia(
+ "(prefers-reduced-motion: reduce)"
+ ).matches;
+
return {
type: "bar",
data,
+ plugins: [gradientPlugin, emptyTooltipPlugin],
options: {
responsive: true,
maintainAspectRatio: false,
- responsiveAnimationDuration: 0,
hover: { mode: "index" },
animation: {
- duration: 0,
+ duration: prefersReducedMotion ? 0 : 300,
},
plugins: {
+ legend: {
+ display: true,
+ position: "bottom",
+ onClick: (e, legendItem, legend) => {
+ const index = legendItem.datasetIndex;
+ const ci = legend.chart;
+ const req = chartData[index].req;
+
+ if (ci.isDatasetVisible(index)) {
+ ci.hide(index);
+ if (!chartOptions.hiddenLabels.includes(req)) {
+ chartOptions.hiddenLabels.push(req);
+ }
+ } else {
+ ci.show(index);
+ chartOptions.hiddenLabels = chartOptions.hiddenLabels.filter(
+ (l) => l !== req
+ );
+ }
+ },
+ labels: {
+ usePointStyle: true,
+ pointStyle: "rectRounded",
+ padding: 25,
+ boxWidth: 10,
+ boxHeight: 10,
+ generateLabels: (chart) => {
+ const textColor = getCSSColor("--primary-high");
+ return chart.data.datasets.map((dataset, i) => {
+ const isVisible = chart.isDatasetVisible(i);
+ return {
+ text: dataset.label,
+ fontColor: textColor,
+ fillStyle: isVisible ? dataset._baseColor : "transparent",
+ strokeStyle: dataset._baseColor,
+ lineWidth: 2,
+ hidden: false,
+ datasetIndex: i,
+ pointStyle: "rectRounded",
+ };
+ });
+ },
+ },
+ },
tooltip: {
mode: "index",
intersect: false,
+ backgroundColor: getCSSColor("--primary"),
+ titleMarginBottom: 16,
+ footerMarginTop: 16,
+ padding: {
+ left: 20,
+ right: 20,
+ top: 12,
+ bottom: 12,
+ },
+ bodySpacing: 8,
+ cornerRadius: 8,
+ boxPadding: 4,
callbacks: {
beforeFooter: (tooltipItem) => {
const total = tooltipItem.reduce(
(sum, item) => sum + parseInt(item.parsed.y || 0, 10),
0
);
- return `= ${total}`;
+ return `Total: ${total}`;
},
title: (tooltipItem) =>
moment(tooltipItem[0].parsed.x).format("LL"),
@@ -72,25 +210,33 @@ export default class AdminReportStackedChart extends Component {
y: {
stacked: true,
display: true,
+ max: maxStackedValue,
+ grid: {
+ color: getCSSColor("--primary-very-low"),
+ },
ticks: {
callback: (label) => number(label),
sampleSize: 5,
maxRotation: 25,
- minRotation: 25,
+ minRotation: 0,
+ step: 1,
},
},
x: {
stacked: true,
display: true,
+
grid: { display: false },
type: "time",
time: {
- unit: Report.unitForDatapoints(data.labels.length),
+ unit: chartOptions.chartGrouping
+ ? Report.unitForGrouping(chartOptions.chartGrouping)
+ : Report.unitForDatapoints(data.labels.length),
},
ticks: {
sampleSize: 5,
maxRotation: 50,
- minRotation: 50,
+ minRotation: 0,
},
},
},
diff --git a/frontend/discourse/admin/components/admin-report.gjs b/frontend/discourse/admin/components/admin-report.gjs
index 20da814fc2b..a78a1cfdadd 100644
--- a/frontend/discourse/admin/components/admin-report.gjs
+++ b/frontend/discourse/admin/components/admin-report.gjs
@@ -1,14 +1,14 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
-import { concat, fn } from "@ember/helper";
import EmberObject, { action } from "@ember/object";
-import didUpdate from "@ember/render-modifiers/modifiers/did-update";
import { next } from "@ember/runloop";
import { service } from "@ember/service";
import { isPresent } from "@ember/utils";
import AdminReportChart from "discourse/admin/components/admin-report-chart";
import AdminReportCounters from "discourse/admin/components/admin-report-counters";
import AdminReportInlineTable from "discourse/admin/components/admin-report-inline-table";
+import AdminReportLegacy from "discourse/admin/components/admin-report-legacy";
+import AdminReportNew from "discourse/admin/components/admin-report-new";
import AdminReportRadar from "discourse/admin/components/admin-report-radar";
import AdminReportStackedChart from "discourse/admin/components/admin-report-stacked-chart";
import AdminReportStackedLineChart from "discourse/admin/components/admin-report-stacked-line-chart";
@@ -23,14 +23,6 @@ import Report, {
DAILY_LIMIT_DAYS,
SCHEMA_VERSION,
} from "discourse/admin/models/report";
-import ConditionalLoadingSection from "discourse/components/conditional-loading-section";
-import DButton from "discourse/components/d-button";
-import DPageSubheader from "discourse/components/d-page-subheader";
-import DateTimeInputRange from "discourse/components/date-time-input-range";
-import DTooltip from "discourse/float-kit/components/d-tooltip";
-import concatClass from "discourse/helpers/concat-class";
-import icon from "discourse/helpers/d-icon";
-import number from "discourse/helpers/number";
import { reportModeComponent } from "discourse/lib/admin-report-additional-modes";
import { uniqueItemsFromArray } from "discourse/lib/array-tools";
import { bind } from "discourse/lib/decorators";
@@ -39,7 +31,6 @@ import { exportEntity } from "discourse/lib/export-csv";
import { outputExportResult } from "discourse/lib/export-result";
import { makeArray } from "discourse/lib/helpers";
import ReportLoader from "discourse/lib/reports-loader";
-import { and } from "discourse/truth-helpers";
import { i18n } from "discourse-i18n";
const TABLE_OPTIONS = {
@@ -184,7 +175,11 @@ export default class AdminReport extends Component {
}
get isChartMode() {
- return this.currentMode === REPORT_MODES.chart;
+ return (
+ this.currentMode === REPORT_MODES.chart ||
+ this.currentMode === REPORT_MODES.stacked_chart ||
+ this.currentMode === REPORT_MODES.stacked_line_chart
+ );
}
@action
@@ -284,11 +279,14 @@ export default class AdminReport extends Component {
const chartGrouping = this.options?.chartGrouping;
const options = ["daily", "weekly", "monthly"];
+ const dataLength = Array.isArray(this.model.chartData?.[0]?.data)
+ ? this.model.chartData[0].data.length
+ : this.model.chartData?.length || 0;
+
return options.map((id) => {
return {
id,
- disabled:
- id === "daily" && this.model.chartData.length >= DAILY_LIMIT_DAYS,
+ disabled: id === "daily" && dataLength >= DAILY_LIMIT_DAYS,
label: `admin.dashboard.reports.${id}`,
class: `chart-grouping ${chartGrouping === id ? "active" : "inactive"}`,
};
@@ -350,6 +348,10 @@ export default class AdminReport extends Component {
Object.assign(args, customFilters);
}
+ if (this.options?.hiddenLabels?.length) {
+ args.hidden_labels = this.options.hiddenLabels.join(",");
+ }
+
exportEntity("report", args).then(outputExportResult);
}
@@ -486,11 +488,19 @@ export default class AdminReport extends Component {
Object.assign(chartOptions, this.args.reportOptions?.chart || {}, {
chartGrouping:
this.args.reportOptions?.chartGrouping ||
+ report.default_group_by ||
Report.groupingForDatapoints(report.chartData.length),
})
);
} else if (mode === REPORT_MODES.stacked_chart) {
- return this.args.reportOptions?.stackedChart || {};
+ const stackedChartOptions = this.args.reportOptions?.stackedChart || {};
+ const firstSeriesData = report.chartData?.[0]?.data || [];
+ return Object.assign(stackedChartOptions, {
+ chartGrouping:
+ this.args.reportOptions?.chartGrouping ||
+ report.default_group_by ||
+ Report.groupingForDatapoints(firstSeriesData.length),
+ });
}
}
@@ -528,248 +538,10 @@ export default class AdminReport extends Component {
}
<template>
- <div
- class={{concatClass "admin-report" this.reportClasses}}
- {{didUpdate this.fetchOrRender @filters.startDate @filters.endDate}}
- >
- {{#unless this.isHidden}}
- <ConditionalLoadingSection @isLoading={{this.isLoading}}>
- {{#if
- (and this.siteSettings.reporting_improvements this.model.legacy)
- }}
- <div class="alert alert-info">
- {{icon "triangle-exclamation"}}
- <span>{{i18n "admin.reports.legacy_warning"}}</span>
- </div>
- {{/if}}
- {{#if this.showHeader}}
- <div class="header">
- {{#unless this.showNotFoundError}}
- <DPageSubheader
- @titleLabel={{this.model.title}}
- @titleUrl={{this.model.reportUrl}}
- @descriptionLabel={{unless
- this.showDescriptionInTooltip
- this.model.description
- }}
- @learnMoreUrl={{this.model.description_link}}
- />
-
- {{#if this.showDescriptionInTooltip}}
- {{#if this.model.description}}
- <DTooltip
- @interactive={{this.model.description_link.length}}
- >
- <:trigger>
- {{icon "circle-question"}}
- </:trigger>
- <:content>
- {{#if this.model.description_link}}
- <a
- target="_blank"
- rel="noopener noreferrer"
- href={{this.model.description_link}}
- class="info"
- >
- {{this.model.description}}
- </a>
- {{else}}
- <span>{{this.model.description}}</span>
- {{/if}}
- </:content>
- </DTooltip>
- {{/if}}
- {{/if}}
- {{/unless}}
-
- {{#if this.shouldDisplayTrend}}
- <div class="trend {{this.model.trend}}">
- <span class="value" title={{this.model.trendTitle}}>
- {{#if this.model.average}}
- {{number this.model.currentAverage}}{{#if
- this.model.percent
- }}%{{/if}}
- {{else}}
- {{number this.model.currentTotal noTitle="true"}}{{#if
- this.model.percent
- }}%{{/if}}
- {{/if}}
-
- {{#if this.model.trendIcon}}
- {{icon this.model.trendIcon class="icon"}}
- {{/if}}
- </span>
- </div>
- {{/if}}
- </div>
- {{/if}}
-
- <div class="body">
- <div class="main">
- {{#if this.showError}}
- {{#if this.showTimeoutError}}
- <div class="alert alert-error report-alert timeout">
- {{icon "triangle-exclamation"}}
- <span>{{i18n "admin.dashboard.timeout_error"}}</span>
- </div>
- {{/if}}
-
- {{#if this.showExceptionError}}
- <div class="alert alert-error report-alert exception">
- {{icon "triangle-exclamation"}}
- <span>{{i18n "admin.dashboard.exception_error"}}</span>
- </div>
- {{/if}}
-
- {{#if this.showNotFoundError}}
- <div class="alert alert-error report-alert not-found">
- {{icon "triangle-exclamation"}}
- <span>{{i18n "admin.dashboard.not_found_error"}}</span>
- </div>
- {{/if}}
- {{else}}
- {{#if this.hasData}}
- {{#if this.currentMode}}
- {{component
- this.modeComponent
- model=this.model
- options=this.options
- }}
-
- {{#if this.model.relatedReport}}
- <AdminReport
- @showFilteringUI={{false}}
- @dataSourceName={{this.model.relatedReport.type}}
- />
- {{/if}}
- {{/if}}
- {{else}}
- {{#if this.rateLimitationString}}
- <div class="alert alert-error report-alert rate-limited">
- {{icon "temperature-three-quarters"}}
- <span>{{this.rateLimitationString}}</span>
- </div>
- {{else}}
- <div class="alert alert-info report-alert no-data">
- {{icon "chart-pie"}}
- {{#if this.model.reportUrl}}
- <a href={{this.model.reportUrl}} class="report-url">
- <span>
- {{#if this.model.title}}
- {{this.model.title}}
- —
- {{/if}}
- {{i18n "admin.dashboard.reports.no_data"}}
- </span>
- </a>
- {{else}}
- <span>{{i18n "admin.dashboard.reports.no_data"}}</span>
- {{/if}}
- </div>
- {{/if}}
- {{/if}}
- {{/if}}
- </div>
-
- {{#if this.showFilteringUI}}
- <div class="filters">
- {{#if this.showModes}}
- <div class="modes">
- {{#each this.displayedModes as |displayedMode|}}
- <DButton
- @action={{fn this.onChangeMode displayedMode.mode}}
- @icon={{displayedMode.icon}}
- class={{displayedMode.cssClass}}
- />
- {{/each}}
- </div>
- {{/if}}
-
- {{#if this.isChartMode}}
- {{#if this.model.average}}
- <span class="average-chart">
- {{i18n "admin.dashboard.reports.average_chart_label"}}
- </span>
- {{/if}}
- <div class="chart-groupings">
- {{#each this.chartGroupings as |chartGrouping|}}
- <DButton
- @label={{chartGrouping.label}}
- @action={{fn this.changeGrouping chartGrouping.id}}
- @disabled={{chartGrouping.disabled}}
- class={{chartGrouping.class}}
- />
- {{/each}}
- </div>
- {{/if}}
-
- {{#if this.showDatesOptions}}
- <div class="control">
- <span class="label">
- {{i18n "admin.dashboard.reports.dates"}}
- </span>
-
- <div class="input">
- <DateTimeInputRange
- @from={{this.startDate}}
- @to={{this.endDate}}
- @onChange={{this.onChangeDateRange}}
- @showFromTime={{false}}
- @showToTime={{false}}
- />
- </div>
- </div>
- {{/if}}
-
- {{#each this.model.available_filters as |filter|}}
- <div class="control">
- <span class="label">
- {{i18n
- (concat
- "admin.dashboard.reports.filters." filter.id ".label"
- )
- }}
- </span>
-
- <div class="input">
- {{component
- (this.reportFilterComponent filter)
- model=this.model
- filter=filter
- applyFilter=this.applyFilter
- }}
- </div>
- </div>
- {{/each}}
-
- <div class="control">
- <div class="input">
- <DButton
- @action={{this.exportCsv}}
- @label="admin.export_csv.button_text"
- @icon="download"
- class="btn-default export-csv-btn"
- />
- </div>
- </div>
-
- {{#if this.showRefresh}}
- <div class="control">
- <div class="input">
- <DButton
- @action={{this.refreshReport}}
- @label="admin.dashboard.reports.refresh_report"
- @icon="arrows-rotate"
- class="refresh-report-btn btn-primary"
- />
- </div>
- </div>
- {{/if}}
- </div>
- {{/if}}
- </div>
- </ConditionalLoadingSection>
- {{/unless}}
- </div>
+ {{#if this.siteSettings.reporting_improvements}}
+ <AdminReportNew @report={{this}} @filters={{@filters}} />
+ {{else}}
+ <AdminReportLegacy @report={{this}} @filters={{@filters}} />
+ {{/if}}
</template>
}
diff --git a/frontend/discourse/admin/components/report-filters/bool.gjs b/frontend/discourse/admin/components/report-filters/bool.gjs
index 2c4d0fdffcb..2cc9c8c469d 100644
--- a/frontend/discourse/admin/components/report-filters/bool.gjs
+++ b/frontend/discourse/admin/components/report-filters/bool.gjs
@@ -1,7 +1,9 @@
import { Input } from "@ember/component";
+import { concat } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
import FilterComponent from "discourse/admin/components/report-filters/filter";
+import { i18n } from "discourse-i18n";
export default class Bool extends FilterComponent {
checked = false;
@@ -17,10 +19,15 @@ export default class Bool extends FilterComponent {
}
<template>
- <Input
- @type="checkbox"
- @checked={{this.checked}}
- {{on "click" this.onChange}}
- />
+ <label class="chart__filter-label checkbox-label">
+ <Input
+ @type="checkbox"
+ @checked={{this.checked}}
+ {{on "click" this.onChange}}
+ />
+ {{i18n
+ (concat "admin.dashboard.reports.filters." this.filter.id ".label")
+ }}
+ </label>
</template>
}
diff --git a/frontend/discourse/admin/templates/admin-reports.gjs b/frontend/discourse/admin/templates/admin-reports.gjs
index 77739690484..35b188fae64 100644
--- a/frontend/discourse/admin/templates/admin-reports.gjs
+++ b/frontend/discourse/admin/templates/admin-reports.gjs
@@ -21,30 +21,32 @@ export default <template>
</DPageHeader>
{{/if}}
{{else}}
- <DPageHeader
- @titleLabel={{i18n "admin.config.reports.title"}}
- @descriptionLabel={{i18n "admin.config.reports.header_description"}}
- @learnMoreUrl="https://meta.discourse.org/t/-/240233"
- @hideTabs={{@controller.hideTabs}}
- >
- <:breadcrumbs>
- <DBreadcrumbsItem @path="/admin" @label={{i18n "admin_title"}} />
- <DBreadcrumbsItem
- @path="/admin/reports"
- @label={{i18n "admin.config.reports.title"}}
- />
- </:breadcrumbs>
- <:tabs>
- <NavItem
- @route="adminReports.dashboardSettings"
- @label="admin.config.reports.sub_pages.settings.title"
- />
- <NavItem
- @route="adminReports.index"
- @label="admin.config.reports.title"
- />
- </:tabs>
- </DPageHeader>
+ {{#if @controller.showHeader}}
+ <DPageHeader
+ @titleLabel={{i18n "admin.config.reports.title"}}
+ @descriptionLabel={{i18n "admin.config.reports.header_description"}}
+ @learnMoreUrl="https://meta.discourse.org/t/-/240233"
+ @hideTabs={{@controller.hideTabs}}
+ >
+ <:breadcrumbs>
+ <DBreadcrumbsItem @path="/admin" @label={{i18n "admin_title"}} />
+ <DBreadcrumbsItem
+ @path="/admin/reports"
+ @label={{i18n "admin.config.reports.title"}}
+ />
+ </:breadcrumbs>
+ <:tabs>
+ <NavItem
+ @route="adminReports.dashboardSettings"
+ @label="admin.config.reports.sub_pages.settings.title"
+ />
+ <NavItem
+ @route="adminReports.index"
+ @label="admin.config.reports.title"
+ />
+ </:tabs>
+ </DPageHeader>
+ {{/if}}
{{/if}}
<div class="admin-container admin-config-page__main-area">
diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/admin-report-sentiment-analysis.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/admin-report-sentiment-analysis.gjs
index e31ef507ec6..43dfa64f981 100644
--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/admin-report-sentiment-analysis.gjs
+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/admin-report-sentiment-analysis.gjs
@@ -30,6 +30,7 @@ import DoughnutChart from "./doughnut-chart";
export default class AdminReportSentimentAnalysis extends Component {
@service router;
+ @service siteSettings;
@tracked selectedChart = null;
@tracked posts = [];
@@ -330,7 +331,7 @@ export default class AdminReportSentimentAnalysis extends Component {
<span {{didInsert this.openToChart}}></span>
{{#unless this.showingSelectedChart}}
- <div class="admin-report-sentiment-analysis">
+ {{#if this.siteSettings.reporting_improvements}}
<table class="sentiment-analysis-table md-table">
<thead>
<th>{{this.groupingType}}</th>
@@ -380,7 +381,59 @@ export default class AdminReportSentimentAnalysis extends Component {
{{/each}}
</tbody>
</table>
- </div>
+ {{else}}
+ <div class="admin-report-sentiment-analysis">
+ <table class="sentiment-analysis-table md-table">
+ <thead>
+ <th>{{this.groupingType}}</th>
+ <th>{{i18n
+ "discourse_ai.sentiments.sentiment_analysis.table.total_count"
+ }}</th>
+ <th>{{i18n
+ "discourse_ai.sentiments.sentiment_analysis.table.sentiment"
+ }}</th>
+ </thead>
+
+ <tbody>
+ {{#each this.transformedData as |data|}}
+ <tr
+ class="sentiment-analysis-table__row"
+ role="button"
+ {{on "click" (fn this.showDetails data)}}
+ >
+ <td class="sentiment-analysis-table__title">
+ {{#if data.category}}
+ {{categoryBadge data.category}}
+ {{else}}
+ {{data.title}}
+ {{/if}}
+ </td>
+ <td
+ class="sentiment-analysis-table__total-score"
+ >{{data.total_score}}</td>
+ <td class="sentiment-horizontal-bar">
+ <AiSentimentHorizontalBar
+ @type="positive"
+ @score={{data.score_map.positive}}
+ @width={{data.widths.positive}}
+ />
+ <AiSentimentHorizontalBar
+ @type="negative"
+ @score={{data.score_map.negative}}
+ @width={{data.widths.negative}}
+ />
+ <AiSentimentHorizontalBar
+ @type="neutral"
+ @score={{data.score_map.neutral}}
+ @width={{data.widths.neutral}}
+ />
+ </td>
+ </tr>
+ {{/each}}
+ </tbody>
+ </table>
+ </div>
+ {{/if}}
{{/unless}}
{{#if (and this.selectedChart this.showingSelectedChart)}}
diff --git a/plugins/discourse-ai/assets/stylesheets/modules/sentiment/common/dashboard.scss b/plugins/discourse-ai/assets/stylesheets/modules/sentiment/common/dashboard.scss
index 8ce5132f713..abc24ff5c00 100644
--- a/plugins/discourse-ai/assets/stylesheets/modules/sentiment/common/dashboard.scss
+++ b/plugins/discourse-ai/assets/stylesheets/modules/sentiment/common/dashboard.scss
@@ -13,108 +13,57 @@
}
}
-@mixin report-container-box() {
- border: 1px solid var(--primary-low);
- border-radius: var(--d-border-radius);
- padding: 1rem;
-}
-
-.admin-report.sentiment-analysis .body {
- display: flex;
- flex-flow: row wrap;
- gap: 1rem;
-
- .filters {
- @include report-container-box;
- order: 1;
- width: 100%;
- margin-left: 0;
- flex-flow: row wrap;
- align-items: flex-start;
- justify-content: flex-start;
- gap: 0.5rem;
-
- .control {
- min-width: 200px;
- }
-
- .control:nth-of-type(-n + 4) {
- flex: 1;
- }
+.admin-report.sentiment-analysis {
+ --d-sentiment-report-positive-rgb: 46, 204, 112;
+ --d-sentiment-report-neutral-rgb: 149, 166, 167;
+ --d-sentiment-report-negative-rgb: 231, 77, 60;
- // Hides tag selector when showing subcategories selector
- .control:nth-of-type(6):nth-last-of-type(3) {
- display: none;
+ .chart {
+ &__wrapper {
+ display: flex;
+ gap: 1rem;
}
- .control:last-child {
- align-self: flex-end;
+ &__body {
+ display: flex;
+ flex-flow: row wrap;
+ align-items: flex-start;
+ position: relative;
}
- .control:has(.export-csv-btn) {
- display: none;
+ &__filters {
+ // Hides tag selector when showing subcategories selector
+ .chart__filter.--include_subcategories ~ .chart__filter.--tag {
+ display: none;
+ }
}
}
- .main {
- flex: 100%;
- display: flex;
- flex-flow: row wrap;
- order: 2;
- align-items: flex-start;
- max-height: 100vh;
+ .control:has(.export-csv-btn) {
+ display: none;
}
-}
-
-.admin-report-sentiment-analysis {
- @include report-container-box;
- flex: 2;
- display: flex;
- gap: 2rem 1rem;
- justify-content: space-evenly;
- align-items: center;
- flex-flow: row wrap;
- padding-inline: 0;
- padding-block: 1.5rem;
- .admin-report-doughnut {
- padding: 0.25rem;
+ .doughnut-chart-title {
+ @include ellipsis;
+ margin: 0 auto;
+ margin-top: 1rem;
+ text-align: center;
+ font-size: var(--font-up-2);
}
- &__chart-wrapper {
- height: fit-content;
- position: relative;
- transition:
- transform 0.25s ease,
- box-shadow 0.25s ease;
- border-radius: var(--d-border-radius);
-
- .doughnut-chart-title {
- @include ellipsis;
- margin: 0 auto;
- margin-top: 1rem;
- text-align: center;
- }
-
- &:hover {
- box-shadow: var(--shadow-card);
- transform: translateY(-0.5rem);
- cursor: pointer;
+ .admin-report-doughnut {
+ .chart-canvas-container {
+ width: 300px;
+ height: 300px;
}
}
+}
+.admin-report-sentiment-analysis {
&__selected-chart {
border: 1px solid var(--primary-low);
border-radius: var(--d-border-radius);
padding: 1rem;
-
- .doughnut-chart-title {
- font-size: var(--font-up-2);
- margin: 0 auto;
- text-align: center;
- margin-top: 0.3rem;
- padding-top: 2rem;
- }
}
&__selected-chart-actions {
@@ -133,14 +82,10 @@
}
}
-:root {
- --d-sentiment-report-positive-rgb: 46, 204, 112;
- --d-sentiment-report-neutral-rgb: 149, 166, 167;
- --d-sentiment-report-negative-rgb: 231, 77, 60;
-}
-
.admin-report-sentiment-analysis-details {
- @include report-container-box;
+ border: 1px solid var(--primary-low);
+ border-radius: var(--d-border-radius);
+ padding: 1rem;
flex: 1 1 300px;
min-width: 300px;
margin-left: 1rem;
@@ -224,10 +169,8 @@
height: 100%;
}
}
-}
-.admin-reports.admin-contents .sentiment-analysis {
- .horizontal-overflow-nav {
+ nav.horizontal-overflow-nav {
background: var(--secondary);
position: sticky;
top: 0;
@@ -238,8 +181,7 @@
.showing-sentiment-analysis-chart
.admin-report.sentiment-analysis
- .body
- .filters {
+ .chart__filters {
// Hide elements 2 - 6 when showing selected chart
// as they're not supported being changed in this view
.control:first-of-type {
@@ -252,16 +194,8 @@
}
.sentiment-analysis-table {
- margin: 1rem;
-
- &__total-score {
- font-weight: bold;
- font-size: var(--font-up-1);
- }
-
- &__row {
- cursor: pointer;
- }
+ font-weight: bold;
+ font-size: var(--font-up-1);
}
.sentiment-horizontal-bar {
diff --git a/spec/jobs/export_csv_file_spec.rb b/spec/jobs/export_csv_file_spec.rb
index af06020ff87..ce24c2c65d7 100644
--- a/spec/jobs/export_csv_file_spec.rb
+++ b/spec/jobs/export_csv_file_spec.rb
@@ -269,6 +269,20 @@ RSpec.describe Jobs::ExportCsvFile do
expect(report[3]).to contain_exactly("2010-01-03", "3", "6", "9")
end
+ it "works with stacked_chart reports and hidden_labels" do
+ ApplicationRequest.create!(date: "2010-01-01", req_type: "page_view_logged_in", count: 1)
+ ApplicationRequest.create!(date: "2010-01-01", req_type: "page_view_anon", count: 4)
+ ApplicationRequest.create!(date: "2010-01-01", req_type: "page_view_crawler", count: 7)
+
+ exporter.extra["name"] = "consolidated_page_views"
+ exporter.extra["hidden_labels"] = "page_view_crawler"
+
+ report = export_report
+
+ expect(report[0]).to contain_exactly("Day", "Logged in users", "Anonymous users")
+ expect(report[1]).to contain_exactly("2010-01-01", "1", "4")
+ end
+
it "works with posts reports and filters" do
category = Fabricate(:category)
subcategory = Fabricate(:category, parent_category: category)
diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb
index 27e0fd0bf2f..1e1c1a3de2e 100644
--- a/spec/models/report_spec.rb
+++ b/spec/models/report_spec.rb
@@ -158,6 +158,47 @@ RSpec.describe Report do
expect(report.prev30Days).to eq(2)
end
end
+
+ context "when reporting_improvements is enabled" do
+ before { SiteSetting.reporting_improvements = true }
+
+ fab!(:user)
+ fab!(:user_2, :user)
+
+ it "returns a stacked chart with desktop and mobile series" do
+ freeze_time_safe
+ user.user_visits.create!(visited_at: 1.day.ago, mobile: false)
+ user_2.user_visits.create!(visited_at: 1.day.ago, mobile: true)
+ user.user_visits.create!(visited_at: 2.days.ago, mobile: false)
+
+ expect(report.modes).to eq([Report::MODES[:stacked_chart]])
+ expect(report.default_group_by).to eq("weekly")
+ expect(report.data.length).to eq(2)
+ expect(report.data[0][:req]).to eq("desktop")
+ expect(report.data[1][:req]).to eq("mobile")
+ expect(report.data[0][:data].length).to eq(2)
+ expect(report.data[1][:data].length).to eq(1)
+ expect(report.total).to eq(3)
+ expect(report.prev30Days).to eq(0)
+ end
+
+ it "filters by group" do
+ freeze_time_safe
+ group = Fabricate(:group)
+ group.add(user)
+
+ user.user_visits.create!(visited_at: 1.day.ago, mobile: false)
+ user_2.user_visits.create!(visited_at: 1.day.ago, mobile: true)
+
+ filtered_report = Report.find("visits", filters: { group: group.id })
+
+ desktop_data = filtered_report.data[0][:data]
+ mobile_data = filtered_report.data[1][:data]
+
+ expect(desktop_data.length).to eq(1)
+ expect(mobile_data.length).to eq(0)
+ end
+ end
end
describe "mobile visits report" do