Current section

43 Versions

Jump to

Compare versions

6 files changed
+43 additions
-20 deletions
  @@ -1,5 +1,10 @@
1 1 # CHANGELOG
2 2
3 + ## v0.5.1 (2020-09-07)
4 +
5 + * Clarify "No Ecto Repos" messages
6 + * Support strings on navbars titles
7 +
3 8 ## v0.5.0 (2020-08-10)
4 9
5 10 * Require LiveView v0.16.0
  @@ -79,4 +79,4 @@
79 79 {<<"optional">>,true},
80 80 {<<"repository">>,<<"hexpm">>},
81 81 {<<"requirement">>,<<"~> 3.6.2 or ~> 3.7">>}]]}.
82 - {<<"version">>,<<"0.5.0">>}.
82 + {<<"version">>,<<"0.5.1">>}.
  @@ -14,19 +14,15 @@ defmodule Phoenix.LiveDashboard.NavBarComponent do
14 14 end
15 15
16 16 defp current_item(params, items, nav_param) do
17 - nav_param = Atom.to_string(nav_param)
18 -
19 17 with %{^nav_param => item} <- params,
20 - true <- Enum.any?(items, fn {id, _} -> Atom.to_string(id) == item end) do
21 - String.to_existing_atom(item)
18 + true <- List.keymember?(items, item, 0) do
19 + item
22 20 else
23 21 _ -> default_item(items)
24 22 end
25 23 end
26 24
27 - defp default_item([{id, _} | _]) do
28 - id
29 - end
25 + defp default_item([{id, _} | _]), do: id
30 26
31 27 def normalize_params(params) do
32 28 case Map.fetch(params, :items) do
  @@ -55,21 +51,23 @@ defmodule Phoenix.LiveDashboard.NavBarComponent do
55 51 []
56 52
57 53 {:ok, extra_params_list} when is_list(extra_params_list) ->
58 - unless Enum.all?(extra_params_list, &is_atom/1) do
59 - msg = ":extra_params must be a list of atoms, got: "
54 + unless Enum.all?(extra_params_list, &(is_binary(&1) or is_atom(&1))) do
55 + msg = ":extra_params must be a list of strings or atoms, got: "
60 56 raise ArgumentError, msg <> inspect(extra_params_list)
61 57 end
62 58
59 + extra_params_list = Enum.map(extra_params_list, &to_string/1)
60 +
63 61 if nav_param in extra_params_list do
64 62 msg = ":extra_params must not contain the :nav_param field name #{inspect(nav_param)}"
65 63
66 64 raise ArgumentError, msg
67 65 end
68 66
69 - Enum.map(extra_params_list, &to_string/1)
67 + extra_params_list
70 68
71 69 {:ok, extra_params} ->
72 - msg = ":extra_params must be a list of atoms, got: "
70 + msg = ":extra_params must be a list of strings or atoms, got: "
73 71 raise ArgumentError, msg <> inspect(extra_params)
74 72 end
75 73 end
  @@ -77,13 +75,17 @@ defmodule Phoenix.LiveDashboard.NavBarComponent do
77 75 defp normalize_nav_param(params) do
78 76 case Map.fetch(params, :nav_param) do
79 77 :error ->
80 - :nav
78 + "nav"
81 79
82 - {:ok, nav_param} when is_atom(nav_param) ->
80 + {:ok, nav_param} when is_binary(nav_param) ->
83 81 nav_param
84 82
83 + {:ok, nav_param} when is_atom(nav_param) ->
84 + Atom.to_string(nav_param)
85 +
85 86 {:ok, nav_param} ->
86 - raise ArgumentError, ":nav_param parameter must be an atom, got: #{inspect(nav_param)}"
87 + raise ArgumentError,
88 + ":nav_param parameter must be an string or atom, got: #{inspect(nav_param)}"
87 89 end
88 90 end
89 91
  @@ -102,6 +104,10 @@ defmodule Phoenix.LiveDashboard.NavBarComponent do
102 104 end
103 105
104 106 defp normalize_item({id, item}) when is_atom(id) and is_list(item) do
107 + normalize_item({Atom.to_string(id), item})
108 + end
109 +
110 + defp normalize_item({id, item}) when is_binary(id) and is_list(item) do
105 111 {id,
106 112 item
107 113 |> validate_item_render()
  @@ -110,7 +116,7 @@ defmodule Phoenix.LiveDashboard.NavBarComponent do
110 116 end
111 117
112 118 defp normalize_item(invalid_item) do
113 - msg = ":items must be [{atom(), [name: string(), render: fun()], got: "
119 + msg = ":items must be [{string() | atom(), [name: string(), render: fun()], got: "
114 120
115 121 raise ArgumentError, msg <> inspect(invalid_item)
116 122 end
  @@ -176,7 +182,7 @@ defmodule Phoenix.LiveDashboard.NavBarComponent do
176 182 </ul>
177 183 </div>
178 184 </div>
179 - <%= render_content(@page, @items[@current][:render]) %>
185 + <%= render_item_content(@page, @items, @current) %>
180 186 </div>
181 187 """
182 188 end
  @@ -201,6 +207,11 @@ defmodule Phoenix.LiveDashboard.NavBarComponent do
201 207 end
202 208 end
203 209
210 + defp render_item_content(page, items, id) do
211 + {_, opts} = List.keyfind(items, id, 0)
212 + render_content(page, opts[:render])
213 + end
214 +
204 215 defp render_content(page, component_or_fun) do
205 216 case component_or_fun do
206 217 {component, component_assigns} ->
  @@ -781,7 +781,7 @@ defmodule Phoenix.LiveDashboard.PageBuilder do
781 781 @doc """
782 782 Computes a router path to the current page with merged params.
783 783 """
784 - @spec live_dashboard_path(Socket.t(), page :: %__MODULE__{}, map()) :: binary()
784 + @spec live_dashboard_path(Socket.t(), page :: %__MODULE__{}, map() | Keyword.t()) :: binary()
785 785 def live_dashboard_path(socket, %{route: route, node: node, params: old_params}, extra) do
786 786 new_params = Enum.into(extra, old_params, fn {k, v} -> {Atom.to_string(k), v} end)
787 787 live_dashboard_path(socket, route, node, old_params, new_params)
  @@ -239,7 +239,14 @@ defmodule Phoenix.LiveDashboard.EctoStatsPage do
239 239 error_message =
240 240 case assigns.error do
241 241 :no_ecto_repos_available ->
242 - "No Ecto repository was found. Currently only PSQL databases are supported."
242 + error_details = """
243 + No Ecto repository was found or Ecto PSQL Extras is not installed.
244 + Currently only PSQL databases are supported.
245 +
246 + Check the <a href="https://hexdocs.pm/phoenix_live_dashboard/ecto_stats.html" target="_blank">documentation</a> for details.
247 + """
248 +
249 + {:safe, error_details}
243 250 end
244 251
245 252 row(
Loading more files…