diff --git a/assets/ui-rework/app.css b/assets/ui-rework/app.css index e522d4602..129a4f93a 100644 --- a/assets/ui-rework/app.css +++ b/assets/ui-rework/app.css @@ -123,16 +123,6 @@ font-size: 12px; } - .action-button { - @apply border border-base-600 bg-base-800 text-base-300; - display: flex; - gap: 8px; - padding: 6px 12px; - justify-content: center; - align-items: center; - border-radius: 4px; - } - .pager-button { @apply rounded-sm px-[12px] py-[6px]; font-size: 14px; diff --git a/lib/nerves_hub_web.ex b/lib/nerves_hub_web.ex index 20e393e30..9153b12f7 100644 --- a/lib/nerves_hub_web.ex +++ b/lib/nerves_hub_web.ex @@ -85,6 +85,9 @@ defmodule NervesHubWeb do import NervesHubWeb.Helpers.Authorization + import NervesHubWeb.Components.Icons + import NervesHubWeb.CoreComponents, only: [button: 1, input: 1, core_label: 1, error: 1] + # Shortcut for generating JS commands alias Phoenix.LiveView.JS @@ -137,6 +140,9 @@ defmodule NervesHubWeb do import NervesHubWeb.Helpers.Authorization + import NervesHubWeb.Components.Icons + import NervesHubWeb.CoreComponents, only: [button: 1, input: 1, core_label: 1, error: 1] + def ok(socket), do: {:ok, socket} def noreply(socket), do: {:noreply, socket} diff --git a/lib/nerves_hub_web/components/core_components.ex b/lib/nerves_hub_web/components/core_components.ex index 3c0087127..f0b287838 100644 --- a/lib/nerves_hub_web/components/core_components.ex +++ b/lib/nerves_hub_web/components/core_components.ex @@ -187,12 +187,69 @@ defmodule NervesHubWeb.CoreComponents do <.button>Send! <.button phx-click="go" class="ml-2">Send! """ + attr(:style, :string, default: "secondary") attr(:type, :string, default: nil) attr(:class, :string, default: nil) - attr(:rest, :global, include: ~w(disabled form name value)) + attr(:rest, :global, include: ~w(disabled form name value href navigate download)) slot(:inner_block, required: true) + def button(%{type: "link", style: "secondary"} = assigns) do + ~H""" + <.link + class={[ + "phx-submit-loading:opacity-75 flex items-center justify-center px-3 py-1.5 gap-2 rounded", + "bg-zinc-800 hover:bg-zinc-700 active:bg-indigo-500 disabled:bg-zinc-800", + "border rounded border-zinc-600 active:border-indigo-500", + "stroke-zinc-400 active:stroke-zinc-100 disabled:stroke-zinc-600", + "text-sm font-medium text-zinc-300 hover:text-neutral-50 active:text-neutral-50 disabled:text-zinc-500", + @class + ]} + {@rest} + > + {render_slot(@inner_block)} + + """ + end + + def button(%{style: "primary"} = assigns) do + ~H""" + + {render_slot(@inner_block)} + + """ + end + + def button(%{style: "secondary"} = assigns) do + ~H""" + + {render_slot(@inner_block)} + + """ + end + def button(assigns) do ~H""" - + <.input field={@form[:name]} label="Name" placeholder="Production" /> @@ -48,7 +48,7 @@ defmodule NervesHubWeb.Components.DeploymentPage.Settings do - - - + <.input field={@form[:tags]} value={tags_to_string(@form[:conditions])} label="Tag(s) distributed to" placeholder="eg. batch-123" /> - + <.input field={@form[:version]} value={@form[:conditions].value["version"]} label="Version requirement" placeholder="eg. 1.2.3" /> @@ -100,7 +100,7 @@ defmodule NervesHubWeb.Components.DeploymentPage.Settings do - - - Failure rate + <.core_label for={@form[:failure_rate_amount].id}>Failure rate - + <.input field={@form[:failure_threshold]} label="Failure threshold" type="number" hint={help_message_for(:failure_threshold)} /> @@ -171,7 +171,7 @@ defmodule NervesHubWeb.Components.DeploymentPage.Settings do - Device failure rate + <.core_label for={@form[:device_failure_rate_amount].id}>Device failure rate Maximum number of device failures within X seconds a device can have for this deployment before being marked unhealthy - + <.error :for={msg <- Enum.map(@form[:device_failure_rate_amount].errors ++ @form[:device_failure_rate_seconds].errors, &NervesHubWeb.CoreComponents.translate_error(&1))}> {msg} - + - + <.input field={@form[:device_failure_threshold]} label="Device failure threshold" type="number" hint={help_message_for(:device_failure_threshold)} /> - + <.input field={@form[:penalty_timeout_minutes]} label="Device penalty box timeout minutes" type="number" hint={help_message_for(:penalty_timeout_minutes)} /> @@ -232,7 +230,7 @@ defmodule NervesHubWeb.Components.DeploymentPage.Settings do - + <.input field={@form[:connecting_code]} type="textarea" rows={8} label="Run this code when the device first connects to the console."> <:rich_hint> Make sure this is valid Elixir and will not crash the device. @@ -241,27 +239,16 @@ defmodule NervesHubWeb.Components.DeploymentPage.Settings do This will run before device specific first connect code. - + - - - - - - Save changes - - + <.button style="secondary" type="submit"> + <.icon name="save" /> Save changes + diff --git a/lib/nerves_hub_web/components/device_page/details.ex b/lib/nerves_hub_web/components/device_page/details.ex index e255544b2..58ec41c50 100644 --- a/lib/nerves_hub_web/components/device_page/details.ex +++ b/lib/nerves_hub_web/components/device_page/details.ex @@ -294,7 +294,7 @@ defmodule NervesHubWeb.Components.DevicePage.Details do - Note: Device will be removed from the deployment upon connection if the aarch and platform doesn't match. + Please note: The device will be removed from the deployment upon connection if the aarch and platform don't match. @@ -308,13 +308,9 @@ defmodule NervesHubWeb.Components.DevicePage.Details do {deployment.name} - ({deployment.firmware.platform}, {deployment.firmware.architecture}) - + <.button type="submit" aria-label="Add to deployment" data-confirm="Are you sure you want to add the device to the deployment?"> Add to deployment - + @@ -335,16 +331,15 @@ defmodule NervesHubWeb.Components.DevicePage.Details do An update is available in the assigned deployment. - Skip the queue - + @@ -359,14 +354,10 @@ defmodule NervesHubWeb.Components.DevicePage.Details do {firmware.version} - + + <.button type="submit" disabled={disconnected?(@device_connection)} aria-label="Send firmware update" data-confirm="Are you sure you want to send this firmware to the device?"> Send update - + @@ -434,9 +425,9 @@ defmodule NervesHubWeb.Components.DevicePage.Details do - <.link navigate={~p"/org/#{@org.name}/#{@product.name}/scripts"} class="box-content h-5 py-1.5 px-3 rounded border border-base-600 bg-zinc-800 text-sm font-medium text-zinc-300"> - Add a support script - + <.button type="link" navigate={~p"/org/#{@org.name}/#{@product.name}/scripts/new"} aria-label="Add a support script"> + <.icon name="add" />Add a support script + diff --git a/lib/nerves_hub_web/components/device_page/settings.ex b/lib/nerves_hub_web/components/device_page/settings.ex index 89dfad9cc..dd48dbf06 100644 --- a/lib/nerves_hub_web/components/device_page/settings.ex +++ b/lib/nerves_hub_web/components/device_page/settings.ex @@ -40,20 +40,9 @@ defmodule NervesHubWeb.Components.DevicePage.Settings do General settings - - - - - - Save changes - - + <.button style="secondary" type="submit"> + <.icon name="save" /> Save changes + @@ -79,13 +68,13 @@ defmodule NervesHubWeb.Components.DevicePage.Settings do --%> - + <.input field={@settings_form[:description]} label="Description" placeholder="eg. sensor hub at customer X" /> - + <.input field={@settings_form[:tags]} value={tags_to_string(@settings_form[:tags])} label="Tags" placeholder="eg. batch-123" /> - + <.input field={@settings_form[:first_connect_code]} label="First connect code" type="textarea" rows="10" /> Make sure this is valid Elixir and will not crash the device diff --git a/lib/nerves_hub_web/components/icons.ex b/lib/nerves_hub_web/components/icons.ex new file mode 100644 index 000000000..9d015392f --- /dev/null +++ b/lib/nerves_hub_web/components/icons.ex @@ -0,0 +1,85 @@ +defmodule NervesHubWeb.Components.Icons do + use Phoenix.Component + + @doc """ + A little icon helper. + + ## Examples + + <.icon name="save" /> + <.icon name="trash" class="ml-1 w-3 h-3" /> + """ + attr(:name, :string, required: true) + attr(:class, :string, default: nil) + + def icon(%{name: "save"} = assigns) do + ~H""" + + + + """ + end + + def icon(%{name: "export"} = assigns) do + ~H""" + + + + """ + end + + def icon(%{name: "add"} = assigns) do + ~H""" + + + + """ + end + + def icon(%{name: "filter"} = assigns) do + ~H""" + + + + """ + end + + def icon(%{name: "power"} = assigns) do + ~H""" + + + + """ + end + + def icon(%{name: "download"} = assigns) do + ~H""" + + + + """ + end +end diff --git a/lib/nerves_hub_web/live/archive_templates/show_archive_template_new.html.heex b/lib/nerves_hub_web/live/archive_templates/show_archive_template_new.html.heex index 16578b3a3..26dfa5f7d 100644 --- a/lib/nerves_hub_web/live/archive_templates/show_archive_template_new.html.heex +++ b/lib/nerves_hub_web/live/archive_templates/show_archive_template_new.html.heex @@ -33,17 +33,9 @@ - <.link class="flex px-3 py-1.5 gap-2 rounded border border-base-600 bg-zinc-800" href={~p"/org/#{@org.name}/#{@product.name}/archives/#{@archive.uuid}/download"} download> - - - - Download - + <.button type="link" href={~p"/org/#{@org.name}/#{@product.name}/archives/#{@archive.uuid}/download"} download> + <.icon name="download" />Download + All Deployments {@pager_meta.total_count} - <.link class="action-button" navigate={~p"/org/#{@org.name}/#{@product.name}/deployments/new"} aria-label="Create new deployment"> - - - - Create Deployment - + <.button type="link" navigate={~p"/org/#{@org.name}/#{@product.name}/deployments/new"} aria-label="Add a new deployment"> + <.icon name="add" /> Create Deployment + <%= if Enum.empty?(@entries) do %> diff --git a/lib/nerves_hub_web/live/deployments/show-new.html.heex b/lib/nerves_hub_web/live/deployments/show-new.html.heex index 9156afb0c..b8f34cd2a 100644 --- a/lib/nerves_hub_web/live/deployments/show-new.html.heex +++ b/lib/nerves_hub_web/live/deployments/show-new.html.heex @@ -10,25 +10,15 @@ {@deployment.name} - - - - - {(@deployment.is_active && "Pause") || "Resume"} - + <.icon name="power" />{(@deployment.is_active && "Pause") || "Resume"} + @@ -45,8 +35,6 @@ - <%!-- --%> - @@ -119,6 +107,4 @@ <.live_component :if={@tab == :activity} module={ActivityTab} id="deployment_activity" deployment={@deployment} org={@org} product={@product} user={@user} /> <.live_component :if={@tab == :settings} module={SettingsTab} id="deployment_settings" deployment={@deployment} org={@org} product={@product} user={@user} org_user={@org_user} /> - <%!-- - <.live_component :if={@tab == :settings} module={SettingsPage} id="device_settings" device={@device} org={@org} product={@product} user={@user} org_user={@org_user} /> --%> diff --git a/lib/nerves_hub_web/live/devices/index-new.html.heex b/lib/nerves_hub_web/live/devices/index-new.html.heex index bca52c468..78eff48df 100644 --- a/lib/nerves_hub_web/live/devices/index-new.html.heex +++ b/lib/nerves_hub_web/live/devices/index-new.html.heex @@ -41,36 +41,15 @@ - <.link :if={Enum.any?(@devices) || @currently_filtering} class="action-button" aria-label="Export devices" href={~p"/org/#{@org.name}/#{@product.name}/devices/export"} download> - - - - Export - - <.link class="action-button" navigate={~p"/org/#{@org.name}/#{@product.name}/devices/new"} aria-label="Add new device"> - - - - Add Device - - - - - - - Filters - - + <.button :if={Enum.any?(@devices) || @currently_filtering} type="link" aria-label="Export devices" href={~p"/org/#{@org.name}/#{@product.name}/devices/export"} download> + <.icon name="export" /> Export + + <.button type="link" navigate={~p"/org/#{@org.name}/#{@product.name}/devices/new"} aria-label="Add new device"> + <.icon name="add" /> Add Device + + <.button :if={Enum.any?(@devices) || @currently_filtering} type="button" phx-click="toggle-filters" phx-value-toggle={to_string(@show_filters)}> + <.icon name="filter" /> Filters + <%= if Enum.empty?(@devices) && !@currently_filtering do %> @@ -288,7 +267,8 @@ @@ -407,7 +387,8 @@ diff --git a/lib/nerves_hub_web/live/devices/new-new.html.heex b/lib/nerves_hub_web/live/devices/new-new.html.heex index de1ad7555..9a16860b9 100644 --- a/lib/nerves_hub_web/live/devices/new-new.html.heex +++ b/lib/nerves_hub_web/live/devices/new-new.html.heex @@ -37,31 +37,22 @@ - + <.input field={@form[:identifier]} label="Identifier" placeholder="eg. a-random-uuid" /> - + <.input field={@form[:description]} label="Description" placeholder="eg. sensor hub at customer X" /> - + <.input field={@form[:tags]} value={tags_to_string(@form[:tags])} label="Tags" placeholder="eg. batch-123" /> - + <.input field={@form[:first_connect_code]} label="First connect code" type="textarea" rows="10" /> Make sure this is valid Elixir and will not crash the device - - - - - Save changes - + <.button style="secondary" type="submit"> + <.icon name="save" /> Save changes + diff --git a/lib/nerves_hub_web/live/firmware_templates/show_firmware_template_new.html.heex b/lib/nerves_hub_web/live/firmware_templates/show_firmware_template_new.html.heex index 74aa57487..dd132e5b3 100644 --- a/lib/nerves_hub_web/live/firmware_templates/show_firmware_template_new.html.heex +++ b/lib/nerves_hub_web/live/firmware_templates/show_firmware_template_new.html.heex @@ -33,17 +33,9 @@ - <.link class="flex px-3 py-1.5 gap-2 rounded border border-base-600 bg-zinc-800" href={~p"/org/#{@org.name}/#{@product.name}/firmware/#{@firmware.uuid}/download"} download> - - - - Download - + <.button type="link" href={~p"/org/#{@org.name}/#{@product.name}/firmware/#{@firmware.uuid}/download"} download> + <.icon name="download" />Download + - + <.input field={@form[:name]} label="Name" hint="Once created, a product name cannot be changed" disabled /> - + <.input field={@form[:delta_updatable]} type="checkbox" label="Delta updates" phx-click="toggle-delta-updates"> <:rich_hint> Check out the <.link class="underline" href="https://docs.nerves-hub.org/nerves-hub/setup/firmware#delta-updates" target="_blank">NervesHub documentation for more information on delta updates. - - <%!-- - - - --%> + @@ -134,19 +130,20 @@ - - Copy Secret - - + Copy secret + + + <.button phx-click="deactivate-shared-secret" phx-value-shared_secret_id={auth.id} disabled={!authorized?(:"product:update", @org_user)} - data-confirm="Are you sure?" + data-confirm="Are you sure you want to deactivate this shared secret?" + aria-label="Copy secret" > Deactivate - + @@ -162,24 +159,14 @@ - - - - - Create a Shared Secret - + <.icon name="add" />Create a Shared Secret + <% else %> diff --git a/lib/nerves_hub_web/live/support_scripts/edit-new.html.heex b/lib/nerves_hub_web/live/support_scripts/edit-new.html.heex index 1bc49d992..96177d1db 100644 --- a/lib/nerves_hub_web/live/support_scripts/edit-new.html.heex +++ b/lib/nerves_hub_web/live/support_scripts/edit-new.html.heex @@ -37,27 +37,18 @@ - + <.input field={@form[:name]} label="Name" placeholder="eg. System Debugging" /> - + <.input field={@form[:text]} label="Script code" type="textarea" rows="10" /> Make sure this is valid Elixir and will not crash the device - - - - - Save changes - + <.button style="secondary" type="submit"> + <.icon name="save" /> Save changes + diff --git a/lib/nerves_hub_web/live/support_scripts/index-new.html.heex b/lib/nerves_hub_web/live/support_scripts/index-new.html.heex index 42115b322..9ad0c4d96 100644 --- a/lib/nerves_hub_web/live/support_scripts/index-new.html.heex +++ b/lib/nerves_hub_web/live/support_scripts/index-new.html.heex @@ -50,45 +50,6 @@ {Calendar.strftime(script.inserted_at, "%Y-%m-%d at %I:%M %p UTC")} - - <%!-- - - - - - - - - <.link phx-click="reboot-device" phx-value-device_identifier={device.identifier} class="dropdown-item"> - Reboot - - - <.link navigate={~p"/org/#{@org.name}/#{@product.name}/devices/#{device.identifier}/console"} class="dropdown-item"> - Console - - - - <.link phx-click="toggle-device-updates" phx-value-device_identifier={device.identifier} class="dropdown-item"> - - <%= if device.updates_enabled, do: "Disable Updates", else: "Enable Updates" %> - - - - - - <%= link to: Routes.device_path(@socket, :export_audit_logs, @org.name, @product.name, device.identifier), class: "dropdown-item", aria: [label: "Download Audit Logs"] do %> - - Download Audit Logs - <% end %> - - - --%> diff --git a/lib/nerves_hub_web/live/support_scripts/new-new.html.heex b/lib/nerves_hub_web/live/support_scripts/new-new.html.heex index edf883122..4da9eb186 100644 --- a/lib/nerves_hub_web/live/support_scripts/new-new.html.heex +++ b/lib/nerves_hub_web/live/support_scripts/new-new.html.heex @@ -37,27 +37,18 @@ - + <.input field={@form[:name]} label="Name" placeholder="eg. System Debugging" /> - + <.input field={@form[:text]} label="Script code" type="textarea" rows="10" /> Make sure this is valid Elixir and will not crash the device - - - - - Save changes - + <.button style="secondary" type="submit"> + <.icon name="save" /> Save changes +
Make sure this is valid Elixir and will not crash the device. @@ -241,27 +239,16 @@ defmodule NervesHubWeb.Components.DeploymentPage.Settings do This will run before device specific first connect code.