// src/gcodefiles.js import React, { useState, useContext, useRef } from 'react' import { useNavigate } from 'react-router-dom' import { Button, Flex, Space, Modal, Dropdown, Typography, Checkbox, Popover, Input, message } from 'antd' import { DownloadOutlined } from '@ant-design/icons' import { AuthContext } from '../context/AuthContext' import IdDisplay from '../common/IdDisplay' import ObjectTable from '../common/ObjectTable' import NewProduct from './Products/NewProduct' import PartIcon from '../../Icons/PartIcon' import InfoCircleIcon from '../../Icons/InfoCircleIcon' import PlusIcon from '../../Icons/PlusIcon' import ReloadIcon from '../../Icons/ReloadIcon' import XMarkIcon from '../../Icons/XMarkIcon' import CheckIcon from '../../Icons/CheckIcon' import useColumnVisibility from '../hooks/useColumnVisibility' import TimeDisplay from '../common/TimeDisplay' import GridIcon from '../../Icons/GridIcon' import ListIcon from '../../Icons/ListIcon' import useViewMode from '../hooks/useViewMode' import config from '../../../config' const { Text } = Typography const Parts = () => { const [messageApi, contextHolder] = message.useMessage() const navigate = useNavigate() const [newProductOpen, setNewProductOpen] = useState(false) const tableRef = useRef() const { authenticated } = useContext(AuthContext) const [viewMode, setViewMode] = useViewMode('Parts') // Column definitions const columns = [ { title: , key: 'icon', width: 40, fixed: 'left', render: () => }, { title: 'Name', dataIndex: 'name', key: 'name', width: 200, fixed: 'left', render: (text) => {text}, filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters }) => getFilterDropdown({ setSelectedKeys, selectedKeys, confirm, clearFilters, propertyName: 'name' }), onFilter: (value, record) => record.name.toLowerCase().includes(value.toLowerCase()) }, { title: 'ID', dataIndex: '_id', key: 'id', width: 180, render: (text) => }, { title: 'Product Name', key: 'productName', width: 200, render: (record) => {record?.product?.name}, filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters }) => getFilterDropdown({ setSelectedKeys, selectedKeys, confirm, clearFilters, propertyName: 'product name' }), onFilter: (value, record) => record.product.name.toLowerCase().includes(value.toLowerCase()) }, { title: 'Product ID', key: 'productId', width: 180, render: (record) => ( ) }, { title: 'Created At', dataIndex: 'createdAt', key: 'createdAt', width: 180, render: (createdAt) => { if (createdAt) { return } else { return 'n/a' } }, sorter: true }, { title: 'Updated At', dataIndex: 'updatedAt', key: 'updatedAt', width: 180, render: (updatedAt) => { if (updatedAt) { return } else { return 'n/a' } }, sorter: true }, { title: 'Actions', key: 'actions', fixed: 'right', width: 150, render: (record) => { return ( ) } } ] const [columnVisibility, updateColumnVisibility] = useColumnVisibility( 'Parts', columns ) const getPartActionItems = (id) => { return { items: [ { label: 'Info', key: 'info', icon: }, { label: 'Download', key: 'download', icon: } ], onClick: ({ key }) => { if (key === 'info') { navigate(`/dashboard/management/parts/info?partId=${id}`) } } } } const getFilterDropdown = ({ setSelectedKeys, selectedKeys, confirm, clearFilters, propertyName }) => { return (
setSelectedKeys(e.target.value ? [e.target.value] : []) } onPressEnter={() => confirm()} style={{ width: 200, display: 'block' }} />
) } const actionItems = { items: [ { label: 'New Product', key: 'newProduct', icon: }, { type: 'divider' }, { label: 'Reload List', key: 'reloadList', icon: } ], onClick: ({ key }) => { if (key === 'reloadList') { tableRef.current?.reload() } else if (key === 'newProduct') { setNewProductOpen(true) } } } const getViewDropdownItems = () => { const columnItems = columns .filter((col) => col.key && col.title !== '') .map((col) => ( { updateColumnVisibility(col.key, e.target.checked) }} > {col.title} )) return ( {columnItems} ) } const visibleColumns = columns.filter( (col) => !col.key || columnVisibility[col.key] ) return ( <> {contextHolder}