From f68151fc006f35622b6e570f33b8c099deca2545 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 28 Jul 2023 21:42:02 +0200 Subject: [PATCH 1/2] handle empty children --- src/app/dashapp.jl | 3 ++- test/core.jl | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/dashapp.jl b/src/app/dashapp.jl index 92fccce..37dd25e 100644 --- a/src/app/dashapp.jl +++ b/src/app/dashapp.jl @@ -49,7 +49,8 @@ function Base.getindex(component::DashBase.Component, id::AbstractString) return if cc isa Union{VecChildTypes, DashBase.Component} cc[id] elseif cc isa AbstractVector - identity.(filter(x->hasproperty(x, :id), cc))[id] + fcc = identity.(filter(x->hasproperty(x, :id), cc)) + isempty(fcc) ? nothing : fcc[id] else nothing end diff --git a/test/core.jl b/test/core.jl index fd9f030..45ebb7d 100644 --- a/test/core.jl +++ b/test/core.jl @@ -206,7 +206,7 @@ end app.layout = html_div() do dcc_input(id = "my-id", value="initial value", type = "text"), html_div(id = "my-div", children = [ - html_div(), + html_div(children = []), "string", html_div(id = "target") ]), From 68dca5e25cf9f967dc226b21b1d1b92c4c7d0494 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Wed, 2 Aug 2023 14:41:17 +0200 Subject: [PATCH 2/2] move logic to DashBase --- Project.toml | 2 +- src/app/dashapp.jl | 22 ---------------------- test/core.jl | 14 -------------- 3 files changed, 1 insertion(+), 37 deletions(-) diff --git a/Project.toml b/Project.toml index 4a27bc0..9182ea3 100644 --- a/Project.toml +++ b/Project.toml @@ -26,7 +26,7 @@ YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" [compat] Aqua = "0.6" CodecZlib = "0.6, 0.7" -DashBase = "0.2" +DashBase = "0.2.1" DashCoreComponents = "2.0.0" DashHtmlComponents = "2.0.0" DashTable = "5.0.0" diff --git a/src/app/dashapp.jl b/src/app/dashapp.jl index 37dd25e..7c050b3 100644 --- a/src/app/dashapp.jl +++ b/src/app/dashapp.jl @@ -40,28 +40,6 @@ mutable struct DashApp end -const VecChildTypes = Union{NTuple{N, DashBase.Component} where {N}, Vector{<:DashBase.Component}} - -function Base.getindex(component::DashBase.Component, id::AbstractString) - component.id == id && return component - hasproperty(component, :children) || return nothing - cc = component.children - return if cc isa Union{VecChildTypes, DashBase.Component} - cc[id] - elseif cc isa AbstractVector - fcc = identity.(filter(x->hasproperty(x, :id), cc)) - isempty(fcc) ? nothing : fcc[id] - else - nothing - end -end -function Base.getindex(children::VecChildTypes, id::AbstractString) - for element in children - element.id == id && return element - el = element[id] - el !== nothing && return el - end -end #only name, index_string and layout are available to set function Base.setproperty!(app::DashApp, property::Symbol, value) diff --git a/test/core.jl b/test/core.jl index 45ebb7d..99370b2 100644 --- a/test/core.jl +++ b/test/core.jl @@ -201,17 +201,3 @@ end @test_throws ErrorException make_handler(app) end -@testset "Index by id" begin - app = dash() - app.layout = html_div() do - dcc_input(id = "my-id", value="initial value", type = "text"), - html_div(id = "my-div", children = [ - html_div(children = []), - "string", - html_div(id = "target") - ]), - html_div(id = "my-div2") - end - @test app.layout["target"].id == "target" - @test app.layout["ups"] === nothing -end