Skip to content

Commit

Permalink
When the selected job was not run, do not say the dataclip is wiped (#…
Browse files Browse the repository at this point in the history
…2516)

* say that job was not run instead of dataclip is wiped
  • Loading branch information
midigofrank authored Sep 20, 2024
1 parent 0ef3b93 commit 115ce62
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ and this project adheres to

### Fixed

- Dataclip selector always shows that the dataclip is wiped even when the job wasn't run
[#2303](https://github.com/OpenFn/lightning/issues/2303)

## [v2.9.5] - 2024-09-18

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,12 @@ defmodule LightningWeb.WorkflowLive.AiAssistantComponent do
ai_limit_result != :ok
end

defp job_is_unsaved?(selected_job) do
selected_job.__meta__.state == :built
defp job_is_unsaved?(%{__meta__: %{state: :built}} = _job) do
true
end

defp job_is_unsaved?(_job), do: false

defp disabled_tooltip_message(can_edit_workflow, ai_limit_result, selected_job) do
case {can_edit_workflow, ai_limit_result, selected_job} do
{false, _, _} ->
Expand Down
16 changes: 10 additions & 6 deletions lib/lightning_web/live/workflow_live/edit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,11 @@ defmodule LightningWeb.WorkflowLive.Edit do
project={@project}
admin_contacts={@admin_contacts}
can_edit_data_retention={@can_edit_data_retention}
follow_run_id={@follow_run && @follow_run.id}
show_wiped_dataclip_selector={@show_wiped_dataclip_selector}
follow_run={@follow_run}
step={@step}
show_missing_dataclip_selector={
@show_missing_dataclip_selector
}
/>
</div>
</:panel>
Expand Down Expand Up @@ -1021,7 +1024,7 @@ defmodule LightningWeb.WorkflowLive.Edit do
workflow_params: %{},
selected_credential_type: nil,
oauth_clients: OauthClients.list_clients(assigns.project),
show_wiped_dataclip_selector: false,
show_missing_dataclip_selector: false,
admin_contacts: Projects.list_project_admin_emails(assigns.project.id)
)
|> assign(initial_presence_summary(socket.assigns.current_user))}
Expand Down Expand Up @@ -1478,8 +1481,9 @@ defmodule LightningWeb.WorkflowLive.Edit do
|> put_flash(:info, "Copied webhook URL to clipboard")}
end

def handle_event("toggle_wiped_dataclip_selector", _, socket) do
{:noreply, update(socket, :show_wiped_dataclip_selector, fn val -> !val end)}
def handle_event("toggle_missing_dataclip_selector", _, socket) do
{:noreply,
update(socket, :show_missing_dataclip_selector, fn val -> !val end)}
end

def handle_event("manual_run_change", %{"manual" => params}, socket) do
Expand Down Expand Up @@ -1819,7 +1823,7 @@ defmodule LightningWeb.WorkflowLive.Edit do
selectable_dataclips:
maybe_add_selected_dataclip(selectable_dataclips, step_dataclip)
)
|> assign(show_wiped_dataclip_selector: is_map(step_dataclip))
|> assign(show_missing_dataclip_selector: is_map(step_dataclip))
end

defp get_selected_dataclip(run, job_id) do
Expand Down
89 changes: 65 additions & 24 deletions lib/lightning_web/live/workflow_live/manual_workorder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ defmodule LightningWeb.WorkflowLive.ManualWorkorder do
doc: "list of project admin emails"

attr :can_edit_data_retention, :boolean, required: true
attr :follow_run_id, :string, required: true
attr :show_wiped_dataclip_selector, :boolean, default: false
attr :follow_run, :map, required: true
attr :step, :map, required: true
attr :show_missing_dataclip_selector, :boolean, default: false

