diff --git a/src/components/Dashboard/common/StatsDisplay.jsx b/src/components/Dashboard/common/StatsDisplay.jsx index 988d5f6..00ddab9 100644 --- a/src/components/Dashboard/common/StatsDisplay.jsx +++ b/src/components/Dashboard/common/StatsDisplay.jsx @@ -1,5 +1,5 @@ import { useEffect, useState, useContext, useRef } from 'react' -import { Flex, Alert, Card, Typography, Skeleton } from 'antd' +import { Flex, Tag, Card, Typography, Skeleton, Badge } from 'antd' import PropTypes from 'prop-types' import { getModelByName } from '../../../database/ObjectModels' import { ApiServerContext } from '../context/ApiServerContext' @@ -9,9 +9,9 @@ import { round } from '../utils/Utils' const { Text } = Typography /** - * Maps stat names to Alert types for visual indication + * Maps stat names to Tag colors for visual indication */ -const getAlertType = (statName) => { +const getTagColor = (statName) => { const name = statName.toLowerCase() // Success states @@ -43,14 +43,14 @@ const getAlertType = (statName) => { } if (name.includes('printing')) { - return 'info' + return 'processing' } // Default states return 'default' } -/** +/*i* * Gets a nested value from an object using dot notation * e.g., getNestedValue(obj, 'states.ready') -> obj.states.ready */ @@ -255,18 +255,41 @@ const StatsDisplay = ({ objectType, stats: statsProp }) => { {modelStats.map((statDef) => { const baseStatName = extractBaseStatName(statDef.name) var statValue = getStatValue(stats, baseStatName, statDef) - const alertType = getAlertType(statDef.name) + const tagColor = statDef.color || getTagColor(statDef.name) const label = statDef.label || statDef.name if (statDef?.roundNumber) { statValue = round(statValue, statDef?.roundNumber) } + const statusColors = [ + 'success', + 'warning', + 'error', + 'processing', + 'default' + ] + + var badgeProps = { + status: tagColor + } + + if (!statusColors.includes(tagColor)) { + badgeProps = { color: tagColor } + } + const content = ( - - {label} - - {Icon && } + + + + {label} + + + {Icon && ( + + + + )} {loading ? ( { ) - if (alertType === 'default') { + if (tagColor === 'default') { return ( {content} @@ -299,12 +322,17 @@ const StatsDisplay = ({ objectType, stats: statsProp }) => { } return ( - + color={tagColor} + style={{ + minWidth: statDef?.cardWidth || 175, + padding: '16px 24px', + margin: 0 + }} + > + {content} + ) })}