From 02fb9de1b15edc5289b08a19c8547fcc8d3a28da Mon Sep 17 00:00:00 2001 From: Alexandr Romanenko Date: Wed, 20 May 2020 21:20:44 +0300 Subject: [PATCH 1/2] fix issue with missing children prop --- src/Components.jl | 6 ++++++ .../jlcmdc001_default_children.jl | 12 ++++++++++++ .../components/test_default_children.py | 15 +++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 test/integration/components/jl_default_children/jlcmdc001_default_children.jl create mode 100644 test/integration/components/test_default_children.py diff --git a/src/Components.jl b/src/Components.jl index cca15f2..e89ad38 100644 --- a/src/Components.jl +++ b/src/Components.jl @@ -11,6 +11,12 @@ struct Component <: AbstractComponent props ::Dict{Symbol, Any} available_props ::Set{Symbol} wildcard_props ::Set{Symbol} + function Component(type, namespace, props, available_props, wildcard_props) + if :children in available_props && !haskey(props, :children) + props[:children] = nothing + end + return new(type, namespace, props, available_props, wildcard_props) + end end JSON2.@format Component begin diff --git a/test/integration/components/jl_default_children/jlcmdc001_default_children.jl b/test/integration/components/jl_default_children/jlcmdc001_default_children.jl new file mode 100644 index 0000000..4e65a7a --- /dev/null +++ b/test/integration/components/jl_default_children/jlcmdc001_default_children.jl @@ -0,0 +1,12 @@ +using Dash +using DashHtmlComponents +using DashCoreComponents + +app = dash() +app.layout = html_div(id="outer-div") do + html_div("A div", id="first-inner-div"), + html_br(), + html_div("Another div", id="second-inner-div") +end + +run_server(app) diff --git a/test/integration/components/test_default_children.py b/test/integration/components/test_default_children.py new file mode 100644 index 0000000..3952fb3 --- /dev/null +++ b/test/integration/components/test_default_children.py @@ -0,0 +1,15 @@ +import pathlib +import os.path +import logging +logger = logging.getLogger(__name__) + +curr_path = pathlib.Path(__file__).parent.absolute() +def jl_test_file_path(filename): + return os.path.join(curr_path, "jl_default_children", filename) + +def test_jlcmdc001_default_children(dashjl): + fp = jl_test_file_path("jlcmdc001_default_children.jl") + dashjl.start_server(fp) + dashjl.wait_for_element_by_css_selector( + "#first-inner-div", timeout=2 + ) \ No newline at end of file From 0f6ef2c9554c8c61c777765c3b8bd26572e290c9 Mon Sep 17 00:00:00 2001 From: Alexandr Romanenko Date: Wed, 20 May 2020 23:32:33 +0300 Subject: [PATCH 2/2] fix headers --- src/Components.jl | 6 ------ src/handler/handlers.jl | 7 +++---- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/Components.jl b/src/Components.jl index e89ad38..cca15f2 100644 --- a/src/Components.jl +++ b/src/Components.jl @@ -11,12 +11,6 @@ struct Component <: AbstractComponent props ::Dict{Symbol, Any} available_props ::Set{Symbol} wildcard_props ::Set{Symbol} - function Component(type, namespace, props, available_props, wildcard_props) - if :children in available_props && !haskey(props, :children) - props[:children] = nothing - end - return new(type, namespace, props, available_props, wildcard_props) - end end JSON2.@format Component begin diff --git a/src/handler/handlers.jl b/src/handler/handlers.jl index 4d76433..55779a5 100644 --- a/src/handler/handlers.jl +++ b/src/handler/handlers.jl @@ -12,7 +12,7 @@ end function process_dependencies(request::HTTP.Request, state::HandlerState) return HTTP.Response( 200, - ["Content-Type", "application/json"], + ["Content-Type" => "application/json"], body = state.cache.dependencies_json ) end @@ -20,7 +20,7 @@ end function process_index(request::HTTP.Request, state::HandlerState) return HTTP.Response( 200, - ["Content-Type", "text/html"], + ["Content-Type" => "text/html"], body = state.cache.index_string ) end @@ -28,10 +28,9 @@ end layout_data(layout::Component) = layout layout_data(layout::Function) = layout() function process_layout(request::HTTP.Request, state::HandlerState) - body = return HTTP.Response( 200, - ["Content-Type", "application/json"], + ["Content-Type" => "application/json"], body = JSON2.write(layout_data(state.app.layout)) ) end