Skip to content

A platform for community discussion. Free, open, simple.

UX: Improve AI logs filtering (#42759)

Sam4b550140c8d8
diff --git a/frontend/discourse/app/ui-kit/d-filter-controls.gjs b/frontend/discourse/app/ui-kit/d-filter-controls.gjs
index 15e842d5a87..a4678ce0ae3 100644
--- a/frontend/discourse/app/ui-kit/d-filter-controls.gjs
+++ b/frontend/discourse/app/ui-kit/d-filter-controls.gjs
@@ -45,9 +45,11 @@ const ResetButton = <template>
* @param {String|Object} [defaultDropdownValue="all"] - Default dropdown value(s). For single dropdown: "all",
* for multiple: { dropdown1: "all", dropdown2: "all" }
* @param {String|Object} [dropdownValue] - Current dropdown value(s), defaults to defaultDropdownValue
+ * @param {Boolean} [showDropdownFilterToggle] - Whether to render the dropdown drawer toggle. Defaults to true for multiple dropdowns or when forced.
* @param {Boolean} [forceShowDropdownFilterToggle=false] - Whether to place a single dropdown behind the filter toggle
* @param {String} [noResultsMessage] - Message shown when no results found
* @param {Boolean} [showNoResults=true] - Whether to show the built-in no-results state
+ * @param {Boolean} [showTextFilter=true] - Whether to show the text filter input
* @param {Boolean} [showResetButton=true] - Whether to show the reset filters button
* @param {Boolean} [loading] - Whether data is loading (hides reset button during loading)
* @param {Number} [minItemsForFilter] - Minimum items before showing filters (default: always show)
@@ -92,6 +94,10 @@ export default class DFilterControls extends Component {
}
get initialTextFilterValue() {
+ if (!this.showTextFilter) {
+ return "";
+ }
+
// reading router.currentURL makes this getter re-evaluate on transitions,
// so same-route links carrying the query param re-seed the input
const fromUrl =
@@ -152,7 +158,10 @@ export default class DFilterControls extends Component {
}
get showDropdownFilterToggle() {
- return this.hasMultipleDropdowns || this.args.forceShowDropdownFilterToggle;
+ return (
+ this.args.showDropdownFilterToggle ??
+ (this.hasMultipleDropdowns || this.args.forceShowDropdownFilterToggle)
+ );
}
get showDropdownFilter() {
@@ -173,6 +182,10 @@ export default class DFilterControls extends Component {
);
}
+ get showTextFilter() {
+ return this.args.showTextFilter ?? true;
+ }
+
get showResetButton() {
return this.args.showResetButton ?? true;
}
@@ -279,6 +292,19 @@ export default class DFilterControls extends Component {
return defaults[key] || "all";
}
+ @action
+ dropdownLabel(key) {
+ const options = this.dropdownOptions[key] || [];
+ return options.find((option) => option.value === this.defaultValue(key))
+ ?.label;
+ }
+
+ get singleDropdownLabel() {
+ return this.dropdownOptions.find(
+ (option) => option.value === this.defaultDropdownValue
+ )?.label;
+ }
+
@action
applyDropdownsFromUrl() {
if (!this.showFilters || !this.hasUrlOwnedDropdowns) {
@@ -420,7 +446,11 @@ export default class DFilterControls extends Component {
}
schedule("afterRender", () => {
- document.querySelector(".d-filter-controls__input")?.focus();
+ (
+ document.querySelector(".d-filter-controls__input") ||
+ document.querySelector(".d-filter-controls__toggle-filters") ||
+ document.querySelector(".d-filter-controls__dropdown")
+ )?.focus();
});
}
@@ -448,31 +478,35 @@ export default class DFilterControls extends Component {
@dropdownValue
}}
>
- <div class="d-filter-controls__inputs">
- <DFilterInput
- placeholder={{@inputPlaceholder}}
- @filterAction={{this.onTextFilterChange}}
- @value={{this.textFilter}}
- class="d-filter-controls__input"
- @icons={{hash left="magnifying-glass"}}
- />
-
- {{#if this.showDropdownFilterToggle}}
- <DButton
- class="btn-default d-filter-controls__toggle-filters"
- @icon={{if
- this.showDropdownFilter
- "filter-circle-xmark"
- "filter"
- }}
- @title="filter_controls.toggle"
- @action={{this.toggleFilters}}
- />
- {{#if (and this.showResetButton this.hasActiveFilters)}}
- <ResetButton @action={{this.resetFilters}} />
+ {{#if (or this.showTextFilter this.showDropdownFilterToggle)}}
+ <div class="d-filter-controls__inputs">
+ {{#if this.showTextFilter}}
+ <DFilterInput
+ placeholder={{@inputPlaceholder}}
+ @filterAction={{this.onTextFilterChange}}
+ @value={{this.textFilter}}
+ class="d-filter-controls__input"
+ @icons={{hash left="magnifying-glass"}}
+ />
{{/if}}
- {{/if}}
- </div>
+
+ {{#if this.showDropdownFilterToggle}}
+ <DButton
+ class="btn-default d-filter-controls__toggle-filters"
+ @icon={{if
+ this.showDropdownFilter
+ "filter-circle-xmark"
+ "filter"
+ }}
+ @title="filter_controls.toggle"
+ @action={{this.toggleFilters}}
+ />
+ {{#if (and this.showResetButton this.hasActiveFilters)}}
+ <ResetButton @action={{this.resetFilters}} />
+ {{/if}}
+ {{/if}}
+ </div>
+ {{/if}}
{{#if this.showDropdownFilter}}
<div class="d-filter-controls__dropdowns">
@@ -492,6 +526,7 @@ export default class DFilterControls extends Component {
"--active"
)
}}
+ aria-label={{this.dropdownLabel key}}
data-dropdown-key={{key}}
as |select|
>
@@ -514,6 +549,7 @@ export default class DFilterControls extends Component {
"--active"
)
}}
+ aria-label={{this.singleDropdownLabel}}
as |select|
>
{{#each this.dropdownOptions as |option|}}
diff --git a/frontend/discourse/tests/integration/ui-kit/d-filter-controls-test.gjs b/frontend/discourse/tests/integration/ui-kit/d-filter-controls-test.gjs
index 151b0631e17..51809c2ed5e 100644
--- a/frontend/discourse/tests/integration/ui-kit/d-filter-controls-test.gjs
+++ b/frontend/discourse/tests/integration/ui-kit/d-filter-controls-test.gjs
@@ -79,6 +79,73 @@ module("Integration | ui-kit | DFilterControls", function (hooks) {
.hasAttribute("placeholder", "Search...", "has correct placeholder");
});
+ test("can hide the text filter without affecting other controls", async function (assert) {
+ this.set("data", SAMPLE_DATA);
+ this.set("dropdownOptions", {
+ category: SAMPLE_DROPDOWN_OPTIONS,
+ });
+ this.set("resetCount", 0);
+ this.set("onReset", () => this.set("resetCount", this.resetCount + 1));
+
+ await render(
+ <template>
+ <DFilterControls
+ @array={{this.data}}
+ @dropdownOptions={{this.dropdownOptions}}
+ @showTextFilter={{false}}
+ @onResetFilters={{this.onReset}}
+ >
+ <:actions>
+ <button type="button" class="custom-action">Custom action</button>
+ </:actions>
+ <:content as |filteredData|>
+ <div class="results">{{filteredData.length}}</div>
+ </:content>
+ </DFilterControls>
+ </template>
+ );
+
+ assert
+ .dom(".d-filter-controls__input")
+ .doesNotExist("hides the text input");
+ assert
+ .dom(".d-filter-controls__dropdown--category")
+ .hasAttribute("aria-label", "All", "labels the dropdown filter");
+ assert.dom(".custom-action").exists("renders yielded actions");
+ assert.dom(".results").hasText("3", "renders yielded content");
+
+ await select(".d-filter-controls__dropdown--category", "feature");
+ await click(".d-filter-controls__reset");
+
+ assert.strictEqual(this.resetCount, 1, "calls the reset callback once");
+ assert
+ .dom(".d-filter-controls__dropdown--category")
+ .hasValue("all", "resets dropdown filters");
+ assert
+ .dom(".d-filter-controls__input")
+ .doesNotExist("keeps the input hidden");
+ assert
+ .dom(".d-filter-controls__toggle-filters")
+ .isFocused("moves focus to the remaining filter control");
+ });
+
+ test("does not render an empty inputs container when text filtering is hidden", async function (assert) {
+ await render(
+ <template>
+ <DFilterControls @array={{SAMPLE_DATA}} @showTextFilter={{false}}>
+ <:content as |filteredData|>
+ <div class="results">{{filteredData.length}}</div>
+ </:content>
+ </DFilterControls>
+ </template>
+ );
+
+ assert
+ .dom(".d-filter-controls__inputs")
+ .doesNotExist("omits the empty inputs container");
+ assert.dom(".results").hasText("3", "still renders yielded content");
+ });
+
test("filters data by text (client-side)", async function (assert) {
this.set("data", SAMPLE_DATA);
this.set("searchableProps", ["name", "description"]);
@@ -172,6 +239,36 @@ module("Integration | ui-kit | DFilterControls", function (hooks) {
.exists("reveals the dropdown after toggling filters");
});
+ test("can show expanded dropdowns without a filter toggle", async function (assert) {
+ this.set("data", SAMPLE_DATA);
+ this.set("dropdownOptions", {
+ category: SAMPLE_DROPDOWN_OPTIONS,
+ status: [
+ { label: "All statuses", value: "all" },
+ { label: "Enabled", value: "enabled" },
+ ],
+ });
+
+ await render(
+ <template>
+ <DFilterControls
+ @array={{this.data}}
+ @dropdownOptions={{this.dropdownOptions}}
+ @filterDropdownsExpanded={{true}}
+ @showDropdownFilterToggle={{false}}
+ @showTextFilter={{false}}
+ />
+ </template>
+ );
+
+ assert
+ .dom(".d-filter-controls__toggle-filters")
+ .doesNotExist("hides the filter toggle");
+ assert
+ .dom(".d-filter-controls__dropdown")
+ .exists({ count: 2 }, "keeps the dropdowns expanded");
+ });
+
test("shows one reset button with a forced single-dropdown toggle", async function (assert) {
this.set("data", SAMPLE_DATA);
this.set("searchableProps", ["name"]);
diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-logs.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-logs.gjs
index 53a59b69a74..189680c1ceb 100644
--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-logs.gjs
+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-logs.gjs
@@ -1,5 +1,5 @@
import Component from "@glimmer/component";
-import { tracked } from "@glimmer/tracking";
+import { cached, tracked } from "@glimmer/tracking";
import { fn, hash } from "@ember/helper";
import { action } from "@ember/object";
import { next } from "@ember/runloop";
@@ -13,6 +13,7 @@ import { eq } from "discourse/truth-helpers";
import DButton from "discourse/ui-kit/d-button";
import DConditionalLoadingSpinner from "discourse/ui-kit/d-conditional-loading-spinner";
import DDateTimeInputRange from "discourse/ui-kit/d-date-time-input-range";
+import DFilterControls from "discourse/ui-kit/d-filter-controls";
import DLoadMore from "discourse/ui-kit/d-load-more";
import DPageSubheader from "discourse/ui-kit/d-page-subheader";
import { i18n } from "discourse-i18n";
@@ -128,9 +129,6 @@ export default class AiLogs extends Component {
return {
period: this.selectedPeriod,
date_range: { from: this.startDate, to: this.endDate },
- outcome: this.selectedOutcome || ALL_FILTER_VALUE,
- model: this.selectedModel || ALL_FILTER_VALUE,
- feature: this.selectedFeature,
usernames: this.selectedUsernames,
has_retries: this.hasRetries,
unattributed: this.unattributed,
@@ -150,8 +148,15 @@ export default class AiLogs extends Component {
get outcomeOptions() {
return [
- { id: "successful", name: i18n("discourse_ai.logs.successful") },
- { id: "failed", name: i18n("discourse_ai.logs.failed") },
+ {
+ value: ALL_FILTER_VALUE,
+ label: i18n("discourse_ai.logs.all_outcomes"),
+ },
+ {
+ value: "successful",
+ label: i18n("discourse_ai.logs.successful"),
+ },
+ { value: "failed", label: i18n("discourse_ai.logs.failed") },
];
}
@@ -163,11 +168,67 @@ export default class AiLogs extends Component {
];
}
+ @cached
get modelOptions() {
- return this.models.map((model) => ({
- id: String(model.id),
- name: model.name,
+ const options = this.models.map((model) => ({
+ value: String(model.id),
+ label: model.name,
}));
+
+ if (
+ this.selectedModel &&
+ !options.some((option) => option.value === this.selectedModel)
+ ) {
+ options.push({ value: this.selectedModel, label: this.selectedModel });
+ }
+
+ return [
+ { value: ALL_FILTER_VALUE, label: i18n("discourse_ai.logs.all_models") },
+ ...options,
+ ];
+ }
+
+ @cached
+ get featureOptions() {
+ const features = [...this.features];
+ if (this.selectedFeature && !features.includes(this.selectedFeature)) {
+ features.push(this.selectedFeature);
+ }
+
+ return [
+ {
+ value: ALL_FILTER_VALUE,
+ label: i18n("discourse_ai.logs.all_features"),
+ },
+ ...features.map((feature) => ({ value: feature, label: feature })),
+ ];
+ }
+
+ @cached
+ get dropdownOptions() {
+ return {
+ outcome: this.outcomeOptions,
+ model: this.modelOptions,
+ feature: this.featureOptions,
+ };
+ }
+
+ @cached
+ get dropdownValues() {
+ return {
+ outcome: this.selectedOutcome || ALL_FILTER_VALUE,
+ model: this.selectedModel || ALL_FILTER_VALUE,
+ feature: this.selectedFeature || ALL_FILTER_VALUE,
+ };
+ }
+
+ @cached
+ get defaultDropdownValues() {
+ return {
+ outcome: ALL_FILTER_VALUE,
+ model: ALL_FILTER_VALUE,
+ feature: ALL_FILTER_VALUE,
+ };
}
get hasFilters() {
@@ -183,29 +244,6 @@ export default class AiLogs extends Component {
);
}
- get lifecycleSummary() {
- const detailed = this.meta.retention?.detailed_days ?? 0;
- const summary = this.meta.retention?.summary_days ?? 0;
-
- if (detailed === 0 && summary === 0) {
- return i18n("discourse_ai.logs.retention.lifecycle.complete_forever");
- }
- if (detailed === 0) {
- return i18n("discourse_ai.logs.retention.lifecycle.detail_until_delete", {
- summary,
- });
- }
- if (summary === 0) {
- return i18n("discourse_ai.logs.retention.lifecycle.summary_forever", {
- detailed,
- });
- }
- return i18n("discourse_ai.logs.retention.lifecycle.finite", {
- detailed,
- summary,
- });
- }
-
get requestParams() {
const params = {
outcome: this.selectedOutcome || undefined,
@@ -259,7 +297,7 @@ export default class AiLogs extends Component {
}
updateUrl(extra = {}) {
- this.router.transitionTo(this.router.currentRouteName, {
+ return this.router.transitionTo(this.router.currentRouteName, {
queryParams: { ...this.queryParams, ...extra },
});
}
@@ -277,7 +315,7 @@ export default class AiLogs extends Component {
}
@action
- async refresh() {
+ async refresh({ focusFilters = false } = {}) {
const requestId = ++this._requestId;
this.loading = true;
this.loadingMore = false;
@@ -300,7 +338,16 @@ export default class AiLogs extends Component {
result.features || this.features,
result.logs
);
- this.updateUrl();
+ await this.updateUrl();
+ if (focusFilters) {
+ next(() =>
+ document
+ .querySelector(
+ ".ai-logs .d-filter-controls__toggle-filters, .ai-logs .d-filter-controls__dropdown"
+ )
+ ?.focus()
+ );
+ }
} catch (error) {
if (
requestId === this._requestId &&
@@ -374,11 +421,6 @@ export default class AiLogs extends Component {
this.selectedPeriod = data.period || undefined;
this.startDate = data.date_range?.from || this.startDate;
this.endDate = data.date_range?.to || this.endDate;
- this.selectedOutcome =
- data.outcome === ALL_FILTER_VALUE ? undefined : data.outcome;
- this.selectedModel =
- data.model === ALL_FILTER_VALUE ? undefined : data.model;
- this.selectedFeature = data.feature || undefined;
this.hasRetries = Boolean(data.has_retries);
this.unattributed = Boolean(data.unattributed);
this.selectedUsernames = this.unattributed ? [] : data.usernames || [];
@@ -412,18 +454,17 @@ export default class AiLogs extends Component {
}
@action
- changeOutcome(value, { set }) {
- set("outcome", value);
- this.selectedOutcome =
- value === ALL_FILTER_VALUE ? undefined : value || undefined;
- this.refresh();
- }
+ changeDropdown(key, value) {
+ const selectedValue = value === ALL_FILTER_VALUE ? undefined : value;
+
+ if (key === "outcome") {
+ this.selectedOutcome = selectedValue;
+ } else if (key === "model") {
+ this.selectedModel = selectedValue;
+ } else if (key === "feature") {
+ this.selectedFeature = selectedValue;
+ }
- @action
- changeModel(value, { set }) {
- set("model", value);
- this.selectedModel =
- value === ALL_FILTER_VALUE ? undefined : value || undefined;
this.refresh();
}
@@ -455,12 +496,6 @@ export default class AiLogs extends Component {
this.refresh();
}
- @action
- setFeature(value, { set }) {
- set("feature", value);
- this.selectedFeature = value || undefined;
- }
-
@action
setIdValue(value, { set }) {
set("id_value", value);
@@ -484,9 +519,6 @@ export default class AiLogs extends Component {
from: moment().subtract(24, "hours").toDate(),
to: new Date(),
},
- outcome: ALL_FILTER_VALUE,
- model: ALL_FILTER_VALUE,
- feature: undefined,
usernames: [],
has_retries: false,
unattributed: false,
@@ -505,7 +537,7 @@ export default class AiLogs extends Component {
this.unattributed = false;
this.idType = "id";
this.idValue = undefined;
- this.refresh();
+ this.refresh({ focusFilters: true });
}
@action
@@ -569,17 +601,6 @@ export default class AiLogs extends Component {
</:actions>
</DPageSubheader>
- <aside class="ai-logs__retention">
- <p class="ai-logs__retention-warning">{{i18n
- "discourse_ai.logs.sensitive_warning"
- }}</p>
- <DButton
- class="btn-transparent ai-logs__retention-action"
- @action={{this.configureRetention}}
- @translatedLabel={{this.lifecycleSummary}}
- />
- </aside>
-
<Form
class="ai-logs__filters"
@data={{this.filterFormData}}
@@ -630,149 +651,111 @@ export default class AiLogs extends Component {
</form.Fieldset>
{{/if}}
- <div class="ai-logs__filter-grid">
- <form.Field
- class="ai-logs__outcome-filter"
- @name="outcome"
- @title={{i18n "discourse_ai.logs.outcome"}}
- @type="select"
- @onSet={{this.changeOutcome}}
- as |field|
- >
- <field.Control @includeNone={{false}} as |select|>
- <select.Option @value={{ALL_FILTER_VALUE}}>{{i18n
- "discourse_ai.logs.all_outcomes"
- }}</select.Option>
- {{#each this.outcomeOptions as |outcome|}}
- <select.Option @value={{outcome.id}}>
- {{outcome.name}}
- </select.Option>
- {{/each}}
- </field.Control>
- </form.Field>
-
- <form.Field
- class="ai-logs__model-filter"
- @name="model"
- @title={{i18n "discourse_ai.logs.model"}}
- @type="select"
- @onSet={{this.changeModel}}
- as |field|
- >
- <field.Control @includeNone={{false}} as |select|>
- <select.Option @value={{ALL_FILTER_VALUE}}>{{i18n
- "discourse_ai.logs.all_models"
- }}</select.Option>
- {{#each this.modelOptions as |model|}}
- <select.Option @value={{model.id}}>
- {{model.name}}
- </select.Option>
- {{/each}}
- </field.Control>
- </form.Field>
-
- <form.Field
- class="ai-logs__feature-filter"
- @name="feature"
- @title={{i18n "discourse_ai.logs.feature"}}
- @type="input"
- @onSet={{this.setFeature}}
- as |field|
- >
- <field.Control
- placeholder={{i18n "discourse_ai.logs.feature_placeholder"}}
- list="ai-log-features"
- />
- </form.Field>
- <datalist id="ai-log-features">
- {{#each this.features as |feature|}}
- <option value={{feature}}></option>
- {{/each}}
- </datalist>
+ <form.Fieldset
+ class="ai-logs__filter-panel"
+ @name="log-filters"
+ @title={{i18n "discourse_ai.logs.filters.title"}}
+ >
+ <DFilterControls
+ @array={{this.logs}}
+ @dropdownOptions={{this.dropdownOptions}}
+ @dropdownValue={{this.dropdownValues}}
+ @defaultDropdownValue={{this.defaultDropdownValues}}
+ @filterDropdownsExpanded={{true}}
+ @showDropdownFilterToggle={{false}}
+ @showTextFilter={{false}}
+ @showResetButton={{false}}
+ @showNoResults={{false}}
+ @loading={{this.loading}}
+ @onDropdownFilterChange={{this.changeDropdown}}
+ />
- <form.Fieldset
- class="ai-logs__user-filter"
- @name="user-filter"
- @title={{i18n "discourse_ai.logs.user"}}
- >
- <UserChooser
- @value={{this.selectedUsernames}}
- @onChange={{this.changeUser}}
- @options={{hash
- maximum=1
- none="discourse_ai.logs.user_placeholder"
- filterPlaceholder="discourse_ai.logs.user_placeholder"
- headerAriaLabel=(i18n "discourse_ai.logs.user_placeholder")
- }}
- />
- </form.Fieldset>
+ <div class="ai-logs__specialized-filters">
+ <form.Fieldset
+ class="ai-logs__user-filter"
+ @name="user-filter"
+ @title={{i18n "discourse_ai.logs.user"}}
+ >
+ <UserChooser
+ @value={{this.selectedUsernames}}
+ @onChange={{this.changeUser}}
+ @options={{hash
+ maximum=1
+ none="discourse_ai.logs.user_placeholder"
+ filterPlaceholder="discourse_ai.logs.user_placeholder"
+ headerAriaLabel=(i18n "discourse_ai.logs.user_placeholder")
+ }}
+ />
+ </form.Fieldset>
+
+ <form.Field
+ class="ai-logs__toggle"
+ @name="has_retries"
+ @title={{i18n "discourse_ai.logs.has_retries"}}
+ @type="checkbox"
+ @onSet={{this.toggleRetries}}
+ as |field|
+ >
+ <field.Control />
+ </form.Field>
+
+ <form.Field
+ class="ai-logs__toggle"
+ @name="unattributed"
+ @title={{i18n "discourse_ai.logs.unattributed"}}
+ @type="checkbox"
+ @onSet={{this.toggleUnattributed}}
+ as |field|
+ >
+ <field.Control />
+ </form.Field>
+ </div>
- <form.Field
- class="ai-logs__toggle"
- @name="has_retries"
- @title={{i18n "discourse_ai.logs.has_retries"}}
- @type="checkbox"
- @onSet={{this.toggleRetries}}
- as |field|
- >
- <field.Control />
- </form.Field>
-
- <form.Field
- class="ai-logs__toggle"
- @name="unattributed"
- @title={{i18n "discourse_ai.logs.unattributed"}}
- @type="checkbox"
- @onSet={{this.toggleUnattributed}}
- as |field|
- >
- <field.Control />
- </form.Field>
- </div>
-
- <div class="ai-logs__id-filter">
- <form.Field
- @name="id_type"
- @title={{i18n "discourse_ai.logs.filters.id_type"}}
- @type="select"
- @onSet={{this.changeIdType}}
- as |field|
- >
- <field.Control @includeNone={{false}} as |select|>
- {{#each this.idTypeOptions as |idType|}}
- <select.Option @value={{idType.id}}>
- {{idType.name}}
- </select.Option>
- {{/each}}
- </field.Control>
- </form.Field>
-
- <form.Field
- @name="id_value"
- @title={{i18n "discourse_ai.logs.filters.id_value"}}
- @type="input-number"
- @onSet={{this.setIdValue}}
- as |field|
- >
- <field.Control
- min="1"
- max={{MAX_SAFE_ID}}
- placeholder={{i18n "discourse_ai.logs.id_placeholder"}}
- />
- </form.Field>
+ <div class="ai-logs__id-filter">
+ <form.Field
+ @name="id_type"
+ @title={{i18n "discourse_ai.logs.filters.id_type"}}
+ @type="select"
+ @onSet={{this.changeIdType}}
+ as |field|
+ >
+ <field.Control @includeNone={{false}} as |select|>
+ {{#each this.idTypeOptions as |idType|}}
+ <select.Option @value={{idType.id}}>
+ {{idType.name}}
+ </select.Option>
+ {{/each}}
+ </field.Control>
+ </form.Field>
+
+ <form.Field
+ @name="id_value"
+ @title={{i18n "discourse_ai.logs.filters.id_value"}}
+ @type="input-number"
+ @onSet={{this.setIdValue}}
+ as |field|
+ >
+ <field.Control
+ min="1"
+ max={{MAX_SAFE_ID}}
+ placeholder={{i18n "discourse_ai.logs.id_placeholder"}}
+ />
+ </form.Field>
- <form.Submit
- class="btn-default ai-logs__find"
- @label="discourse_ai.logs.find"
- />
- {{#if this.hasFilters}}
- <DButton
- class="btn-transparent ai-logs__clear"
- @action={{this.clearFilters}}
- @label="discourse_ai.logs.clear_filters"
+ <form.Submit
+ class="btn-default ai-logs__find"
+ @label="discourse_ai.logs.find"
/>
- {{/if}}
- </div>
+ {{#if this.hasFilters}}
+ <DButton
+ class="btn-transparent ai-logs__clear"
+ @action={{this.clearFilters}}
+ @label="discourse_ai.logs.clear_filters"
+ />
+ {{/if}}
+ </div>
+ </form.Fieldset>
+
</Form>
<DConditionalLoadingSpinner @condition={{this.loading}}>
@@ -801,9 +784,14 @@ export default class AiLogs extends Component {
<th class="ai-logs__col-user" scope="col">{{i18n
"discourse_ai.logs.user"
}}</th>
- <th class="ai-logs__col-duration" scope="col">{{i18n
- "discourse_ai.logs.duration_tokens"
- }}</th>
+ <th class="ai-logs__col-duration" scope="col">
+ <span class="ai-logs__duration-heading">{{i18n
+ "discourse_ai.logs.duration"
+ }}</span>
+ <span class="ai-logs__tokens-heading">{{i18n
+ "discourse_ai.logs.tokens_direction"
+ }}</span>
+ </th>
<th class="ai-logs__col-context" scope="col">{{i18n
"discourse_ai.logs.context"
}}</th>
diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-logs.js b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-logs.js
index d70fffb6116..b67b967d54c 100644
--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-logs.js
+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-logs.js
@@ -32,7 +32,7 @@ export default class DiscourseAiLogsRoute extends DiscourseRoute {
: null;
const hasRetries = String(params.has_retries) === "true" ? "true" : null;
const unattributed = String(params.unattributed) === "true" ? "true" : null;
- const selectedModel = /^[1-9]\d*$/.test(params.selectedModel || "")
+ const selectedModel = /^-?[1-9]\d*$/.test(params.selectedModel || "")
? params.selectedModel
: null;
const idValue = /^[1-9]\d*$/.test(params.id_value || "")
diff --git a/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_logs_controller.rb b/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_logs_controller.rb
index 925457ea3a8..d6454434b00 100644
--- a/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_logs_controller.rb
+++ b/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_logs_controller.rb
@@ -189,7 +189,7 @@ module DiscourseAi
scope = apply_date_filters(scope)
scope = apply_outcome_filter(scope)
scope = scope.where.not(request_attempts: nil) if boolean_param(:has_retries)
- scope = scope.where(llm_id: positive_integer!(:llm_id)) if params[:llm_id].present?
+ scope = scope.where(llm_id: params[:llm_id]) if params[:llm_id].present?
scope = scope.where(feature_name: params[:feature].to_s) if params[:feature].present?
if params[:user_id].present? || params[:username].present?
diff --git a/plugins/discourse-ai/assets/stylesheets/admin/ai-logs.scss b/plugins/discourse-ai/assets/stylesheets/admin/ai-logs.scss
index 623e3f1e724..9baaf66794e 100644
--- a/plugins/discourse-ai/assets/stylesheets/admin/ai-logs.scss
+++ b/plugins/discourse-ai/assets/stylesheets/admin/ai-logs.scss
@@ -3,28 +3,29 @@
.ai-logs {
padding: var(--space-4);
- &__retention {
+ &__filters {
display: flex;
- flex-wrap: wrap;
- align-items: center;
- justify-content: space-between;
- gap: var(--space-2);
+ flex-direction: column;
+ gap: var(--space-3);
margin-bottom: var(--space-4);
- padding: var(--space-3);
- border: 1px solid var(--content-border-color);
- background: var(--primary-very-low);
- }
- &__retention-warning {
- margin: 0;
- color: var(--primary-high);
+ .d-filter-controls {
+ align-self: stretch;
+ margin-block: 0;
+ }
+
+ .d-filter-controls__dropdowns {
+ grid-template-columns: repeat(auto-fit, minmax(min(12rem, 100%), 1fr));
+ }
}
- &__filters {
+ &__filter-panel {
+ align-self: stretch;
display: flex;
flex-direction: column;
- gap: var(--space-3);
- margin-bottom: var(--space-4);
+ gap: var(--space-2);
+ padding: var(--space-3);
+ border: 1px solid var(--content-border-color);
}
&__periods,
@@ -35,29 +36,20 @@
gap: var(--space-2);
}
- &__filter-grid {
+ &__specialized-filters {
display: grid;
- grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
+ grid-template-columns: minmax(15rem, 1fr) repeat(2, auto);
align-items: end;
- width: 100%;
gap: var(--space-2);
> * {
min-width: 0;
}
-
- .d-select {
- width: 100%;
- }
}
&__user-filter .select-kit {
width: 100%;
max-width: var(--form-kit-medium-input);
-
- @include viewport.until(sm) {
- max-width: 100%;
- }
}
&__toggle {
@@ -72,7 +64,17 @@
gap: var(--space-2);
> .form-kit__field {
- min-width: 10rem;
+ min-width: min(10rem, 100%);
+ }
+ }
+
+ @include viewport.until(sm) {
+ &__specialized-filters {
+ grid-template-columns: 1fr;
+ }
+
+ &__user-filter .select-kit {
+ max-width: 100%;
}
}
@@ -129,12 +131,21 @@
}
&__col-duration {
- width: 7.5rem;
+ width: 10rem;
text-align: end;
font-variant-numeric: tabular-nums;
+ }
+
+ td.ai-logs__col-duration {
+ white-space: nowrap;
+ }
+
+ &__duration-heading {
white-space: nowrap;
}
+ &__duration-heading,
+ &__tokens-heading,
&__duration-value,
&__token-summary {
display: block;
@@ -257,7 +268,7 @@
}
&__col-duration {
- width: 6.5rem;
+ width: 9.5rem;
}
&__model {
@@ -265,13 +276,30 @@
}
}
- @include viewport.until(md) {
+ @include viewport.until(lg) {
&__table {
+ display: block;
margin-bottom: 0;
+ table-layout: auto;
+
+ thead,
+ tbody {
+ display: block;
+ }
+
+ thead {
+ position: absolute;
+ width: 1px;
+ height: 1px;
+ overflow: hidden;
+ clip-path: inset(50%);
+ white-space: nowrap;
+ }
}
&__row {
display: grid;
+ width: 100%;
grid-template-columns: auto 1fr auto;
grid-template-areas:
"outcome time actions"
diff --git a/plugins/discourse-ai/config/locales/client.en.yml b/plugins/discourse-ai/config/locales/client.en.yml
index 8109d10bf10..1bcd174950b 100644
--- a/plugins/discourse-ai/config/locales/client.en.yml
+++ b/plugins/discourse-ai/config/locales/client.en.yml
@@ -671,21 +671,20 @@ en:
logs:
short_title: "Logs"
description: "Inspect individual requests sent to AI models and their responses"
- sensitive_warning: "Only administrators can view AI logs."
refresh: "Refresh logs"
retry: "Try again"
apply: "Apply"
find: "Find"
- clear_filters: "Clear filters"
+ clear_filters: "Clear all filters"
all_outcomes: "All outcomes"
all_models: "All models"
+ all_features: "All features"
successful: "Successful"
failed: "Failed"
unknown: "Unknown"
has_retries: "Has retries"
retried: "Retried"
unattributed: "Unattributed"
- feature_placeholder: "Feature name"
user_placeholder: "Filter by user"
id_placeholder: "Enter an ID"
log_id: "Log ID"
@@ -711,7 +710,7 @@ en:
post: "Post"
post_short: "Post %{id}"
duration: "Duration"
- duration_tokens: "Duration / tokens"
+ tokens_direction: "Tokens (in → out)"
first_token: "First token"
cost: "Cost"
actions: "Actions"
@@ -720,6 +719,7 @@ en:
no_results: "No AI logs match these filters."
no_logs: "No retained AI logs were found."
filters:
+ title: "Filters"
period: "Time period"
date_range: "Date range"
id_type: "ID type"
diff --git a/plugins/discourse-ai/spec/requests/admin/ai_logs_controller_spec.rb b/plugins/discourse-ai/spec/requests/admin/ai_logs_controller_spec.rb
index 80c3e23de40..21da36a2891 100644
--- a/plugins/discourse-ai/spec/requests/admin/ai_logs_controller_spec.rb
+++ b/plugins/discourse-ai/spec/requests/admin/ai_logs_controller_spec.rb
@@ -232,6 +232,28 @@ RSpec.describe DiscourseAi::Admin::AiLogsController do
expect(response.parsed_body["logs"].map { |log| log["id"] }).to eq([matching_log.id])
end
+ it "filters by seeded models and exposes them in filter metadata" do
+ seeded_model = Fabricate(:seeded_model, id: -1)
+ matching_log = Fabricate(:ai_api_audit_log, llm_model: seeded_model)
+ Fabricate(:ai_api_audit_log, llm_model: llm_model)
+
+ get index_path, params: { llm_id: seeded_model.id, include_meta: true }
+
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["logs"].map { |returned_log| returned_log["id"] }).to eq(
+ [matching_log.id],
+ )
+ expect(response.parsed_body["models"]).to include(
+ "id" => seeded_model.id,
+ "name" => seeded_model.display_name,
+ )
+
+ get index_path, params: { llm_id: -999_999 }
+
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["logs"]).to be_empty
+ end
+
it "uses the health-check outcome semantics" do
success_with_no_tokens =
Fabricate(:ai_api_audit_log, response_status: 200, response_tokens: 0)
diff --git a/plugins/discourse-ai/spec/system/ai_logs_spec.rb b/plugins/discourse-ai/spec/system/ai_logs_spec.rb
index 49350e5ca3e..b752efee02a 100644
--- a/plugins/discourse-ai/spec/system/ai_logs_spec.rb
+++ b/plugins/discourse-ai/spec/system/ai_logs_spec.rb
@@ -63,21 +63,22 @@ RSpec.describe "AI logs admin page" do
sign_in(admin)
end
- it "applies typed feature and ID filters" do
+ it "applies outcome, feature, and ID filters" do
+ Fabricate(:ai_api_audit_log, feature_name: "other-feature")
ai_logs_page.visit
- select I18n.t("js.discourse_ai.logs.failed"), from: I18n.t("js.discourse_ai.logs.outcome")
+ ai_logs_page.select_outcome(I18n.t("js.discourse_ai.logs.failed"))
expect(ai_logs_page).to have_no_log(log)
- select I18n.t("js.discourse_ai.logs.all_outcomes"), from: I18n.t("js.discourse_ai.logs.outcome")
+ ai_logs_page.select_outcome(I18n.t("js.discourse_ai.logs.all_outcomes"))
expect(ai_logs_page).to have_log(log)
- find("input[placeholder='#{I18n.t("js.discourse_ai.logs.feature_placeholder")}']").fill_in(
- with: "missing-feature",
- )
- find("input[placeholder='#{I18n.t("js.discourse_ai.logs.feature_placeholder")}']").send_keys(
- :enter,
- )
+ configured_feature = DiscourseAi::Configuration::Feature.all.first.name
+ feature_select = find(".d-filter-controls__dropdown--feature")
+ expect(feature_select).to have_selector("option", text: configured_feature)
+ expect(feature_select).to have_selector("option", text: "system-test")
+ expect(feature_select).to have_selector("option", text: "other-feature")
+ ai_logs_page.select_feature("other-feature")
expect(ai_logs_page).to have_no_log(log)
find("input[placeholder='#{I18n.t("js.discourse_ai.logs.id_placeholder")}']").fill_in(
@@ -87,17 +88,16 @@ RSpec.describe "AI logs admin page" do
expect(ai_logs_page).to have_log(log)
end
- it "keeps focus in the feature input while typing" do
+ it "keeps focus in the ID input while typing" do
ai_logs_page.visit
- feature_input =
- find("input[placeholder='#{I18n.t("js.discourse_ai.logs.feature_placeholder")}']")
- feature_input.click
- "abc".each_char { |char| feature_input.send_keys(char) }
+ id_input = find("input[placeholder='#{I18n.t("js.discourse_ai.logs.id_placeholder")}']")
+ id_input.click
+ "123".each_char { |character| id_input.send_keys(character) }
- expect(feature_input.value).to eq("abc")
+ expect(id_input.value).to eq("123")
expect(page.evaluate_script("document.activeElement.placeholder")).to eq(
- I18n.t("js.discourse_ai.logs.feature_placeholder"),
+ I18n.t("js.discourse_ai.logs.id_placeholder"),
)
end
@@ -117,11 +117,66 @@ RSpec.describe "AI logs admin page" do
expect(ai_logs_page).to have_no_log(log)
end
- it "lets an admin inspect a raw log and open retention configuration" do
+ it "filters by a seeded model from selection and a shareable URL" do
+ seeded_model = Fabricate(:seeded_model, id: -1)
+ seeded_log =
+ Fabricate(:ai_api_audit_log, llm_model: seeded_model, language_model: seeded_model.name)
+
+ ai_logs_page.visit
+ ai_logs_page.select_model(seeded_model.display_name)
+
+ expect(ai_logs_page).to have_log(seeded_log)
+ expect(ai_logs_page).to have_no_log(log)
+ expect(page).to have_current_path(/model=-1/, url: true)
+
+ ai_logs_page.visit("model=-1")
+
+ expect(ai_logs_page.filter_value(:model)).to eq("-1")
+ expect(ai_logs_page).to have_log(seeded_log)
+ expect(ai_logs_page).to have_no_log(log)
+ end
+
+ it "clears shared and specialized filters" do
ai_logs_page.visit
+ ai_logs_page.select_model(llm_model.display_name)
+ click_button I18n.t("js.discourse_ai.logs.periods.day")
+ expect(page).to have_current_path(/model=#{llm_model.id}/, url: true)
+ expect(page).to have_current_path(/period=day/, url: true)
+
+ ai_logs_page.clear_filters
+ expect(page).to have_current_path(%r{/ai-logs$}, url: true)
+ expect(page).to have_css(".d-filter-controls__dropdown--outcome:focus")
expect(ai_logs_page).to have_log(log)
+ click_button I18n.t("js.discourse_ai.logs.periods.day")
+ ai_logs_page.clear_filters
+ expect(page).to have_current_path(%r{/ai-logs$}, url: true)
+ end
+
+ it "lets an admin inspect a raw log and open retention configuration" do
+ ai_logs_page.visit
+ expect(ai_logs_page).to have_log(log)
+ expect(page).to have_no_css(".d-filter-controls__input")
+ expect(page).to have_no_css(".d-filter-controls__toggle-filters")
+ expect(page).to have_no_css(".d-filter-controls__reset")
+ expect(page).to have_css(
+ ".ai-logs__filter-panel",
+ text: I18n.t("js.discourse_ai.logs.filters.title"),
+ )
+ expect(ai_logs_page).to have_expanded_filter_dropdowns
+ expect(page).to have_no_css(".ai-logs__retention")
+ expect(page).to have_button(I18n.t("js.discourse_ai.logs.retention.configure"))
+ expect(page).to have_button(I18n.t("js.discourse_ai.logs.refresh"))
+ expect(page).to have_css(
+ ".ai-logs__duration-heading",
+ text: I18n.t("js.discourse_ai.logs.duration"),
+ )
+ expect(page).to have_css(
+ ".ai-logs__tokens-heading",
+ text: I18n.t("js.discourse_ai.logs.tokens_direction"),
+ )
+
ai_logs_page.open_log(log)
expect(ai_logs_page).to have_payload("Inspect this request")
expect_modal_body_to_own_scrolling
diff --git a/plugins/discourse-ai/spec/system/page_objects/pages/ai_logs.rb b/plugins/discourse-ai/spec/system/page_objects/pages/ai_logs.rb
index f580325039b..c1f65740214 100644
--- a/plugins/discourse-ai/spec/system/page_objects/pages/ai_logs.rb
+++ b/plugins/discourse-ai/spec/system/page_objects/pages/ai_logs.rb
@@ -9,6 +9,31 @@ module PageObjects
self
end
+ def select_outcome(label)
+ select_filter(:outcome, label)
+ end
+
+ def select_model(label)
+ select_filter(:model, label)
+ end
+
+ def select_feature(label)
+ select_filter(:feature, label)
+ end
+
+ def clear_filters
+ find(".ai-logs__clear").click
+ self
+ end
+
+ def filter_value(key)
+ find(".d-filter-controls__dropdown--#{key}").value
+ end
+
+ def has_expanded_filter_dropdowns?
+ page.has_css?(".d-filter-controls__dropdown", count: 3)
+ end
+
def open_log(log)
find(%(.ai-logs__row[data-log-id="#{log.id}"])).find(".btn").click
self
@@ -37,6 +62,13 @@ module PageObjects
def has_retention_modal?
page.has_css?(".ai-log-retention-modal")
end
+
+ private
+
+ def select_filter(key, label)
+ find(".d-filter-controls__dropdown--#{key}").select(label)
+ self
+ end
end
end
end