Implement editDisabled state across various components for improved editing control
Some checks failed
farmcontrol/farmcontrol-ui/pipeline/head There was a failure building this commit

- Added editDisabled state to multiple components, enhancing control over editing actions based on the current state.
- Updated the disabled property in relevant components to utilize the new editDisabled state, ensuring consistent behavior across the dashboard.
- Refactored imports to remove unused getModelByName function calls, streamlining the codebase.
This commit is contained in:
Tom Butcher 2026-08-09 23:33:34 +01:00
parent 7065cd312b
commit ed4f1c7505
49 changed files with 223 additions and 193 deletions

View File

@ -26,10 +26,7 @@ import InfoCollapsePlaceholder from '../../common/InfoCollapsePlaceholder.jsx'
import DocumentPrintButton from '../../common/DocumentPrintButton.jsx'
import UserNotifierToggle from '../../common/UserNotifierToggle.jsx'
import ScrollBox from '../../common/ScrollBox.jsx'
import {
getModelByName,
getModelProperty
} from '../../../../database/ObjectModels.js'
import { getModelProperty } from '../../../../database/ObjectModels.js'
import OrderItemIcon from '../../../Icons/OrderItemIcon.jsx'
import ShipmentIcon from '../../../Icons/ShipmentIcon.jsx'
@ -65,6 +62,7 @@ const InvoiceInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -87,11 +85,6 @@ const InvoiceInfo = () => {
},
}
const editDisabled =
getModelByName('invoice')
?.actions?.find((action) => action.name === 'edit')
?.disabled(objectFormState.objectData) ?? false
return (
<Flex
gap='large'
@ -156,7 +149,7 @@ const InvoiceInfo = () => {
disabled={
objectFormState.beingEditedByOther ||
objectFormState.loading ||
editDisabled
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -24,7 +24,6 @@ import InfoCollapsePlaceholder from '../../common/InfoCollapsePlaceholder.jsx'
import DocumentPrintButton from '../../common/DocumentPrintButton.jsx'
import UserNotifierToggle from '../../common/UserNotifierToggle.jsx'
import ScrollBox from '../../common/ScrollBox.jsx'
import { getModelByName } from '../../../../database/ObjectModels.js'
const log = loglevel.getLogger('PaymentInfo')
log.setLevel(config.logLevel)
@ -55,6 +54,7 @@ const PaymentInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -77,11 +77,6 @@ const PaymentInfo = () => {
},
}
const editDisabled =
getModelByName('payment')
?.actions?.find((action) => action.name === 'edit')
?.disabled(objectFormState.objectData) ?? false
return (
<Flex
gap='large'
@ -143,7 +138,7 @@ const PaymentInfo = () => {
disabled={
objectFormState.beingEditedByOther ||
objectFormState.loading ||
editDisabled
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -45,6 +45,7 @@ const TaxRecordInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -124,7 +125,9 @@ const TaxRecordInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -47,6 +47,7 @@ const FilamentStockInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -123,7 +124,11 @@ const FilamentStockInfo = () => {
}}
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={true}
disabled={
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>
<ObjectTableNavigationButtons

View File

@ -46,6 +46,7 @@ const OrderItemInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -123,7 +124,9 @@ const OrderItemInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -52,6 +52,7 @@ const PartStockInfo = () => {
formValid: false,
activities: [],
loading: false,
editDisabled: false,
objectData: {}
})
@ -132,7 +133,9 @@ const PartStockInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -10,10 +10,7 @@ import InfoCollapse from '../../common/InfoCollapse.jsx'
import ObjectInfo from '../../common/ObjectInfo.jsx'
import ObjectProperty from '../../common/ObjectProperty.jsx'
import ViewButton from '../../common/ViewButton.jsx'
import {
getModelProperty,
getModelByName
} from '../../../../database/ObjectModels.js'
import { getModelProperty } from '../../../../database/ObjectModels.js'
import InfoCircleIcon from '../../../Icons/InfoCircleIcon.jsx'
import NoteIcon from '../../../Icons/NoteIcon.jsx'
import AuditLogIcon from '../../../Icons/AuditLogIcon.jsx'
@ -71,6 +68,7 @@ const ProductStockInfo = () => {
formValid: false,
activities: [],
loading: false,
editDisabled: false,
objectData: {}
})
@ -93,11 +91,6 @@ const ProductStockInfo = () => {
},
}
const editDisabled =
getModelByName('productStock')
?.actions?.find((action) => action.name === 'edit')
?.disabled(objectFormState.objectData) ?? false
return (
<Flex
gap='large'
@ -162,7 +155,7 @@ const ProductStockInfo = () => {
disabled={
objectFormState.beingEditedByOther ||
objectFormState.loading ||
editDisabled
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -28,7 +28,6 @@ import OrderItemsIcon from '../../../Icons/OrderItemIcon.jsx'
import ShipmentIcon from '../../../Icons/ShipmentIcon.jsx'
import InvoiceIcon from '../../../Icons/InvoiceIcon.jsx'
import StockEventIcon from '../../../Icons/StockEventIcon.jsx'
import { getModelByName } from '../../../../database/ObjectModels.js'
const log = loglevel.getLogger('PurchaseOrderInfo')
log.setLevel(config.logLevel)
@ -70,6 +69,7 @@ const PurchaseOrderInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -95,10 +95,6 @@ const PurchaseOrderInfo = () => {
},
}
const editDisabled = getModelByName('purchaseOrder')
.actions.find((action) => action.name === 'edit')
.disabled(objectFormState.objectData)
return (
<Flex
gap='large'
@ -164,7 +160,7 @@ const PurchaseOrderInfo = () => {
disabled={
objectFormState.beingEditedByOther ||
objectFormState.loading ||
editDisabled
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -61,6 +61,7 @@ const PurchaseOrderInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -159,7 +160,9 @@ const PurchaseOrderInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -58,6 +58,7 @@ const ShipmentInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
const actions = {
@ -138,7 +139,9 @@ const ShipmentInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -48,6 +48,7 @@ const StockAuditInfo = () => {
formValid: false,
activities: [],
loading: false,
editDisabled: false,
objectData: {}
})
@ -126,7 +127,9 @@ const StockAuditInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -49,6 +49,7 @@ const StockLocationInfo = () => {
formValid: false,
activities: [],
loading: false,
editDisabled: false,
objectData: {}
})
@ -127,7 +128,9 @@ const StockLocationInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -8,10 +8,7 @@ import InfoCollapse from '../../common/InfoCollapse.jsx'
import ObjectInfo from '../../common/ObjectInfo.jsx'
import ObjectProperty from '../../common/ObjectProperty.jsx'
import ViewButton from '../../common/ViewButton.jsx'
import {
getModelProperty,
getModelByName
} from '../../../../database/ObjectModels.js'
import { getModelProperty } from '../../../../database/ObjectModels.js'
import InfoCircleIcon from '../../../Icons/InfoCircleIcon.jsx'
import NoteIcon from '../../../Icons/NoteIcon.jsx'
import AuditLogIcon from '../../../Icons/AuditLogIcon.jsx'
@ -61,6 +58,7 @@ const StockTransferInfo = () => {
formValid: false,
activities: [],
loading: false,
editDisabled: false,
objectData: {}
})
@ -83,11 +81,6 @@ const StockTransferInfo = () => {
},
}
const editDisabled =
getModelByName('stockTransfer')
?.actions?.find((action) => action.name === 'edit')
?.disabled(objectFormState.objectData) ?? false
return (
<Flex
gap='large'
@ -150,7 +143,7 @@ const StockTransferInfo = () => {
disabled={
objectFormState.beingEditedByOther ||
objectFormState.loading ||
editDisabled
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -1,4 +1,4 @@
import { useRef, useState, useEffect, useContext } from 'react'
import { useRef, useState, useEffect } from 'react'
import { useLocation } from 'react-router-dom'
import { Flex, Space } from 'antd'
import { LoadingOutlined } from '@ant-design/icons'
@ -20,8 +20,6 @@ import InfoCollapsePlaceholder from '../../common/InfoCollapsePlaceholder.jsx'
import DocumentPrintButton from '../../common/DocumentPrintButton.jsx'
import UserNotifierToggle from '../../common/UserNotifierToggle.jsx'
import ScrollBox from '../../common/ScrollBox.jsx'
import { getModelByName } from '../../../../database/ObjectModels.js'
import { AuthContext } from '../../context/AuthContext.jsx'
const AppPasswordInfo = () => {
const location = useLocation()
@ -36,7 +34,6 @@ const AppPasswordInfo = () => {
})
return () => setOnModalOk(null)
}, [setOnModalOk])
const { userProfile } = useContext(AuthContext)
const appPasswordId = new URLSearchParams(location.search).get(
'appPasswordId'
)
@ -53,6 +50,7 @@ const AppPasswordInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -71,10 +69,6 @@ const AppPasswordInfo = () => {
}
}
const editDisabled = getModelByName('appPassword')
.actions.find((action) => action.name === 'edit')
.disabled({ ...objectFormState.objectData, _user: userProfile })
return (
<Flex
gap='large'
@ -132,7 +126,7 @@ const AppPasswordInfo = () => {
disabled={
objectFormState.beingEditedByOther ||
objectFormState.loading ||
editDisabled
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -47,6 +47,7 @@ const CourierServiceInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -126,7 +127,9 @@ const CourierServiceInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -43,6 +43,7 @@ const CourierInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -122,7 +123,9 @@ const CourierInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -48,6 +48,7 @@ const DocumentJobInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -123,7 +124,9 @@ const DocumentJobInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -50,6 +50,7 @@ const DocumentPrinterInfo = () => {
formValid: false,
activities: [],
loading: false,
editDisabled: false,
objectData: {}
})
@ -131,7 +132,9 @@ const DocumentPrinterInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -48,6 +48,7 @@ const DocumentSizeInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -123,7 +124,9 @@ const DocumentSizeInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -50,6 +50,7 @@ const DocumentTemplateInfo = () => {
formValid: false,
activities: [],
loading: false,
editDisabled: false,
objectData: {}
})
@ -128,7 +129,9 @@ const DocumentTemplateInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -42,6 +42,7 @@ const FilamentSkuInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -121,7 +122,9 @@ const FilamentSkuInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -61,6 +61,7 @@ const FilamentInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -144,7 +145,9 @@ const FilamentInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -49,6 +49,7 @@ const FileInfo = () => {
formValid: false,
lock: null,
loading: true,
editDisabled: false
objectData: {
_id: fileId
}
@ -137,7 +138,9 @@ const FileInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -57,6 +57,7 @@ const HostInfo = () => {
formValid: false,
activities: [],
loading: false,
editDisabled: false,
objectData: {}
})
@ -140,7 +141,9 @@ const HostInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -45,6 +45,7 @@ const MaterialInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -124,7 +125,9 @@ const MaterialInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -38,6 +38,7 @@ const NoteTypeInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -112,7 +113,9 @@ const NoteTypeInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -47,6 +47,7 @@ const NoteInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -127,7 +128,9 @@ const NoteInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -37,6 +37,7 @@ const PartSkuInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -116,7 +117,9 @@ const PartSkuInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -50,6 +50,7 @@ const PartInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -125,7 +126,9 @@ const PartInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -42,6 +42,7 @@ const ProductCategoryInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -121,7 +122,9 @@ const ProductCategoryInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -44,6 +44,7 @@ const ProductSkuInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -124,7 +125,9 @@ const ProductSkuInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -50,6 +50,7 @@ const ProductInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -125,7 +126,9 @@ const ProductInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -42,6 +42,7 @@ const TaxRateInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -121,7 +122,9 @@ const TaxRateInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -44,6 +44,7 @@ const UserInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
const isMobile = useMediaQuery({ maxWidth: 768 })
@ -120,7 +121,9 @@ const UserInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -42,6 +42,7 @@ const VendorInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -121,7 +122,9 @@ const VendorInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -80,6 +80,7 @@ const FilamentProfileInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -166,7 +167,11 @@ const FilamentProfileInfo = () => {
startEditing={() => actionHandlerRef.current.callAction('edit')}
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={objectFormState.beingEditedByOther || objectFormState.loading}
disabled={
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>
<ObjectTableNavigationButtons

View File

@ -51,6 +51,7 @@ const GCodeFileInfo = () => {
formValid: false,
activities: [],
loading: false,
editDisabled: false,
objectData: {}
})
@ -130,7 +131,9 @@ const GCodeFileInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -25,7 +25,6 @@ import JobIcon from '../../../Icons/JobIcon.jsx'
import DocumentPrintButton from '../../common/DocumentPrintButton.jsx'
import UserNotifierToggle from '../../common/UserNotifierToggle.jsx'
import ScrollBox from '../../common/ScrollBox.jsx'
import { getModelByName } from '../../../../database/ObjectModels.js'
const log = loglevel.getLogger('JobInfo')
log.setLevel(config.logLevel)
@ -57,16 +56,12 @@ const JobInfo = () => {
formValid: false,
activities: [],
loading: false,
editDisabled: false,
objectData: {
_id: jobId
}
})
const editDisabled =
getModelByName('job')
?.actions?.find((action) => action.name === 'edit')
?.disabled(objectFormState.objectData) ?? false
const actions = {
edit: () => {
objectFormRef?.current.startEditing()
@ -144,7 +139,7 @@ const JobInfo = () => {
disabled={
objectFormState.beingEditedByOther ||
objectFormState.loading ||
editDisabled
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -59,6 +59,7 @@ const PrinterProfileInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -139,7 +140,11 @@ const PrinterProfileInfo = () => {
startEditing={() => actionHandlerRef.current.callAction('edit')}
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={objectFormState.beingEditedByOther || objectFormState.loading}
disabled={
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>
<ObjectTableNavigationButtons

View File

@ -51,6 +51,7 @@ const PrinterInfo = () => {
formValid: false,
activities: [],
loading: false,
editDisabled: false,
objectData: {}
})
@ -137,7 +138,9 @@ const PrinterInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -42,6 +42,7 @@ const ClientInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -121,7 +122,9 @@ const ClientInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -57,6 +57,7 @@ const ListingVarientInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -135,7 +136,9 @@ const ListingVarientInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -55,6 +55,7 @@ const ListingInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -134,7 +135,9 @@ const ListingInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -66,6 +66,7 @@ const MarketplaceInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -202,7 +203,9 @@ const MarketplaceInfo = () => {
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther || objectFormState.loading
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -28,7 +28,6 @@ import OrderItemsIcon from '../../../Icons/OrderItemIcon.jsx'
import ShipmentIcon from '../../../Icons/ShipmentIcon.jsx'
import InvoiceIcon from '../../../Icons/InvoiceIcon.jsx'
import StockEventIcon from '../../../Icons/StockEventIcon.jsx'
import { getModelByName } from '../../../../database/ObjectModels.js'
const log = loglevel.getLogger('SalesOrderInfo')
log.setLevel(config.logLevel)
@ -68,6 +67,7 @@ const SalesOrderInfo = () => {
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
@ -93,10 +93,6 @@ const SalesOrderInfo = () => {
},
}
const editDisabled = getModelByName('salesOrder')
.actions.find((action) => action.name === 'edit')
.disabled(objectFormState.objectData)
return (
<Flex
gap='large'
@ -162,7 +158,7 @@ const SalesOrderInfo = () => {
disabled={
objectFormState.beingEditedByOther ||
objectFormState.loading ||
editDisabled
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>

View File

@ -6,7 +6,10 @@ import { useNavigate, useLocation } from 'react-router-dom'
import { useActionsModal } from '../context/ActionsModalContext'
import KeyboardShortcut from './KeyboardShortcut'
import { AuthContext } from '../context/AuthContext'
import { buildActionUrl, stripPageActionParams } from '../../../utils/modelActions'
import {
buildActionUrl,
stripPageActionParams
} from '../../../utils/modelActions'
// Recursively filter actions based on visibleActions
function filterActionsByVisibility(actions, visibleActions) {
@ -238,7 +241,7 @@ const ObjectActions = ({
<Dropdown menu={menu} {...dropdownProps}>
<Button
{...buttonProps}
disabled={disabled}
disabled={disabled || filteredActions.length === 0}
onClick={() => showActionsModal(id, type, objectData)}
>
Actions

View File

@ -76,6 +76,23 @@ const buildObjectFromEntries = (entries = []) => {
}, {})
}
const getEditDisabled = (model, objectData, userProfile) => {
if (model?.readOnly === true) {
return true
}
const editAction = model?.actions?.find((action) => action.name === 'edit')
if (!editAction?.disabled) {
return false
}
if (typeof editAction.disabled === 'function') {
return (
editAction.disabled({ ...objectData, _user: userProfile }) ?? false
)
}
return !!editAction.disabled
}
/**
* ObjectForm is a reusable form component for editing any object type.
* It handles fetching, updating, locking, unlocking, and validation logic.
@ -85,9 +102,10 @@ const buildObjectFromEntries = (entries = []) => {
* - type: string (required)
* - formItems: array (for ObjectInfo/ObjectProperty items)
* - children: function({
* loading, isEditing, startEditing, cancelEditing, handleUpdate, form, formValid, objectData, setIsEditing, setObjectData
* loading, isEditing, startEditing, cancelEditing, handleUpdate, form, formValid, objectData, setIsEditing, setObjectData, editDisabled
* }) => ReactNode
* - setCurrentObject: boolean (sync object data to ActionsContext)
* - onStateChange: receives form state including editDisabled (from model edit action)
*/
const ObjectForm = forwardRef(
(
@ -388,20 +406,22 @@ const ObjectForm = forwardRef(
setFormValid(true)
onStateChangeRef.current({
formValid: true,
objectData: mergedObjectData
objectData: mergedObjectData,
editDisabled: getEditDisabled(model, mergedObjectData, userProfile)
})
})
.catch(() => {
setFormValid(false)
onStateChangeRef.current({
formValid: false,
objectData: mergedObjectData
objectData: mergedObjectData,
editDisabled: getEditDisabled(model, mergedObjectData, userProfile)
})
})
}, 150)
return () => clearTimeout(timeoutId)
}, [form, formUpdateValues])
}, [form, formUpdateValues, model, userProfile])
// Cleanup on unmount
useEffect(() => {
@ -592,10 +612,13 @@ const ObjectForm = forwardRef(
// Debounce objectData updates sent to parent to limit re-renders
useEffect(() => {
const timeoutId = setTimeout(() => {
onStateChangeRef.current({ objectData })
onStateChangeRef.current({
objectData,
editDisabled: getEditDisabled(model, objectData, userProfile)
})
}, 150)
return () => clearTimeout(timeoutId)
}, [objectData])
}, [objectData, model, userProfile])
useEffect(() => {
if (!setCurrentObject) {
@ -651,13 +674,15 @@ const ObjectForm = forwardRef(
...computedValuesObject,
_isEditing: true
}))
const nextObjectData = {
...objectData,
...computedValuesObject,
_isEditing: true
}
onStateChangeRef.current({
isEditing: true,
objectData: {
...objectData,
...computedValuesObject,
_isEditing: true
}
objectData: nextObjectData,
editDisabled: getEditDisabled(model, nextObjectData, userProfile)
})
} catch (err) {
console.error(err)
@ -831,6 +856,7 @@ const ObjectForm = forwardRef(
setIsEditing,
setObjectData,
editLoading,
editDisabled: getEditDisabled(model, objectData, userProfile),
activities,
handleFetchObject,
handleDelete

View File

@ -1,13 +1,11 @@
import { createElement, lazy } from 'react'
const FilamentStockInfo = lazy(
() => import('../../components/Dashboard/Inventory/FilamentStocks/FilamentStockInfo')
() =>
import('../../components/Dashboard/Inventory/FilamentStocks/FilamentStockInfo')
)
import FilamentStockIcon from '../../components/Icons/FilamentStockIcon'
import InfoCircleIcon from '../../components/Icons/InfoCircleIcon'
import EditIcon from '../../components/Icons/EditIcon'
import CheckIcon from '../../components/Icons/CheckIcon'
import XMarkIcon from '../../components/Icons/XMarkIcon'
export const FilamentStock = {
name: 'filamentStock',
@ -15,6 +13,7 @@ export const FilamentStock = {
labelPlural: 'Filament Stocks',
url: '/dashboard/inventory/filamentstocks',
prefix: 'FLS',
readOnly: true,
icon: FilamentStockIcon,
actions: [
{
@ -25,38 +24,7 @@ export const FilamentStock = {
default: true,
row: true,
icon: InfoCircleIcon
},
{
name: 'edit',
type: 'page',
pageName: 'info',
label: 'Edit',
row: true,
icon: EditIcon,
visible: (objectData) => {
return !(objectData?._isEditing && objectData?._isEditing == true)
}
},
{
name: 'cancelEdit',
label: 'Cancel Edits',
type: 'page',
pageName: 'info',
icon: XMarkIcon,
visible: (objectData) => {
return objectData?._isEditing && objectData?._isEditing == true
}
},
{
name: 'finishEdit',
label: 'Save Edits',
type: 'page',
pageName: 'info',
icon: CheckIcon,
visible: (objectData) => {
return objectData?._isEditing && objectData?._isEditing == true
}
},
}
],
pages: [
{
@ -89,13 +57,7 @@ export const FilamentStock = {
'updatedAt',
'_reference'
],
sorters: [
'createdAt',
'updatedAt',
'filament',
'filamentSku',
'state'
],
sorters: ['createdAt', 'updatedAt', 'filament', 'filamentSku', 'state'],
group: ['filament', 'filamentSku'],
properties: [
{

View File

@ -5,9 +5,6 @@ const PartStockInfo = lazy(
)
import PartStockIcon from '../../components/Icons/PartStockIcon'
import InfoCircleIcon from '../../components/Icons/InfoCircleIcon'
import EditIcon from '../../components/Icons/EditIcon'
import CheckIcon from '../../components/Icons/CheckIcon'
import XMarkIcon from '../../components/Icons/XMarkIcon'
export const PartStock = {
name: 'partStock',
@ -15,6 +12,7 @@ export const PartStock = {
labelPlural: 'Part Stocks',
url: '/dashboard/inventory/partstocks',
prefix: 'PTS',
readOnly: true,
icon: PartStockIcon,
actions: [
{
@ -25,38 +23,7 @@ export const PartStock = {
default: true,
row: true,
icon: InfoCircleIcon
},
{
name: 'edit',
type: 'page',
pageName: 'info',
label: 'Edit',
row: true,
icon: EditIcon,
visible: (objectData) => {
return !(objectData?._isEditing && objectData?._isEditing == true)
}
},
{
name: 'cancelEdit',
label: 'Cancel Edits',
type: 'page',
pageName: 'info',
icon: XMarkIcon,
visible: (objectData) => {
return objectData?._isEditing && objectData?._isEditing == true
}
},
{
name: 'finishEdit',
label: 'Save Edits',
type: 'page',
pageName: 'info',
icon: CheckIcon,
visible: (objectData) => {
return objectData?._isEditing && objectData?._isEditing == true
}
},
}
],
pages: [
{