def component(assigns) do
assigns =
Expand All @@ -38,8 +39,8 @@ defmodule LightningWeb.WorkflowLive.ManualWorkorder do
phx-submit="manual_run_submit"
class="h-full flex flex-col gap-4"
>
<%= if @follow_run_id && is_nil(@selected_dataclip) do %>
<%= if @show_wiped_dataclip_selector do %>
<%= if @follow_run && is_nil(@selected_dataclip) do %>
<%= if @show_missing_dataclip_selector do %>
<.dataclip_selector_fields
form={@form}
dataclips={@dataclips}
Expand All @@ -50,26 +51,7 @@ defmodule LightningWeb.WorkflowLive.ManualWorkorder do
can_edit_data_retention={@can_edit_data_retention}
/>
<% else %>
<LightningWeb.Components.Viewers.wiped_dataclip_viewer
input_or_output={:input}
project_id={@project.id}
admin_contacts={@admin_contacts}
can_edit_data_retention={@can_edit_data_retention}
>
<:footer>
<div class="text-center text-gray-500 text-sm mt-4">
<span>To create a new work order, first</span>
<span
id="toggle_dataclip_selector_button"
phx-click="toggle_wiped_dataclip_selector"
class="link"
>
click here
</span>
<span>to select/build an input.</span>
</div>
</:footer>
</LightningWeb.Components.Viewers.wiped_dataclip_viewer>
<.missing_dataclip_viewer {assigns} />
<% end %>
<% else %>
<.dataclip_selector_fields
Expand Down Expand Up @@ -150,4 +132,63 @@ defmodule LightningWeb.WorkflowLive.ManualWorkorder do
</div>
"""
end

defp missing_dataclip_viewer(assigns) do
~H"""
<%= if dataclip_wiped?(@step, @selected_dataclip) do %>
<LightningWeb.Components.Viewers.wiped_dataclip_viewer
input_or_output={:input}
project_id={@project.id}
admin_contacts={@admin_contacts}
can_edit_data_retention={@can_edit_data_retention}
>
<:footer>
<div class="text-center text-gray-500 text-sm mt-4">
<span>To create a new work order, first</span>
<span
id="toggle_dataclip_selector_button"
phx-click="toggle_missing_dataclip_selector"
class="link"
>
click here
</span>
<span>to select/build an input.</span>
</div>
</:footer>
</LightningWeb.Components.Viewers.wiped_dataclip_viewer>
<% else %>
<div class="border-2 border-gray-200 border-dashed rounded-lg px-8 pt-6 pb-8 mb-4 flex flex-col">
<div class="mb-4">
<div class="h-12 w-12 border-2 border-gray-300 border-solid mx-auto flex items-center justify-center rounded-full text-gray-400">
<.icon name="hero-code-bracket" class="w-4 h-4" />
</div>
</div>
<div class="text-center mb-4 text-gray-500">
<h3 class="font-bold text-lg">
<span class="capitalize">No Input Data</span> here!
</h3>
<p class="text-sm">
This job was not/is not yet included in this Run. Select a step from this run in the Run tab or create a new work order by
<span
id="toggle_dataclip_selector_button"
phx-click="toggle_missing_dataclip_selector"
class="link"
>
clicking here
</span>
to select/build an input
</p>
</div>
</div>
<% end %>
"""
end

defp dataclip_wiped?(nil, _), do: false

defp dataclip_wiped?(_step, %{wiped_at: %_{}}), do: true

defp dataclip_wiped?(step, _dataclip) do
is_struct(step.finished_at) and is_nil(step.input_dataclip_id)
end
end
79 changes: 79 additions & 0 deletions test/lightning_web/live/workflow_live/editor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,85 @@ defmodule LightningWeb.WorkflowLive.EditorTest do
live_children(view) |> Enum.each(&render_async/1)
end

test "shows the missing dataclip viewer if the selected step wasn't executed in the run",
%{
conn: conn,
project: project,
workflow: %{jobs: [job_1, job_2 | _rest]} = workflow,
snapshot: snapshot
} do
input_dataclip =
insert(:dataclip,
project: project,
type: :saved_input,
wiped_at: DateTime.utc_now(),
body: %{}
)

%{runs: [run]} =
insert(:workorder,
workflow: workflow,
snapshot: snapshot,
dataclip: input_dataclip,
runs: [
build(:run,
snapshot: snapshot,
dataclip: input_dataclip,
starting_job: job_1,
steps: [
build(:step,
snapshot: snapshot,
job: job_1,
input_dataclip: input_dataclip,
output_dataclip: nil,
started_at: build(:timestamp),
finished_at: build(:timestamp),
exit_reason: "success"
)
]
)
]
)

{:ok, view, _html} =
live(
conn,
~p"/projects/#{project}/w/#{workflow}?#{[s: job_2.id, a: run.id, m: "expand", v: workflow.lock_version]}"
)

# the form exists
form = element(view, "#manual-job-#{job_2.id} form")
assert has_element?(form)

# the select input is not present
refute has_element?(view, "select#manual_run_form_dataclip_id")
# the textarea doesn not exist
refute has_element?(view, "textarea#manual_run_form_body")

# the body says that the step wasn't run
assert render(form) =~ "This job was not/is not yet included in this Run"

# the body does not say that it was wiped
refute render(form) =~ "data for this step has not been retained"

refute has_element?(view, "textarea#manual_run_form_body"),
"dataclip body input is missing"

# lets click the button to show the editor
view |> element("#toggle_dataclip_selector_button") |> render_click()

# the dataclip textarea input now exists
assert has_element?(view, "textarea#manual_run_form_body"),
"dataclip body input exists"

# the job not run message is nolonger displayed
refute render(form) =~ "This job was not/is not yet included in this Run"

# Wait out all the async renders on RunViewerLive, avoiding Postgrex client
# disconnection warnings.
live_children(view) |> Enum.each(&render_async/1)
end

test "users can retry a workorder from a followed run",
%{
conn: conn,
Expand Down

0 comments on commit 115ce62

Please sign in to comment.