Skip to content

Commit

Permalink
fix(inspector) Prevent None Controls From Adding Rows To Inspector. (#…
Browse files Browse the repository at this point in the history
…6016)

- Added in cases to stop `none` controls from reaching a
`RowForControl`.
- Changed `RowForControlProps.controlDescription` to `exclude
`NoneControlDescription`.
  • Loading branch information
seanparsons authored and liady committed Dec 13, 2024
1 parent dcfd7ba commit b722caa
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
ArrayControlDescription,
BaseControlDescription,
ControlDescription,
NoneControlDescription,
ObjectControlDescription,
RegularControlDescription,
TupleControlDescription,
Expand Down Expand Up @@ -999,6 +1000,11 @@ const ArrayControlItem = React.memo((props: ArrayControlItemProps) => {
const contextMenuItems = Utils.stripNulls([addOnUnsetValues([index], propMetadata.onUnsetValues)])

const contextMenuId = `context-menu-for-${PP.toString(propPathWithIndex)}`

if (controlDescription.propertyControl.control === 'none') {
return null
}

return (
<InspectorContextMenuWrapper
id={contextMenuId}
Expand Down Expand Up @@ -1147,6 +1153,12 @@ const TupleControlItem = React.memo((props: TupleControlItemProps) => {
)
const contextMenuItems = Utils.stripNulls([addOnUnsetValues([index], propMetadata.onUnsetValues)])

const indexedPropertyControls = controlDescription.propertyControls[index]

if (indexedPropertyControls.control === 'none') {
return null
}

return (
<InspectorContextMenuWrapper
id={`context-menu-for-${PP.toString(propPathWithIndex)}`}
Expand All @@ -1155,7 +1167,7 @@ const TupleControlItem = React.memo((props: TupleControlItemProps) => {
key={index}
>
<RowForControl
controlDescription={controlDescription.propertyControls[index]}
controlDescription={indexedPropertyControls}
isScene={isScene}
propPath={PP.appendPropertyPathElems(propPath, [index])}
setGlobalCursor={props.setGlobalCursor}
Expand Down Expand Up @@ -1309,6 +1321,9 @@ const RowForObjectControl = React.memo((props: RowForObjectControlProps) => {
open,
mapToArray((innerControl: RegularControlDescription, prop: string, index: number) => {
const innerPropPath = PP.appendPropertyPathElems(propPath, [prop])
if (innerControl.control === 'none') {
return null
}
return (
<RowForControl
key={`object-control-row-${PP.toString(innerPropPath)}`}
Expand Down Expand Up @@ -1408,7 +1423,7 @@ const RowForUnionControl = React.memo((props: RowForUnionControlProps) => {
RowForUnionControl.displayName = 'RowForUnionControl'

interface RowForControlProps extends AbstractRowForControlProps {
controlDescription: RegularControlDescription
controlDescription: Exclude<RegularControlDescription, NoneControlDescription>
disableToggling?: boolean
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export const FolderSection = React.memo((props: FolderSectionProps) => {

const createRowForControl = (propName: string, focusOnMount: boolean) => {
const controlDescription = props.propertyControls[propName]
if (controlDescription.control === 'none') {
return null
}
return (
<RowOrFolderWrapper
key={`section-row-${propName}`}
Expand Down Expand Up @@ -126,19 +129,23 @@ export const FolderSection = React.memo((props: FolderSectionProps) => {
propValue,
propName,
)
return (
<RowForControl
key={propName}
propPath={PP.create(propName)}
controlDescription={controlDescription}
isScene={false}
setGlobalCursor={props.setGlobalCursor}
indentationLevel={props.indentationLevel}
shouldIncreaseIdentation={true}
showHiddenControl={props.showHiddenControl}
focusOnMount={false}
/>
)
if (controlDescription.control === 'none') {
return null
} else {
return (
<RowForControl
key={propName}
propPath={PP.create(propName)}
controlDescription={controlDescription}
isScene={false}
setGlobalCursor={props.setGlobalCursor}
indentationLevel={props.indentationLevel}
shouldIncreaseIdentation={true}
showHiddenControl={props.showHiddenControl}
focusOnMount={false}
/>
)
}
}
}),
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ type RowOrFolderWrapperProps = {
}

export const RowOrFolderWrapper = React.memo((props: RowOrFolderWrapperProps) => {
if (props.controlDescription.control === 'none') {
return null
}
return (
<UIGridRow padded={false} tall={false} variant='<-------------1fr------------->'>
<RowForControl
Expand Down

0 comments on commit b722caa

Please sign in to comment.