Skip to content

Commit e485987

Browse files
committed
Remove hardacoded cpu- from shared usage IDs
1 parent ff5d630 commit e485987

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

lib/phoenix/live_dashboard/page_builder.ex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ defmodule Phoenix.LiveDashboard.PageBuilder do
497497
attr :current, :integer, required: true, doc: "The current value of the usage."
498498
attr :limit, :integer, required: true, doc: "The max value of usage."
499499

500-
attr :dom_sub_id, :string,
500+
attr :dom_id, :string,
501501
required: true,
502502
doc: "An unique identifier for the usage that will be concatenated to `dom_id`."
503503

@@ -513,7 +513,7 @@ defmodule Phoenix.LiveDashboard.PageBuilder do
513513
<div class="card">
514514
<div class="card-body card-usage">
515515
<%= for usage <- @usage do %>
516-
<.title_bar_component dom_id={"#{@dom_id}-#{usage.dom_sub_id}"} percent={usage.percent} csp_nonces={@csp_nonces} >
516+
<.title_bar_component dom_id={"#{@dom_id}-#{usage.dom_id}"} percent={usage.percent} csp_nonces={@csp_nonces} >
517517
<div>
518518
<%= usage.title %>
519519
<.hint text={usage[:hint]} :if={usage[:hint]}/>
@@ -574,7 +574,7 @@ defmodule Phoenix.LiveDashboard.PageBuilder do
574574
doc: """
575575
A list of `Map` with the following keys:
576576
* `:data` - A list of tuples with 4 elements with the following data: `{usage_name, usage_percent, color, hint}`
577-
* `:dom_sub_id` - Required. Usage identifier.
577+
* `:dom_id` - Required. Usage identifier.
578578
* `:title`- Bar title.
579579
"""
580580

@@ -585,6 +585,7 @@ defmodule Phoenix.LiveDashboard.PageBuilder do
585585

586586
attr :total_legend, :string, required: true, doc: "The legent of the total usage."
587587
attr :total_usage, :string, required: true, doc: "The value of the total usage."
588+
attr :dom_id, :string, default: nil, doc: "id attribute for the HTML the main tag."
588589

589590
attr :csp_nonces, :any,
590591
required: true,
@@ -606,12 +607,12 @@ defmodule Phoenix.LiveDashboard.PageBuilder do
606607
<div class="card">
607608
<.card_title title={@inner_title} hint={@inner_hint} />
608609
<div class="card-body">
609-
<div phx-hook="PhxColorBarHighlight" id="cpu-color-bars">
610+
<div phx-hook="PhxColorBarHighlight" id={"#{@dom_id}-color-bars"}>
610611
<div :for={usage <- @usages} class="flex-grow-1 mb-3">
611612
<div class="progress color-bar-progress flex-grow-1 mb-3">
612613
<span :if={usage[:title]} class="color-bar-progress-title"><%= usage[:title] %></span>
613614
<%= for {{name, value, color, _desc}, index} <- Enum.with_index(usage.data) do %>
614-
<style nonce={@csp_nonces.style}>#<%= "cpu-#{usage.dom_sub_id}-progress-#{index}" %>{width:<%= value %>%}</style>
615+
<style nonce={@csp_nonces.style}>#<%= "#{@dom_id}-#{usage.dom_id}-progress-#{index}" %>{width:<%= value %>%}</style>
615616
<div
616617
title={"#{name} - #{Phoenix.LiveDashboard.Helpers.format_percent(value)}"}
617618
class={"progress-bar color-bar-progress-bar bg-gradient-#{color}"}
@@ -621,7 +622,7 @@ defmodule Phoenix.LiveDashboard.PageBuilder do
621622
aria-valuemax="100"
622623
data-name={name}
623624
data-empty={empty?(value)}
624-
id={"cpu-#{usage.dom_sub_id}-progress-#{index}"}>
625+
id={"#{@dom_id}-#{usage.dom_id}-progress-#{index}"}>
625626
</div>
626627
<% end %>
627628
</div>

