From 4820082248cf39327f366a849e50ac0013020210 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 13 Jan 2021 10:58:50 +0300 Subject: [PATCH] Hide nodes without visible children in the property editor --- .../vision/bootstrap/tabComponent.kt | 2 +- .../vision/bootstrap/threeControls.kt | 2 +- .../dataforge/vision/react/PropertyEditor.kt | 23 ++++++++++--------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/tabComponent.kt b/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/tabComponent.kt index 5f22a353..fa61d3d4 100644 --- a/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/tabComponent.kt +++ b/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/tabComponent.kt @@ -45,7 +45,7 @@ public val TabPane: FunctionalComponent = functionalComponent("Tab +(cp.title ?: cp.id) attrs { if (cp.id == activeTab) { - classes += "active" + classes = classes + "active" } onClickFunction = { activeTab = cp.id diff --git a/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/threeControls.kt b/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/threeControls.kt index 7c26abbf..33b94244 100644 --- a/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/threeControls.kt +++ b/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/threeControls.kt @@ -22,7 +22,7 @@ public external interface ThreeControlsProps : RProps { @JsExport public val ThreeControls: FunctionalComponent = functionalComponent { props -> val vision = props.canvas.content - tabPane { + tabPane(if (props.selected != null) "Properties" else null) { tab("Canvas") { card("Canvas configuration") { canvasControls(props.canvas) diff --git a/ui/react/src/main/kotlin/hep/dataforge/vision/react/PropertyEditor.kt b/ui/react/src/main/kotlin/hep/dataforge/vision/react/PropertyEditor.kt index 53678275..28432ab0 100644 --- a/ui/react/src/main/kotlin/hep/dataforge/vision/react/PropertyEditor.kt +++ b/ui/react/src/main/kotlin/hep/dataforge/vision/react/PropertyEditor.kt @@ -66,12 +66,9 @@ private val PropertyEditorItem: FunctionalComponent = private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) { var expanded: Boolean by useState { true } val descriptorItem: ItemDescriptor? = props.descriptor?.get(props.name) - if (descriptorItem?.hidden == true) return //fail fast for hidden property var ownProperty: MetaItem? by useState { props.ownProperties.getItem(props.name) } val actualItem: MetaItem? = props.allProperties?.getItem(props.name) - println("Actual item for ${props.name?.toString()} is ${actualItem.toString()}") - val token = props.name.lastOrNull()?.toString() ?: "Properties" fun update() { @@ -108,6 +105,17 @@ private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) { } if (actualItem is NodeItem) { + val keys = buildSet { + (descriptorItem as? NodeDescriptor)?.items?.filterNot { + it.key.startsWith("@") || it.value.hidden + }?.forEach { + add(NameToken(it.key)) + } + ownProperty?.node?.items?.keys?.filterNot { it.body.startsWith("@") }?.let { addAll(it) } + } + // Do not show nodes without visible children + if (keys.isEmpty()) return + styledDiv { css { +TreeStyles.treeLeaf @@ -138,14 +146,7 @@ private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) { css { +TreeStyles.tree } - val keys = buildSet { - (descriptorItem as? NodeDescriptor)?.items?.keys?.forEach { - add(NameToken(it)) - } - ownProperty?.node?.items?.keys?.let { addAll(it) } - } - - keys.filter { !it.body.startsWith("@") }.forEach { token -> + keys.forEach { token -> styledLi { css { +TreeStyles.treeItem