fix: implement handleSort method for sortable table headers

- Update th_sortable macro to call handleSort(key) instead of inline logic
- Add handleSort method to subscriptions.js, subscription-tiers.js, billing-history.js
- Add sort_by and sort_order params to API calls in all three files
- Reset to page 1 when sort changes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-25 22:44:33 +01:00
parent abfd823ec8
commit dbcbe38217
4 changed files with 45 additions and 7 deletions

View File

@@ -136,6 +136,8 @@ function adminBillingHistory() {
params.append('per_page', this.pagination.per_page);
if (this.filters.vendor_id) params.append('vendor_id', this.filters.vendor_id);
if (this.filters.status) params.append('status', this.filters.status);
if (this.sortBy) params.append('sort_by', this.sortBy);
if (this.sortOrder) params.append('sort_order', this.sortOrder);
const data = await apiClient.get(`/admin/subscriptions/billing/history?${params}`);
this.invoices = data.invoices || [];
@@ -154,6 +156,17 @@ function adminBillingHistory() {
}
},
handleSort(key) {
if (this.sortBy === key) {
this.sortOrder = this.sortOrder === 'asc' ? 'desc' : 'asc';
} else {
this.sortBy = key;
this.sortOrder = 'asc';
}
this.pagination.page = 1;
this.loadInvoices();
},
updateStatusCounts() {
// Reset counts
this.statusCounts = {

View File

@@ -74,6 +74,8 @@ function adminSubscriptionTiers() {
try {
const params = new URLSearchParams();
params.append('include_inactive', this.includeInactive);
if (this.sortBy) params.append('sort_by', this.sortBy);
if (this.sortOrder) params.append('sort_order', this.sortOrder);
const data = await apiClient.get(`/admin/subscriptions/tiers?${params}`);
this.tiers = data.tiers || [];
@@ -86,6 +88,16 @@ function adminSubscriptionTiers() {
}
},
handleSort(key) {
if (this.sortBy === key) {
this.sortOrder = this.sortOrder === 'asc' ? 'desc' : 'asc';
} else {
this.sortBy = key;
this.sortOrder = 'asc';
}
this.loadTiers();
},
async loadStats() {
try {
const data = await apiClient.get('/admin/subscriptions/stats');

View File

@@ -144,6 +144,8 @@ function adminSubscriptions() {
if (this.filters.status) params.append('status', this.filters.status);
if (this.filters.tier) params.append('tier', this.filters.tier);
if (this.filters.search) params.append('search', this.filters.search);
if (this.sortBy) params.append('sort_by', this.sortBy);
if (this.sortOrder) params.append('sort_order', this.sortOrder);
const data = await apiClient.get(`/admin/subscriptions?${params}`);
this.subscriptions = data.subscriptions || [];
@@ -168,6 +170,17 @@ function adminSubscriptions() {
this.loadSubscriptions();
},
handleSort(key) {
if (this.sortBy === key) {
this.sortOrder = this.sortOrder === 'asc' ? 'desc' : 'asc';
} else {
this.sortBy = key;
this.sortOrder = 'asc';
}
this.pagination.page = 1;
this.loadSubscriptions();
},
previousPage() {
if (this.pagination.page > 1) {
this.pagination.page--;