fix: tab titles on ai chats on reload

This commit is contained in:
2026-05-02 08:47:27 +02:00
parent 631ceb0521
commit e0f13e325b
2 changed files with 36 additions and 2 deletions

View File

@@ -2,7 +2,7 @@ defmodule BDS.Desktop.ShellLive.TabHelpers do
@moduledoc false
alias BDS.Desktop.ShellData
alias BDS.{BoundedAtoms, Media, Posts}
alias BDS.{AI, BoundedAtoms, Media, Posts}
alias BDS.Media.Media, as: MediaRecord
alias BDS.Posts.Post
alias BDS.UI.Registry
@@ -21,10 +21,12 @@ defmodule BDS.Desktop.ShellLive.TabHelpers do
def tab_subtitle(tab, tab_meta) do
case Map.get(tab_meta, {tab.type, tab.id}) do
%{subtitle: subtitle} when is_binary(subtitle) and subtitle != "" -> subtitle
_other -> "Desktop workbench content routed through the Elixir shell."
_other -> default_tab_subtitle(tab)
end
end
def default_tab_title(%{type: :chat, id: conversation_id}), do: chat_title(conversation_id)
def default_tab_title(%{type: type, id: id}) do
case Registry.editor_route(type) do
%{singleton: true} -> ShellData.route_label(type)
@@ -32,6 +34,9 @@ defmodule BDS.Desktop.ShellLive.TabHelpers do
end
end
defp default_tab_subtitle(%{type: :chat}), do: translated("AI conversations")
defp default_tab_subtitle(_tab), do: "Desktop workbench content routed through the Elixir shell."
def tab_route_label(nil), do: translated("Dashboard")
def tab_route_label(%{type: type}), do: ShellData.route_label(type)
@@ -88,6 +93,14 @@ defmodule BDS.Desktop.ShellLive.TabHelpers do
end
end
def chat_title(conversation_id) do
case AI.get_chat_conversation(conversation_id) do
%{title: title} when is_binary(title) and title != "" -> title
%{id: id} when is_binary(id) and id != "" -> id
_other -> "Chat"
end
end
def parse_integer(value) when is_integer(value), do: value
def parse_integer(value) do

View File

@@ -707,6 +707,27 @@ defmodule BDS.Desktop.ShellLiveTest do
assert html =~ ~s(class="tab active transient")
end
test "workbench session restore rehydrates chat tab titles from stored conversations" do
assert {:ok, conversation} = AI.start_chat(%{title: "Editorial Plan"})
{:ok, view, _html} = live_isolated(build_conn(), BDS.Desktop.ShellLive)
session_payload =
Workbench.new()
|> Workbench.open_tab(:chat, conversation.id, :pin)
|> Session.serialize()
_html = render_hook(view, "restore_workbench_session", %{"session" => session_payload})
assert has_element?(
view,
".tab[data-tab-type='chat'][data-tab-id='#{conversation.id}'] .tab-title",
"Editorial Plan"
)
assert has_element?(view, ".chat-panel-title-main", "Editorial Plan")
end
test "metadata diff refresh reruns after workbench session restore", %{project: project} do
:ok = BDS.Tasks.clear_finished()