11import Component from " @glimmer/component" ;
22import { tracked } from " @glimmer/tracking" ;
3- import { array } from " @ember/helper" ;
3+ import { hash } from " @ember/helper" ;
44import { action } from " @ember/object" ;
55import { service } from " @ember/service" ;
66import DatePicker from " discourse/components/date-picker" ;
@@ -18,12 +18,6 @@ export default class AiUsage extends Component {
1818 @tracked selectedModel;
1919 @tracked period = " day" ;
2020
21- constructor () {
22- super (... arguments );
23- console .log (this .args .model );
24- console .log (this .data );
25- }
26-
2721 @action
2822 async fetchData () {
2923 const response = await ajax (" /admin/plugins/discourse-ai/ai-usage.json" , {
@@ -48,20 +42,31 @@ export default class AiUsage extends Component {
4842 await this .fetchData ();
4943 }
5044
45+ @action
46+ onFeatureChanged (value ) {
47+ this .selectedFeature = value;
48+ this .onFilterChange ();
49+ }
50+
51+ @action
52+ onModelChanged (value ) {
53+ this .selectedModel = value;
54+ this .onFilterChange ();
55+ }
56+
5157 get chartConfig () {
52- console .log (" here" );
5358 if (! this .data ? .data ) {
5459 return ;
5560 }
5661
57- const x = {
62+ return {
5863 type: " line" ,
5964 data: {
60- labels: this .data .data .map (pair => pair[0 ]),
65+ labels: this .data .data .map (( pair ) => pair[0 ]),
6166 datasets: [
6267 {
6368 label: " Tokens" ,
64- data: this .data .data .map (pair => pair[1 ]),
69+ data: this .data .data .map (( pair ) => pair[1 ]),
6570 fill: false ,
6671 borderColor: " rgb(75, 192, 192)" ,
6772 tension: 0.1 ,
@@ -77,9 +82,20 @@ export default class AiUsage extends Component {
7782 },
7883 },
7984 };
85+ }
86+
87+ get availableFeatures () {
88+ return (this .data ? .features || []).map ((f ) => ({
89+ id: f .feature_name ,
90+ name: f .feature_name ,
91+ }));
92+ }
8093
81- console .log (x);
82- return x;
94+ get availableModels () {
95+ return (this .data ? .models || []).map ((m ) => ({
96+ id: m .llm ,
97+ name: m .llm ,
98+ }));
8399 }
84100
85101 <template >
@@ -96,18 +112,25 @@ export default class AiUsage extends Component {
96112 @ onChange ={{this .onDateChange }}
97113 class =" ai-usage__date-picker"
98114 />
99- </div >
100115
101- <div class =" ai-usage__filters-period" >
102- <label class =" ai-usage__period-label" >
103- {{i18n " discourse_ai.usage.period" }}
104- </label >
105- <ComboBox
106- @ value ={{this .period }}
107- @ content ={{array " hour" " day" " month" }}
108- @ onChange ={{this .onFilterChange }}
109- class =" ai-usage__period-selector"
110- />
116+ <div class =" ai-usage__filters-row" >
117+ <ComboBox
118+ @ value ={{this .selectedFeature }}
119+ @ content ={{this .availableFeatures }}
120+ @ onChange ={{this .onFeatureChanged }}
121+ @ options ={{hash none =" discourse_ai.usage.all_features" }}
122+ class =" ai-usage__feature-selector"
123+ />
124+
125+ <ComboBox
126+ @ value ={{this .selectedModel }}
127+ @ content ={{this .availableModels }}
128+ @ onChange ={{this .onModelChanged }}
129+ @ options ={{hash none =" discourse_ai.usage.all_models" }}
130+ class =" ai-usage__model-selector"
131+ />
132+ </div >
133+
111134 </div >
112135
113136 {{#if this . data }}
@@ -126,7 +149,10 @@ export default class AiUsage extends Component {
126149 <h3 class =" ai-usage__chart-title" >
127150 {{i18n " discourse_ai.usage.tokens_over_time" }}
128151 </h3 >
129- <Chart @ chartConfig ={{this .chartConfig }} class =" ai-usage__chart" />
152+ <Chart
153+ @ chartConfig ={{this .chartConfig }}
154+ class =" ai-usage__chart"
155+ />
130156 </div >
131157
132158 <div class =" ai-usage__breakdowns" >
0 commit comments