From 2df603a0743ef04df8daaa47687da4e47eaff754 Mon Sep 17 00:00:00 2001 From: James Greenwood Date: Mon, 17 Nov 2025 14:37:33 +0000 Subject: [PATCH] drop to 15 records per page --- README.md | 4 +- .../action_requests/action_request.ex | 2 +- lib/action_requests_demo/release.ex | 44 ++++++++++++++++++- .../action_requests_live_test.exs | 12 ++--- 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 9a2e2ac..ad841f1 100644 --- a/README.md +++ b/README.md @@ -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? diff --git a/lib/action_requests_demo/action_requests/action_request.ex b/lib/action_requests_demo/action_requests/action_request.ex index df2469c..cbf75a8 100644 --- a/lib/action_requests_demo/action_requests/action_request.ex +++ b/lib/action_requests_demo/action_requests/action_request.ex @@ -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} diff --git a/lib/action_requests_demo/release.ex b/lib/action_requests_demo/release.ex index 4069918..8e7771f 100644 --- a/lib/action_requests_demo/release.ex +++ b/lib/action_requests_demo/release.ex @@ -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 diff --git a/test/action_requests_demo_web/action_requests_live_test.exs b/test/action_requests_demo_web/action_requests_live_test.exs index f555311..892d6a8 100644 --- a/test/action_requests_demo_web/action_requests_live_test.exs +++ b/test/action_requests_demo_web/action_requests_live_test.exs @@ -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