From a8752b6b8dc19acb5b919b2b0a40aef7697b8b91 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 1 Feb 2026 10:10:38 -0600 Subject: [PATCH] Refactor DomLabel and SelectionOption components for improved readability - Simplified conditional logic for caret visibility in the SelectionOption component. - Enhanced the rendering logic in the ConfirmingPage to improve clarity and maintainability. - Updated the Abort button rendering to use a more concise syntax for conditional display. --- .../Components/PatchVisualizer/DomLabel.lua | 21 ++++++++----------- plugin/src/App/StatusPages/Confirming.lua | 16 +++++++------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/plugin/src/App/Components/PatchVisualizer/DomLabel.lua b/plugin/src/App/Components/PatchVisualizer/DomLabel.lua index 6f61d0e9..f6a54403 100644 --- a/plugin/src/App/Components/PatchVisualizer/DomLabel.lua +++ b/plugin/src/App/Components/PatchVisualizer/DomLabel.lua @@ -71,10 +71,7 @@ function SelectionOption:render() -- Determine if we should show the caret: -- - Parent-only nodes: always show caret (they only do subtree operations) -- - Normal nodes with children: show caret when already selected AND hovering - local showCaret = if isParentOnly - then true - elseif hasChildren and isSelected and isHovered then true - else false + local showCaret = if isParentOnly then true elseif hasChildren and isSelected and isHovered then true else false local bgColor = if isSelected then (if props.optionType == "push" @@ -125,13 +122,8 @@ function SelectionOption:render() self:setState({ isHovered = false }) end, [Roact.Event.Activated] = function() - if isParentOnly then - -- Parent-only: single click applies to subtree - if props.onSubtreeClick then - props.onSubtreeClick() - end - elseif isSelected and hasChildren then - -- Already selected with children: click applies to subtree + if isParentOnly or (isSelected and hasChildren) then + -- Parent-only or already selected with children: click applies to subtree if props.onSubtreeClick then props.onSubtreeClick() end @@ -508,7 +500,12 @@ function DomLabel:render() SelectionRadio = e(SelectionRadio, { -- Visible for nodes with patchType, or for parent-only nodes on hover visible = (props.patchType ~= nil and props.onSelectionChange ~= nil) - or (props.patchType == nil and props.hasChildren and self.state.isHovered and props.onSubtreeSelectionChange ~= nil), + or ( + props.patchType == nil + and props.hasChildren + and self.state.isHovered + and props.onSubtreeSelectionChange ~= nil + ), nodeId = props.nodeId, selection = props.selection, transparency = props.transparency, diff --git a/plugin/src/App/StatusPages/Confirming.lua b/plugin/src/App/StatusPages/Confirming.lua index 9eddceef..2f9d05a2 100644 --- a/plugin/src/App/StatusPages/Confirming.lua +++ b/plugin/src/App/StatusPages/Confirming.lua @@ -163,13 +163,15 @@ function ConfirmingPage:render() BackgroundTransparency = 1, }, { -- Only show Abort button when there are changes - Abort = if hasChanges then e(TextButton, { - text = "Abort", - style = "Bordered", - transparency = self.props.transparency, - layoutOrder = 1, - onClick = self.props.onAbort, - }) else nil, + Abort = if hasChanges + then e(TextButton, { + text = "Abort", + style = "Bordered", + transparency = self.props.transparency, + layoutOrder = 1, + onClick = self.props.onAbort, + }) + else nil, Accept = e(TextButton, { text = if hasChanges then "Accept" else "OK",