Move star below menu (#1870)

This commit is contained in:
José Valim 2023-04-18 12:46:54 +02:00 committed by GitHub
parent eb15e12b1b
commit a8c7af5519
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 103 deletions

View file

@ -170,36 +170,6 @@ defmodule LivebookWeb.HomeLive.SessionListComponent do
<span>Fork</span>
</button>
</.menu_item>
<span
class="tooltip left"
data-tooltip={session.file == nil && "Save this notebook before starring it"}
>
<.menu_item disabled={session.file == nil}>
<%= if notebook_starred?(session, @starred_notebooks) do %>
<button
type="button"
role="menuitem"
phx-click="unstar_notebook"
phx-target={@myself}
phx-value-id={session.id}
>
<.remix_icon icon="star-fill" />
<span>Unstar notebook</span>
</button>
<% else %>
<button
type="button"
role="menuitem"
phx-click="star_notebook"
phx-target={@myself}
phx-value-id={session.id}
>
<.remix_icon icon="star-line" />
<span>Star notebook</span>
</button>
<% end %>
</.menu_item>
</span>
<.menu_item>
<a role="menuitem" href={live_dashboard_process_path(session.pid)} target="_blank">
<.remix_icon icon="dashboard-2-line" />
@ -366,18 +336,6 @@ defmodule LivebookWeb.HomeLive.SessionListComponent do
)}
end
def handle_event("star_notebook", %{"id" => session_id}, socket) do
session = Enum.find(socket.assigns.sessions, &(&1.id == session_id))
Livebook.NotebookManager.add_starred_notebook(session.file, session.notebook_name)
{:noreply, socket}
end
def handle_event("unstar_notebook", %{"id" => session_id}, socket) do
session = Enum.find(socket.assigns.sessions, &(&1.id == session_id))
Livebook.NotebookManager.remove_starred_notebook(session.file)
{:noreply, socket}
end
def handle_event("disconnect_runtime", %{"id" => session_id}, socket) do
session = Enum.find(socket.assigns.sessions, &(&1.id == session_id))
Session.disconnect_runtime(session.pid)
@ -439,10 +397,4 @@ defmodule LivebookWeb.HomeLive.SessionListComponent do
JS.dispatch("lb:set_value", to: "#bulk-action-input", detail: %{value: action})
|> JS.dispatch("submit", to: "#bulk-action-form")
end
defp notebook_starred?(%{file: nil} = _session, _starred_notebooks), do: false
defp notebook_starred?(session, starred_notebooks) do
Enum.any?(starred_notebooks, &(&1.file == session.file))
end
end

View file

