Refactor components to improve logging and ID handling
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good

- 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.
This commit is contained in:
Tom Butcher 2026-08-01 16:18:37 +01:00
parent a2d27c692a
commit d982b8dfb3
7 changed files with 15 additions and 13 deletions

View File

@ -36,8 +36,6 @@ const FilePreview = ({ file, style = {} }) => {
} }
}, [file._id, file?.type, fetchPreview, token]) }, [file._id, file?.type, fetchPreview, token])
console.log(file)
if (loading == true || !file?.type) { if (loading == true || !file?.type) {
return <LoadingPlaceholder message={'Loading file preview...'} /> return <LoadingPlaceholder message={'Loading file preview...'} />
} }

View File

@ -1,6 +1,10 @@
import { useEffect, useRef, cloneElement, useMemo } from 'react' import { useEffect, useRef, cloneElement, useMemo } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { Popover, Typography } from 'antd' 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 = { const MODIFIER_ALIASES = {
cmd: 'meta', cmd: 'meta',
@ -59,7 +63,9 @@ const KeyboardShortcut = ({
} }
if (log) { if (log) {
console.log('Key Down:', key, 'Pressed Keys:', [...pressedKeysRef.current]) logger.info('Key Down:', key, 'Pressed Keys:', [
...pressedKeysRef.current
])
} }
if ( if (

View File

@ -127,8 +127,6 @@ const ObjectForm = forwardRef(
searchParams.delete(actionParam) searchParams.delete(actionParam)
const newSearch = searchParams.toString() const newSearch = searchParams.toString()
console.log('newSearch', newSearch)
console.log('location.pathname', location.pathname)
const newPath = location.pathname + (newSearch ? `?${newSearch}` : '') const newPath = location.pathname + (newSearch ? `?${newSearch}` : '')
navigate(newPath, { replace: true }) navigate(newPath, { replace: true })
}, },
@ -537,7 +535,7 @@ const ObjectForm = forwardRef(
} }
const activityUnsubscribe = subscribeToObjectActivity( const activityUnsubscribe = subscribeToObjectActivity(
id, id?.toLowerCase(),
type, type,
activityHandler activityHandler
) )
@ -565,7 +563,7 @@ const ObjectForm = forwardRef(
} }
const objectUpdatesUnsubscribe = subscribeToObjectUpdates( const objectUpdatesUnsubscribe = subscribeToObjectUpdates(
id, id?.toLowerCase(),
type, type,
objectUpdateHandler objectUpdateHandler
) )

View File

@ -693,7 +693,7 @@ const ObjectTable = forwardRef(
// Subscribe to new items only // Subscribe to new items only
newItemIds.forEach((itemId) => { newItemIds.forEach((itemId) => {
const unsubscribe = subscribeToObjectUpdates( const unsubscribe = subscribeToObjectUpdates(
itemId, itemId?.toLowerCase(),
type, type,
(updateData) => { (updateData) => {
updateEventHandlerRef.current(itemId, updateData) updateEventHandlerRef.current(itemId, updateData)

View File

@ -55,7 +55,7 @@ const PrinterMiscPanel = ({
useEffect(() => { useEffect(() => {
if (id && connected == true) { if (id && connected == true) {
const miscEventUnsubscribe = subscribeToObjectEvent( const miscEventUnsubscribe = subscribeToObjectEvent(
id, id?.toLowerCase(),
'printer', 'printer',
'misc', 'misc',
(event) => { (event) => {

View File

@ -90,7 +90,7 @@ const PrinterPositionPanel = ({
useEffect(() => { useEffect(() => {
if (id && connected == true) { if (id && connected == true) {
const motionEventUnsubscribe = subscribeToObjectEvent( const motionEventUnsubscribe = subscribeToObjectEvent(
id, id?.toLowerCase(),
'printer', 'printer',
'motion', 'motion',
(event) => { (event) => {

View File

@ -84,9 +84,9 @@ const PrinterTemperaturePanel = ({
}, [temperatureData.bed?.target]) }, [temperatureData.bed?.target])
useEffect(() => { useEffect(() => {
if (id && connected == true) { if (id && connected == true && offline == false) {
const temperatureEventUnsubscribe = subscribeToObjectEvent( const temperatureEventUnsubscribe = subscribeToObjectEvent(
id, id?.toLowerCase(),
'printer', 'printer',
'temperature', 'temperature',
(event) => { (event) => {
@ -100,7 +100,7 @@ const PrinterTemperaturePanel = ({
if (temperatureEventUnsubscribe) temperatureEventUnsubscribe() if (temperatureEventUnsubscribe) temperatureEventUnsubscribe()
} }
} }
}, [id, connected, subscribeToObjectEvent]) }, [id, connected, subscribeToObjectEvent, offline])
const [extruderTarget, setExtruderTarget] = useState(0) const [extruderTarget, setExtruderTarget] = useState(0)
const [bedTarget, setBedTarget] = useState(0) const [bedTarget, setBedTarget] = useState(0)