@@ -6,22 +6,35 @@ import { useHistory, useParams, Link } from 'react-router-dom';
66import { useTheme } from '@mui/material/styles' ;
77import { TableCell } from '@mui/material' ;
88
9- // Local data
9+ // Local data and utilities
1010import JobsBase , { useFetchJobs , useFetchTotalCount , Job , headerStyles } from './JobsBase' ;
1111
1212const JobsAll : React . FC = ( ) => {
13+ // Extract instrument name from URL parameters
1314 const { instrumentName } = useParams < { instrumentName : string } > ( ) ;
15+
16+ // Retrieve the current theme for styling
1417 const theme = useTheme ( ) ;
18+
19+ // Hook for handling navigation within the app
1520 const history = useHistory ( ) ;
16- const [ jobs , setJobs ] = useState < Job [ ] > ( [ ] ) ;
17- const [ totalRows , setTotalRows ] = useState ( 0 ) ;
18- const [ currentPage , setCurrentPage ] = useState ( 0 ) ;
19- const [ rowsPerPage , setRowsPerPage ] = useState ( 25 ) ;
20- const [ orderDirection , setOrderDirection ] = useState < 'asc' | 'desc' > ( 'desc' ) ;
21- const [ selectedInstrument , setSelectedInstrument ] = useState ( instrumentName || 'ALL' ) ;
22- const [ orderBy , setOrderBy ] = useState < string > ( 'run_start' ) ;
21+
22+ // State variables for job data and table pagination
23+ const [ jobs , setJobs ] = useState < Job [ ] > ( [ ] ) ; // Stores fetched job data
24+ const [ totalRows , setTotalRows ] = useState ( 0 ) ; // Stores total number of job entries
25+ const [ currentPage , setCurrentPage ] = useState ( 0 ) ; // Current page in pagination
26+ const [ rowsPerPage , setRowsPerPage ] = useState ( 25 ) ; // Number of rows displayed per page
27+ const [ orderDirection , setOrderDirection ] = useState < 'asc' | 'desc' > ( 'desc' ) ; // Sorting order (ascending/descending)
28+ const [ selectedInstrument , setSelectedInstrument ] = useState ( instrumentName || 'ALL' ) ; // Selected instrument filter
29+ const [ orderBy , setOrderBy ] = useState < string > ( 'run_start' ) ; // Column to sort by
30+
31+ // Calculate the offset for API query based on current page
2332 const offset = currentPage * rowsPerPage ;
33+
34+ // Construct API query string with pagination and sorting parameters
2435 const query = `limit=${ rowsPerPage } &offset=${ offset } &order_by=${ orderBy } &order_direction=${ orderDirection } &include_run=true` ;
36+
37+ // Fetch job data and total count using custom hooks
2538 const fetchJobs = useFetchJobs ( `/jobs` , query , setJobs ) ;
2639 const fetchTotalCount = useFetchTotalCount ( `/jobs/count` , setTotalRows ) ;
2740
@@ -32,25 +45,27 @@ const JobsAll: React.FC = () => {
3245 const newInstrument = event . target . value ;
3346 setSelectedInstrument ( newInstrument ) ;
3447 setCurrentPage ( 0 ) ;
35- history . push ( `/reduction-history/${ newInstrument } ` ) ;
48+ history . push ( `/reduction-history/${ newInstrument } ` ) ; // Navigate to selected instrument's history
3649 } }
3750 jobs = { jobs }
3851 totalRows = { totalRows }
3952 currentPage = { currentPage }
4053 rowsPerPage = { rowsPerPage }
41- handleChangePage = { ( _ , newPage ) => setCurrentPage ( newPage ) }
42- handleChangeRowsPerPage = { ( e ) => setRowsPerPage ( parseInt ( e . target . value , 10 ) ) }
54+ handleChangePage = { ( _ , newPage ) => setCurrentPage ( newPage ) } // Update page number
55+ handleChangeRowsPerPage = { ( e ) => setRowsPerPage ( parseInt ( e . target . value , 10 ) ) } // Update rows per page based on what the user has selected (10 is the radix, do not confuse for number of rows)
4356 handleSort = { ( property ) => {
4457 const isAsc = orderBy === property && orderDirection === 'asc' ;
45- setOrderDirection ( isAsc ? 'desc' : 'asc' ) ;
58+ setOrderDirection ( isAsc ? 'desc' : 'asc' ) ; // Toggle sorting order
4659 setOrderBy ( property ) ;
47- setCurrentPage ( 0 ) ;
60+ setCurrentPage ( 0 ) ; // Reset to first page after sorting
4861 } }
4962 orderBy = { orderBy }
5063 orderDirection = { orderDirection }
5164 fetchJobs = { fetchJobs }
5265 fetchTotalCount = { fetchTotalCount }
66+ // Custom table header for instrument column
5367 customHeaders = { < TableCell sx = { { width : '10%' , ...headerStyles ( theme ) } } > Instrument</ TableCell > }
68+ // Custom rendering of job row cells for instrument name with a clickable link
5469 customRowCells = { ( job : Job ) => (
5570 < TableCell sx = { { width : '10%' } } >
5671 { job . run ?. instrument_name ? (
@@ -60,17 +75,17 @@ const JobsAll: React.FC = () => {
6075 color : theme . palette . mode === 'dark' ? '#86b4ff' : theme . palette . primary . main ,
6176 textDecoration : 'none' ,
6277 } }
63- onMouseEnter = { ( e ) => ( e . currentTarget . style . textDecoration = 'underline' ) }
64- onMouseLeave = { ( e ) => ( e . currentTarget . style . textDecoration = 'none' ) }
78+ onMouseEnter = { ( e ) => ( e . currentTarget . style . textDecoration = 'underline' ) } // Underline on hover
79+ onMouseLeave = { ( e ) => ( e . currentTarget . style . textDecoration = 'none' ) } // Remove underline on hover out
6580 >
6681 { job . run . instrument_name }
6782 </ Link >
6883 ) : (
69- 'Unknown'
84+ 'Unknown' // Display 'Unknown' if no instrument name exists
7085 ) }
7186 </ TableCell >
7287 ) }
73- maxHeight = { 650 }
88+ maxHeight = { 650 } // Limit table height
7489 />
7590 ) ;
7691} ;
0 commit comments