2021-08-14 03:17:43 +08:00
|
|
|
defmodule LivebookWeb.SettingsLive.FileSystemsComponent do
|
|
|
|
use LivebookWeb, :live_component
|
|
|
|
|
|
|
|
alias Livebook.FileSystem
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def render(assigns) do
|
|
|
|
~H"""
|
|
|
|
<div class="flex flex-col space-y-4">
|
|
|
|
<div class="flex flex-col space-y-4">
|
2023-02-23 02:34:54 +08:00
|
|
|
<div
|
2023-03-07 01:14:33 +08:00
|
|
|
:for={file_system <- @file_systems}
|
2023-02-23 02:34:54 +08:00
|
|
|
class="flex items-center justify-between border border-gray-200 rounded-lg p-4"
|
|
|
|
>
|
|
|
|
<div class="flex items-center space-x-12">
|
|
|
|
<.file_system_info file_system={file_system} />
|
2022-10-13 21:16:52 +08:00
|
|
|
</div>
|
2023-02-23 02:34:54 +08:00
|
|
|
<.file_system_actions
|
2023-03-07 01:14:33 +08:00
|
|
|
file_system_id={file_system.id}
|
2023-02-23 02:34:54 +08:00
|
|
|
default_file_system_id={@default_file_system_id}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-08-14 03:17:43 +08:00
|
|
|
</div>
|
|
|
|
<div class="flex">
|
2023-02-23 02:34:54 +08:00
|
|
|
<.link patch={~p"/settings/add-file-system"} class="button-base button-blue">
|
|
|
|
Add file system
|
|
|
|
</.link>
|
2021-08-14 03:17:43 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
defp file_system_info(%{file_system: %FileSystem.Local{}} = assigns) do
|
|
|
|
~H"""
|
2022-04-15 20:23:41 +08:00
|
|
|
<.labeled_text label="Type">Local disk</.labeled_text>
|
2021-08-14 03:17:43 +08:00
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
defp file_system_info(%{file_system: %FileSystem.S3{}} = assigns) do
|
|
|
|
~H"""
|
2022-04-15 20:23:41 +08:00
|
|
|
<.labeled_text label="Type">S3</.labeled_text>
|
|
|
|
<.labeled_text label="Bucket URL"><%= @file_system.bucket_url %></.labeled_text>
|
2021-08-14 03:17:43 +08:00
|
|
|
"""
|
|
|
|
end
|
2022-10-13 21:31:06 +08:00
|
|
|
|
|
|
|
defp file_system_actions(assigns) do
|
|
|
|
~H"""
|
|
|
|
<div class="flex items-center space-x-2">
|
2023-02-23 02:34:54 +08:00
|
|
|
<span
|
|
|
|
:if={@default_file_system_id == @file_system_id}
|
|
|
|
class="inline-flex items-center font-sans rounded-full px-2.5 py-0.5 text-xs font-medium bg-gray-100 bg-gray-100 text-gray-800"
|
|
|
|
>
|
|
|
|
Default
|
|
|
|
</span>
|
|
|
|
<.menu
|
|
|
|
:if={@default_file_system_id != @file_system_id or @file_system_id != "local"}
|
|
|
|
id={"file-system-#{@file_system_id}-menu"}
|
|
|
|
>
|
|
|
|
<:toggle>
|
|
|
|
<button class="icon-button" aria-label="open file system menu" type="button">
|
|
|
|
<.remix_icon icon="more-2-fill" class="text-xl" />
|
|
|
|
</button>
|
|
|
|
</:toggle>
|
2023-02-24 02:07:00 +08:00
|
|
|
<.menu_item>
|
2023-02-23 02:34:54 +08:00
|
|
|
<button
|
|
|
|
:if={@default_file_system_id != @file_system_id}
|
|
|
|
type="button"
|
|
|
|
role="menuitem"
|
|
|
|
phx-click="make_default_file_system"
|
|
|
|
phx-value-id={@file_system_id}
|
|
|
|
>
|
|
|
|
<.remix_icon icon="star-line" />
|
2023-02-24 02:07:00 +08:00
|
|
|
<span>Make default</span>
|
2023-02-23 02:34:54 +08:00
|
|
|
</button>
|
2023-02-24 02:07:00 +08:00
|
|
|
</.menu_item>
|
|
|
|
<.menu_item variant={:danger}>
|
2023-02-23 02:34:54 +08:00
|
|
|
<button
|
|
|
|
:if={@file_system_id != "local"}
|
|
|
|
type="button"
|
|
|
|
role="menuitem"
|
2023-02-24 02:07:00 +08:00
|
|
|
class="text-red-600"
|
2023-02-23 02:34:54 +08:00
|
|
|
phx-click={
|
|
|
|
with_confirm(
|
|
|
|
JS.push("detach_file_system", value: %{id: @file_system_id}),
|
|
|
|
title: "Detach file system",
|
|
|
|
description:
|
|
|
|
"Are you sure you want to detach this file system? Any sessions using it will keep the access until they get closed.",
|
|
|
|
confirm_text: "Detach",
|
|
|
|
confirm_icon: "close-circle-line"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<.remix_icon icon="delete-bin-line" />
|
2023-02-24 02:07:00 +08:00
|
|
|
<span>Detach</span>
|
2023-02-23 02:34:54 +08:00
|
|
|
</button>
|
2023-02-24 02:07:00 +08:00
|
|
|
</.menu_item>
|
2023-02-23 02:34:54 +08:00
|
|
|
</.menu>
|
2022-10-13 21:31:06 +08:00
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
2021-08-14 03:17:43 +08:00
|
|
|
end
|