Add support for additional property types in ObjectProperty component, including variance, markdown, and object list displays. Enhance prop types to accommodate functions for prefix, suffix, and object type. Update ObjectInfo to pass custom property props.

This commit is contained in:
Tom Butcher 2025-07-14 23:09:56 +01:00
parent 38f03f8fe9
commit cd83679232
2 changed files with 62 additions and 8 deletions

View File

@ -13,6 +13,7 @@ const ObjectInfo = ({
properties = [], properties = [],
required = undefined, required = undefined,
visibleProperties = {}, visibleProperties = {},
objectPropertyProps = {},
...rest ...rest
}) => { }) => {
const allItems = getModelProperties(type) const allItems = getModelProperties(type)
@ -55,6 +56,7 @@ const ObjectInfo = ({
children: ( children: (
<ObjectProperty <ObjectProperty
{...item} {...item}
{...objectPropertyProps}
isEditing={isEditing} isEditing={isEditing}
objectData={objectData} objectData={objectData}
/> />
@ -91,7 +93,8 @@ ObjectInfo.propTypes = {
type: PropTypes.string.isRequired, type: PropTypes.string.isRequired,
objectData: PropTypes.object, objectData: PropTypes.object,
required: PropTypes.bool, required: PropTypes.bool,
visibleProperties: PropTypes.object visibleProperties: PropTypes.object,
objectPropertyProps: PropTypes.object
} }
export default ObjectInfo export default ObjectInfo

View File

@ -37,6 +37,10 @@ import { getPropertyValue } from '../../../database/ObjectModels'
import PropertyChanges from './PropertyChanges' import PropertyChanges from './PropertyChanges'
import NetGrossDisplay from './NetGrossDisplay' import NetGrossDisplay from './NetGrossDisplay'
import NetGrossInput from './NetGrossInput' import NetGrossInput from './NetGrossInput'
import ObjectList from './ObjectList'
import VarianceDisplay from './VarianceDisplay'
import OperationDisplay from './OperationDisplay'
import MarkdownDisplay from './MarkdownDisplay'
const { Text } = Typography const { Text } = Typography
@ -71,7 +75,7 @@ const ObjectProperty = ({
initial = false, initial = false,
...rest ...rest
}) => { }) => {
if (typeof value == 'function' && objectData) { if (value && typeof value == 'function' && objectData) {
value = value(objectData) value = value(objectData)
} }
@ -87,6 +91,14 @@ const ObjectProperty = ({
difference = difference(objectData) difference = difference(objectData)
} }
if (prefix && typeof prefix == 'function' && objectData) {
prefix = prefix(objectData)
}
if (suffix && typeof suffix == 'function' && objectData) {
suffix = suffix(objectData)
}
if (!value) { if (!value) {
value = getPropertyValue(objectData, name) value = getPropertyValue(objectData, name)
} }
@ -218,6 +230,19 @@ const ObjectProperty = ({
) )
} }
} }
case 'variance': {
if (value != null) {
return (
<VarianceDisplay value={value} prefix={prefix} suffix={suffix} />
)
} else {
return (
<Text type='secondary' {...textParams}>
n/a
</Text>
)
}
}
case 'text': case 'text':
if (value != null && value != '') { if (value != null && value != '') {
return ( return (
@ -234,6 +259,16 @@ const ObjectProperty = ({
</Text> </Text>
) )
} }
case 'markdown':
if (value != null && value != '') {
return <MarkdownDisplay content={value} />
} else {
return (
<Text type='secondary' {...textParams}>
n/a
</Text>
)
}
case 'email': case 'email':
if (value != null && value != '') { if (value != null && value != '') {
return <EmailDisplay email={value} /> return <EmailDisplay email={value} />
@ -265,6 +300,9 @@ const ObjectProperty = ({
) )
} }
} }
case 'objectList': {
return <ObjectList value={value} objectType={objectType} />
}
case 'state': { case 'state': {
if (value && value?.type) { if (value && value?.type) {
switch (objectType) { switch (objectType) {
@ -346,6 +384,17 @@ const ObjectProperty = ({
) )
} }
} }
case 'operation': {
if (value != null) {
return <OperationDisplay operation={value} />
} else {
return (
<Text type='secondary' {...textParams}>
n/a
</Text>
)
}
}
case 'propertyChanges': { case 'propertyChanges': {
return <PropertyChanges type={objectType} value={value} /> return <PropertyChanges type={objectType} value={value} />
} }
@ -555,7 +604,7 @@ const ObjectProperty = ({
<PrinterSelect placeholder={label} /> <PrinterSelect placeholder={label} />
</Form.Item> </Form.Item>
) )
case 'gcodefile': case 'gcodeFile':
return ( return (
<Form.Item name={formItemName} {...mergedFormItemProps}> <Form.Item name={formItemName} {...mergedFormItemProps}>
<GCodeFileSelect placeholder={label} /> <GCodeFileSelect placeholder={label} />
@ -603,20 +652,22 @@ const ObjectProperty = ({
ObjectProperty.propTypes = { ObjectProperty.propTypes = {
type: PropTypes.string.isRequired, type: PropTypes.string.isRequired,
value: PropTypes.any, value: PropTypes.oneOfType([PropTypes.any, PropTypes.func]),
isEditing: PropTypes.bool, isEditing: PropTypes.bool,
formItemProps: PropTypes.object, formItemProps: PropTypes.object,
required: PropTypes.bool, required: PropTypes.bool,
name: PropTypes.string, name: PropTypes.string,
prefix: PropTypes.string, prefix: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
suffix: PropTypes.string, suffix: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
min: PropTypes.number, min: PropTypes.number,
max: PropTypes.number, max: PropTypes.number,
step: PropTypes.number, step: PropTypes.number,
showLabel: PropTypes.bool, showLabel: PropTypes.bool,
objectType: PropTypes.string, objectType: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
readOnly: PropTypes.bool, readOnly: PropTypes.bool,
disabled: PropTypes.bool disabled: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
difference: PropTypes.oneOfType([PropTypes.any, PropTypes.func]),
objectData: PropTypes.object
} }
export default ObjectProperty export default ObjectProperty