lib/phoenix/live_dashboard/pages/home_page.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ defmodule Phoenix.LiveDashboard.HomePage do
276276
current: system_usage[type],
277277
limit: system_limits[type],
278278
percent: percentage(system_usage[type], system_limits[type]),
279-
dom_sub_id: "total",
279+
dom_id: "total",
280280
hint: raw(@hints[type]),
281281
title: Phoenix.Naming.humanize(type)
282282
}
@@ -293,6 +293,7 @@ defmodule Phoenix.LiveDashboard.HomePage do
293293
<.row>
294294
<:col>
295295
<.shared_usage_card
296+
dom_id="memory"
296297
title="Memory"
297298
usages={[calculate_memory_usage_percent(@memory_usage, @system_usage.memory.total)]}
298299
total_data={@memory_usage}
@@ -320,7 +321,7 @@ defmodule Phoenix.LiveDashboard.HomePage do
320321

321322
%{
322323
data: data,
323-
dom_sub_id: "total"
324+
dom_id: "total"
324325
}
325326
end
326327

lib/phoenix/live_dashboard/pages/os_mon_page.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ defmodule Phoenix.LiveDashboard.OSMonPage do
7171
current: format_bytes(current),
7272
limit: format_bytes(limit),
7373
percent: percentage(current, limit),
74-
dom_sub_id: value_key,
74+
dom_id: value_key,
7575
hint: hint,
7676
title: key
7777
}
@@ -102,7 +102,7 @@ defmodule Phoenix.LiveDashboard.OSMonPage do
102102
current: format_percent(percent),
103103
limit: format_bytes(kbytes * 1024),
104104
percent: percent,
105-
dom_sub_id: index,
105+
dom_id: index,
106106
title: mountpoint
107107
}
108108
end)

test/phoenix/live_dashboard/page_builder_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ defmodule Phoenix.LiveDashboard.PageBuilderTest do
9191
usages={[
9292
%{
9393
data: [{"foo", 123, "green", nil}, {"bar", 456, "blue", nil}],
94-
dom_sub_id: "test-dom-sub-id",
94+
dom_id: "sub-id",
9595
title: "test-usage-title"
9696
}
9797
]}
@@ -120,12 +120,12 @@ defmodule Phoenix.LiveDashboard.PageBuilderTest do
120120
assert result =~ ~S|<span class="color-bar-progress-title">test-usage-title</span>|
121121

122122
assert result =~
123-
~r|<style nonce="style_nonce">#cpu-test-dom-sub-id-progress-(1\|2){width:(123\|456)%}</style>|
123+
~r|<style nonce="style_nonce">#test-dom-id-sub-id-progress-(1\|2){width:(123\|456)%}</style>|
124124

125125
assert result =~ ~r|title=\"(foo\|bar) - (123\|456)%\"|
126126
assert result =~ ~r|class=\"progress-bar color-bar-progress-bar bg-gradient-(blue\|green)\"|
127127
assert result =~ ~r|data-name=\"(foo\|bar)\"|
128-
assert result =~ ~r|id=\"cpu-test-dom-sub-id-progress-(0\|1)\"|
128+
assert result =~ ~r|id=\"test-dom-id-sub-id-progress-(0\|1)\"|
129129

130130
assert result =~ ~r|color-bar-legend-entry\" data-name=\"(foo\|bar)\"|
131131
assert result =~ ~r|<div class="color-bar-legend-color bg-(blue\|green) mr-2"></div>|
@@ -149,7 +149,7 @@ defmodule Phoenix.LiveDashboard.PageBuilderTest do
149149
<:usage
150150
current={10}
151151
limit={150}
152-
dom_sub_id="test-dom-sub-id"
152+
dom_id="test-dom-sub-id"
153153
title="test-usage-title"
154154
hint="test-usage-hint"
155155
percent={13}

0 commit comments

Comments
 (0)