Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add conversion transformation #1596

Merged
merged 3 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/andi/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Andi.MixProject do
def project do
[
app: :andi,
version: "2.5.48",
version: "2.5.49",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,43 @@ defmodule AndiWeb.IngestionLiveView.Transformations.TransformationFormTest do
assert element(view, "##{target_format_id}") |> has_element?()
end

test "after selecting conversion transformation, conversion fields appear" do
transformation_changeset = Transformation.changeset_for_draft(%{})
assert {:ok, view, html} = render_transformation_form(transformation_changeset)

select_type("conversion", view)

target_field_id = build_field_id("field")
source_field_type = build_field_id("sourceType")
target_field_type = build_field_id("targetType")

assert has_element?(view, ".transformation-field")
assert element(view, "label[for=#{target_field_id}]", "Field to Convert") |> has_element?()
assert element(view, "label[for=#{source_field_type}]", "Source Data Type") |> has_element?()
assert element(view, "label[for=#{target_field_type}]", "Target Data Type") |> has_element?()
assert element(view, "##{target_field_id}") |> has_element?()
assert element(view, "##{source_field_type}") |> has_element?()
assert element(view, "##{target_field_type}") |> has_element?()
end

test "if conversion transformation is selected show fields on load" do
transformation_changeset = Transformation.changeset_for_draft(%{type: "conversion"})

assert {:ok, view, html} = render_transformation_form(transformation_changeset)

target_field_id = build_field_id("field")
source_field_type = build_field_id("sourceType")
target_field_type = build_field_id("targetType")

assert has_element?(view, ".transformation-field")
assert element(view, "label[for=#{target_field_id}]", "Field to Convert") |> has_element?()
assert element(view, "label[for=#{source_field_type}]", "Source Data Type") |> has_element?()
assert element(view, "label[for=#{target_field_type}]", "Target Data Type") |> has_element?()
assert element(view, "##{target_field_id}") |> has_element?()
assert element(view, "##{source_field_type}") |> has_element?()
assert element(view, "##{target_field_type}") |> has_element?()
end

test "shows error message if field missing" do
transformation_changeset = Transformation.changeset_for_draft(%{type: "remove"})
assert {:ok, view, html} = render_transformation_form(transformation_changeset)
Expand Down
4 changes: 4 additions & 0 deletions apps/transformers/lib/transformation_fields.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ defmodule Transformers.TransformationFields do
Transformers.DateTime.fields()
end

def fields_for("conversion") do
Transformers.TypeConversion.fields()
end

def fields_for(_unsupported) do
[]
end
Expand Down
23 changes: 23 additions & 0 deletions apps/transformers/lib/transformations/type_conversion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,27 @@ defmodule Transformers.TypeConversion do
_ -> {:error, "Cannot parse field #{field} with value #{value} into #{target_type}"}
end
end

def fields() do
[
%{
field_name: @field,
field_type: "string",
field_label: "Field to Convert",
options: nil
},
%{
field_name: @source_type,
field_type: "string",
field_label: "Source Data Type",
options: ["integer", "string", "float"]
},
%{
field_name: @target_type,
field_type: "string",
field_label: "Target Data Type",
options: ["integer", "string", "float"]
}
]
end
end
2 changes: 1 addition & 1 deletion apps/transformers/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Transformers.MixProject do
def project do
[
app: :transformers,
version: "1.0.11",
version: "1.0.12",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
Expand Down