From a9a2801e27c2ff6be3f289828013027a4e5652b9 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Mon, 18 Aug 2025 00:58:10 +0100 Subject: [PATCH] Refactor ObjectProperty component and introduce StateDisplay - Removed unused components (PrinterState, SubJobState, JobState, FilamentStockState). - Added new StateDisplay component for handling state representation. - Enhanced ObjectProperty to support new properties and rendering logic for code blocks and object types. - Updated import paths and prop types accordingly for improved clarity and functionality. --- .../Dashboard/common/ObjectProperty.jsx | 98 +++++++++--- .../{PrinterState.jsx => StateDisplay.jsx} | 10 +- .../Dashboard/common/SubJobState.jsx | 147 ------------------ .../Dashboard/context/SpotlightContext.js | 35 +---- 4 files changed, 83 insertions(+), 207 deletions(-) rename src/components/Dashboard/common/{PrinterState.jsx => StateDisplay.jsx} (75%) delete mode 100644 src/components/Dashboard/common/SubJobState.jsx diff --git a/src/components/Dashboard/common/ObjectProperty.jsx b/src/components/Dashboard/common/ObjectProperty.jsx index 38d6e71..ce531d5 100644 --- a/src/components/Dashboard/common/ObjectProperty.jsx +++ b/src/components/Dashboard/common/ObjectProperty.jsx @@ -20,14 +20,10 @@ import CountrySelect from './CountrySelect' import TagsDisplay from './TagsDisplay' import TagsInput from './TagsInput' import BoolDisplay from './BoolDisplay' -import PrinterState from './PrinterState' -import SubJobState from './SubJobState' -import JobState from './JobState' import ColorSelector from './ColorSelector' import SecretDisplay from './SecretDisplay' import EyeIcon from '../../Icons/EyeIcon' import EyeSlashIcon from '../../Icons/EyeSlashIcon' -import FilamentStockState from './FilamentStockState' import { getPropertyValue } from '../../../database/ObjectModels' import PropertyChanges from './PropertyChanges' import NetGrossDisplay from './NetGrossDisplay' @@ -38,6 +34,10 @@ import OperationDisplay from './OperationDisplay' import MarkdownDisplay from './MarkdownDisplay' import ObjectSelect from './ObjectSelect' import ObjectDisplay from './ObjectDisplay' +import ObjectTypeSelect from './ObjectTypeSelect' +import ObjectTypeDisplay from './ObjectTypeDisplay' +import CodeBlockEditor from './CodeBlockEditor' +import StateDisplay from './StateDisplay' const { Text } = Typography @@ -65,11 +65,16 @@ const ObjectProperty = ({ name, label, showLabel = false, + masterFilter = {}, + language = '', objectData = null, objectType = 'unknown', readOnly = false, disabled = false, + empty = false, initial = false, + height = 'auto', + minimal = false, ...rest }) => { if (value && typeof value == 'function' && objectData) { @@ -84,6 +89,10 @@ const ObjectProperty = ({ disabled = disabled(objectData) } + if (empty && typeof empty == 'function' && objectData) { + empty = empty(objectData) + } + if (difference && typeof difference == 'function' && objectData) { difference = difference(objectData) } @@ -114,6 +123,9 @@ const ObjectProperty = ({ } const renderProperty = () => { + if (empty == true) { + return n/a + } if (!isEditing || (readOnly && !initial)) { switch (type) { case 'netGross': @@ -256,6 +268,24 @@ const ObjectProperty = ({ ) } + case 'codeBlock': + if (value != null && value != '') { + return ( + + ) + } else { + return ( + + n/a + + ) + } case 'markdown': if (value != null && value != '') { return @@ -297,27 +327,23 @@ const ObjectProperty = ({ ) } } + case 'objectType': { + if (value) { + return + } else { + return ( + + n/a + + ) + } + } case 'objectList': { return } case 'state': { if (value && value?.type) { - switch (objectType) { - case 'printer': - return - case 'job': - return - case 'subJob': - return - case 'filamentStock': - return - default: - return ( - - No Object Type Specified - - ) - } + return } else { return ( @@ -566,6 +592,18 @@ const ObjectProperty = ({ /> ) + case 'codeBlock': + return ( + + + + ) case 'material': return ( @@ -590,13 +628,23 @@ const ObjectProperty = ({ case 'object': return ( - + + + ) + case 'objectType': + return ( + + ) case 'objectList': return ( - + ) case 'tags': @@ -624,8 +672,10 @@ ObjectProperty.propTypes = { value: PropTypes.oneOfType([PropTypes.any, PropTypes.func]), isEditing: PropTypes.bool, formItemProps: PropTypes.object, + masterFilter: PropTypes.object, required: PropTypes.bool, name: PropTypes.string, + language: PropTypes.string, prefix: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), suffix: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), min: PropTypes.number, @@ -635,8 +685,10 @@ ObjectProperty.propTypes = { objectType: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), readOnly: PropTypes.bool, disabled: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]), + empty: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]), difference: PropTypes.oneOfType([PropTypes.any, PropTypes.func]), - objectData: PropTypes.object + objectData: PropTypes.object, + height: PropTypes.string } export default ObjectProperty diff --git a/src/components/Dashboard/common/PrinterState.jsx b/src/components/Dashboard/common/StateDisplay.jsx similarity index 75% rename from src/components/Dashboard/common/PrinterState.jsx rename to src/components/Dashboard/common/StateDisplay.jsx index dca0b84..bf0c1c9 100644 --- a/src/components/Dashboard/common/PrinterState.jsx +++ b/src/components/Dashboard/common/StateDisplay.jsx @@ -4,7 +4,7 @@ import { Progress, Flex, Space } from 'antd' import React from 'react' import StateTag from './StateTag' -const PrinterState = ({ state, showProgress = true, showState = true }) => { +const StateDisplay = ({ state, showProgress = true, showState = true }) => { const currentState = state || { type: 'unknown', progress: 0 @@ -17,9 +17,7 @@ const PrinterState = ({ state, showProgress = true, showState = true }) => { )} - {showProgress && - (currentState.type === 'printing' || - currentState.type === 'deploying') ? ( + {showProgress && currentState?.progress && currentState?.progress > 0 ? ( { ) } -PrinterState.propTypes = { +StateDisplay.propTypes = { state: PropTypes.object, showProgress: PropTypes.bool, showState: PropTypes.bool } -export default PrinterState +export default StateDisplay diff --git a/src/components/Dashboard/common/SubJobState.jsx b/src/components/Dashboard/common/SubJobState.jsx deleted file mode 100644 index 42288c4..0000000 --- a/src/components/Dashboard/common/SubJobState.jsx +++ /dev/null @@ -1,147 +0,0 @@ -import PropTypes from 'prop-types' -import { Progress, Flex, Button, Space, Tooltip } from 'antd' // eslint-disable-line -import { CaretLeftOutlined } from '@ant-design/icons' // eslint-disable-line -import React, { useContext } from 'react' -import { PrintServerContext } from '../context/PrintServerContext' -import IdDisplay from './IdDisplay' -import StateTag from './StateTag' -import XMarkIcon from '../../Icons/XMarkIcon' -import PauseIcon from '../../Icons/PauseIcon' -import BinIcon from '../../Icons/BinIcon' -import config from '../../../config' -import loglevel from 'loglevel' -const logger = loglevel.getLogger('SubJobState') -logger.setLevel(config.logLevel) - -const SubJobState = ({ - state, - showStatus = true, - showId = true, - showProgress = true, - showControls = true //eslint-disable-line -}) => { - const { printServer } = useContext(PrintServerContext) - const currentState = state || { - type: 'unknown', - progress: 0 - } - return ( - - {showId && state?._id && ( - - )} - {showStatus && ( - - - - )} - {showProgress && - (currentState.type === 'printing' || - currentState.type === 'processing') ? ( - - ) : null} - {showControls && - (currentState.type === 'printing' || currentState.type === 'paused') && - state?.printer ? ( - - - - - -