Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, when you have a route with parameters (e.g.
live_resource "users/:user_id/posts", PostLive
), you will get a bunch of errors in Backpex which come from the fact thatBackpex.Router.get_path/5
function struggles with route parameters that are not controlled by Backpex. This funcion (through some helper functions) will try to rebuild the full URL from the route path given (which contains the.../:user_id/...
part) and the given parameters by merging the parameters into the route. Currently, theget_path/5
function doesn't use all the available parameters from the socket assigns. This can be a problem if you want a view of posts belonging to a given user, for example.With these changes, the get_path function will merge the
params
variable with the values taken from thesocket.assigns
. However, I'm not sure this is really stable because I'm probably using some private APIs that are not meant to be used. I'm not aware of any public API to access LiveView.Socket assigns at the stage of the socket lifecycle in whichget_path/5
is invoked.I thought of adding some tests here, but that would require building a whole test suite from the ground up because Backpex doesn't have any integration tests already set up. I might do it when I have the time for that.
So this is definitely not ready to be merged into the main repo, but I think it's a good basis for finding a good way of handling route parameters set "outside" of Backpex.