From a2d27c692a8dc40f06ed4264a50f6506cb2acad0 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sat, 1 Aug 2026 15:54:00 +0100 Subject: [PATCH] Add PrinterControlButtons component for enhanced printer action management - Introduced PrinterControlButtons to encapsulate start, pause, and cancel actions for printers, improving user interaction. - Updated ControlPrinter component to integrate PrinterControlButtons, enhancing layout with Flex for better alignment. - Adjusted button states based on printer status and loading state, ensuring appropriate user feedback and action availability. --- .../Production/Printers/ControlPrinter.jsx | 26 ++++-- .../common/PrinterControlButtons.jsx | 89 +++++++++++++++++++ 2 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 src/components/Dashboard/common/PrinterControlButtons.jsx diff --git a/src/components/Dashboard/Production/Printers/ControlPrinter.jsx b/src/components/Dashboard/Production/Printers/ControlPrinter.jsx index 00ae6ec..f8991f9 100644 --- a/src/components/Dashboard/Production/Printers/ControlPrinter.jsx +++ b/src/components/Dashboard/Production/Printers/ControlPrinter.jsx @@ -33,6 +33,7 @@ import LoadFilamentStock from '../../Inventory/FilamentStocks/LoadFilamentStock. import UnloadFilamentStock from '../../Inventory/FilamentStocks/UnloadFilamentStock.jsx' import ScrollBox from '../../common/ScrollBox.jsx' import ObjectTableNavigationButtons from '../../common/ObjectTableNavigationButtons.jsx' +import PrinterControlButtons from '../../common/PrinterControlButtons.jsx' const log = loglevel.getLogger('ControlPrinter') log.setLevel(config.logLevel) @@ -321,13 +322,26 @@ const ControlPrinter = ({ slicerIntegration = false }) => { /> - {!slicerIntegration && ( - + + actionHandlerRef.current?.callAction(action) + } + objectData={objectFormState.objectData} + disabled={ + !objectFormState.objectData?.online || objectFormState.loading + } + loading={objectFormState.loading} /> - )} + {!slicerIntegration && ( + + )} + { + for (const action of actions) { + if (action.name === name) return action + if (action.children) { + const found = findAction(action.children, name) + if (found) return found + } + } + return null +} + +const isActionDisabled = (action, objectData, userProfile, disabled) => { + if (disabled) return true + if (!action?.disabled) return false + if (typeof action.disabled === 'function') { + return action.disabled({ ...objectData, _user: userProfile }) + } + return action.disabled +} + +const PrinterControlButtons = ({ callAction, objectData, disabled }) => { + const { userProfile } = useContext(AuthContext) + const model = getModelByName('printer') + const startQueueAction = findAction(model.actions, 'startQueue') + const pauseJobAction = findAction(model.actions, 'pauseJob') + const resumeJobAction = findAction(model.actions, 'resumeJob') + const cancelJobAction = findAction(model.actions, 'cancelJob') + + const isPaused = objectData?.state?.type === 'paused' + const startAction = isPaused ? resumeJobAction : startQueueAction + const startActionName = isPaused ? 'resumeJob' : 'startQueue' + + return ( + +