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