From d982b8dfb362a7311322cf9941c69ae626c77ccd Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sat, 1 Aug 2026 16:18:37 +0100 Subject: [PATCH] Refactor components to improve logging and ID handling - Removed console.log statements from FilePreview and ObjectForm components for cleaner code. - Replaced console.log with loglevel in KeyboardShortcut for better logging management. - Updated ID handling in ObjectForm, ObjectTable, PrinterMiscPanel, PrinterPositionPanel, and PrinterTemperaturePanel components to ensure IDs are consistently converted to lowercase, enhancing data integrity. --- src/components/Dashboard/common/FilePreview.jsx | 2 -- src/components/Dashboard/common/KeyboardShortcut.jsx | 8 +++++++- src/components/Dashboard/common/ObjectForm.jsx | 6 ++---- src/components/Dashboard/common/ObjectTable.jsx | 2 +- src/components/Dashboard/common/PrinterMiscPanel.jsx | 2 +- src/components/Dashboard/common/PrinterPositionPanel.jsx | 2 +- .../Dashboard/common/PrinterTemperaturePanel.jsx | 6 +++--- 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/components/Dashboard/common/FilePreview.jsx b/src/components/Dashboard/common/FilePreview.jsx index 1c2546b..bc33a53 100644 --- a/src/components/Dashboard/common/FilePreview.jsx +++ b/src/components/Dashboard/common/FilePreview.jsx @@ -36,8 +36,6 @@ const FilePreview = ({ file, style = {} }) => { } }, [file._id, file?.type, fetchPreview, token]) - console.log(file) - if (loading == true || !file?.type) { return } diff --git a/src/components/Dashboard/common/KeyboardShortcut.jsx b/src/components/Dashboard/common/KeyboardShortcut.jsx index 9913d3a..182bf36 100644 --- a/src/components/Dashboard/common/KeyboardShortcut.jsx +++ b/src/components/Dashboard/common/KeyboardShortcut.jsx @@ -1,6 +1,10 @@ import { useEffect, useRef, cloneElement, useMemo } from 'react' import PropTypes from 'prop-types' import { Popover, Typography } from 'antd' +import loglevel from 'loglevel' +import config from '../../../config' +const logger = loglevel.getLogger('ApiServerContext') +logger.setLevel(config.logLevel) const MODIFIER_ALIASES = { cmd: 'meta', @@ -59,7 +63,9 @@ const KeyboardShortcut = ({ } if (log) { - console.log('Key Down:', key, 'Pressed Keys:', [...pressedKeysRef.current]) + logger.info('Key Down:', key, 'Pressed Keys:', [ + ...pressedKeysRef.current + ]) } if ( diff --git a/src/components/Dashboard/common/ObjectForm.jsx b/src/components/Dashboard/common/ObjectForm.jsx index 47db3c9..89cb19f 100644 --- a/src/components/Dashboard/common/ObjectForm.jsx +++ b/src/components/Dashboard/common/ObjectForm.jsx @@ -127,8 +127,6 @@ const ObjectForm = forwardRef( searchParams.delete(actionParam) const newSearch = searchParams.toString() - console.log('newSearch', newSearch) - console.log('location.pathname', location.pathname) const newPath = location.pathname + (newSearch ? `?${newSearch}` : '') navigate(newPath, { replace: true }) }, @@ -537,7 +535,7 @@ const ObjectForm = forwardRef( } const activityUnsubscribe = subscribeToObjectActivity( - id, + id?.toLowerCase(), type, activityHandler ) @@ -565,7 +563,7 @@ const ObjectForm = forwardRef( } const objectUpdatesUnsubscribe = subscribeToObjectUpdates( - id, + id?.toLowerCase(), type, objectUpdateHandler ) diff --git a/src/components/Dashboard/common/ObjectTable.jsx b/src/components/Dashboard/common/ObjectTable.jsx index e006a0c..e811243 100644 --- a/src/components/Dashboard/common/ObjectTable.jsx +++ b/src/components/Dashboard/common/ObjectTable.jsx @@ -693,7 +693,7 @@ const ObjectTable = forwardRef( // Subscribe to new items only newItemIds.forEach((itemId) => { const unsubscribe = subscribeToObjectUpdates( - itemId, + itemId?.toLowerCase(), type, (updateData) => { updateEventHandlerRef.current(itemId, updateData) diff --git a/src/components/Dashboard/common/PrinterMiscPanel.jsx b/src/components/Dashboard/common/PrinterMiscPanel.jsx index ca8311e..845de98 100644 --- a/src/components/Dashboard/common/PrinterMiscPanel.jsx +++ b/src/components/Dashboard/common/PrinterMiscPanel.jsx @@ -55,7 +55,7 @@ const PrinterMiscPanel = ({ useEffect(() => { if (id && connected == true) { const miscEventUnsubscribe = subscribeToObjectEvent( - id, + id?.toLowerCase(), 'printer', 'misc', (event) => { diff --git a/src/components/Dashboard/common/PrinterPositionPanel.jsx b/src/components/Dashboard/common/PrinterPositionPanel.jsx index fc1e95c..f839606 100644 --- a/src/components/Dashboard/common/PrinterPositionPanel.jsx +++ b/src/components/Dashboard/common/PrinterPositionPanel.jsx @@ -90,7 +90,7 @@ const PrinterPositionPanel = ({ useEffect(() => { if (id && connected == true) { const motionEventUnsubscribe = subscribeToObjectEvent( - id, + id?.toLowerCase(), 'printer', 'motion', (event) => { diff --git a/src/components/Dashboard/common/PrinterTemperaturePanel.jsx b/src/components/Dashboard/common/PrinterTemperaturePanel.jsx index 3dce0bd..c0fc1b9 100644 --- a/src/components/Dashboard/common/PrinterTemperaturePanel.jsx +++ b/src/components/Dashboard/common/PrinterTemperaturePanel.jsx @@ -84,9 +84,9 @@ const PrinterTemperaturePanel = ({ }, [temperatureData.bed?.target]) useEffect(() => { - if (id && connected == true) { + if (id && connected == true && offline == false) { const temperatureEventUnsubscribe = subscribeToObjectEvent( - id, + id?.toLowerCase(), 'printer', 'temperature', (event) => { @@ -100,7 +100,7 @@ const PrinterTemperaturePanel = ({ if (temperatureEventUnsubscribe) temperatureEventUnsubscribe() } } - }, [id, connected, subscribeToObjectEvent]) + }, [id, connected, subscribeToObjectEvent, offline]) const [extruderTarget, setExtruderTarget] = useState(0) const [bedTarget, setBedTarget] = useState(0)