Skip to content

Commit

Permalink
Dont clear dataclip input when user saves workflow (#2979)
Browse files Browse the repository at this point in the history
  • Loading branch information
midigofrank authored Feb 28, 2025
1 parent 83443d2 commit 635ade1
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ and this project adheres to

### Fixed

- Dont clear dataclip input when user saves workflow
[#2944](https://github.com/OpenFn/lightning/issues/2944)

## [v2.10.16-pre.0] - 2025-02-26

### Added
Expand Down
28 changes: 27 additions & 1 deletion lib/lightning_web/live/workflow_live/edit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2028,9 +2028,16 @@ defmodule LightningWeb.WorkflowLive.Edit do
assigns[:follow_run] &&
get_selected_dataclip(assigns[:follow_run], job.id)

body =
new_manual_run_form_body(
assigns.manual_run_form,
job,
dataclip
)

changeset =
WorkOrders.Manual.new(
%{dataclip_id: dataclip && dataclip.id},
%{dataclip_id: dataclip && dataclip.id, body: body},
project: socket.assigns.project,
workflow: socket.assigns.workflow,
job: socket.assigns.selected_job,
Expand All @@ -2057,6 +2064,25 @@ defmodule LightningWeb.WorkflowLive.Edit do
end
end

defp new_manual_run_form_body(
prev_manual_run_form,
selected_job,
selected_dataclip
) do
prev_job =
prev_manual_run_form &&
Ecto.Changeset.get_embed(
prev_manual_run_form.source,
:job,
:struct
)

if is_nil(selected_dataclip) and is_struct(prev_job) and
prev_job.id == selected_job.id do
Ecto.Changeset.get_change(prev_manual_run_form.source, :body)
end
end

defp assign_dataclips(socket, selectable_dataclips, step_dataclip) do
socket
|> assign(
Expand Down
44 changes: 44 additions & 0 deletions test/lightning_web/live/workflow_live/edit_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,50 @@ defmodule LightningWeb.WorkflowLive.EditTest do
"#toggle-container-workflow[aria-label='This workflow is active (webhook trigger enabled)']"
)
end

test "manual run form body remains unchanged even after save workflow form is submitted",
%{conn: conn, project: project, test: test} do
%{jobs: [job_1, job_2 | _rest]} =
workflow = insert(:complex_workflow, project: project)

Lightning.Workflows.Snapshot.create(workflow)

{:ok, view, _html} =
live(
conn,
~p"/projects/#{project}/w/#{workflow}?#{[s: job_1, m: "expand"]}"
)

body = Jason.encode!(%{test: test})

body_part = to_string(test)

refute view |> element("#manual_run_form") |> render() =~ body_part

assert view
|> form("#manual_run_form")
|> render_change(manual: %{body: body}) =~ body_part

# submit workflow form
view |> form("#workflow-form") |> render_submit()

workflow = Lightning.Repo.reload(workflow)

assert_patched(
view,
~p"/projects/#{project}/w/#{workflow}?#{[m: "expand", s: job_1.id, v: workflow.lock_version]}"
)

# manual run form still has the body
assert view |> element("#manual_run_form") |> render() =~ body_part

# select another job
select_node(view, %{id: job_2.id})
click_edit(view, %{id: job_2.id})

# manual run form body is cleared
refute view |> element("#manual_run_form") |> render() =~ body_part
end
end

describe "Tracking Workflow editor metrics" do
Expand Down

0 comments on commit 635ade1

Please sign in to comment.