Sort ordering in the admin panel isn't being applied unless an order has already been applied by the runwayListing scope.
In the method \StatamicRadPack\Runway\Http\Controllers\CP\ResourceListingController::index(...) the following check only successfully applies a user selected sort order if an order has already been applied to the query.
$query->when($query->getQuery()->orders, function ($query) use ($request) {
if ($request->input('sort')) {
$query->reorder($request->input('sort'), $request->input('order'));
}
}, fn ($query) => $query->orderBy($resource->orderBy(), $resource->orderByDirection()));
One can see that $query->getQuery()->orders will be null unless $query->orderBy(...) has already been called.
Steps to reproduce
Attempt to apply a non-default sort order in the admin panel for a model that doesn't call $query->orderBy(...) in it's runwayListing scope.
Description
Sort ordering in the admin panel isn't being applied unless an order has already been applied by the
runwayListing
scope.In the method
\StatamicRadPack\Runway\Http\Controllers\CP\ResourceListingController::index(...)
the following check only successfully applies a user selected sort order if an order has already been applied to the query.One can see that
$query->getQuery()->orders
will benull
unless$query->orderBy(...)
has already been called.Steps to reproduce
$query->orderBy(...)
in it'srunwayListing
scope.See https://github.com/statamic-rad-pack/runway/commit/c9ec2aec506a195782f18c4924f84ce990266ecb for an examlpe test that reproduces this issue.
Environment
Tests have been executed outside of an application environment.