Enhance ObjectInfo component by adding support for property definitions and controlled property changes. Introduce new props for parent data and property change handling, improving flexibility and data management in the component.

This commit is contained in:
Tom Butcher 2026-07-20 02:06:22 +01:00
parent 37d6ba9148
commit a38d9c91f6

View File

@ -13,7 +13,10 @@ const ObjectInfo = ({
showHyperlink,
showLabels = true,
objectData = null,
parentData = null,
properties = [],
propertyDefinitions = null,
onPropertyChange = null,
required = undefined,
visibleProperties = {},
objectPropertyProps = {},
@ -39,7 +42,9 @@ const ObjectInfo = ({
// If properties array is empty, show all properties
// Otherwise, filter and order by the properties array
let items
if (properties.length === 0) {
if (Array.isArray(propertyDefinitions) && propertyDefinitions.length > 0) {
items = propertyDefinitions
} else if (properties.length === 0) {
items = allItems
} else {
items = properties
@ -80,6 +85,8 @@ const ObjectInfo = ({
}
})
const isControlled = typeof onPropertyChange === 'function'
// Map items to Descriptions 'items' prop format
const descriptionItems = items.map((item, idx) => {
const key = item.name || item.label || idx
@ -98,7 +105,17 @@ const ObjectInfo = ({
{...objectPropertyProps}
isEditing={isEditing}
objectData={combinedObjectData}
parentData={parentData}
showSince={true}
useFormItem={isControlled ? false : objectPropertyProps.useFormItem}
value={
isControlled ? combinedObjectData?.[item.name] : undefined
}
onChange={
isControlled
? (newVal) => onPropertyChange(item.name, newVal)
: objectPropertyProps.onChange
}
/>
</div>
),
@ -130,8 +147,11 @@ ObjectInfo.propTypes = {
bordered: PropTypes.bool,
items: PropTypes.arrayOf(PropTypes.object),
isEditing: PropTypes.bool,
type: PropTypes.string.isRequired,
type: PropTypes.string,
objectData: PropTypes.object,
parentData: PropTypes.object,
propertyDefinitions: PropTypes.array,
onPropertyChange: PropTypes.func,
required: PropTypes.bool,
visibleProperties: PropTypes.object,
objectPropertyProps: PropTypes.object,