farmcontrol-ui/src/database/models/FilamentStock.js
Tom Butcher 5ed086cf8b Enhance Sidebar and Object Models with List Action Integration
- Added a 'list' action to various object models, including AppPassword, AuditLog, Client, and more, to standardize access to list views across the application.
- Updated the ObjectModels.js to include a new label for the 'list' action, improving clarity in the permission matrix.
- Refactored Sidebar.js to incorporate user profile permissions for sidebar item visibility, enhancing user experience based on access rights.
- Introduced utility functions for normalizing paths and filtering sidebar items based on user permissions, streamlining sidebar management.
- Improved the overall structure and readability of the Sidebar and ObjectModels components.
2026-08-20 20:14:57 +01:00

201 lines
4.4 KiB
JavaScript

import { createElement, lazy } from 'react'
const FilamentStockInfo = lazy(
() =>
import('../../components/Dashboard/Inventory/FilamentStocks/FilamentStockInfo')
)
const NewFilamentStock = lazy(
() => import('../../components/Dashboard/Inventory/FilamentStocks/NewFilamentStock')
)
import FilamentStockIcon from '../../components/Icons/FilamentStockIcon'
import PlusIcon from '../../components/Icons/PlusIcon'
import InfoCircleIcon from '../../components/Icons/InfoCircleIcon'
import ListIcon from '../../components/Icons/ListIcon'
export const FilamentStock = {
name: 'filamentStock',
label: 'Filament Stock',
labelPlural: 'Filament Stocks',
url: '/dashboard/inventory/filamentstocks',
prefix: 'FLS',
readOnly: true,
icon: FilamentStockIcon,
actions: [
{
name: 'new',
type: 'modal',
pageName: 'list',
modalWidth: 800,
label: 'New Filament Stock',
icon: PlusIcon,
content: (objectData, { onOk } = {}) => {
return createElement(NewFilamentStock, { defaultValues: objectData, onOk, reset: true })
}
},
{
name: 'list',
type: 'page',
pageName: 'list',
label: 'List',
icon: ListIcon
},
{
name: 'info',
type: 'page',
pageName: 'info',
label: 'Info',
default: true,
row: true,
icon: InfoCircleIcon
}
],
pages: [
{
name: 'info',
content: () => createElement(FilamentStockInfo)
}
],
columns: [
'_reference',
'state',
'currentWeight',
'startingWeight',
'filament',
'filamentSku',
'stockLocation',
'createdAt',
'updatedAt'
],
filters: [
'filament',
'filamentSku',
'state',
'startingWeight',
'currentWeight',
'stockLocation',
'createdAt',
'updatedAt',
'_reference'
],
sorters: ['createdAt', 'updatedAt', 'filament', 'filamentSku', 'state'],
group: ['filament', 'filamentSku'],
properties: [
{
name: '_id',
label: 'ID',
type: 'id',
columnFixed: 'left',
objectType: 'filamentStock',
showCopy: true,
columnWidth: 140
},
{
name: 'createdAt',
label: 'Created At',
type: 'dateTime',
readOnly: true,
columnWidth: 175
},
{
name: '_reference',
label: 'Reference',
type: 'reference',
columnFixed: 'left',
objectType: 'filamentStock',
showCopy: true,
readOnly: true,
columnWidth: 180
},
{
name: 'updatedAt',
label: 'Updated At',
type: 'dateTime',
readOnly: true,
columnWidth: 175
},
{
name: 'state',
label: 'State',
type: 'state',
objectType: 'filamentStock',
readOnly: true,
columnWidth: 260
},
{
name: 'filament',
label: 'Filament',
type: 'object',
value: null,
objectType: 'filament',
required: true,
showHyperlink: true,
columnWidth: 200,
initial: true
},
{
name: 'filamentSku',
label: 'Filament SKU',
type: 'object',
objectType: 'filamentSku',
readOnly: true,
initial: true,
required: true,
showHyperlink: true,
columnWidth: 200,
masterFilter: (objectData) => {
return {
filament: objectData?.filament?._id
}
}
},
{
name: 'stockLocation',
label: 'Stock location',
type: 'object',
objectType: 'stockLocation',
required: true,
showHyperlink: true,
columnWidth: 200
},
{
name: 'currentWeight',
label: 'Current Weight',
type: 'netGross',
suffix: 'g',
readOnly: true,
required: true,
columnWidth: 300,
value: (objectData) => {
if (objectData?.state?.type === 'unconsumed') {
return objectData?.startingWeight
} else {
return objectData.currentWeight
}
}
},
{
name: 'startingWeight',
label: 'Starting Weight',
type: 'netGross',
suffix: 'g',
readOnly: true,
initial: true,
required: true,
columnWidth: 300,
difference: (objectData) => {
return objectData?.filamentSku?.filament?.emptySpoolWeight
}
}
],
stats: [
{
name: 'totalCurrentWeight.sum',
label: 'Total Current Weight',
type: 'number',
roundNumber: 2,
suffix: 'g',
cardWidth: 200
}
]
}