From 22d1faf818319c6c1fcd039a9eb089bcc47a32f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Macdara=20=C3=93=20Murch=C3=BA?= Date: Wed, 1 Apr 2026 10:31:11 +0800 Subject: [PATCH 1/2] Fix collaborative_editor_url mapping s param to wrong type without assigns When switching from legacy to collaborative editor, the s (selection) param was always mapped to job= regardless of whether the selected item was a trigger or edge. This happened because determine_selection_type/2 needs atom-keyed socket assigns, but collaborative_editor_url/2 was passing the string-keyed URL params map instead. Adds an optional third assigns argument to collaborative_editor_url/3 and passes socket.assigns from the handle_event caller in edit.ex. Fixes #4375 --- CHANGELOG.md | 3 ++ lib/lightning_web/live/workflow_live/edit.ex | 2 +- .../live/workflow_live/helpers.ex | 4 +- .../live/workflow_live/helpers_test.exs | 39 +++++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcd6c8109a..7daaf0faec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,9 @@ and this project adheres to ### Fixed +- Fix `collaborative_editor_url/2` incorrectly mapping trigger/edge selections + to `job` param when switching from legacy to collaborative editor + [#4375](https://github.com/OpenFn/lightning/issues/4375) - Consider manual runs for "next cron run input" via the `last_run_final_dataclip` function [#4584](https://github.com/OpenFn/lightning/issues/4584) diff --git a/lib/lightning_web/live/workflow_live/edit.ex b/lib/lightning_web/live/workflow_live/edit.ex index 6fe805d3d3..13bfb5f64e 100644 --- a/lib/lightning_web/live/workflow_live/edit.ex +++ b/lib/lightning_web/live/workflow_live/edit.ex @@ -1644,7 +1644,7 @@ defmodule LightningWeb.WorkflowLive.Edit do }) collaborative_url = - Helpers.collaborative_editor_url(params, socket.assigns.live_action) + Helpers.collaborative_editor_url(params, socket.assigns.live_action, socket.assigns) {:noreply, push_navigate(socket, to: collaborative_url)} end diff --git a/lib/lightning_web/live/workflow_live/helpers.ex b/lib/lightning_web/live/workflow_live/helpers.ex index 4f32430eb7..8870021dca 100644 --- a/lib/lightning_web/live/workflow_live/helpers.ex +++ b/lib/lightning_web/live/workflow_live/helpers.ex @@ -417,12 +417,12 @@ defmodule LightningWeb.WorkflowLive.Helpers do "/projects/proj-1/w/wf-1?custom=value&job=job-123&v=42" """ - def collaborative_editor_url(params, live_action) do + def collaborative_editor_url(params, live_action, assigns \\ %{}) do collaborative_params = params |> Map.drop(["id", "project_id"]) |> Enum.reduce(%{}, fn {key, value}, acc -> - convert_param(key, value, acc, params) + convert_param(key, value, acc, assigns) end) base_url = collaborative_base_url(params, live_action) diff --git a/test/lightning_web/live/workflow_live/helpers_test.exs b/test/lightning_web/live/workflow_live/helpers_test.exs index 25d8bf0239..a3af2f9aad 100644 --- a/test/lightning_web/live/workflow_live/helpers_test.exs +++ b/test/lightning_web/live/workflow_live/helpers_test.exs @@ -78,6 +78,45 @@ defmodule LightningWeb.WorkflowLive.HelpersTest do assert result == "/projects/proj-1/w/wf-1?job=unknown-id" end + test "maps 's' to 'trigger' when assigns identify it as a trigger" do + params = %{ + "s" => "trigger-xyz", + "project_id" => "proj-1", + "id" => "wf-1" + } + + assigns = %{selected_trigger: %{id: "trigger-xyz"}} + + result = Helpers.collaborative_editor_url(params, :edit, assigns) + assert result == "/projects/proj-1/w/wf-1?trigger=trigger-xyz" + end + + test "maps 's' to 'edge' when assigns identify it as an edge" do + params = %{ + "s" => "edge-123", + "project_id" => "proj-1", + "id" => "wf-1" + } + + assigns = %{selected_edge: %{id: "edge-123"}} + + result = Helpers.collaborative_editor_url(params, :edit, assigns) + assert result == "/projects/proj-1/w/wf-1?edge=edge-123" + end + + test "maps 's' to 'job' when assigns identify it as a job" do + params = %{ + "s" => "job-abc", + "project_id" => "proj-1", + "id" => "wf-1" + } + + assigns = %{selected_job: %{id: "job-abc"}} + + result = Helpers.collaborative_editor_url(params, :edit, assigns) + assert result == "/projects/proj-1/w/wf-1?job=job-abc" + end + test "converts 'm=expand' to 'panel=editor'" do params = %{ "m" => "expand", From 62bd716738317142bab75fea26c056423b4dda43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Macdara=20=C3=93=20Murch=C3=BA?= Date: Wed, 1 Apr 2026 12:57:35 +0800 Subject: [PATCH 2/2] Fix line length in edit.ex to pass mix format check --- lib/lightning_web/live/workflow_live/edit.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/lightning_web/live/workflow_live/edit.ex b/lib/lightning_web/live/workflow_live/edit.ex index 13bfb5f64e..81f77ec330 100644 --- a/lib/lightning_web/live/workflow_live/edit.ex +++ b/lib/lightning_web/live/workflow_live/edit.ex @@ -1644,7 +1644,11 @@ defmodule LightningWeb.WorkflowLive.Edit do }) collaborative_url = - Helpers.collaborative_editor_url(params, socket.assigns.live_action, socket.assigns) + Helpers.collaborative_editor_url( + params, + socket.assigns.live_action, + socket.assigns + ) {:noreply, push_navigate(socket, to: collaborative_url)} end