@ -273,24 +273,6 @@ defmodule LivebookWeb.SessionLive do
<span>Fork</span>
</button>
</.menu_item>
<span
class="tooltip left"
data-tooltip={@data_view.file == nil && "Save this notebook before starring it"}
>
<.menu_item disabled={@data_view.file == nil}>
<%= if @data_view.file in @starred_files do %>
<button type="button" role="menuitem" phx-click="unstar_notebook">
<.remix_icon icon="star-fill" />
<span>Unstar notebook</span>
</button>
<% else %>
<button type="button" role="menuitem" phx-click="star_notebook">
<.remix_icon icon="star-line" />
<span>Star notebook</span>
</button>
<% end %>
</.menu_item>
</span>
<.menu_item>
<a role="menuitem" href={live_dashboard_process_path(@session.pid)} target="_blank">
<.remix_icon icon="dashboard-2-line" />
@ -305,35 +287,66 @@ defmodule LivebookWeb.SessionLive do
</.menu_item>
</.menu>
</div>
<.menu position={:bottom_left} id="notebook-hub-menu">
<:toggle>
<div
class="inline-flex items-center group cursor-pointer gap-1 mt-1 text-sm text-gray-600 hover:text-gray-800 focus:text-gray-800"
aria-label={@data_view.hub.hub_name}
>
<span>in</span>
<span class="text-lg pl-1"><%= @data_view.hub.hub_emoji %></span>
<span><%= @data_view.hub.hub_name %></span>
<.remix_icon icon="arrow-down-s-line" class="invisible group-hover:visible" />
</div>
</:toggle>
<.menu_item :for={hub <- @saved_hubs}>
<button
id={"select-hub-#{hub.id}"}
phx-click={JS.push("select_hub", value: %{id: hub.id})}
aria-label={hub.name}
role="menuitem"
>
<%= hub.emoji %>
<span class="ml-2"><%= hub.name %></span>
</button>
</.menu_item>
<.menu_item>
<.link navigate={~p"/hub"} aria-label="Add Hub" role="menuitem">
<.remix_icon icon="add-line" class="align-middle mr-1" /> Add Hub
</.link>
</.menu_item>
</.menu>
<div class="flex flex-nowrap place-content-between items-center gap-2">
<.menu position={:bottom_left} id="notebook-hub-menu">
<:toggle>
<div
class="inline-flex items-center group cursor-pointer gap-1 mt-1 text-sm text-gray-600 hover:text-gray-800 focus:text-gray-800"
aria-label={@data_view.hub.hub_name}
>
<span>in</span>
<span class="text-lg pl-1"><%= @data_view.hub.hub_emoji %></span>
<span><%= @data_view.hub.hub_name %></span>
<.remix_icon icon="arrow-down-s-line" class="invisible group-hover:visible" />
</div>
</:toggle>
<.menu_item :for={hub <- @saved_hubs}>
<button
id={"select-hub-#{hub.id}"}
phx-click={JS.push("select_hub", value: %{id: hub.id})}
aria-label={hub.name}
role="menuitem"
>
<%= hub.emoji %>
<span class="ml-2"><%= hub.name %></span>
</button>
</.menu_item>
<.menu_item>
<.link navigate={~p"/hub"} aria-label="Add Hub" role="menuitem">
<.remix_icon icon="add-line" class="align-middle mr-1" /> Add Hub
</.link>
</.menu_item>
</.menu>
<div class="icon-button text-lg pr-[5px]">
<%= cond do %>
<% @data_view.file == nil -> %>
<span class="tooltip left" data-tooltip="Save this notebook before starring it">
<.remix_icon icon="star-line" />
</span>
<% @data_view.file in @starred_files -> %>
<button
class="text-yellow-600 tooltip left"
data-tooltip="Unstar notebook"
type="button"
role="menuitem"
phx-click="unstar_notebook"
>
<.remix_icon icon="star-fill" />
</button>
<% true -> %>
<button
class="tooltip left"
data-tooltip="Star notebook"
type="button"
role="menuitem"
phx-click="star_notebook"
>
<.remix_icon icon="star-line" />
</button>
<% end %>
</div>
</div>
</div>
<div>
<.live_component

View file

@ -150,17 +150,15 @@ defmodule LivebookWeb.HomeLiveTest do
{:ok, view, _} = live(conn, ~p"/")
view
|> element(~s{[data-test-session-id="#{session.id}"] button}, "Star notebook")
|> render_click()
Livebook.NotebookManager.add_starred_notebook(file, "Special notebook")
render(view)
assert view
|> element(~s/#starred-notebooks/, "Special notebook")
|> has_element?()
view
|> element(~s{[data-test-session-id="#{session.id}"] button}, "Unstar notebook")
|> render_click()
Livebook.NotebookManager.remove_starred_notebook(file)
render(view)
refute view
|> element(~s/#starred-notebooks/, "Special notebook")

View file

@ -710,7 +710,7 @@ defmodule LivebookWeb.SessionLiveTest do
{:ok, view, _} = live(conn, ~p"/sessions/#{session.id}")
view
|> element("button", "Star notebook")
|> element("button[data-tooltip=\"Star notebook\"]")
|> render_click()
assert_receive {:starred_notebooks_updated, starred_notebooks}
@ -718,7 +718,7 @@ defmodule LivebookWeb.SessionLiveTest do
assert Enum.any?(starred_notebooks, &(&1.file == file))
view
|> element("button", "Unstar notebook")
|> element("button[data-tooltip=\"Unstar notebook\"]")
|> render_click()
assert_receive {:starred_notebooks_updated, starred_notebooks}