From 7cf65c4668415840a6530407ba352e348dadcb0d Mon Sep 17 00:00:00 2001 From: Samuel <47388695+Dagonite@users.noreply.github.com> Date: Fri, 7 Feb 2025 13:37:21 +0000 Subject: [PATCH] Add code comments (#437) * Add code comments * Set rows per page to 25 * Update handle row change comment * Revert radix value --- src/App.tsx | 31 ++++++++++----- src/ConfigSettings/ConfigSettingsLOQ.tsx | 12 ++++-- src/ConfigSettings/FileUploader.tsx | 5 ++- src/GlobalStyles.tsx | 5 +++ src/Instruments.tsx | 13 +++++++ src/Jobs/JobsAll.tsx | 49 ++++++++++++++++-------- src/Jobs/JobsGeneral.tsx | 40 ++++++++++++------- 7 files changed, 111 insertions(+), 44 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 9cd58033..ede7413e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -12,33 +12,43 @@ import ValueEditor from './ValueEditor'; import GlobalStyles from './GlobalStyles'; import { clearFailedAuthRequestsQueue, retryFailedAuthRequests } from './api'; -// Initialize Google Analytics +// Initialize Google Analytics with the given tracking ID ReactGA.initialize('G-7XJBCP6P75'); +// Track the initial page load event ReactGA.send({ hitType: 'pageview', page: window.location.pathname }); const App: FC = () => { - // Need to call forceUpdate if SciGateway tells us to rerender but there's no - // forceUpdate in functional components, so this is the hooks equivalent. See - // https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate + // Force update mechanism using React's useReducer hook + // This is used to trigger a re-render when necessary (e.g. when SciGateway requests it) + // There is no direct forceUpdate in functional components, so we increment a state variable instead // eslint-disable-next-line @typescript-eslint/no-unused-vars const [_, forceUpdate] = React.useReducer((x) => x + 1, 0); function handler(e: Event): void { - // Attempt to re-render the plugin if we get told to + // Handle custom SciGateway events for triggering actions in the app const action = (e as CustomEvent).detail; + + // If SciGateway requests a plugin re-render, trigger a re-render if ('scigateway:api:plugin_rerender'.match(action)) { forceUpdate(); } + + // If SciGateway invalidates the token, retry failed authentication requests if ('scigateway:api:invalidate_token'.match(action)) { retryFailedAuthRequests(); } + + // If SciGateway requests signout, clear the authentication request queue if ('scigateway:api:signout'.match(action)) { clearFailedAuthRequestsQueue(); } } + // Attach event listener for SciGateway events when the component mounts React.useEffect(() => { document.addEventListener('scigateway', handler); + + // Remove event listener when the component unmounts return () => { document.removeEventListener('scigateway', handler); }; @@ -48,20 +58,21 @@ const App: FC = () => { + {/* Define application routes */} - + {/* Renders the HomePage component on the root path */} - + {/* Renders the Instruments page */} - + {/* Displays all reduction jobs */} - + {/* Displays reduction jobs filtered by instrument name */} - + {/* Opens the ValueEditor for a specific job */} diff --git a/src/ConfigSettings/ConfigSettingsLOQ.tsx b/src/ConfigSettings/ConfigSettingsLOQ.tsx index 2554b746..b72a8469 100644 --- a/src/ConfigSettings/ConfigSettingsLOQ.tsx +++ b/src/ConfigSettings/ConfigSettingsLOQ.tsx @@ -5,26 +5,32 @@ import React from 'react'; import { Box, Button } from '@mui/material'; import { UploadFile, Edit } from '@mui/icons-material'; -// Local data +// Local components import ConfigSettingsGeneral from './ConfigSettingsGeneral'; import FileUploader from './FileUploader'; +// API base URL for LOQ-specific requests const fiaApiUrl = process.env.REACT_APP_FIA_REST_API_URL; const instrument_url = `${fiaApiUrl}/extras/loq`; + const ConfigSettingsLOQ: React.FC = () => { - // Insert LOQ specifc buttons into the ConfigSettingsGeneral component + // File uploader logic for LOQ const { selectedFile, uploadMessage, handleFileSelection, handleFileUpload } = FileUploader(instrument_url); + return ( + // Render ConfigSettingsGeneral with additional LOQ-specific elements + {/* File upload button */} + {/* Display upload message if a file is selected */} {selectedFile && {uploadMessage}} - {/* Change script button -- disabled for now */} + {/* Change script button (currently disabled) */}