Keep the homepage available before imports

fdd00d4c40a4 · AtlantisPleb · · parent 9fc34a2cd254

Keep the homepage available before imports

Deploy story

What this commit did to the running system — joined from the forge receipt chain, the part a commit page elsewhere cannot show.

Not deployed through the forge lane

No push, promotion, build, or deploy receipt references this commit (receipts are scanned over a bounded recent window). Changes shipped by full node replacement carry their proof in the release gate receipt instead.

Changed files

  • modified lib/openagents_web/live/home_live.ex
  • modified test/openagents_web/home_controller_test.exs

Diff

2 files changed, +54 -9

lib/openagents_web/live/home_live.ex modified +42 -9

@@ -39,15 +39,16 @@ defmodule OpenAgentsWeb.HomeLive do

39 39
  # Loaded once at mount rather than per render: none of it changes within a
40 40
  # visit, and the dashboard should not re-query on every diff.
41 41
  defp assign_dashboard(socket) do
42
    repository = Repositories.initial_repository!()
43
    {owner, name} = Repositories.initial_path()
44 42
    repositories = Repositories.list_visible_repositories(socket.assigns.current_user)
43
    repository = dashboard_repository(repositories)
44
    {owner, name} = repository_path(repository)
45 45
46
    open_issues = Issues.list_issues(repository, state: "open")
47
    closed_issues = Issues.list_issues(repository, state: "closed")
48
    projects = Projects.list_projects(repository)
46
    open_issues = list_issues(repository, "open")
47
    closed_issues = list_issues(repository, "closed")
48
    projects = list_projects(repository)
49 49
50 50
    socket
51
    |> assign(:repository, repository)
51 52
    |> assign(:owner, owner)
52 53
    |> assign(:name, name)
53 54
    |> assign(:open_count, length(open_issues))

@@ -59,6 +60,24 @@ defmodule OpenAgentsWeb.HomeLive do

59 60
    |> stream(:repositories, repositories)
60 61
  end
61 62
63
  defp dashboard_repository(repositories) do
64
    {initial_owner, initial_name} = Repositories.initial_path()
65
66
    Enum.find(repositories, fn repository ->
67
      String.downcase(repository.namespace.slug) == String.downcase(initial_owner) and
68
        String.downcase(repository.name) == String.downcase(initial_name)
69
    end) || Enum.find(repositories, &(&1.lifecycle_state == "ready"))
70
  end
71
72
  defp repository_path(nil), do: Repositories.initial_path()
73
  defp repository_path(repository), do: {repository.namespace.slug, repository.name}
74
75
  defp list_issues(nil, _state), do: []
76
  defp list_issues(repository, state), do: Issues.list_issues(repository, state: state)
77
78
  defp list_projects(nil), do: []
79
  defp list_projects(repository), do: Projects.list_projects(repository)
80
62 81
  # The ledger is a bounded public projection and can legitimately refuse. An
63 82
  # empty rail is the honest answer; the home page should not crash over it.
64 83
  defp changelog_entries do

@@ -83,7 +102,11 @@ defmodule OpenAgentsWeb.HomeLive do

83 102
          <section class="panel" aria-labelledby="dashboard-issues">
84 103
            <header class="panel__header">
85 104
              <h2 id="dashboard-issues" class="panel__title">Open issues</h2>
86
              <.link navigate={~p"/#{@owner}/#{@name}/issues"} class="panel__more">
105
              <.link
106
                :if={@repository}
107
                navigate={~p"/#{@owner}/#{@name}/issues"}
108
                class="panel__more"
109
              >
87 110
                View all <.icon name="arrow-right" />
88 111
              </.link>
89 112
            </header>

@@ -108,15 +131,22 @@ defmodule OpenAgentsWeb.HomeLive do

108 131
              </li>
109 132
            </ul>
110 133
111
            <p :if={@issues == []} class="panel__empty">
134
            <p :if={@issues == [] and @repository} class="panel__empty">
112 135
              No open issues. <.link navigate={~p"/#{@owner}/#{@name}/issues/new"}>Open one</.link>.
113 136
            </p>
137
            <p :if={is_nil(@repository)} class="panel__empty">
138
              Import your first repository to start tracking issues.
139
            </p>
114 140
          </section>
115 141
116 142
          <section class="panel" aria-labelledby="dashboard-projects">
117 143
            <header class="panel__header">
118 144
              <h2 id="dashboard-projects" class="panel__title">Projects</h2>
119
              <.link navigate={~p"/#{@owner}/#{@name}/projects"} class="panel__more">
145
              <.link
146
                :if={@repository}
147
                navigate={~p"/#{@owner}/#{@name}/projects"}
148
                class="panel__more"
149
              >
120 150
                View all <.icon name="arrow-right" />
121 151
              </.link>
122 152
            </header>

@@ -136,7 +166,10 @@ defmodule OpenAgentsWeb.HomeLive do

136 166
              </li>
137 167
            </ul>
138 168
139
            <p :if={@projects == []} class="panel__empty">No projects yet.</p>
169
            <p :if={@projects == [] and @repository} class="panel__empty">No projects yet.</p>
170
            <p :if={is_nil(@repository)} class="panel__empty">
171
              Projects appear after you import a repository.
172
            </p>
140 173
          </section>
141 174
        </div>
142 175
test/openagents_web/home_controller_test.exs modified +12

@@ -1,6 +1,8 @@

1 1
defmodule OpenAgentsWeb.HomeControllerTest do
2 2
  use OpenAgentsWeb.ConnCase, async: true
3 3
4
  alias OpenAgents.{Repo, Repositories}
5
4 6
  test "the public homepage is the OpenAgents hero", %{conn: conn} do
5 7
    response = get(conn, ~p"/")
6 8
    html = html_response(response, 200)

@@ -34,6 +36,16 @@ defmodule OpenAgentsWeb.HomeControllerTest do

34 36
    assert html =~ ~s(class="dashboard")
35 37
  end
36 38
39
  test "an authenticated account sees the dashboard before the first import", %{conn: conn} do
40
    conn = log_in_github_user(conn, "authenticated-empty-home-user")
41
    Repositories.initial_repository!() |> Repo.delete!()
42
43
    html = html_response(get(conn, ~p"/"), 200)
44
45
    assert html =~ ~s(class="dashboard")
46
    assert html =~ "No repositories yet."
47
  end
48
37 49
  test "the browser policy permits only the narrow GitHub avatar origin", %{conn: conn} do
38 50
    response = get(conn, ~p"/")
39 51

This page updates live while a promote is in flight · changelog