Skip to content

Commit 1833f8b

Browse files
authored
Update to work with phoenix_live_dashboard 0.8 (#26)
* Update to work with phoenix_live_dashboard 0.8 * Only phoenix_live_dashboard 0.8 works now * Change function name * Fix layout regression
1 parent 6f42027 commit 1833f8b

3 files changed

Lines changed: 114 additions & 121 deletions

File tree

lib/broadway_dashboard.ex

Lines changed: 95 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ defmodule BroadwayDashboard do
137137
end
138138

139139
@impl true
140-
def render_page(assigns) do
140+
def render(assigns) do
141141
if assigns[:error] do
142142
render_error(assigns)
143143
else
@@ -149,10 +149,22 @@ defmodule BroadwayDashboard do
149149
name: name, render: fn -> render_pipeline_or_error(assigns) end, method: :redirect}
150150
end
151151

152-
nav_bar(items: items)
152+
nav_bar(items: items, page: assigns[:page])
153153
end
154154
end
155155

156+
defp nav_bar(opts) do
157+
assigns = Map.new(opts)
158+
159+
~H"""
160+
<.live_nav_bar id="broadway_navbar" page={@page}>
161+
<:item name={name} :for={{name, item} <- @items}>
162+
<%= item[:render].() %>
163+
</:item>
164+
</.live_nav_bar>
165+
"""
166+
end
167+
156168
defp render_pipeline_or_error(assigns) do
157169
if assigns[:error] do
158170
render_error(assigns)
@@ -162,108 +174,91 @@ defmodule BroadwayDashboard do
162174
end
163175

164176
defp render_pipeline(assigns) do
165-
row(
166-
components: [
167-
columns(
168-
components: [
169-
pipeline_throughput_row(assigns.stats)
170-
]
171-
),
172-
columns(
173-
components: [
174-
pipeline_graph_row(assigns.layers)
175-
]
176-
)
177-
]
178-
)
177+
~H"""
178+
<.row>
179+
<:col>
180+
<.pipeline_throughput_row stats={@stats} />
181+
<.pipeline_graph_row layers={@layers} />
182+
</:col>
183+
</.row>
184+
"""
179185
end
180186

181187
defp render_error(assigns) do
182-
error_message =
183-
case assigns.error do
184-
:connection_is_not_available ->
185-
"Dashboard is not connected yet."
188+
error_message = error_message(assigns)
189+
assigns = Map.put(assigns, :error_message, error_message)
190+
191+
~H"""
192+
<.row>
193+
<:col>
194+
<.card><%= @error_message %></.card>
195+
</:col>
196+
</.row>
197+
"""
198+
end
186199

187-
:pipeline_not_found ->
188-
"This pipeline is not available for this node."
200+
defp error_message(assigns) do
201+
case assigns.error do
202+
:connection_is_not_available ->
203+
"Dashboard is not connected yet."
189204

190-
:pipeline_is_not_running ->
191-
"This pipeline is not running on this node."
205+
:pipeline_not_found ->
206+
"This pipeline is not available for this node."
192207

193-
:broadway_is_not_available ->
194-
"Broadway is not available on remote node."
208+
:pipeline_is_not_running ->
209+
"This pipeline is not running on this node."
195210

196-
:version_is_not_enough ->
197-
"Broadway is outdated on remote node. Minimum version required is #{@minimum_broadway_version}"
211+
:broadway_is_not_available ->
212+
"Broadway is not available on remote node."
198213

199-
:no_pipelines_available ->
200-
"There is no pipeline running on this node."
214+
:version_is_not_enough ->
215+
"Broadway is outdated on remote node. Minimum version required is #{@minimum_broadway_version}"
201216

202-
:cannot_list_running_pipelines ->
203-
"Could not list running pipelines at remote node. Please try again later."
217+
:no_pipelines_available ->
218+
"There is no pipeline running on this node."
204219

205-
:not_able_to_start_remotely ->
206-
"Could not start the metrics server remotely. Please try again later."
220+
:cannot_list_running_pipelines ->
221+
"Could not list running pipelines at remote node. Please try again later."
207222

208-
{:badrpc, _} ->
209-
"Could not send request to node. Try again later."
210-
end
223+
:not_able_to_start_remotely ->
224+
"Could not start the metrics server remotely. Please try again later."
211225

