discourse/app/assets/javascripts/admin/addon/components/admin-reports.gjs
Kris d538b50847
DEV: apply common filter component to AI persona admin (#34300)
This applies the common `AdminFilterControls` component here: 

<img width="2216" height="144" alt="image"
src="https://github.com/user-attachments/assets/3e6ad0e9-9f14-4974-a80c-49e0d1b0b108"
/>

I also wanted to add the layout control button, so I added the ability
to use an actions block in `AdminFilterControls` — this required
creating two separate blocks `actions` and `content`, which required
updating the other instances of `AdminFilterControls` ... but this
should allow more flexibility going forward
2025-08-14 10:25:18 -04:00

58 lines
2 KiB
Text
Vendored

import Component from "@glimmer/component";
import { array } from "@ember/helper";
import { service } from "@ember/service";
import AsyncContent from "discourse/components/async-content";
import { ajax } from "discourse/lib/ajax";
import { bind } from "discourse/lib/decorators";
import { i18n } from "discourse-i18n";
import AdminFilterControls from "admin/components/admin-filter-controls";
import AdminSectionLandingItem from "admin/components/admin-section-landing-item";
import AdminSectionLandingWrapper from "admin/components/admin-section-landing-wrapper";
export default class AdminReports extends Component {
@service siteSettings;
@bind
async loadReports() {
const response = await ajax("/admin/reports");
return response.reports;
}
@bind
filterReports(reports) {
if (!reports) {
return [];
}
const hiddenReports = (this.siteSettings.dashboard_hidden_reports || "")
.split("|")
.filter(Boolean);
return reports.filter((report) => !hiddenReports.includes(report.type));
}
<template>
<AsyncContent @asyncData={{this.loadReports}}>
<:content as |reports|>
<AdminFilterControls
@array={{this.filterReports reports}}
@searchableProps={{array "title" "description"}}
@inputPlaceholder={{i18n "admin.filter_reports"}}
@noResultsMessage={{i18n "admin.filter_reports_no_results"}}
>
<:content as |filteredReports|>
<AdminSectionLandingWrapper class="admin-reports-list">
{{#each filteredReports as |report|}}
<AdminSectionLandingItem
@titleLabelTranslated={{report.title}}
@descriptionLabelTranslated={{report.description}}
@titleRoute="adminReports.show"
@titleRouteModel={{report.type}}
/>
{{/each}}
</AdminSectionLandingWrapper>
</:content>
</AdminFilterControls>
</:content>
</AsyncContent>
</template>
}