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">
|
2022-02-23 05:42:54 +08:00
|
|
|
<%= for {file_system_id, file_system} <- @file_systems do %>
|
2021-08-14 03:17:43 +08:00
|
|
|
<div 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} />
|
|
|
|
</div>
|
2022-10-13 21:16:52 +08:00
|
|
|
|
2021-08-14 03:17:43 +08:00
|
|
|
<%= unless is_struct(file_system, FileSystem.Local) do %>
|
2022-08-02 21:51:02 +08:00
|
|
|
<button
|
|
|
|
class="button-base button-outlined-red"
|
2022-03-02 07:26:40 +08:00
|
|
|
phx-click={
|
|
|
|
with_confirm(
|
|
|
|
JS.push("detach_file_system", value: %{id: file_system_id}),
|
|
|
|
title: "Detach file system",
|
2022-08-02 21:51:02 +08:00
|
|
|
description:
|
|
|
|
"Are you sure you want to detach this file system? Any sessions using it will keep the access until they get closed.",
|
2022-03-02 07:26:40 +08:00
|
|
|
confirm_text: "Detach",
|
|
|
|
confirm_icon: "close-circle-line"
|
|
|
|
)
|
2022-08-02 21:51:02 +08:00
|
|
|
}
|
|
|
|
>
|
2022-03-02 07:26:40 +08:00
|
|
|
Detach
|
|
|
|
</button>
|
2021-08-14 03:17:43 +08:00
|
|
|
<% end %>
|
|
|
|
</div>
|
2022-10-13 21:16:52 +08:00
|
|
|
<div class="flex justify-end">
|
|
|
|
<%= unless @default_file_system_id == file_system_id do %>
|
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
phx-click="make_default_file_system"
|
|
|
|
class="button-base button-outlined-gray"
|
|
|
|
phx-value-id={file_system_id}
|
|
|
|
>
|
|
|
|
Make default
|
|
|
|
</button>
|
|
|
|
<% end %>
|
|
|
|
</div>
|
2021-08-14 03:17:43 +08:00
|
|
|
<% end %>
|
|
|
|
</div>
|
|
|
|
<div class="flex">
|
2022-08-02 21:51:02 +08:00
|
|
|
<%= live_patch("Add file system",
|
|
|
|
to: Routes.settings_path(@socket, :add_file_system),
|
|
|
|
class: "button-base button-blue"
|
|
|
|
) %>
|
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
|
|
|
|
end
|