@@ -5,6 +5,7 @@ import { action } from "@ember/object";
55import { LinkTo } from " @ember/routing" ;
66import { service } from " @ember/service" ;
77import { eq } from " truth-helpers" ;
8+ import ConditionalLoadingSpinner from " discourse/components/conditional-loading-spinner" ;
89import DButton from " discourse/components/d-button" ;
910import DateTimeInputRange from " discourse/components/date-time-input-range" ;
1011import avatar from " discourse/helpers/avatar" ;
@@ -24,18 +25,30 @@ export default class AiUsage extends Component {
2425 @tracked selectedModel;
2526 @tracked selectedPeriod = " month" ;
2627 @tracked isCustomDateActive = false ;
28+ @tracked loadingData = true ;
29+
30+ constructor () {
31+ super (... arguments );
32+ this .fetchData ();
33+ }
2734
2835 @action
2936 async fetchData () {
30- const response = await ajax (" /admin/plugins/discourse-ai/ai-usage.json" , {
31- data: {
32- start_date: moment (this .startDate ).format (" YYYY-MM-DD" ),
33- end_date: moment (this .endDate ).format (" YYYY-MM-DD" ),
34- feature: this .selectedFeature ,
35- model: this .selectedModel ,
36- },
37- });
37+ const response = await ajax (
38+ " /admin/plugins/discourse-ai/ai-usage-report.json" ,
39+ {
40+ data: {
41+ start_date: moment (this .startDate ).format (" YYYY-MM-DD" ),
42+ end_date: moment (this .endDate ).format (" YYYY-MM-DD" ),
43+ feature: this .selectedFeature ,
44+ model: this .selectedModel ,
45+ },
46+ }
47+ );
3848 this .data = response;
49+ this .loadingData = false ;
50+ this ._cachedFeatures = null ;
51+ this ._cachedModels = null ;
3952 }
4053
4154 @action
@@ -312,7 +325,7 @@ export default class AiUsage extends Component {
312325 />
313326 </div >
314327
315- {{# if this . data }}
328+ < ConditionalLoadingSpinner @ condition = {{ this .loadingData }} >
316329 <AdminConfigAreaCard
317330 @ heading =" discourse_ai.usage.summary"
318331 class =" ai-usage__summary"
@@ -492,7 +505,7 @@ export default class AiUsage extends Component {
492505 </: content >
493506 </AdminConfigAreaCard >
494507 </div >
495- {{/ if }}
508+ </ ConditionalLoadingSpinner >
496509 </div >
497510 </div >
498511 </template >
0 commit comments