From 0b9e4d469ea74b5f2d3db0a864b4b4b395e44d69 Mon Sep 17 00:00:00 2001 From: Cristine Guadelupe Date: Mon, 4 Sep 2023 19:03:32 +0700 Subject: [PATCH] Fix: invalid var names (#103) --- lib/kino_explorer/data_transform_cell.ex | 1 + .../data_transform_cell_test.exs | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/kino_explorer/data_transform_cell.ex b/lib/kino_explorer/data_transform_cell.ex index 626c2ca..2097f47 100644 --- a/lib/kino_explorer/data_transform_cell.ex +++ b/lib/kino_explorer/data_transform_cell.ex @@ -434,6 +434,7 @@ defmodule KinoExplorer.DataTransformCell do defp to_quoted(%{"data_frame" => df, "assign_to" => variable} = attrs) do attrs = Map.new(attrs, fn {k, v} -> convert_field(k, v) end) missing_require = attrs.missing_require + variable = if variable && Kino.SmartCell.valid_variable_name?(variable), do: variable nodes = attrs.operations diff --git a/test/kino_explorer/data_transform_cell_test.exs b/test/kino_explorer/data_transform_cell_test.exs index e4ec1a4..3247a31 100644 --- a/test/kino_explorer/data_transform_cell_test.exs +++ b/test/kino_explorer/data_transform_cell_test.exs @@ -1036,6 +1036,37 @@ defmodule KinoExplorer.DataTransformCellTest do """ end + test "source with export to an invalid var" do + root = %{"data_frame_alias" => DF, "assign_to" => "exported_df invalid"} + + operations = %{ + filters: [ + %{ + "column" => "name", + "filter" => "equal", + "type" => "string", + "value" => "Ana", + "active" => true, + "operation_type" => "filters" + }, + %{ + "column" => "id", + "filter" => "less", + "type" => "integer", + "value" => "2", + "active" => true, + "operation_type" => "filters" + } + ] + } + + attrs = build_attrs(root, operations) + + assert DataTransformCell.to_source(attrs) == """ + people |> DF.to_lazy() |> DF.filter(name == "Ana" and id < 2) |> DF.collect()\ + """ + end + test "source with inactive operations" do root = %{"data_frame_alias" => DF, "assign_to" => "exported_df"}