From 54825c57dbcd403f737ba3b694b7de669fcc36b2 Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Wed, 22 Oct 2025 18:58:58 +0100 Subject: [PATCH 1/9] Replaced TIFF file download requeest URL with general file download request URL --- src/loaders/general.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/loaders/general.tsx b/src/loaders/general.tsx index 0997abc..a37c8f0 100644 --- a/src/loaders/general.tsx +++ b/src/loaders/general.tsx @@ -25,7 +25,9 @@ export const getInstrumentConnectionStatus = async () => { return response.data } -export const getUpstreamVisits = async (sessid: number) => { +export const getUpstreamVisits = async ( + sessid: number +): Promise> | null> => { const response = await client.get( `session_info/correlative/sessions/${sessid}/upstream_visits` ) @@ -37,12 +39,17 @@ export const getUpstreamVisits = async (sessid: number) => { } export const upstreamDataDownloadRequest = async ( + instrumentName: string, + sessid: number, visitName: string, - sessid: number + visitPath: string ) => { const response = await client.post( - `instrument_server/visits/${visitName}/sessions/${sessid}/upstream_tiff_data_request`, - {} + `instrument_server/visits/${visitName}/sessions/${sessid}/upstream_file_data_request`, + { + upstream_instrument: instrumentName, + upstream_visit_path: visitPath, + } ) if (response.status !== 200) { From f4ff53edb8568370b36f8f8735133a79b05d40e0 Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Wed, 22 Oct 2025 19:01:26 +0100 Subject: [PATCH 2/9] Added logic to display upstream visits according to their instrument of origin --- src/components/upstreamVisitsCard.tsx | 77 ++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 14 deletions(-) diff --git a/src/components/upstreamVisitsCard.tsx b/src/components/upstreamVisitsCard.tsx index 1aeb37b..1d301ac 100644 --- a/src/components/upstreamVisitsCard.tsx +++ b/src/components/upstreamVisitsCard.tsx @@ -7,14 +7,60 @@ interface SessionId { sessid: number } -export const UpstreamVisitCard = ({ sessid }: SessionId) => { - const [upstreamVisits, setUpstreamVisits] = React.useState({}) +const InstrumentUpstreamVisitsCard = ({ + sessid, + instrumentName, + instrumentVisits, +}: { + sessid: number + instrumentName: string + instrumentVisits: Record +}) => { + // Display upstream visits for a single instrument + // Parameters to take: instrument name and upstream visits dict + console.log(instrumentVisits) + return ( + + {instrumentName} + {/* Map each visit to a button */} + {Object.entries(instrumentVisits).map( + ([visitName, visitPath]: [string, string]) => { + return ( + + + + ) + } + )} + + ) +} + +export const UpstreamVisitsCard = ({ sessid }: SessionId) => { + const [upstreamVisits, setUpstreamVisits] = React.useState< + Record> + >({}) + // Load all visits associated with current session const resolveVisits = useCallback(async () => { const visits = await getUpstreamVisits(sessid) + if (!visits) return // Handle null or false-y cases setUpstreamVisits(visits) console.log(visits) }, [sessid]) + useEffect(() => { resolveVisits() }, [sessid, resolveVisits]) @@ -22,18 +68,21 @@ export const UpstreamVisitCard = ({ sessid }: SessionId) => { return upstreamVisits ? ( Upstream Visit Data Download - {Object.keys(upstreamVisits).map((k) => { - return ( - - - - ) - })} + {/* Map each instrument to its own card */} + {Object.entries(upstreamVisits).map( + ([instrumentName, instrumentVisits]: [ + string, + Record, + ]) => { + return ( + + ) + } + )} ) : ( <> From 54ed6a1ec9db363efc940b91faf492b742158120 Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Wed, 22 Oct 2025 19:02:41 +0100 Subject: [PATCH 3/9] Used new name for 'UpstreamVisitsCard' --- src/routes/Session.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/Session.tsx b/src/routes/Session.tsx index d2a6227..c9b958a 100644 --- a/src/routes/Session.tsx +++ b/src/routes/Session.tsx @@ -27,7 +27,7 @@ import { import { useQuery } from '@tanstack/react-query' import { InstrumentCard } from 'components/instrumentCard' import { RsyncCard } from 'components/rsyncCard' -import { UpstreamVisitCard } from 'components/upstreamVisitsCard' +import { UpstreamVisitsCard } from 'components/upstreamVisitsCard' import { getInstrumentConnectionStatus } from 'loaders/general' import { sessionTokenCheck, sessionHandshake } from 'loaders/jwt' import { getMachineConfigData } from 'loaders/machineConfig' @@ -573,7 +573,7 @@ export const Session = () => { - + From 6d3c9f96b9b80942a4466a69d27ee39415564966 Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Thu, 23 Oct 2025 17:23:03 +0100 Subject: [PATCH 4/9] Some cosmetic changes to 'UpstreamVisitsCard' --- src/components/upstreamVisitsCard.tsx | 69 ++++++++++++++------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/src/components/upstreamVisitsCard.tsx b/src/components/upstreamVisitsCard.tsx index 1d301ac..3f8fb1c 100644 --- a/src/components/upstreamVisitsCard.tsx +++ b/src/components/upstreamVisitsCard.tsx @@ -3,10 +3,6 @@ import { getUpstreamVisits, upstreamDataDownloadRequest } from 'loaders/general' import React, { useCallback, useEffect } from 'react' import { MdFileDownload } from 'react-icons/md' -interface SessionId { - sessid: number -} - const InstrumentUpstreamVisitsCard = ({ sessid, instrumentName, @@ -20,15 +16,18 @@ const InstrumentUpstreamVisitsCard = ({ // Parameters to take: instrument name and upstream visits dict console.log(instrumentVisits) return ( - - {instrumentName} - {/* Map each visit to a button */} - {Object.entries(instrumentVisits).map( - ([visitName, visitPath]: [string, string]) => { - return ( - + + + {instrumentName} + + + {/* Map each visit to a button */} + {Object.entries(instrumentVisits).map( + ([visitName, visitPath]: [string, string]) => { + return ( - - ) - } - )} + ) + } + )} + ) } -export const UpstreamVisitsCard = ({ sessid }: SessionId) => { +export const UpstreamVisitsCard = ({ sessid }: { sessid: number }) => { const [upstreamVisits, setUpstreamVisits] = React.useState< Record> >({}) @@ -66,23 +65,27 @@ export const UpstreamVisitsCard = ({ sessid }: SessionId) => { }, [sessid, resolveVisits]) return upstreamVisits ? ( - - Upstream Visit Data Download - {/* Map each instrument to its own card */} - {Object.entries(upstreamVisits).map( - ([instrumentName, instrumentVisits]: [ - string, - Record, - ]) => { - return ( - - ) - } - )} + + + Upstream Visit Data Download + + + {/* Map each instrument to its own card */} + {Object.entries(upstreamVisits).map( + ([instrumentName, instrumentVisits]: [ + string, + Record, + ]) => { + return ( + + ) + } + )} + ) : ( <> From 9e6fc666a4e0f52fdffd91319e1216aaccd936ff Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Thu, 23 Oct 2025 18:26:05 +0100 Subject: [PATCH 5/9] Moved 'getInstrumentInfo' to general Loaders page --- src/loaders/general.tsx | 10 ++++++++++ src/loaders/hub.tsx | 10 +--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/loaders/general.tsx b/src/loaders/general.tsx index a37c8f0..e535b95 100644 --- a/src/loaders/general.tsx +++ b/src/loaders/general.tsx @@ -1,5 +1,15 @@ import { client } from 'utils/api/client' +export const getInstrumentInfo = async () => { + const response = await client.hub_get(`instruments`) + + if (response.status !== 200) { + return null + } + + return response.data +} + export const getInstrumentName = async () => { const response = await client.get( `display/instruments/${sessionStorage.getItem('instrumentName')}/instrument_name` diff --git a/src/loaders/hub.tsx b/src/loaders/hub.tsx index 1ffd0f6..1a600cf 100644 --- a/src/loaders/hub.tsx +++ b/src/loaders/hub.tsx @@ -1,15 +1,7 @@ import { QueryClient } from '@tanstack/react-query' import { client } from 'utils/api/client' -const getInstrumentInfo = async () => { - const response = await client.hub_get(`instruments`) - - if (response.status !== 200) { - return null - } - - return response.data -} +import { getInstrumentInfo } from './general' const query = { queryKey: ['instrumentInfo'], From 2038023864e9441c6024e9a99251f670bc15dd50 Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Thu, 23 Oct 2025 18:26:55 +0100 Subject: [PATCH 6/9] Added logic to 'UpstreamVisitsCard' to lookup and display human readable instrument names --- src/components/upstreamVisitsCard.tsx | 36 +++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/components/upstreamVisitsCard.tsx b/src/components/upstreamVisitsCard.tsx index 3f8fb1c..d4c3146 100644 --- a/src/components/upstreamVisitsCard.tsx +++ b/src/components/upstreamVisitsCard.tsx @@ -1,15 +1,19 @@ import { Card, CardBody, Button, CardHeader } from '@chakra-ui/react' +import { useQuery } from '@tanstack/react-query' import { getUpstreamVisits, upstreamDataDownloadRequest } from 'loaders/general' +import { getInstrumentInfo } from 'loaders/general' import React, { useCallback, useEffect } from 'react' import { MdFileDownload } from 'react-icons/md' const InstrumentUpstreamVisitsCard = ({ sessid, instrumentName, + displayName, instrumentVisits, }: { sessid: number instrumentName: string + displayName: string instrumentVisits: Record }) => { // Display upstream visits for a single instrument @@ -18,7 +22,7 @@ const InstrumentUpstreamVisitsCard = ({ return ( - {instrumentName} + {displayName} {/* Map each visit to a button */} @@ -64,7 +68,34 @@ export const UpstreamVisitsCard = ({ sessid }: { sessid: number }) => { resolveVisits() }, [sessid, resolveVisits]) - return upstreamVisits ? ( + // Set up queryClient to load names of all instruments + type InstrumentInfo = { + instrument_name: string + display_name: string + instrument_url: string + } + const { data: instrumentInfo } = useQuery({ + queryKey: ['instrumentInfo'], + queryFn: getInstrumentInfo, + staleTime: 60000, + }) + + // Set up function to get the corresponding display name of the instrument + const getDisplayName = (instrumentName: string) => { + if (!instrumentInfo) return instrumentName + const result = instrumentInfo.find( + (item) => item.instrument_name === instrumentName + ) + console.log(`Found match:`, result) + // Use instrument name if no results were found or if display name wasn't set + return result + ? result.display_name + ? result.display_name + : instrumentName + : instrumentName + } + + return upstreamVisits && instrumentInfo ? ( Upstream Visit Data Download @@ -80,6 +111,7 @@ export const UpstreamVisitsCard = ({ sessid }: { sessid: number }) => { ) From 4ee30b855956718c31aa5cd6d47c6263d4aca555 Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Thu, 23 Oct 2025 18:51:39 +0100 Subject: [PATCH 7/9] Removed debugging logs from 'upstreamVisitsCard' --- src/components/upstreamVisitsCard.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/components/upstreamVisitsCard.tsx b/src/components/upstreamVisitsCard.tsx index d4c3146..7d36960 100644 --- a/src/components/upstreamVisitsCard.tsx +++ b/src/components/upstreamVisitsCard.tsx @@ -18,7 +18,6 @@ const InstrumentUpstreamVisitsCard = ({ }) => { // Display upstream visits for a single instrument // Parameters to take: instrument name and upstream visits dict - console.log(instrumentVisits) return ( @@ -61,7 +60,6 @@ export const UpstreamVisitsCard = ({ sessid }: { sessid: number }) => { const visits = await getUpstreamVisits(sessid) if (!visits) return // Handle null or false-y cases setUpstreamVisits(visits) - console.log(visits) }, [sessid]) useEffect(() => { @@ -86,7 +84,6 @@ export const UpstreamVisitsCard = ({ sessid }: { sessid: number }) => { const result = instrumentInfo.find( (item) => item.instrument_name === instrumentName ) - console.log(`Found match:`, result) // Use instrument name if no results were found or if display name wasn't set return result ? result.display_name From 43d1f12632a06d42c072cfffe7fc4fb52adae7a5 Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Mon, 27 Oct 2025 11:28:52 +0000 Subject: [PATCH 8/9] Removed unnecessary import --- src/loaders/hub.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/loaders/hub.tsx b/src/loaders/hub.tsx index 1a600cf..e8cb75b 100644 --- a/src/loaders/hub.tsx +++ b/src/loaders/hub.tsx @@ -1,5 +1,4 @@ import { QueryClient } from '@tanstack/react-query' -import { client } from 'utils/api/client' import { getInstrumentInfo } from './general' From 1e2e9c5a95fae0a70a0926338eab0285ef72aefa Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Mon, 27 Oct 2025 11:40:13 +0000 Subject: [PATCH 9/9] Display message when no visits are found, and hide card entirely when no upstream directories are configured --- src/components/upstreamVisitsCard.tsx | 44 +++++++++++++++------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/components/upstreamVisitsCard.tsx b/src/components/upstreamVisitsCard.tsx index 7d36960..e37bc40 100644 --- a/src/components/upstreamVisitsCard.tsx +++ b/src/components/upstreamVisitsCard.tsx @@ -25,25 +25,29 @@ const InstrumentUpstreamVisitsCard = ({ {/* Map each visit to a button */} - {Object.entries(instrumentVisits).map( - ([visitName, visitPath]: [string, string]) => { - return ( - - ) - } + {!!Object.keys(instrumentVisits).length ? ( + Object.entries(instrumentVisits).map( + ([visitName, visitPath]: [string, string]) => { + return ( + + ) + } + ) + ) : ( + <>No related visits found )} @@ -92,7 +96,7 @@ export const UpstreamVisitsCard = ({ sessid }: { sessid: number }) => { : instrumentName } - return upstreamVisits && instrumentInfo ? ( + return !!Object.keys(upstreamVisits).length && !!instrumentInfo ? ( Upstream Visit Data Download