Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit d28bdfc

Browse files
committed
FIX: component import error for non-admins
1 parent 91b4521 commit d28bdfc

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

assets/javascripts/discourse/components/doughnut-chart.gjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export default class DoughnutChart extends Component {
6060
}
6161

6262
<template>
63-
<Chart @chartConfig={{this.config}} class="admin-report-doughnut" />
63+
{{#if this.config}}
64+
<Chart @chartConfig={{this.config}} class="admin-report-doughnut" />
65+
{{/if}}
6466
</template>
6567
}

assets/javascripts/initializers/admin-reports.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { withPluginApi } from "discourse/lib/plugin-api";
22
import AdminReportEmotion from "discourse/plugins/discourse-ai/discourse/components/admin-report-emotion";
3-
import AdminReportSentimentAnalysis from "../discourse/components/admin-report-sentiment-analysis";
43

54
export default {
65
name: "discourse-ai-admin-reports",
@@ -11,7 +10,13 @@ export default {
1110
return;
1211
}
1312

14-
withPluginApi("2.0.1", (api) => {
13+
// We need to import dynamically with CommonJS require because
14+
// using ESM import would cause the component to be imported globally
15+
// and cause errors for non-admin users since the component is only available to admins
16+
const AdminReportSentimentAnalysis =
17+
require("discourse/plugins/discourse-ai/discourse/components/admin-report-sentiment-analysis").default;
18+
19+
withPluginApi((api) => {
1520
api.registerReportModeComponent("emotion", AdminReportEmotion);
1621
api.registerReportModeComponent(
1722
"sentiment_analysis",

0 commit comments

Comments
 (0)