Compare commits

..

No commits in common. "8d0f92af453ba7fac47122ebf2451e8c29ab38be" and "e730e2c83224b8762f650b017add999579316152" have entirely different histories.

6 changed files with 38 additions and 90 deletions

View File

@ -278,8 +278,8 @@ const ControlPrinter = ({ slicerIntegration = false }) => {
</Flex>
<AlertsDisplay
object={objectFormState.objectData}
objectType='printer'
alerts={objectFormState.objectData?.alerts}
printerId={printerId}
/>
<ScrollBox>

View File

@ -1,36 +1,27 @@
import PropTypes from 'prop-types'
import { createElement, useContext } from 'react'
import { createElement } from 'react'
import { Flex, Alert, Button, Dropdown } from 'antd'
import ExclamationOctagonIcon from '../../Icons/ExclamationOctagonIcon'
import InfoCircleIcon from '../../Icons/InfoCircleIcon'
import XMarkIcon from '../../Icons/XMarkIcon'
import { CaretDownOutlined } from '@ant-design/icons'
import { getModelByName } from '../../../database/ObjectModels'
import { useNavigate } from 'react-router-dom'
import ActionsIcon from '../../Icons/ActionsIcon'
import { ApiServerContext } from '../context/ApiServerContext'
const AlertsDisplay = ({
object,
objectType,
alerts = [],
printerId,
showDismiss = true,
showActions = true
}) => {
const alerts = object?.alerts ?? []
const objectId = object?._id
const getAlertType = (type, priority) => {
if (type === 'error' || priority === '9') return 'error'
if (type === 'warning' || priority === '8') return 'warning'
return 'info'
}
const model = objectType ? getModelByName(objectType) : null
const printerModel = getModelByName('printer')
const navigate = useNavigate()
const { updateObject } = useContext(ApiServerContext)
const handleDismissAlert = (alertId) => {
const updatedAlerts = alerts.filter((a) => a._id !== alertId)
updateObject(objectId, objectType, { alerts: updatedAlerts })
}
const getAlertIcon = (type, priority) => {
if (type === 'error' || priority === '9') return <ExclamationOctagonIcon />
if (type === 'warning' || priority === '8')
@ -112,7 +103,7 @@ const AlertsDisplay = ({
}
const alertElements = alerts.map((alert, index) => {
const objectActions = model?.actions || []
const printerActions = printerModel?.actions || []
const alertActionKeys = Array.isArray(alert?.actions)
? alert.actions
@ -125,7 +116,7 @@ const AlertsDisplay = ({
: []
const allowedKeys = new Set(alertActionKeys)
const filteredActions = filterActionsByKeys(objectActions, allowedKeys)
const filteredActions = filterActionsByKeys(printerActions, allowedKeys)
const findActionByKey = (actions, key) => {
if (!Array.isArray(actions)) return null
@ -153,7 +144,7 @@ const AlertsDisplay = ({
const action = findActionByKey(filteredActions, key)
if (action?.url) {
navigate(action.url(objectId))
navigate(action.url(printerId))
} else {
console.warn('No action found for key:', key)
}
@ -164,46 +155,20 @@ const AlertsDisplay = ({
<Alert
key={`${alert.createdAt}-${index}-${alert._id}`}
message={alert.message}
style={{ padding: '4px 5px 4px 10px', minHeight: '35px' }}
style={{ padding: '4px 10px 4px 8px' }}
type={getAlertType(alert.type, alert.priority)}
icon={getAlertIcon(alert.type, alert.priority)}
showIcon
closable={false}
closable={showDismiss && alert.canDismiss}
onClose={() => {}}
action={
<Flex gap='1px'>
{showActions && filteredActions.length >= 0 && (
<Dropdown menu={menu} on>
<Button
size='small'
type='text'
style={{ marginLeft: '5px' }}
icon={
<ActionsIcon
style={{ fontSize: '12px', marginBottom: '3.5px' }}
/>
}
/>
</Dropdown>
)}
{showDismiss && alert.canDismiss && (
<Button
size='small'
type='text'
style={{ marginLeft: '5px' }}
onClick={() => handleDismissAlert(alert._id)}
icon={
<XMarkIcon
style={{
fontSize: '10px',
marginBottom: '5px',
marginLeft: '0.5px'
}}
/>
}
/>
)}
</Flex>
showActions ? (
<Dropdown menu={menu} on>
<Button size='small' type='text' style={{ marginLeft: '5px' }}>
<CaretDownOutlined />
</Button>
</Dropdown>
) : null
}
/>
)
@ -217,24 +182,20 @@ const AlertsDisplay = ({
}
AlertsDisplay.propTypes = {
object: PropTypes.shape({
_id: PropTypes.string.isRequired,
alerts: PropTypes.arrayOf(
PropTypes.shape({
canDismiss: PropTypes.bool.isRequired,
_id: PropTypes.string.isRequired,
code: PropTypes.string,
type: PropTypes.string.isRequired,
createdAt: PropTypes.string.isRequired,
updatedAt: PropTypes.string.isRequired,
message: PropTypes.string,
actions: PropTypes.arrayOf(PropTypes.string)
})
)
}).isRequired,
objectType: PropTypes.string.isRequired,
showActions: PropTypes.bool,
showDismiss: PropTypes.bool
printerId: PropTypes.string.isRequired,
showActions: PropTypes.bool.isRequired,
showDismiss: PropTypes.bool.isRequired,
alerts: PropTypes.arrayOf(
PropTypes.shape({
canDismiss: PropTypes.bool.isRequired,
_id: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
createdAt: PropTypes.string.isRequired,
updatedAt: PropTypes.string.isRequired,
message: PropTypes.string,
actions: PropTypes.arrayOf(PropTypes.string)
})
).isRequired
}
export default AlertsDisplay

View File

@ -538,7 +538,7 @@ const ObjectChildTable = ({
dataSource={rollupDataSource}
showHeader={false}
columns={rollupColumns}
loading={{ spinning: loading, indicator: <></> }}
loading={{ spinning: loading, indicator: null }}
pagination={false}
size={size}
rowKey={resolvedRowKey}

View File

@ -553,8 +553,8 @@ const ObjectProperty = ({
if (value != null && value?.length != 0) {
return (
<AlertsDisplay
object={objectData}
objectType={objectType}
alerts={value}
printerId={objectData._id}
showDismiss={false}
showActions={false}
/>

View File

@ -720,7 +720,7 @@ const ObjectSelect = ({
// --- Main TreeSelect UI ---
return (
<div style={{ ...style, position: 'relative' }}>
<div style={style}>
<TreeSelect
key={treeVersion}
treeDataSimpleMode={false}

View File

@ -288,19 +288,6 @@ export const GCodeFile = {
required: true,
showHyperlink: true
},
{
name: 'partSku',
label: 'Part SKU',
type: 'object',
objectType: 'partSku',
required: true,
showHyperlink: true,
masterFilter: (objectData) => {
const partId = objectData?.part?._id
if (partId == null) return {}
return { part: partId }
}
},
{
name: 'quantity',
label: 'Quantity',