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.
This commit is contained in:
Joe 2026-02-01 10:10:38 -06:00
parent af65056c44
commit a8752b6b8d
2 changed files with 18 additions and 19 deletions

View file

@ -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,

View file

@ -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",