drop to 15 records per page

This commit is contained in:
James Greenwood 2025-11-17 14:37:33 +00:00
parent 50e9a9de3f
commit 2df603a074
4 changed files with 51 additions and 11 deletions

View File

@ -52,7 +52,7 @@ This project implements a fully-featured data table with **filtering, sorting, a
- ✅ **Status Filter**: Dropdown (All, Resolved, Unresolved)
- ✅ **Assignment Filter**: Dropdown (All, Mine, Assigned, Unassigned)
- ✅ **Sorting**: All columns with ascending/descending indicators
- ✅ **Pagination**: 25 records per page with full navigation
- ✅ **Pagination**: 15 records per page with full navigation
- ✅ **URL State**: All filters/sorting/pagination in URL (bookmarkable/shareable)
- ✅ **Progressive Enhancement**: Works with and without JavaScript
@ -179,7 +179,7 @@ All state is in the URL for bookmarking/sharing:
### Default Behavior
- Sort: `inserted_at DESC` (newest first)
- Per page: 25 records
- Per page: 15 records
- Current user: ID 1 (for demo purposes)
## Why Elixir/Phoenix?

View File

@ -6,7 +6,7 @@ defmodule ActionRequestsDemo.ActionRequests.ActionRequest do
Flop.Schema,
filterable: [:patient_name, :status, :assigned_user_id],
sortable: [:patient_name, :status, :inserted_at, :delivery_scheduled_at],
default_limit: 25
default_limit: 15
}
@primary_key {:id, :binary_id, autogenerate: true}

View File

@ -19,12 +19,52 @@ defmodule ActionRequestsDemo.Release do
`priv/repo/seeds.exs` file, which uses `ActionRequestsDemo.Repo`.
"""
def seed do
# Ensure Faker is started in this eval process so Faker.Person.name/0 works
{:ok, _} = Application.ensure_all_started(:faker)
ensure_app_started(ActionRequestsDemo.Repo)
ensure_app_started(:faker)
seeds_path = Application.app_dir(@app, "priv/repo/seeds.exs")
Code.require_file(seeds_path)
end
defp ensure_app_started(app_or_repo) do
case Application.ensure_all_started(app_or_repo) do
{:ok, _} ->
:ok
{:error, {:already_started, _pid}} ->
:ok
{:error, {:not_started, _}} ->
start_repo(app_or_repo)
{:error, reason} ->
raise "Could not start #{inspect(app_or_repo)}: #{inspect(reason)}"
end
rescue
UndefinedFunctionError ->
start_repo(app_or_repo)
end
defp start_repo(repo) when is_atom(repo) do
case repo.start_link() do
{:ok, _pid} ->
:ok
{:error, {:already_started, _pid}} ->
:ok
other ->
raise "Could not start #{inspect(repo)}: #{inspect(other)}"
end
end
defp start_repo(app) do
case Application.ensure_all_started(app) do
{:ok, _} -> :ok
{:error, {:already_started, _}} -> :ok
other -> raise "Could not start #{inspect(app)}: #{inspect(other)}"
end
end
end

View File

@ -75,14 +75,14 @@ defmodule ActionRequestsDemoWeb.ActionRequestsLiveTest do
test "pagination displays correct records per page", %{conn: conn} do
{:ok, view, _html} = live(conn, "/")
# Default ordering is inserted_at: :desc, so page 1 shows Patient 30..6
for i <- 30..6//-1 do
for i <- 30..16//-1 do
assert has_element?(view, "td", "Patient #{i}")
end
# Page 2 should show Patient 5..1
render_click(element(view, "a", "Next"))
for i <- 5..1//-1 do
for i <- 15..1//-1 do
assert has_element?(view, "td", "Patient #{i}")
end
end
@ -167,17 +167,17 @@ defmodule ActionRequestsDemoWeb.ActionRequestsLiveTest do
test "pagination metadata displays correctly", %{conn: conn} do
{:ok, view, _html} = live(conn, "/")
# Page 1 of 2, showing 25 of 30 records
# Page 1 of 2, showing 15 of 30 records
assert has_element?(view, "div", "Page 1 of 2")
assert has_element?(view, "div", "showing 25 of 30 records")
assert has_element?(view, "div", "showing 15 of 30 records")
end
test "pagination metadata updates after navigating", %{conn: conn} do
{:ok, view, _html} = live(conn, "/")
render_click(element(view, "a", "Next"))
# Page 2 of 2, showing 5 of 30 records
# Page 2 of 2, showing 15 of 30 records
assert has_element?(view, "div", "Page 2 of 2")
assert has_element?(view, "div", "showing 5 of 30 records")
assert has_element?(view, "div", "showing 15 of 30 records")
end
test "pagination metadata updates with filters", %{conn: conn} do