diff --git a/src/components/BMDashboard/ItemList/ItemListView.jsx b/src/components/BMDashboard/ItemList/ItemListView.jsx index 118146a9f5..53c423260d 100644 --- a/src/components/BMDashboard/ItemList/ItemListView.jsx +++ b/src/components/BMDashboard/ItemList/ItemListView.jsx @@ -253,6 +253,7 @@ export function ItemListView({ UpdateItemModal={UpdateItemModal} dynamicColumns={dynamicColumns} darkMode={darkMode} + itemType={itemType} sortConfig={sortConfig} onSort={handleSort} totalItems={totalItems} diff --git a/src/components/BMDashboard/ItemList/ItemsTable.jsx b/src/components/BMDashboard/ItemList/ItemsTable.jsx index 278962e77f..5f106f8f07 100644 --- a/src/components/BMDashboard/ItemList/ItemsTable.jsx +++ b/src/components/BMDashboard/ItemList/ItemsTable.jsx @@ -1,25 +1,18 @@ import { useState } from 'react'; -import { Table, Button } from 'reactstrap'; +import PropTypes from 'prop-types'; +import { Table, Button, Badge } from 'reactstrap'; import { BiPencil } from 'react-icons/bi'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faSortDown, faSort, faSortUp } from '@fortawesome/free-solid-svg-icons'; import RecordsModal from './RecordsModal'; +import styles from './ItemListView.module.css'; const rowsPerPageOptions = [25, 50, 100]; function generatePageNumbers(current, total) { - if (total <= 7) { - return Array.from({ length: total }, (_, i) => i + 1); - } - - if (current <= 3) { - return [1, 2, 3, 4, 5, '...', total]; - } - - if (current >= total - 2) { - return [1, '...', total - 4, total - 3, total - 2, total - 1, total]; - } - + if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1); + if (current <= 3) return [1, 2, 3, 4, 5, '...', total]; + if (current >= total - 2) return [1, '...', total - 4, total - 3, total - 2, total - 1, total]; return [1, '...', current - 1, current, current + 1, '...', total]; } @@ -30,6 +23,7 @@ export default function ItemsTable({ UpdateItemModal, dynamicColumns, darkMode = false, + itemType, sortConfig, onSort, totalItems, @@ -60,9 +54,8 @@ export default function ItemsTable({ setRecordType(type); }; - const getNestedValue = (obj, path) => { - return path.split('.').reduce((acc, part) => (acc ? acc[part] : null), obj); - }; + const getNestedValue = (obj, path) => + path.split('.').reduce((acc, part) => (acc ? acc[part] : null), obj); const getIconFor = key => { if (!sortConfig?.key || sortConfig.key !== key) return faSort; @@ -77,6 +70,18 @@ export default function ItemsTable({ Hold: 'hold', }; + const numericKeys = new Set(['stockBought', 'stockUsed', 'stockAvailable', 'stockWasted']); + + const getColumnStyle = (key, isAction = false) => { + const base = { verticalAlign: 'middle' }; + if (numericKeys.has(key)) base.textAlign = 'right'; + if (isAction) { + base.borderLeft = '2px solid #dee2e6'; + base.textAlign = 'center'; + } + return base; + }; + return ( <> - onSort?.('project')} className={styles.sortableTh}> + onSort?.('project')} + className={styles.sortableTh} + style={{ verticalAlign: 'middle' }} + > Project - - onSort?.('name')} className={styles.sortableTh}> + onSort?.('name')} + className={styles.sortableTh} + style={{ verticalAlign: 'middle' }} + > Name - - {dynamicColumns.map(({ label }) => { + {dynamicColumns.map(({ label, key }) => { const sortKey = dynamicSortKeyByLabel[label]; const clickable = Boolean(sortKey); - return ( onSort?.(sortKey) : undefined} className={clickable ? styles.sortableTh : undefined} + style={getColumnStyle(key)} > {label} {clickable && } ); })} - - Usage Record - Updates - Purchases + + Usage Record + + + Updates + + + Purchases + - {filteredItems && filteredItems.length > 0 ? ( filteredItems.map(el => ( - {el.project?.name} - {el.itemType?.name} - - {dynamicColumns.map(({ label, key }) => ( - {getNestedValue(el, key)} - ))} - - + {el.project?.name} + {el.itemType?.name} + {dynamicColumns.map(({ label, key }) => { + const value = getNestedValue(el, key); + if (key === 'stockAvailable' && Number(value) < 10) { + return ( + + + Low + + {value} + + ); + } + return ( + + {value} + + ); + })} + - - + - - + - - {generatePageNumbers(currentPage, totalPages).map((p, idx) => typeof p === 'number' ? ( -