Tom Butcher ae8d4532c0
Some checks reported errors
farmcontrol/farmcontrol-ui/pipeline/head Something is wrong with the build of this commit
Implement Cancel Sub Job Feature and Enhance Printer Queue Management
- Added CancelSubJob component for handling sub job cancellation with user confirmation.
- Updated PrinterQueue and PrinterQueueItem components to support cancellation actions and display appropriate controls based on user permissions.
- Enhanced ObjectDisplay component to trigger data updates via onData callback, improving state management.
- Introduced new styles for printer queue steps in App.css to improve layout consistency.
2026-11-09 00:00:05 +00:00

70 lines
1.9 KiB
JavaScript

import { useState, useContext } from 'react'
import PropTypes from 'prop-types'
import { ApiServerContext } from '../../context/ApiServerContext'
import { message } from 'antd'
import MessageDialogView from '../../common/MessageDialogView.jsx'
const getRefId = (value) => {
if (!value) return null
if (typeof value === 'string') return value
if (typeof value._id === 'string') return value._id
if (typeof value._id === 'object' && value._id?._id) return value._id._id
return null
}
const CancelSubJob = ({ onOk, objectData }) => {
const [cancelLoading, setCancelLoading] = useState(false)
const { connected, sendObjectAction } = useContext(ApiServerContext)
const handleCancel = async () => {
if (!connected) {
message.error('Not connected to server')
return
}
const printerId = getRefId(objectData?.printer)
const subJobId = getRefId(objectData)
if (!printerId || !subJobId) {
message.error('Sub job is not assigned to a printer')
return
}
setCancelLoading(true)
try {
sendObjectAction(printerId, 'printer', {
type: 'cancelSubJob',
data: {
_id: subJobId
}
})
message.success('Sub job cancel initiated')
onOk()
} catch (error) {
console.error('Error cancelling sub job:', error)
} finally {
setCancelLoading(false)
}
}
const subJobLabel =
objectData?.name || objectData?._reference || objectData?._id
return (
<MessageDialogView
title='Are you sure you want to cancel this sub job?'
description={`Cancelling sub job ${subJobLabel} will remove it from the printer queue.`}
onOk={handleCancel}
okText='Cancel Sub Job'
okLoading={cancelLoading}
danger
/>
)
}
CancelSubJob.propTypes = {
onOk: PropTypes.func.isRequired,
objectData: PropTypes.object
}
export default CancelSubJob