From 2a18f3d697a7b5ca32ee0e5d6982e214b727351a Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Mon, 14 Jul 2025 22:59:47 +0100 Subject: [PATCH] Refactoring --- .../FilamentStocks/FilamentStockInfo.jsx | 13 ++++--- .../Management/Filaments/FilamentInfo.jsx | 10 ++--- .../Dashboard/Management/NoteTypes.jsx | 6 +-- .../Management/NoteTypes/NoteTypeInfo.jsx | 4 +- .../Dashboard/Management/Parts/PartInfo.jsx | 8 ++-- .../Dashboard/Management/Products.jsx | 7 +--- .../Management/Products/ProductInfo.jsx | 10 ++--- src/components/Dashboard/Management/Users.jsx | 6 +-- .../Dashboard/Management/Users/UserInfo.jsx | 8 ++-- .../Dashboard/Management/Vendors.jsx | 6 +-- .../Production/GCodeFiles/GCodeFileInfo.jsx | 10 ++--- src/components/Dashboard/Production/Jobs.jsx | 6 +-- .../Dashboard/Production/Jobs/JobInfo.jsx | 39 +++---------------- .../Production/Printers/PrinterInfo.jsx | 12 +++--- .../Dashboard/Production/SubJobs.jsx | 6 +-- 15 files changed, 55 insertions(+), 96 deletions(-) diff --git a/src/components/Dashboard/Inventory/FilamentStocks/FilamentStockInfo.jsx b/src/components/Dashboard/Inventory/FilamentStocks/FilamentStockInfo.jsx index 407d110..8dc0c38 100644 --- a/src/components/Dashboard/Inventory/FilamentStocks/FilamentStockInfo.jsx +++ b/src/components/Dashboard/Inventory/FilamentStocks/FilamentStockInfo.jsx @@ -113,7 +113,7 @@ const FilamentStockInfo = () => { onToggle={(expanded) => updateCollapseState('info', expanded) } - key='info' + collapseKey='info' > { onToggle={(expanded) => updateCollapseState('events', expanded) } - key='events' + collapseKey='events' > {loading ? ( @@ -150,10 +150,13 @@ const FilamentStockInfo = () => { onToggle={(expanded) => updateCollapseState('notes', expanded) } - key='notes' + collapseKey='notes' > - + @@ -164,7 +167,7 @@ const FilamentStockInfo = () => { onToggle={(expanded) => updateCollapseState('auditLogs', expanded) } - key='auditLogs' + collapseKey='auditLogs' > {loading ? ( diff --git a/src/components/Dashboard/Management/Filaments/FilamentInfo.jsx b/src/components/Dashboard/Management/Filaments/FilamentInfo.jsx index 304665f..cf2fc4c 100644 --- a/src/components/Dashboard/Management/Filaments/FilamentInfo.jsx +++ b/src/components/Dashboard/Management/Filaments/FilamentInfo.jsx @@ -133,7 +133,7 @@ const FilamentInfo = () => { onToggle={(expanded) => updateCollapseState('info', expanded) } - key='info' + collapseKey='info' > { onToggle={(expanded) => updateCollapseState('stocks', expanded) } - key='stocks' + collapseKey='stocks' > {loading ? ( @@ -175,10 +175,10 @@ const FilamentInfo = () => { onToggle={(expanded) => updateCollapseState('notes', expanded) } - key='notes' + collapseKey='notes' > - + @@ -189,7 +189,7 @@ const FilamentInfo = () => { onToggle={(expanded) => updateCollapseState('auditLogs', expanded) } - key='auditLogs' + collapseKey='auditLogs' > {loading ? ( diff --git a/src/components/Dashboard/Management/NoteTypes.jsx b/src/components/Dashboard/Management/NoteTypes.jsx index d0d17ba..7311086 100644 --- a/src/components/Dashboard/Management/NoteTypes.jsx +++ b/src/components/Dashboard/Management/NoteTypes.jsx @@ -1,6 +1,5 @@ -import React, { useState, useContext, useRef } from 'react' +import React, { useState, useRef } from 'react' import { Button, Flex, Space, Modal, Dropdown, message } from 'antd' -import { AuthContext } from '../context/AuthContext' import NewNoteType from './NoteTypes/NewNoteType' import ObjectTable from '../common/ObjectTable' import PlusIcon from '../../Icons/PlusIcon' @@ -15,7 +14,7 @@ const NoteTypes = () => { const [messageApi, contextHolder] = message.useMessage() const [newNoteTypeOpen, setNewNoteTypeOpen] = useState(false) const tableRef = useRef() - const { authenticated } = useContext(AuthContext) + const [viewMode, setViewMode] = useViewMode('noteType') const [columnVisibility, setColumnVisibility] = @@ -73,7 +72,6 @@ const NoteTypes = () => { ref={tableRef} visibleColumns={columnVisibility} type='noteType' - authenticated={authenticated} cards={viewMode === 'cards'} /> diff --git a/src/components/Dashboard/Management/NoteTypes/NoteTypeInfo.jsx b/src/components/Dashboard/Management/NoteTypes/NoteTypeInfo.jsx index 267918f..97865af 100644 --- a/src/components/Dashboard/Management/NoteTypes/NoteTypeInfo.jsx +++ b/src/components/Dashboard/Management/NoteTypes/NoteTypeInfo.jsx @@ -122,7 +122,7 @@ const NoteTypeInfo = () => { onToggle={(expanded) => updateCollapseState('info', expanded) } - key='info' + collapseKey='info' > { onToggle={(expanded) => updateCollapseState('auditLogs', expanded) } - key='auditLogs' + collapseKey='auditLogs' > {loading ? ( diff --git a/src/components/Dashboard/Management/Parts/PartInfo.jsx b/src/components/Dashboard/Management/Parts/PartInfo.jsx index fb23e26..327ddc7 100644 --- a/src/components/Dashboard/Management/Parts/PartInfo.jsx +++ b/src/components/Dashboard/Management/Parts/PartInfo.jsx @@ -131,7 +131,7 @@ const PartInfo = () => { onToggle={(expanded) => updateCollapseState('info', expanded) } - key='info' + collapseKey='info' > { onToggle={(expanded) => updateCollapseState('notes', expanded) } - key='notes' + collapseKey='notes' > - + @@ -162,7 +162,7 @@ const PartInfo = () => { onToggle={(expanded) => updateCollapseState('auditLogs', expanded) } - key='auditLogs' + collapseKey='auditLogs' > {loading ? ( diff --git a/src/components/Dashboard/Management/Products.jsx b/src/components/Dashboard/Management/Products.jsx index 3b39648..41491cc 100644 --- a/src/components/Dashboard/Management/Products.jsx +++ b/src/components/Dashboard/Management/Products.jsx @@ -1,6 +1,6 @@ // src/gcodefiles.js -import React, { useState, useContext, useRef } from 'react' +import React, { useState, useRef } from 'react' import { useNavigate } from 'react-router-dom' import { Button, @@ -15,8 +15,6 @@ import { Input } from 'antd' import { DownloadOutlined } from '@ant-design/icons' - -import { AuthContext } from '../context/AuthContext' import IdDisplay from '../common/IdDisplay' import TimeDisplay from '../common/TimeDisplay' import ObjectTable from '../common/ObjectTable' @@ -37,7 +35,7 @@ const Products = () => { const navigate = useNavigate() const [newProductOpen, setNewProductOpen] = useState(false) const tableRef = useRef() - const { authenticated } = useContext(AuthContext) + const [viewMode, setViewMode] = useViewMode('Products') const getProductActionItems = (id) => { @@ -350,7 +348,6 @@ const Products = () => { diff --git a/src/components/Dashboard/Management/Products/ProductInfo.jsx b/src/components/Dashboard/Management/Products/ProductInfo.jsx index 4dec3ac..ea442c3 100644 --- a/src/components/Dashboard/Management/Products/ProductInfo.jsx +++ b/src/components/Dashboard/Management/Products/ProductInfo.jsx @@ -123,7 +123,7 @@ const ProductInfo = () => { onToggle={(expanded) => updateCollapseState('info', expanded) } - key='info' + collapseKey='info' > { onToggle={(expanded) => updateCollapseState('parts', expanded) } - key='parts' + collapseKey='parts' > { onToggle={(expanded) => updateCollapseState('notes', expanded) } - key='notes' + collapseKey='notes' > - + @@ -173,7 +173,7 @@ const ProductInfo = () => { onToggle={(expanded) => updateCollapseState('auditLogs', expanded) } - key='auditLogs' + collapseKey='auditLogs' > {loading ? ( diff --git a/src/components/Dashboard/Management/Users.jsx b/src/components/Dashboard/Management/Users.jsx index de8613f..15948a8 100644 --- a/src/components/Dashboard/Management/Users.jsx +++ b/src/components/Dashboard/Management/Users.jsx @@ -1,6 +1,5 @@ -import React, { useContext, useRef } from 'react' +import React, { useRef } from 'react' import { Button, Flex, Space, Dropdown } from 'antd' -import { AuthContext } from '../context/AuthContext' import ObjectTable from '../common/ObjectTable' import ReloadIcon from '../../Icons/ReloadIcon' import useColumnVisibility from '../hooks/useColumnVisibility' @@ -11,7 +10,7 @@ import ColumnViewButton from '../common/ColumnViewButton' const Users = () => { const tableRef = useRef() - const { authenticated } = useContext(AuthContext) + const [viewMode, setViewMode] = useViewMode('user') const [columnVisibility, setColumnVisibility] = useColumnVisibility('user') @@ -56,7 +55,6 @@ const Users = () => { ref={tableRef} type={'user'} visibleColumns={columnVisibility} - authenticated={authenticated} cards={viewMode === 'cards'} /> diff --git a/src/components/Dashboard/Management/Users/UserInfo.jsx b/src/components/Dashboard/Management/Users/UserInfo.jsx index 135850d..7bc1583 100644 --- a/src/components/Dashboard/Management/Users/UserInfo.jsx +++ b/src/components/Dashboard/Management/Users/UserInfo.jsx @@ -123,7 +123,7 @@ const UserInfo = () => { onToggle={(expanded) => updateCollapseState('info', expanded) } - key='info' + collapseKey='info' > { onToggle={(expanded) => updateCollapseState('notes', expanded) } - key='notes' + collapseKey='notes' > - + @@ -155,7 +155,7 @@ const UserInfo = () => { onToggle={(expanded) => updateCollapseState('auditLogs', expanded) } - key='auditLogs' + collapseKey='auditLogs' > {loading ? ( diff --git a/src/components/Dashboard/Management/Vendors.jsx b/src/components/Dashboard/Management/Vendors.jsx index 17e0f8f..43084b1 100644 --- a/src/components/Dashboard/Management/Vendors.jsx +++ b/src/components/Dashboard/Management/Vendors.jsx @@ -1,6 +1,5 @@ -import React, { useState, useContext, useRef } from 'react' +import React, { useState, useRef } from 'react' import { Button, Flex, Space, Modal, Dropdown, message } from 'antd' -import { AuthContext } from '../context/AuthContext' import NewVendor from './Vendors/NewVendor' import ObjectTable from '../common/ObjectTable' import PlusIcon from '../../Icons/PlusIcon' @@ -15,7 +14,7 @@ const Vendors = () => { const [messageApi, contextHolder] = message.useMessage() const [newVendorOpen, setNewVendorOpen] = useState(false) const tableRef = useRef() - const { authenticated } = useContext(AuthContext) + const [viewMode, setViewMode] = useViewMode('vendor') const [columnVisibility, setColumnVisibility] = useColumnVisibility('vendor') @@ -72,7 +71,6 @@ const Vendors = () => { ref={tableRef} visibleColumns={columnVisibility} type='vendor' - authenticated={authenticated} cards={viewMode === 'cards'} /> diff --git a/src/components/Dashboard/Production/GCodeFiles/GCodeFileInfo.jsx b/src/components/Dashboard/Production/GCodeFiles/GCodeFileInfo.jsx index cc8af11..78ff900 100644 --- a/src/components/Dashboard/Production/GCodeFiles/GCodeFileInfo.jsx +++ b/src/components/Dashboard/Production/GCodeFiles/GCodeFileInfo.jsx @@ -144,7 +144,7 @@ const GCodeFileInfo = () => { onToggle={(expanded) => updateCollapseState('info', expanded) } - key='info' + collapseKey='info' > { onToggle={(expanded) => updateCollapseState('preview', expanded) } - key='preview' + collapseKey='preview' > {objectData?.gcodeFileInfo?.thumbnail ? ( @@ -184,10 +184,10 @@ const GCodeFileInfo = () => { onToggle={(expanded) => updateCollapseState('notes', expanded) } - key='notes' + collapseKey='notes' > - + @@ -198,7 +198,7 @@ const GCodeFileInfo = () => { onToggle={(expanded) => updateCollapseState('auditLogs', expanded) } - key='auditLogs' + collapseKey='auditLogs' > {loading ? ( diff --git a/src/components/Dashboard/Production/Jobs.jsx b/src/components/Dashboard/Production/Jobs.jsx index 27ee6fd..b53eb2a 100644 --- a/src/components/Dashboard/Production/Jobs.jsx +++ b/src/components/Dashboard/Production/Jobs.jsx @@ -1,9 +1,7 @@ // src/Jobs.js -import React, { useState, useContext, useRef } from 'react' +import React, { useState, useRef } from 'react' import { Button, Flex, Space, Modal, Dropdown, message } from 'antd' - -import { AuthContext } from '../context/AuthContext.js' import NewJob from './Jobs/NewJob.jsx' import useColumnVisibility from '../hooks/useColumnVisibility.js' import PlusIcon from '../../Icons/PlusIcon.jsx' @@ -19,7 +17,6 @@ const Jobs = () => { const [newJobOpen, setNewJobOpen] = useState(false) const tableRef = useRef() const [viewMode, setViewMode] = useViewMode('job') - const { authenticated } = useContext(AuthContext) const [columnVisibility, setColumnVisibility] = useColumnVisibility('job') @@ -81,7 +78,6 @@ const Jobs = () => { ref={tableRef} type={'job'} visibleColumns={columnVisibility} - authenticated={authenticated} cards={viewMode === 'cards'} /> diff --git a/src/components/Dashboard/Production/Jobs/JobInfo.jsx b/src/components/Dashboard/Production/Jobs/JobInfo.jsx index 42a4b9d..c923ea8 100644 --- a/src/components/Dashboard/Production/Jobs/JobInfo.jsx +++ b/src/components/Dashboard/Production/Jobs/JobInfo.jsx @@ -1,4 +1,4 @@ -import React, { useContext } from 'react' +import React from 'react' import { useLocation } from 'react-router-dom' import { Space, Flex, Card } from 'antd' import { LoadingOutlined } from '@ant-design/icons' @@ -17,14 +17,12 @@ import JobIcon from '../../../Icons/JobIcon' import AuditLogIcon from '../../../Icons/AuditLogIcon' import NoteIcon from '../../../Icons/NoteIcon' import ObjectActions from '../../common/ObjectActions.jsx' -import { ApiServerContext } from '../../context/ApiServerContext' import ObjectTable from '../../common/ObjectTable.jsx' import InfoCollapsePlaceholder from '../../common/InfoCollapsePlaceholder.jsx' const JobInfo = () => { const location = useLocation() const jobId = new URLSearchParams(location.search).get('jobId') - const { fetchObjectContent } = useContext(ApiServerContext) const [collapseState, updateCollapseState] = useCollapseState('JobInfo', { info: true, subJobs: true, @@ -41,9 +39,6 @@ const JobInfo = () => { {({ loading, isEditing, - startEditing, - cancelEditing, - handleUpdate, formValid, objectData, editLoading, @@ -55,28 +50,6 @@ const JobInfo = () => { reload: () => { fetchObject() return true - }, - edit: () => { - startEditing() - return false - }, - cancelEdit: () => { - cancelEditing() - return true - }, - finishEdit: () => { - handleUpdate() - return true - }, - download: () => { - if (jobId) { - fetchObjectContent( - jobId, - 'job', - `${objectData.name || 'job'}.json` - ) - return true - } } } @@ -135,7 +108,7 @@ const JobInfo = () => { onToggle={(expanded) => updateCollapseState('info', expanded) } - key='info' + collapseKey='info' > { onToggle={(expanded) => updateCollapseState('subJobs', expanded) } - key='subJobs' + collapseKey='subJobs' > @@ -165,10 +138,10 @@ const JobInfo = () => { onToggle={(expanded) => updateCollapseState('notes', expanded) } - key='notes' + collapseKey='notes' > - + @@ -179,7 +152,7 @@ const JobInfo = () => { onToggle={(expanded) => updateCollapseState('auditLogs', expanded) } - key='auditLogs' + collapseKey='auditLogs' > {loading ? ( diff --git a/src/components/Dashboard/Production/Printers/PrinterInfo.jsx b/src/components/Dashboard/Production/Printers/PrinterInfo.jsx index 99d6fd9..3c8b48a 100644 --- a/src/components/Dashboard/Production/Printers/PrinterInfo.jsx +++ b/src/components/Dashboard/Production/Printers/PrinterInfo.jsx @@ -135,7 +135,7 @@ const PrinterInfo = () => { onToggle={(expanded) => updateCollapseState('info', expanded) } - key='info' + collapseKey='info' > { onToggle={(expanded) => updateCollapseState('jobs', expanded) } - key='jobs' + collapseKey='jobs' > { onToggle={(expanded) => updateCollapseState('notes', expanded) } - key='notes' + collapseKey='notes' > - + @@ -182,7 +182,7 @@ const PrinterInfo = () => { onToggle={(expanded) => updateCollapseState('auditLogsParent', expanded) } - key='auditLogs' + collapseKey='auditLogs' > {loading ? ( @@ -201,7 +201,7 @@ const PrinterInfo = () => { onToggle={(expanded) => updateCollapseState('auditLogsOwner', expanded) } - key='auditLogs' + collapseKey='auditLogs' > {loading ? ( diff --git a/src/components/Dashboard/Production/SubJobs.jsx b/src/components/Dashboard/Production/SubJobs.jsx index c2b7498..a9e1f08 100644 --- a/src/components/Dashboard/Production/SubJobs.jsx +++ b/src/components/Dashboard/Production/SubJobs.jsx @@ -1,9 +1,7 @@ // src/SubJobs.js -import React, { useContext, useRef } from 'react' +import React, { useRef } from 'react' import { Button, Flex, Space, Dropdown } from 'antd' - -import { AuthContext } from '../context/AuthContext.js' import useColumnVisibility from '../hooks/useColumnVisibility.js' import ReloadIcon from '../../Icons/ReloadIcon.jsx' import ObjectTable from '../common/ObjectTable.jsx' @@ -15,7 +13,6 @@ import ColumnViewButton from '../common/ColumnViewButton.jsx' const SubJobs = () => { const tableRef = useRef() const [viewMode, setViewMode] = useViewMode('subJob') - const { authenticated } = useContext(AuthContext) const [columnVisibility, setColumnVisibility] = useColumnVisibility('subJob') @@ -64,7 +61,6 @@ const SubJobs = () => { ref={tableRef} type={'subJob'} visibleColumns={columnVisibility} - authenticated={authenticated} cards={viewMode === 'cards'} />