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

Commit ddad365

Browse files
UX: Use new DStatTiles reusable component from core
1 parent 04c4ff8 commit ddad365

File tree

5 files changed

+51
-122
lines changed

5 files changed

+51
-122
lines changed

assets/javascripts/discourse/components/ai-spam.gjs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import AdminConfigAreaCard from "admin/components/admin-config-area-card";
1717
import AdminPageSubheader from "admin/components/admin-page-subheader";
1818
import ComboBox from "select-kit/components/combo-box";
1919
import SpamTestModal from "./modal/spam-test-modal";
20+
import DStatTiles from "discourse/components/d-stat-tiles";
2021

2122
export default class AiSpam extends Component {
2223
@service siteSettings;
@@ -121,7 +122,7 @@ export default class AiSpam extends Component {
121122

122123
get metrics() {
123124
const detected = {
124-
label: "discourse_ai.spam.spam_detected",
125+
label: i18n("discourse_ai.spam.spam_detected"),
125126
value: this.stats.spam_detected,
126127
};
127128
if (this.args.model.flagging_username) {
@@ -131,16 +132,16 @@ export default class AiSpam extends Component {
131132
}
132133
return [
133134
{
134-
label: "discourse_ai.spam.scanned_count",
135+
label: i18n("discourse_ai.spam.scanned_count"),
135136
value: this.stats.scanned_count,
136137
},
137138
detected,
138139
{
139-
label: "discourse_ai.spam.false_positives",
140+
label: i18n("discourse_ai.spam.false_positives"),
140141
value: this.stats.false_positives,
141142
},
142143
{
143-
label: "discourse_ai.spam.false_negatives",
144+
label: i18n("discourse_ai.spam.false_negatives"),
144145
value: this.stats.false_negatives,
145146
},
146147
];
@@ -220,22 +221,15 @@ export default class AiSpam extends Component {
220221
class="ai-spam__stats"
221222
>
222223
<:content>
223-
<div class="ai-spam__metrics">
224+
<DStatTiles as |tiles|>
224225
{{#each this.metrics as |metric|}}
225-
<div class="ai-spam__metrics-item">
226-
<span class="ai-spam__metrics-label">{{i18n
227-
metric.label
228-
}}</span>
229-
{{#if metric.href}}
230-
<a href={{metric.href}} class="ai-spam__metrics-value">
231-
{{metric.value}}
232-
</a>
233-
{{else}}
234-
<span class="ai-spam__metrics-value">{{metric.value}}</span>
235-
{{/if}}
236-
</div>
226+
<tiles.Tile
227+
@label={{metric.label}}
228+
@url={{metric.href}}
229+
@value={{metric.value}}
230+
/>
237231
{{/each}}
238-
</div>
232+
</DStatTiles>
239233
</:content>
240234
</AdminConfigAreaCard>
241235
</div>

assets/javascripts/discourse/components/ai-usage.gjs

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Component from "@glimmer/component";
2+
import DStatTiles from "discourse/components/d-stat-tiles";
23
import { tracked } from "@glimmer/tracking";
34
import { fn, hash } from "@ember/helper";
45
import { action } from "@ember/object";
@@ -124,6 +125,32 @@ export default class AiUsage extends Component {
124125
return normalized;
125126
}
126127

128+
get metrics() {
129+
return [
130+
{
131+
label: i18n("discourse_ai.usage.total_requests"),
132+
value: this.data.summary.total_requests,
133+
tooltip: i18n("discourse_ai.usage.stat_tooltips.total_requests"),
134+
},
135+
{
136+
label: i18n("discourse_ai.usage.total_tokens"),
137+
value: this.data.summary.total_tokens,
138+
},
139+
{
140+
label: i18n("discourse_ai.usage.request_tokens"),
141+
value: this.data.summary.total_request_tokens,
142+
},
143+
{
144+
label: i18n("discourse_ai.usage.response_tokens"),
145+
value: this.data.summary.total_response_tokens,
146+
},
147+
{
148+
label: i18n("discourse_ai.usage.cached_tokens"),
149+
value: this.data.summary.total_cached_tokens,
150+
},
151+
];
152+
}
153+
127154
get chartConfig() {
128155
if (!this.data?.data) {
129156
return;
@@ -344,53 +371,16 @@ export default class AiUsage extends Component {
344371
class="ai-usage__summary"
345372
>
346373
<:content>
347-
<div class="ai-usage__summary-stats">
348-
<div class="ai-usage__summary-stat">
349-
<span class="label">{{i18n
350-
"discourse_ai.usage.total_requests"
351-
}}</span>
352-
<span
353-
class="value"
354-
title={{this.data.summary.total_requests}}
355-
>{{number this.data.summary.total_requests}}</span>
356-
</div>
357-
<div class="ai-usage__summary-stat">
358-
<span class="label">{{i18n
359-
"discourse_ai.usage.total_tokens"
360-
}}</span>
361-
<span
362-
class="value"
363-
title={{this.data.summary.total_tokens}}
364-
>{{number this.data.summary.total_tokens}}</span>
365-
</div>
366-
<div class="ai-usage__summary-stat">
367-
<span class="label">{{i18n
368-
"discourse_ai.usage.request_tokens"
369-
}}</span>
370-
<span
371-
class="value"
372-
title={{this.data.summary.total_request_tokens}}
373-
>{{number this.data.summary.total_request_tokens}}</span>
374-
</div>
375-
<div class="ai-usage__summary-stat">
376-
<span class="label">{{i18n
377-
"discourse_ai.usage.response_tokens"
378-
}}</span>
379-
<span
380-
class="value"
381-
title={{this.data.summary.total_response_tokens}}
382-
>{{number this.data.summary.total_response_tokens}}</span>
383-
</div>
384-
<div class="ai-usage__summary-stat">
385-
<span class="label">{{i18n
386-
"discourse_ai.usage.cached_tokens"
387-
}}</span>
388-
<span
389-
class="value"
390-
title={{this.data.summary.total_cached_tokens}}
391-
>{{number this.data.summary.total_cached_tokens}}</span>
392-
</div>
393-
</div>
374+
<DStatTiles as |tiles|>
375+
{{#each this.metrics as |metric|}}
376+
<tiles.Tile
377+
@label={{metric.label}}
378+
@href={{metric.href}}
379+
@value={{metric.value}}
380+
@tooltip={{metric.tooltip}}
381+
/>
382+
{{/each}}
383+
</DStatTiles>
394384
</:content>
395385
</AdminConfigAreaCard>
396386

assets/stylesheets/modules/llms/common/spam.scss

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -45,37 +45,6 @@
4545
&__stats {
4646
margin-top: 2em;
4747
}
48-
49-
&__stats-title {
50-
margin-bottom: 1em;
51-
}
52-
53-
&__metrics {
54-
display: grid;
55-
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
56-
gap: 1em;
57-
margin-bottom: 2em;
58-
}
59-
60-
&__metrics-item {
61-
display: flex;
62-
flex-direction: column;
63-
padding: 1em;
64-
background: var(--primary-very-low);
65-
border-radius: 0.25em;
66-
}
67-
68-
&__metrics-label {
69-
color: var(--primary-medium);
70-
font-size: 0.875em;
71-
margin-bottom: 0.5em;
72-
}
73-
74-
&__metrics-value {
75-
color: var(--primary);
76-
font-size: 1.5em;
77-
font-weight: bold;
78-
}
7948
}
8049

8150
.spam-test-modal {

assets/stylesheets/modules/llms/common/usage.scss

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,6 @@
6868
font-size: 1.2em;
6969
}
7070

71-
&__summary-stats {
72-
display: grid;
73-
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
74-
gap: 1em;
75-
}
76-
77-
&__summary-stat {
78-
display: flex;
79-
flex-direction: column;
80-
padding: 1em;
81-
background: var(--primary-very-low);
82-
border-radius: 0.25em;
83-
84-
.label {
85-
color: var(--primary-medium);
86-
font-size: 0.875em;
87-
margin-bottom: 0.5em;
88-
}
89-
90-
.value {
91-
color: var(--primary);
92-
font-size: 1.5em;
93-
font-weight: bold;
94-
}
95-
}
96-
9771
&__charts {
9872
margin-top: 2em;
9973
}

config/locales/client.en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ en:
182182
no_models: "No model usage data found"
183183
no_features: "No feature usage data found"
184184
subheader_description: "Tokens are the basic units that LLMs use to understand and generate text, usage data may affect costs."
185+
stat_tooltips:
186+
total_requests: "These are all requests made to LLMs through Discourse"
185187
periods:
186188
last_day: "Last 24 hours"
187189
last_week: "Last week"

0 commit comments

Comments
 (0)