2022-09-15 00:24:32 +08:00
|
|
|
defmodule LivebookWeb.EnvVarsComponent do
|
2022-09-12 22:34:39 +08:00
|
|
|
use LivebookWeb, :live_component
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def render(assigns) do
|
2022-09-17 07:37:01 +08:00
|
|
|
assigns =
|
|
|
|
assigns
|
|
|
|
|> assign_new(:target, fn -> nil end)
|
|
|
|
|> assign_new(:edit_label, fn -> "Edit" end)
|
2022-09-15 00:24:32 +08:00
|
|
|
|
2022-09-12 22:34:39 +08:00
|
|
|
~H"""
|
|
|
|
<div id={@id} class="flex flex-col space-y-4">
|
|
|
|
<div class="flex flex-col space-y-4">
|
2023-02-23 02:34:54 +08:00
|
|
|
<div
|
|
|
|
:for={env_var <- @env_vars}
|
|
|
|
class="flex items-center justify-between border border-gray-200 rounded-lg p-4"
|
|
|
|
>
|
|
|
|
<.env_var_info env_var={env_var} edit_label={@edit_label} target={@target} />
|
|
|
|
</div>
|
2022-09-12 22:34:39 +08:00
|
|
|
</div>
|
|
|
|
<div class="flex">
|
2023-02-23 02:34:54 +08:00
|
|
|
<.link patch={@add_env_var_path} class="button-base button-blue" id="add-env-var">
|
|
|
|
Add environment variable
|
|
|
|
</.link>
|
2022-09-12 22:34:39 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
defp env_var_info(assigns) do
|
|
|
|
~H"""
|
|
|
|
<div class="grid grid-cols-1 md:grid-cols-2 w-full">
|
|
|
|
<div class="place-content-start">
|
2022-09-17 07:37:01 +08:00
|
|
|
<.labeled_text label="Name">
|
|
|
|
<%= @env_var.name %>
|
2022-09-12 22:34:39 +08:00
|
|
|
</.labeled_text>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex items-center place-content-end">
|
2022-09-17 07:37:01 +08:00
|
|
|
<.menu id={"env-var-#{@env_var.name}-menu"}>
|
2022-09-12 22:34:39 +08:00
|
|
|
<:toggle>
|
2023-03-09 23:04:47 +08:00
|
|
|
<button class="icon-button" aria-label="open environment variable menu" type="button">
|
2022-09-12 22:34:39 +08:00
|
|
|
<.remix_icon icon="more-2-fill" class="text-xl" />
|
|
|
|
</button>
|
|
|
|
</:toggle>
|
2023-02-24 02:07:00 +08:00
|
|
|
<.menu_item>
|
2022-09-12 22:34:39 +08:00
|
|
|
<button
|
2022-09-17 07:37:01 +08:00
|
|
|
id={"env-var-#{@env_var.name}-edit"}
|
2022-09-12 22:34:39 +08:00
|
|
|
type="button"
|
2022-09-17 07:37:01 +08:00
|
|
|
phx-click={JS.push("edit_env_var", value: %{env_var: @env_var.name})}
|
2022-09-15 00:24:32 +08:00
|
|
|
phx-target={@target}
|
2022-09-12 22:34:39 +08:00
|
|
|
role="menuitem"
|
|
|
|
>
|
|
|
|
<.remix_icon icon="file-edit-line" />
|
2023-02-24 02:07:00 +08:00
|
|
|
<span><%= @edit_label %></span>
|
2022-09-12 22:34:39 +08:00
|
|
|
</button>
|
2023-02-24 02:07:00 +08:00
|
|
|
</.menu_item>
|
|
|
|
<.menu_item variant={:danger}>
|
2022-09-12 22:34:39 +08:00
|
|
|
<button
|
2022-09-17 07:37:01 +08:00
|
|
|
id={"env-var-#{@env_var.name}-delete"}
|
2022-09-12 22:34:39 +08:00
|
|
|
type="button"
|
|
|
|
phx-click={
|
|
|
|
with_confirm(
|
2022-09-17 07:37:01 +08:00
|
|
|
JS.push("delete_env_var", value: %{env_var: @env_var.name}),
|
|
|
|
title: "Delete #{@env_var.name}",
|
2022-09-12 22:34:39 +08:00
|
|
|
description: "Are you sure you want to delete environment variable?",
|
|
|
|
confirm_text: "Delete",
|
|
|
|
confirm_icon: "delete-bin-6-line"
|
|
|
|
)
|
|
|
|
}
|
2022-09-15 00:24:32 +08:00
|
|
|
phx-target={@target}
|
2022-09-12 22:34:39 +08:00
|
|
|
role="menuitem"
|
|
|
|
>
|
|
|
|
<.remix_icon icon="delete-bin-line" />
|
2023-02-24 02:07:00 +08:00
|
|
|
<span>Delete</span>
|
2022-09-12 22:34:39 +08:00
|
|
|
</button>
|
2023-02-24 02:07:00 +08:00
|
|
|
</.menu_item>
|
2022-09-12 22:34:39 +08:00
|
|
|
</.menu>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
end
|