Problem/Motivation
The "Export CSV" link on /admin/reports/ai-metering/log calls a
custom controller route that queries ai_metering_usage directly.
It ignores any exposed filters the user has set (Provider, Model, Period).
Filtering to a specific provider then exporting gives the full unfiltered dataset.
The exports on /admin/reports/ai-metering and
/admin/reports/ai-metering/by-role are out of scope — those
pages have no pagination yet and their export behavior is unchanged.
Steps to reproduce
- Go to
/admin/reports/ai-metering/log. - Set the Provider filter to anthropic and apply.
- Click "Export CSV".
- Observe: the downloaded file contains rows from all providers.
Environment
- ai_metering 1.0.0-alpha1
Proposed resolution
Replace the custom CSV controller with a
views_data_export
display added to the ai_metering_usage_log View. The display
inherits all exposed filters, so the export reflects exactly what the user sees.
Batch processing handles large logs without timeouts.
Remaining tasks
- Add
drupal/views_data_exporttocomposer.json. - Add a VDE CSV display to
ai_metering_usage_log.view.yml. - Remove or redirect the legacy CSV controller route.
- Add a test asserting the export respects the active Provider filter.
- Review.
User interface changes
The "Export CSV" link triggers a views_data_export batch instead of an
immediate download. UX is otherwise unchanged.
API changes
None.
Data model changes
None.
AI assistance
N/A
Comments
Comment #8
codeitwisely commented