Skip to content

Commit

Permalink
Merge pull request #1036 from OpenFn/957-invalid-job-body
Browse files Browse the repository at this point in the history
Show that the jobs' body is invalid
  • Loading branch information
taylordowns2000 committed Aug 24, 2023
2 parents 1ec7733 + 64909d9 commit 3f04975
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 9 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ and this project adheres to
## [Unreleased]

### Added
- Introduces Github sync feature, users can now setup our github app on their instance
and sync projects using our latest portability spec
[#970](https://github.com/OpenFn/Lightning/issues/970)

- Introduces Github sync feature, users can now setup our github app on their
instance and sync projects using our latest portability spec
[#970](https://github.com/OpenFn/Lightning/issues/970)

- Support Backup Codes for Multi-Factor Authentication
[937](https://github.com/OpenFn/Lightning/issues/937)
- Log a warning in the console when the Editor/docs component is given latest
[#958](https://github.com/OpenFn/Lightning/issues/958)
- Improve feedback when a Workflow name is invalid
[#961](https://github.com/OpenFn/Lightning/issues/961)
- Show that the jobs' body is invalid
[#957](https://github.com/OpenFn/Lightning/issues/957)

### Changed

Expand Down
54 changes: 48 additions & 6 deletions lib/lightning_web/live/workflow_live/edit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ defmodule LightningWeb.WorkflowLive.Edit do
<:footer>
<.with_changes_indicator changeset={@changeset}>
<div class="flex flex-row gap-2">
<.empty_editor_error :if={
editor_is_empty(@workflow_form, @selected_job)
} />
<Heroicons.lock_closed
:if={!@can_edit_job}
class="w-5 h-5 place-self-center text-gray-300"
Expand Down Expand Up @@ -152,12 +155,13 @@ defmodule LightningWeb.WorkflowLive.Edit do
/>
<:footer>
<div class="flex flex-row">
<.link
patch={"#{@base_url}?s=#{@selected_job.id}&m=expand"}
class="inline-flex items-center rounded-md bg-white px-3.5 py-2.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
>
<Heroicons.code_bracket class="w-4 h-4 -ml-0.5" />
</.link>
<div class="flex items-center">
<.expand_job_editor
base_url={@base_url}
job={@selected_job}
form={@workflow_form}
/>
</div>
<div class="grow flex justify-end">
<label>
<Common.button
Expand Down Expand Up @@ -234,6 +238,37 @@ defmodule LightningWeb.WorkflowLive.Edit do
"""
end

defp expand_job_editor(assigns) do
is_empty = editor_is_empty(assigns.form, assigns.job)

button_base_classes =
~w(
inline-flex items-center rounded-md bg-white px-3.5 py-2.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset hover:bg-gray-50)

button_classes =
button_base_classes ++
if is_empty,
do: ~w(ring-red-300),
else: ~w(ring-gray-300)

assigns = assign(assigns, is_empty: is_empty, button_classes: button_classes)

~H"""
<.link patch={"#{@base_url}?s=#{@job.id}&m=expand"} class={@button_classes}>
<Heroicons.code_bracket mini class="w-4 h-4 text-grey-400" />
</.link>
<.empty_editor_error :if={@is_empty} />
"""
end

defp empty_editor_error(assigns) do
~H"""
<span class="flex items-center font-medium text-sm text-red-600 mx-1 rounded whitespace-nowrap z-10">
<Icon.exclamation_circle class="h-5 w-5 mx-1 p-0" />The job can't be blank
</span>
"""
end

defp single_inputs_for(form, field, id) do
form
|> inputs_for(field)
Expand Down Expand Up @@ -501,6 +536,13 @@ defmodule LightningWeb.WorkflowLive.Edit do
{:noreply, socket |> assign(follow_run_id: attempt_run.run_id)}
end

defp editor_is_empty(form, job) do
single_inputs_for(form, :jobs, job.id)
|> Map.get(:source)
|> Map.get(:errors)
|> Keyword.has_key?(:body)
end

defp has_child_edges?(workflow_changeset, job_id) do
workflow_changeset
|> Ecto.Changeset.get_assoc(:edges, :struct)
Expand Down
25 changes: 25 additions & 0 deletions test/lightning_web/live/workflow_live/edit_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,31 @@ defmodule LightningWeb.WorkflowLive.EditTest do
|> render_submit() =~ "Workflow saved"
end

test "when a job has an empty body an error message is rendered", %{
conn: conn,
project: project,
workflow: workflow
} do
{:ok, view, _html} =
live(conn, ~p"/projects/#{project.id}/w/#{workflow.id}")

job = workflow.jobs |> Enum.at(1)

view |> select_node(job)

view |> click_edit(job)

view |> change_editor_text("some body")

refute view |> render() =~
"The job can&#39;t be blank"

view |> change_editor_text("")

assert view |> render() =~
"The job can&#39;t be blank"
end

test "users can edit an existing workflow", %{
conn: conn,
project: project,
Expand Down

0 comments on commit 3f04975

Please sign in to comment.