212-
row(
213-
components: [
214-
columns(
215-
components: [
216-
card(value: error_message)
217-
]
218-
)
219-
]
220-
)
226+
{:badrpc, _} ->
227+
"Could not send request to node. Try again later."
228+
end
221229
end
222230

223-
defp pipeline_throughput_row(stats) do
224-
row(
225-
components: [
226-
columns(
227-
components: [
228-
row(
229-
components: [
230-
columns(
231-
components: [
232-
card(
233-
title: "Throughput",
234-
hint: "Messages p/ second.",
235-
inner_title: "successful",
236-
value: stats.throughput_successful
237-
),
238-
card(inner_title: "failed", value: stats.throughput_failed),
239-
card(
240-
inner_title: "total",
241-
value: stats.throughput_successful + stats.throughput_failed
242-
)
243-
]
244-
)
245-
]
246-
),
247-
row(
248-
components: [
249-
columns(
250-
components: [
251-
card(
252-
title: "All time",
253-
hint: "Messages since start.",
254-
inner_title: "successful",
255-
value: stats.successful
256-
),
257-
card(inner_title: "failed", value: stats.failed),
258-
card(inner_title: "total", value: stats.successful + stats.failed)
259-
]
260-
)
261-
]
262-
)
263-
]
264-
)
265-
]
266-
)
231+
defp pipeline_throughput_row(assigns) do
232+
~H"""
233+
<.row>
234+
<:col>
235+
<.row>
236+
<:col>
237+
<.card title="Throughput" hint="Messages p/ second." inner_title="successful"><%= @stats.throughput_successful %></.card>
238+
</:col>
239+
<:col>
240+
<.card inner_title="failed"><%= @stats.throughput_failed %></.card>
241+
</:col>
242+
<:col>
243+
<.card inner_title="total"><%= @stats.throughput_successful + @stats.throughput_failed %></.card>
244+
</:col>
245+
</.row>
246+
</:col>
247+
<:col>
248+
<.row>
249+
<:col>
250+
<.card title="All time" hint="Messages since start." inner_title="successful"><%= @stats.successful %></.card>
251+
</:col>
252+
<:col>
253+
<.card inner_title="failed"><%= @stats.failed %></.card>
254+
</:col>
255+
<:col>
256+
<.card inner_title="total"><%= @stats.successful + @stats.failed %></.card>
257+
</:col>
258+
</.row>
259+
</:col>
260+
</.row>
261+
"""
267262
end
268263

269264
@hint """
@@ -276,23 +271,16 @@ defmodule BroadwayDashboard do
276271
processes in red.
277272
"""
278273

279-
defp pipeline_graph_row(layers) do
280-
row(
281-
title: "Graph",
282-
components: [
283-
columns(
284-
components: [
285-
layered_graph(
286-
layers: layers,
287-
title: "Pipeline",
288-
hint: @hint,
289-
background: &background/1,
290-
format_detail: &format_detail/1
291-
)
292-
]
293-
)
294-
]
295-
)
274+
defp pipeline_graph_row(assigns) do
275+
assigns = Map.put(assigns, :hint, @hint)
276+
277+
~H"""
278+
<.row>
279+
<:col>
280+
<.live_layered_graph layers={@layers} id="pipeline" title="Pipeline" hint={@hint} background={&background/1} format_detail={&format_detail/1} />
281+
</:col>
282+
</.row>
283+
"""
296284
end
297285

298286
defp background(node_data) when is_binary(node_data) do

mix.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ defmodule BroadwayDashboard.MixProject do
3030
defp deps do
3131
[
3232
{:broadway, "~> 1.0"},
33-
{:phoenix_live_dashboard, "~> 0.5.1 or ~> 0.6.0 or ~> 0.7.0"},
33+
{:phoenix_live_dashboard, "~> 0.8.0"},
3434
{:phoenix_live_reload, "~> 1.2", only: :dev},
35+
{:phoenix_view, "~> 2.0 or ~> 1.0", only: [:test]},
3536
{:plug_cowboy, "~> 2.0", only: :dev},
3637
{:jason, "~> 1.0", only: [:dev, :test, :docs]},
3738
{:ex_doc, "~> 0.24", only: [:docs], runtime: false},

0 commit comments

Comments
 (0)