A platform for community discussion. Free, open, simple.
UX: improve AI usage per user table layout (#36225)
Kris46eca8b784c1
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-usage.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-usage.gjsindex fcd8c92bf23..e0ae55f1c0f 100644--- a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-usage.gjs+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-usage.gjs@@ -20,7 +20,7 @@ import { ajax } from "discourse/lib/ajax";import { bind } from "discourse/lib/decorators";import { number } from "discourse/lib/formatter";import ComboBox from "discourse/select-kit/components/combo-box";-import { eq, gt, lt } from "discourse/truth-helpers";+import { eq, gt } from "discourse/truth-helpers";import { i18n } from "discourse-i18n";import AiCreditBar from "./ai-credit-bar";@@ -127,6 +127,13 @@ export default class AiUsage extends Component {return this.data.users.slice(start, end);}+ get userSplitPoint() {+ if (!this.data?.users) {+ return 0;+ }+ return Math.ceil(this.data.users.length / 2);+ }+normalizeTimeSeriesData(data) {if (!data?.length) {return [];@@ -614,58 +621,12 @@ export default class AiUsage extends Component {{{/unless}}{{#if this.data.users.length}}- <table+ <divclass={{concatClass- "ai-usage__users-table"- (if (lt this.data.users.length 25) "-double-width")+ "ai-usage__users-table-wrapper"+ (if (gt this.data.users.length 24) "-multi-column")}}>- <thead>- <tr>- <th class="ai-usage__users-username">{{i18n- "discourse_ai.usage.username"- }}</th>- <th>{{i18n "discourse_ai.usage.usage_count"}}</th>- <th>{{i18n "discourse_ai.usage.total_tokens"}}</th>- <th>{{i18n "discourse_ai.usage.total_spending"}}</th>- </tr>- </thead>- <tbody>- {{#each (this.takeUsers 0 24) as |user|}}- <tr class="ai-usage__users-row">- <td class="ai-usage__users-cell">- <div class="user-info">- <LinkTo- @route="user"- @model={{user.username}}- class="username"- >- {{avatar user imageSize="tiny"}}- {{user.username}}- </LinkTo>- </div></td>- <td- class="ai-usage__users-cell"- title={{user.usage_count}}- >{{number user.usage_count}}</td>- <td- class="ai-usage__users-cell"- title={{user.total_tokens}}- >{{number user.total_tokens}}</td>- <td>- {{this.totalSpending- user.input_spending- user.cache_read_spending- user.cache_write_spending- user.output_spending- }}- </td>- </tr>- {{/each}}- </tbody>- </table>-- {{#if (gt this.data.users.length 25)}}<table class="ai-usage__users-table"><thead><tr>@@ -678,7 +639,10 @@ export default class AiUsage extends Component {</tr></thead><tbody>- {{#each (this.takeUsers 25 49) as |user|}}+ {{#each+ (this.takeUsers 0 this.userSplitPoint)+ as |user|+ }}<tr class="ai-usage__users-row"><td class="ai-usage__users-cell"><div class="user-info">@@ -711,7 +675,60 @@ export default class AiUsage extends Component {{{/each}}</tbody></table>- {{/if}}++ {{#if (gt this.data.users.length 24)}}+ <table class="ai-usage__users-table">+ <thead>+ <tr>+ <th class="ai-usage__users-username">{{i18n+ "discourse_ai.usage.username"+ }}</th>+ <th>{{i18n "discourse_ai.usage.usage_count"}}</th>+ <th>{{i18n "discourse_ai.usage.total_tokens"}}</th>+ <th>{{i18n+ "discourse_ai.usage.total_spending"+ }}</th>+ </tr>+ </thead>+ <tbody>+ {{#each+ (this.takeUsers this.userSplitPoint 50)+ as |user|+ }}+ <tr class="ai-usage__users-row">+ <td class="ai-usage__users-cell">+ <div class="user-info">+ <LinkTo+ @route="user"+ @model={{user.username}}+ class="username"+ >+ {{avatar user imageSize="tiny"}}+ {{user.username}}+ </LinkTo>+ </div></td>+ <td+ class="ai-usage__users-cell"+ title={{user.usage_count}}+ >{{number user.usage_count}}</td>+ <td+ class="ai-usage__users-cell"+ title={{user.total_tokens}}+ >{{number user.total_tokens}}</td>+ <td>+ {{this.totalSpending+ user.input_spending+ user.cache_read_spending+ user.cache_write_spending+ user.output_spending+ }}+ </td>+ </tr>+ {{/each}}+ </tbody>+ </table>+ {{/if}}+ </div>{{/if}}</:content></AdminConfigAreaCard>diff --git a/plugins/discourse-ai/assets/stylesheets/modules/llms/common/usage.scss b/plugins/discourse-ai/assets/stylesheets/modules/llms/common/usage.scssindex 70dd0838a37..70280352679 100644--- a/plugins/discourse-ai/assets/stylesheets/modules/llms/common/usage.scss+++ b/plugins/discourse-ai/assets/stylesheets/modules/llms/common/usage.scss@@ -101,29 +101,30 @@&__users {grid-column: span 2;+ }- .admin-config-area-card__content {- display: flex;+ &__users-table-wrapper {+ &.-multi-column {+ display: grid;+ grid-template-columns: 1fr 1fr;+ gap: 2em;+ align-items: start;.ai-usage__users-table {- &:first-child {- margin-right: 2em;-- &.-double-width {- margin-right: 0;- }- }-- &.-double-width {- .ai-usage__users-username {- width: auto;- }- }-.ai-usage__users-username {width: 50px;}}++ @include viewport.until(md) {+ grid-template-columns: 1fr;+ }+ }++ &:not(.-multi-column) {+ .ai-usage__users-table .ai-usage__users-username {+ width: auto;+ }}}