From ddd48660e05755f11c708cec6944b23e5a3842d1 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sat, 1 Aug 2026 14:09:16 +0100 Subject: [PATCH] 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. --- .../Dashboard/Production/FilamentProfiles.jsx | 68 ++++--------------- .../Dashboard/Production/PrinterProfiles.jsx | 23 +------ 2 files changed, 15 insertions(+), 76 deletions(-) diff --git a/src/components/Dashboard/Production/FilamentProfiles.jsx b/src/components/Dashboard/Production/FilamentProfiles.jsx index becacc1..dfd85e8 100644 --- a/src/components/Dashboard/Production/FilamentProfiles.jsx +++ b/src/components/Dashboard/Production/FilamentProfiles.jsx @@ -1,14 +1,11 @@ -import { useContext, useRef, useState } from 'react' +import { useRef, useState } from 'react' import { Button, Dropdown, Flex, Modal, Space } from 'antd' -import NewFilamentProfile, { - EditFilamentProfile -} from './FilamentProfiles/NewFilamentProfile' +import NewFilamentProfile from './FilamentProfiles/NewFilamentProfile' 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' @@ -16,11 +13,7 @@ import useFilterSidebarVisibility from '../hooks/useFilterSidebarVisibility' import useViewMode from '../hooks/useViewMode' const FilamentProfiles = () => { - const { deleteObject } = useContext(ApiServerContext) - const [profileModal, setProfileModal] = useState({ - open: false, - profileId: null - }) + const [newProfileOpen, setNewProfileOpen] = useState(false) const tableRef = useRef() const [viewMode, setViewMode] = useViewMode('FilamentProfiles') const [columnVisibility, setColumnVisibility] = @@ -46,34 +39,11 @@ const FilamentProfiles = () => { if (key === 'reloadList') { tableRef.current?.reload() } 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 ( <> @@ -108,34 +78,24 @@ const FilamentProfiles = () => { visibleColumns={columnVisibility} showFilterSidebar={showFilterSidebar} expandHeight={true} - onRowAction={handleRowAction} /> setProfileModal({ open: false, profileId: null })} + onCancel={() => setNewProfileOpen(false)} destroyOnHidden > - {profileModal.open && - (profileModal.profileId ? ( - { - setProfileModal({ open: false, profileId: null }) - tableRef.current?.reload() - }} - /> - ) : ( - { - setProfileModal({ open: false, profileId: null }) - tableRef.current?.reload() - }} - /> - ))} + {newProfileOpen && ( + { + setNewProfileOpen(false) + tableRef.current?.reload() + }} + /> + )} ) diff --git a/src/components/Dashboard/Production/PrinterProfiles.jsx b/src/components/Dashboard/Production/PrinterProfiles.jsx index 6076805..503beb1 100644 --- a/src/components/Dashboard/Production/PrinterProfiles.jsx +++ b/src/components/Dashboard/Production/PrinterProfiles.jsx @@ -1,4 +1,4 @@ -import { useContext, useRef, useState } from 'react' +import { useRef, useState } from 'react' import { Button, Dropdown, Flex, Modal, Space } from 'antd' import NewPrinterProfile from './PrinterProfiles/NewPrinterProfile' import ColumnViewButton from '../common/ColumnViewButton' @@ -6,14 +6,12 @@ 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 [newProfileOpen, setNewProfileOpen] = useState(false) const tableRef = useRef() 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 ( <> @@ -97,7 +77,6 @@ const PrinterProfiles = () => { visibleColumns={columnVisibility} showFilterSidebar={showFilterSidebar} expandHeight={true} - onRowAction={handleRowAction} />