- Introduced FilamentProfiles and PrinterProfiles components for managing filament and printer profiles, respectively. - Implemented modal dialogs for creating and editing profiles, enhancing user interaction. - Added ObjectTable for displaying profiles with action handling for edit and delete operations. - Integrated context for API server interactions and improved state management for profile visibility and actions. - Created detailed info components for both filament and printer profiles, allowing for comprehensive data management and display.
144 lines
4.3 KiB
JavaScript
144 lines
4.3 KiB
JavaScript
import { useContext, useRef, useState } from 'react'
|
|
import { Button, Dropdown, Flex, Modal, Space } from 'antd'
|
|
import NewPrinterProfile, {
|
|
EditPrinterProfile
|
|
} from './PrinterProfiles/NewPrinterProfile'
|
|
import ColumnViewButton from '../common/ColumnViewButton'
|
|
import ExportListButton from '../common/ExportListButton'
|
|
import FilterSidebarButton from '../common/FilterSidebarButton'
|
|
import ObjectTable from '../common/ObjectTable'
|
|
import ObjectTableViewButton from '../common/ObjectTableViewButton'
|
|
import { ApiServerContext } from '../context/ApiServerContext'
|
|
import PlusIcon from '../../Icons/PlusIcon'
|
|
import ReloadIcon from '../../Icons/ReloadIcon'
|
|
import useColumnVisibility from '../hooks/useColumnVisibility'
|
|
import useFilterSidebarVisibility from '../hooks/useFilterSidebarVisibility'
|
|
import useViewMode from '../hooks/useViewMode'
|
|
const PrinterProfiles = () => {
|
|
const { deleteObject } = useContext(ApiServerContext)
|
|
const [profileModal, setProfileModal] = useState({
|
|
open: false,
|
|
profileId: null
|
|
})
|
|
const tableRef = useRef()
|
|
const [viewMode, setViewMode] = useViewMode('PrinterProfiles')
|
|
const [columnVisibility, setColumnVisibility] =
|
|
useColumnVisibility('printerProfile')
|
|
const [showFilterSidebar, setShowFilterSidebar] =
|
|
useFilterSidebarVisibility('PrinterProfiles')
|
|
|
|
const actionItems = {
|
|
items: [
|
|
{
|
|
label: 'New Printer Profile',
|
|
key: 'newPrinterProfile',
|
|
icon: <PlusIcon />
|
|
},
|
|
{ type: 'divider' },
|
|
{
|
|
label: 'Reload List',
|
|
key: 'reloadList',
|
|
icon: <ReloadIcon />
|
|
}
|
|
],
|
|
onClick: ({ key }) => {
|
|
if (key === 'reloadList') {
|
|
tableRef.current?.reload()
|
|
} else if (key === 'newPrinterProfile') {
|
|
setProfileModal({ open: true, profileId: null })
|
|
}
|
|
}
|
|
}
|
|
|
|
const handleRowAction = (action, profile) => {
|
|
if (action.name === 'edit') {
|
|
setProfileModal({ open: true, profileId: profile._id })
|
|
return true
|
|
}
|
|
|
|
if (action.name === 'delete') {
|
|
Modal.confirm({
|
|
title: 'Delete printer profile?',
|
|
content: `This will permanently delete ${profile.name || profile._reference}.`,
|
|
okText: 'Delete',
|
|
okType: 'danger',
|
|
onOk: async () => {
|
|
await deleteObject(profile._id, 'printerProfile')
|
|
await tableRef.current?.reload()
|
|
}
|
|
})
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<Flex vertical={'true'} gap='large' className='h-100'>
|
|
<Flex justify={'space-between'}>
|
|
<Space>
|
|
<Dropdown menu={actionItems}>
|
|
<Button>Actions</Button>
|
|
</Dropdown>
|
|
<ColumnViewButton
|
|
type='printerProfile'
|
|
visibleState={columnVisibility}
|
|
updateVisibleState={setColumnVisibility}
|
|
/>
|
|
<ExportListButton objectType='printerProfile' />
|
|
</Space>
|
|
<Space>
|
|
<FilterSidebarButton
|
|
active={showFilterSidebar}
|
|
onClick={() => setShowFilterSidebar(!showFilterSidebar)}
|
|
/>
|
|
<ObjectTableViewButton
|
|
viewMode={viewMode}
|
|
setViewMode={setViewMode}
|
|
/>
|
|
</Space>
|
|
</Flex>
|
|
|
|
<ObjectTable
|
|
ref={tableRef}
|
|
type='printerProfile'
|
|
cards={viewMode === 'cards'}
|
|
visibleColumns={columnVisibility}
|
|
showFilterSidebar={showFilterSidebar}
|
|
expandHeight={true}
|
|
onRowAction={handleRowAction}
|
|
/>
|
|
</Flex>
|
|
|
|
<Modal
|
|
open={profileModal.open}
|
|
footer={null}
|
|
width={800}
|
|
onCancel={() => setProfileModal({ open: false, profileId: null })}
|
|
destroyOnHidden
|
|
>
|
|
{profileModal.open &&
|
|
(profileModal.profileId ? (
|
|
<EditPrinterProfile
|
|
profileId={profileModal.profileId}
|
|
onOk={() => {
|
|
setProfileModal({ open: false, profileId: null })
|
|
tableRef.current?.reload()
|
|
}}
|
|
/>
|
|
) : (
|
|
<NewPrinterProfile
|
|
onOk={() => {
|
|
setProfileModal({ open: false, profileId: null })
|
|
tableRef.current?.reload()
|
|
}}
|
|
/>
|
|
))}
|
|
</Modal>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default PrinterProfiles
|