Tom Butcher f4635d9188
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good
Refactor finance and inventory components to enhance modal handling and state management
- Integrated useEffect hooks in InvoiceInfo, PaymentInfo, and other components to utilize ActionsContext for managing modal states.
- Removed unused modal states and related code to streamline component logic.
- Added setCurrentObject prop to various components for improved object handling during state changes.
- Enhanced overall code maintainability and readability by consolidating modal logic and reducing redundancy.
2026-08-01 18:25:47 +01:00

184 lines
3.8 KiB
JavaScript

import { createElement, lazy } from 'react'
const SubJobInfo = lazy(
() => import('../../components/Dashboard/Production/SubJobs/SubJobInfo')
)
import SubJobIcon from '../../components/Icons/SubJobIcon'
import InfoCircleIcon from '../../components/Icons/InfoCircleIcon'
import XMarkIcon from '../../components/Icons/XMarkIcon'
import dayjs from 'dayjs'
export const SubJob = {
name: 'subJob',
label: 'Sub Job',
labelPlural: 'Sub Jobs',
url: '/dashboard/production/subjobs',
prefix: 'SJB',
icon: SubJobIcon,
actions: [
{
name: 'info',
type: 'page',
pageName: 'info',
label: 'Info',
default: true,
row: true,
icon: InfoCircleIcon
},
{
name: 'cancel',
type: 'page',
pageName: 'info',
label: 'Cancel Sub Job',
row: true,
icon: XMarkIcon,
disabled: (objectData) => {
return objectData?.state?.type !== 'queued'
}
}
],
pages: [
{
name: 'info',
content: () => createElement(SubJobInfo)
}
],
columns: [
'_reference',
'printer',
'job',
'state',
'startedAt',
'finishedAt',
'createdAt'
],
filters: [
'_id',
'job._id',
'printer._id',
'_reference',
'state',
'createdAt',
'updatedAt'
],
sorters: ['createdAt','state','updatedAt'],
group: ['job'],
properties: [
{
name: '_id',
label: 'ID',
type: 'id',
columnFixed: 'left',
objectType: 'subJob',
columnWidth: 140,
showCopy: true
},
{
name: 'createdAt',
label: 'Created At',
type: 'dateTime',
readOnly: true,
columnWidth: 175
},
{
name: '_reference',
label: 'Reference',
type: 'reference',
columnFixed: 'left',
objectType: 'subJob',
showCopy: true,
readOnly: true,
columnWidth: 180
},
{
name: 'updatedAt',
label: 'Updated At',
type: 'dateTime',
readOnly: true,
columnWidth: 175
},
{
name: 'state',
label: 'State',
type: 'state',
objectType: 'subJob',
showStatus: true,
showProgress: true,
showId: false,
showQuantity: false,
columnWidth: 260,
readOnly: true
},
{
name: 'startedAt',
label: 'Started At',
type: 'dateTime',
readOnly: true,
columnWidth: 175
},
{
name: 'moonrakerJobId',
label: 'Moonraker Job ID',
type: 'miscId',
columnWidth: 140,
showCopy: true
},
{
name: 'finishedAt',
label: 'Finished At',
type: 'dateTime',
readOnly: true,
columnWidth: 175
},
{
name: 'job',
label: 'Job',
type: 'object',
objectType: 'job',
showHyperlink: true,
columnWidth: 200
},
{
name: 'printer',
label: 'Printer',
type: 'object',
columnFixed: 'left',
objectType: 'printer',
showHyperlink: true,
columnWidth: 200
},
{
name: 'totalTime',
label: 'Total Time',
type: 'text',
columnWidth: 110,
readOnly: true,
value: (objectData) => {
if (!objectData?.startedAt || !objectData?.finishedAt) {
return '-'
}
const totalSeconds = dayjs(objectData?.finishedAt).diff(
dayjs(objectData?.startedAt),
'seconds'
)
const days = Math.floor(totalSeconds / 86400)
const hours = Math.floor((totalSeconds % 86400) / 3600)
const minutes = Math.floor((totalSeconds % 3600) / 60)
const seconds = totalSeconds % 60
const parts = []
if (days > 0) parts.push(`${days}d`)
if (hours > 0) parts.push(`${hours}h`)
if (minutes > 0) parts.push(`${minutes}m`)
if (seconds > 0 || parts.length === 0) parts.push(`${seconds}s`)
return parts.join(' ')
}
}
]
}