Add VarianceDisplay component and update StockEvent model for variance type

This commit is contained in:
Tom Butcher 2025-07-14 23:05:10 +01:00
parent 0a897e663c
commit b6c2cb22f4
2 changed files with 39 additions and 4 deletions

View File

@ -0,0 +1,32 @@
import React from 'react'
import { Typography } from 'antd'
import PropTypes from 'prop-types'
const { Text } = Typography
const VarianceDisplay = ({ value, prefix, suffix }) => {
if (value === null || value === undefined) {
return <Text type='secondary'>n/a</Text>
}
const isPositive = value > 0
const isNegative = value < 0
const displayValue = Math.abs(value).toFixed(2)
return (
<Text type={isPositive ? 'success' : isNegative ? 'danger' : undefined}>
{prefix || ''}
{isPositive ? '+' : isNegative ? '-' : ''}
{displayValue}
{suffix || ''}
</Text>
)
}
VarianceDisplay.propTypes = {
value: PropTypes.number,
prefix: PropTypes.string,
suffix: PropTypes.string
}
export default VarianceDisplay

View File

@ -60,7 +60,7 @@ export const StockEvent = {
label: 'Parent', label: 'Parent',
type: 'object', type: 'object',
objectType: (objectData) => { objectType: (objectData) => {
return objectData.parentType return objectData?.parentType
}, },
value: null, value: null,
showCopy: true showCopy: true
@ -78,9 +78,12 @@ export const StockEvent = {
{ {
name: 'value', name: 'value',
label: 'Value', label: 'Value',
columnWidth: 100, columnWidth: 120,
type: 'number', type: 'variance',
showCopy: true showCopy: true,
suffix: (objectData) => {
return objectData.unit
}
} }
] ]
} }