Skip to content

Commit

Permalink
Merge pull request #999 from eyra/embed-hotfix
Browse files Browse the repository at this point in the history
Add possibility to skip finished page
  • Loading branch information
mellelieuwes authored Nov 15, 2024
2 parents 0aa5b82 + 1ca5ff8 commit 0457415
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
29 changes: 19 additions & 10 deletions core/systems/assignment/crew_work_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,17 @@ defmodule Systems.Assignment.CrewWorkView do
defp handle_complete_task(%{assigns: %{selected_item: {_, task}}} = socket) do
{:ok, %{crew_task: updated_task}} = Crew.Public.complete_task(task)

socket
|> hide_modal(:tool_ref_view)
|> update_task(updated_task)
|> handle_finished_state()
|> select_next_item()
if embedded?(socket) and singleton?(socket) do
# Keep tool_ref view open and prevent finished view from being shown
# FIXME: This is a temporary solution to allow embeds to work https://github.com/eyra/mono/issues/997
socket
else
socket
|> update_task(updated_task)
|> hide_modal(:tool_ref_view)
|> handle_finished_state()
|> select_next_item()
end
end

defp update_task(%{assigns: %{work_items: work_items}} = socket, updated_task) do
Expand Down Expand Up @@ -596,11 +602,6 @@ defmodule Systems.Assignment.CrewWorkView do
socket |> assign(selected_item_id: selected_item_id)
end

defp handle_finished_state(%{assigns: %{panel_info: %{embedded?: true}}} = socket) do
# Dont show finished view when embedded in external panel UI
socket
end

defp handle_finished_state(%{assigns: %{retry?: true}} = socket), do: socket

defp handle_finished_state(%{assigns: %{work_items: work_items}} = socket) do
Expand Down Expand Up @@ -645,6 +646,14 @@ defmodule Systems.Assignment.CrewWorkView do
|> Concept.ToolModel.launcher()
end

defp embedded?(%{assigns: %{panel_info: %{embedded?: embedded?}}}) do
embedded?
end

defp singleton?(%{assigns: %{work_items: work_items}}) do
length(work_items) == 1
end

@impl true
@spec render(any()) :: Phoenix.LiveView.Rendered.t()
def render(assigns) do
Expand Down
4 changes: 4 additions & 0 deletions core/systems/assignment/external_panel_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ defmodule Systems.Assignment.ExternalPanelController do
String.length(id) <= @id_max_lenght and Regex.match?(@id_valid_regex, id)
end

# FIXME: This is a temporary solution to allow embeds to work https://github.com/eyra/mono/issues/997
defp has_no_access?(_, %{"embed" => "true"}), do: false

defp has_no_access?(%{external_panel: external_panel}, params) do
external_panel = Atom.to_string(external_panel)
external_panel != get_panel(params)
Expand Down Expand Up @@ -117,5 +120,6 @@ defmodule Systems.Assignment.ExternalPanelController do
defp get_participant(_), do: nil

defp embedded?(%{"entry" => "liss"}), do: true
defp embedded?(%{"embed" => "true"}), do: true
defp embedded?(_), do: false
end

0 comments on commit 0457415

Please sign in to comment.