Skip to content

Commit

Permalink
Merge pull request #306 from pulibrary/303-sort
Browse files Browse the repository at this point in the history
Reset sort when changing query parameter
  • Loading branch information
tpendragon authored Feb 12, 2025
2 parents 4fa50f2 + 6ab3a0f commit c2f797a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/dpul_collections_web/live/search_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ defmodule DpulCollectionsWeb.SearchLive do
socket.assigns.search_state
| q: params["q"],
date_to: params["date-to"],
date_from: params["date-from"]
date_from: params["date-from"],
sort_by: params["sort_by"]
}
|> Helpers.clean_params([:page, :per_page])

Expand Down
13 changes: 13 additions & 0 deletions test/dpul_collections_web/live/search_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ defmodule DpulCollectionsWeb.SearchLiveTest do
|> Enum.empty?()
end

test "changing query parameter resets sort_by to default", %{conn: conn} do
{:ok, view, _html} = live(conn, "/search")

view |> render_click("sort", %{"sort-by" => "date_asc"})
assert_patched(view, "/search?sort_by=date_asc")

view
|> element("#search-form")
|> render_submit(%{"q" => "Document"})

assert_patched(view, "/search?q=Document")
end

test "when sorting by date, a nil date always sorts last", %{conn: conn} do
Solr.add(
[
Expand Down

0 comments on commit c2f797a

Please sign in to comment.