Refactor Filament and Printer Profiles components to streamline state management and remove unused context
- Removed unnecessary useContext for ApiServerContext in both FilamentProfiles and PrinterProfiles components. - Simplified modal state handling by consolidating profile modal logic into a single state variable for new profiles. - Cleaned up the handleRowAction function in both components, focusing on new profile creation and removing delete functionality for improved clarity.
This commit is contained in:
parent
e4657cc692
commit
ddd48660e0
@ -1,14 +1,11 @@
|
|||||||
import { useContext, useRef, useState } from 'react'
|
import { useRef, useState } from 'react'
|
||||||
import { Button, Dropdown, Flex, Modal, Space } from 'antd'
|
import { Button, Dropdown, Flex, Modal, Space } from 'antd'
|
||||||
import NewFilamentProfile, {
|
import NewFilamentProfile from './FilamentProfiles/NewFilamentProfile'
|
||||||
EditFilamentProfile
|
|
||||||
} from './FilamentProfiles/NewFilamentProfile'
|
|
||||||
import ColumnViewButton from '../common/ColumnViewButton'
|
import ColumnViewButton from '../common/ColumnViewButton'
|
||||||
import ExportListButton from '../common/ExportListButton'
|
import ExportListButton from '../common/ExportListButton'
|
||||||
import FilterSidebarButton from '../common/FilterSidebarButton'
|
import FilterSidebarButton from '../common/FilterSidebarButton'
|
||||||
import ObjectTable from '../common/ObjectTable'
|
import ObjectTable from '../common/ObjectTable'
|
||||||
import ObjectTableViewButton from '../common/ObjectTableViewButton'
|
import ObjectTableViewButton from '../common/ObjectTableViewButton'
|
||||||
import { ApiServerContext } from '../context/ApiServerContext'
|
|
||||||
import PlusIcon from '../../Icons/PlusIcon'
|
import PlusIcon from '../../Icons/PlusIcon'
|
||||||
import ReloadIcon from '../../Icons/ReloadIcon'
|
import ReloadIcon from '../../Icons/ReloadIcon'
|
||||||
import useColumnVisibility from '../hooks/useColumnVisibility'
|
import useColumnVisibility from '../hooks/useColumnVisibility'
|
||||||
@ -16,11 +13,7 @@ import useFilterSidebarVisibility from '../hooks/useFilterSidebarVisibility'
|
|||||||
import useViewMode from '../hooks/useViewMode'
|
import useViewMode from '../hooks/useViewMode'
|
||||||
|
|
||||||
const FilamentProfiles = () => {
|
const FilamentProfiles = () => {
|
||||||
const { deleteObject } = useContext(ApiServerContext)
|
const [newProfileOpen, setNewProfileOpen] = useState(false)
|
||||||
const [profileModal, setProfileModal] = useState({
|
|
||||||
open: false,
|
|
||||||
profileId: null
|
|
||||||
})
|
|
||||||
const tableRef = useRef()
|
const tableRef = useRef()
|
||||||
const [viewMode, setViewMode] = useViewMode('FilamentProfiles')
|
const [viewMode, setViewMode] = useViewMode('FilamentProfiles')
|
||||||
const [columnVisibility, setColumnVisibility] =
|
const [columnVisibility, setColumnVisibility] =
|
||||||
@ -46,34 +39,11 @@ const FilamentProfiles = () => {
|
|||||||
if (key === 'reloadList') {
|
if (key === 'reloadList') {
|
||||||
tableRef.current?.reload()
|
tableRef.current?.reload()
|
||||||
} else if (key === 'newFilamentProfile') {
|
} else if (key === 'newFilamentProfile') {
|
||||||
setProfileModal({ open: true, profileId: null })
|
setNewProfileOpen(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleRowAction = (action, profile) => {
|
|
||||||
if (action.name === 'edit') {
|
|
||||||
setProfileModal({ open: true, profileId: profile._id })
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action.name === 'delete') {
|
|
||||||
Modal.confirm({
|
|
||||||
title: 'Delete filament profile?',
|
|
||||||
content: `This will permanently delete ${profile.name || profile._reference}.`,
|
|
||||||
okText: 'Delete',
|
|
||||||
okType: 'danger',
|
|
||||||
onOk: async () => {
|
|
||||||
await deleteObject(profile._id, 'filamentProfile')
|
|
||||||
await tableRef.current?.reload()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Flex vertical={'true'} gap='large' className='h-100'>
|
<Flex vertical={'true'} gap='large' className='h-100'>
|
||||||
@ -108,34 +78,24 @@ const FilamentProfiles = () => {
|
|||||||
visibleColumns={columnVisibility}
|
visibleColumns={columnVisibility}
|
||||||
showFilterSidebar={showFilterSidebar}
|
showFilterSidebar={showFilterSidebar}
|
||||||
expandHeight={true}
|
expandHeight={true}
|
||||||
onRowAction={handleRowAction}
|
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
open={profileModal.open}
|
open={newProfileOpen}
|
||||||
footer={null}
|
footer={null}
|
||||||
width={800}
|
width={800}
|
||||||
onCancel={() => setProfileModal({ open: false, profileId: null })}
|
onCancel={() => setNewProfileOpen(false)}
|
||||||
destroyOnHidden
|
destroyOnHidden
|
||||||
>
|
>
|
||||||
{profileModal.open &&
|
{newProfileOpen && (
|
||||||
(profileModal.profileId ? (
|
<NewFilamentProfile
|
||||||
<EditFilamentProfile
|
onOk={() => {
|
||||||
profileId={profileModal.profileId}
|
setNewProfileOpen(false)
|
||||||
onOk={() => {
|
tableRef.current?.reload()
|
||||||
setProfileModal({ open: false, profileId: null })
|
}}
|
||||||
tableRef.current?.reload()
|
/>
|
||||||
}}
|
)}
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<NewFilamentProfile
|
|
||||||
onOk={() => {
|
|
||||||
setProfileModal({ open: false, profileId: null })
|
|
||||||
tableRef.current?.reload()
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</Modal>
|
</Modal>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { useContext, useRef, useState } from 'react'
|
import { useRef, useState } from 'react'
|
||||||
import { Button, Dropdown, Flex, Modal, Space } from 'antd'
|
import { Button, Dropdown, Flex, Modal, Space } from 'antd'
|
||||||
import NewPrinterProfile from './PrinterProfiles/NewPrinterProfile'
|
import NewPrinterProfile from './PrinterProfiles/NewPrinterProfile'
|
||||||
import ColumnViewButton from '../common/ColumnViewButton'
|
import ColumnViewButton from '../common/ColumnViewButton'
|
||||||
@ -6,14 +6,12 @@ import ExportListButton from '../common/ExportListButton'
|
|||||||
import FilterSidebarButton from '../common/FilterSidebarButton'
|
import FilterSidebarButton from '../common/FilterSidebarButton'
|
||||||
import ObjectTable from '../common/ObjectTable'
|
import ObjectTable from '../common/ObjectTable'
|
||||||
import ObjectTableViewButton from '../common/ObjectTableViewButton'
|
import ObjectTableViewButton from '../common/ObjectTableViewButton'
|
||||||
import { ApiServerContext } from '../context/ApiServerContext'
|
|
||||||
import PlusIcon from '../../Icons/PlusIcon'
|
import PlusIcon from '../../Icons/PlusIcon'
|
||||||
import ReloadIcon from '../../Icons/ReloadIcon'
|
import ReloadIcon from '../../Icons/ReloadIcon'
|
||||||
import useColumnVisibility from '../hooks/useColumnVisibility'
|
import useColumnVisibility from '../hooks/useColumnVisibility'
|
||||||
import useFilterSidebarVisibility from '../hooks/useFilterSidebarVisibility'
|
import useFilterSidebarVisibility from '../hooks/useFilterSidebarVisibility'
|
||||||
import useViewMode from '../hooks/useViewMode'
|
import useViewMode from '../hooks/useViewMode'
|
||||||
const PrinterProfiles = () => {
|
const PrinterProfiles = () => {
|
||||||
const { deleteObject } = useContext(ApiServerContext)
|
|
||||||
const [newProfileOpen, setNewProfileOpen] = useState(false)
|
const [newProfileOpen, setNewProfileOpen] = useState(false)
|
||||||
const tableRef = useRef()
|
const tableRef = useRef()
|
||||||
const [viewMode, setViewMode] = useViewMode('PrinterProfiles')
|
const [viewMode, setViewMode] = useViewMode('PrinterProfiles')
|
||||||
@ -45,24 +43,6 @@ const PrinterProfiles = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleRowAction = (action, profile) => {
|
|
||||||
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Flex vertical={'true'} gap='large' className='h-100'>
|
<Flex vertical={'true'} gap='large' className='h-100'>
|
||||||
@ -97,7 +77,6 @@ const PrinterProfiles = () => {
|
|||||||
visibleColumns={columnVisibility}
|
visibleColumns={columnVisibility}
|
||||||
showFilterSidebar={showFilterSidebar}
|
showFilterSidebar={showFilterSidebar}
|
||||||
expandHeight={true}
|
expandHeight={true}
|
||||||
onRowAction={handleRowAction}
|
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user