diff --git a/apps/i15-1/src/AppProviders.tsx b/apps/i15-1/src/AppProviders.tsx index 5c92fc83..352c6870 100644 --- a/apps/i15-1/src/AppProviders.tsx +++ b/apps/i15-1/src/AppProviders.tsx @@ -22,17 +22,19 @@ export function AppProviders({ api, theme, children }: Props) { const config = useLoadPvwsConfig(); return ( - - - - - - {children} - - - - - + + + + + + + {children} + + + + + + ); } diff --git a/apps/i15-1/src/components/ExperimentTable/ULIMSExperimentsTable.tsx b/apps/i15-1/src/components/ExperimentTable/ULIMSExperimentsTable.tsx index 77be34a1..4b3577c9 100644 --- a/apps/i15-1/src/components/ExperimentTable/ULIMSExperimentsTable.tsx +++ b/apps/i15-1/src/components/ExperimentTable/ULIMSExperimentsTable.tsx @@ -19,7 +19,6 @@ import type { import type { ExperimentDefinition, Sample } from "../../../generated/queue"; import { useInstrumentSession, visitTextToVisit } from "@atlas/app-shell"; - export type ExperimentDefinitionData = { q_max: number; frames: number; @@ -76,11 +75,14 @@ export function ExperimentList() { ); } - const visit = visitTextToVisit(instrumentSession); + const visit = visitTextToVisit(instrumentSession ?? "cm0-0"); const { data, loading, error } = useQuery(GET_EXPERIMENTS, { skip: !visit, - variables: { proposal: visit?.proposalNumber ?? 0, session: visit?.number ?? 0 }, + variables: { + proposal: visit?.proposalNumber ?? 0, + session: visit?.number ?? 0, + }, fetchPolicy: "cache-and-network", context: { pathname: location.pathname }, }); @@ -162,9 +164,9 @@ export function ExperimentList() { }, muiToolbarAlertBannerProps: error ? { - color: "error", - children: `Error: ${error.message}`, - } + color: "error", + children: `Error: ${error.message}`, + } : undefined, }); diff --git a/apps/i15-1/src/components/getInstrumentSessionButton.tsx b/apps/i15-1/src/components/getInstrumentSessionButton.tsx new file mode 100644 index 00000000..7fbdf59a --- /dev/null +++ b/apps/i15-1/src/components/getInstrumentSessionButton.tsx @@ -0,0 +1,49 @@ +import { useLazyQuery } from "@apollo/client/react"; +import { getInstrumentSessionsQuery } from "../graphql/getInstrumentSessionsQuery.ts"; +import type { TypedDocumentNode } from "@apollo/client"; +import type { + InstrumentSessionQuery, + InstrumentSessionQueryVariables, +} from "../graphql/getInstrumentSessionsQuery.generated.ts"; +import { useInstrumentSession } from "@atlas/app-shell"; +import { Button } from "@mui/material"; + +export const InstrumentSessionButton = () => { + const { setInstrumentSession, setInstrumentSessionList } = + useInstrumentSession(); + + const GET_SESSIONS: TypedDocumentNode< + InstrumentSessionQuery, + InstrumentSessionQueryVariables + > = getInstrumentSessionsQuery; + + const [fetchSessions] = useLazyQuery(GET_SESSIONS); + + const handleButtonClick = async () => { + try { + const { data } = await fetchSessions({ + variables: { instrumentKey: "I15-1" }, + }); + + const edges = data?.instrumentByKey?.instrumentSessions?.edges; + if (edges && edges.length > 0) { + const sessionsList = edges.flatMap((edge) => { + const ref = edge?.node?.instrumentSessionReference; + return ref ? [ref.toLocaleLowerCase()] : []; + }); + setInstrumentSessionList(sessionsList); + if (sessionsList.length == 1) { + setInstrumentSession(sessionsList[0]); + } + } + } catch (err) { + console.error("Failed to fetch sessions:", err); + } + }; + + return ( + + ); +}; diff --git a/apps/i15-1/src/graphql/getInstrumentSessionsQuery.generated.ts b/apps/i15-1/src/graphql/getInstrumentSessionsQuery.generated.ts new file mode 100644 index 00000000..23a7e74b --- /dev/null +++ b/apps/i15-1/src/graphql/getInstrumentSessionsQuery.generated.ts @@ -0,0 +1,10 @@ +/** Internal type. DO NOT USE DIRECTLY. */ +type Exact = { [K in keyof T]: T[K] }; +/** Internal type. DO NOT USE DIRECTLY. */ +export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type InstrumentSessionQueryVariables = Exact<{ + instrumentKey: string; +}>; + + +export type InstrumentSessionQuery = { instrumentByKey: { __typename: 'Instrument', instrumentSessions: { __typename: 'InstrumentSessionConnection', edges: Array<{ __typename: 'InstrumentSessionEdge', node: { __typename: 'InstrumentSession', instrumentSessionReference: string | null } }> } } | null }; diff --git a/apps/i15-1/src/graphql/getInstrumentSessionsQuery.ts b/apps/i15-1/src/graphql/getInstrumentSessionsQuery.ts new file mode 100644 index 00000000..aa401a8c --- /dev/null +++ b/apps/i15-1/src/graphql/getInstrumentSessionsQuery.ts @@ -0,0 +1,15 @@ +import { gql } from "@apollo/client"; + +export const getInstrumentSessionsQuery = gql` + query InstrumentSession($instrumentKey: String!) { + instrumentByKey(key: $instrumentKey) { + instrumentSessions(filterBy: { state: { eq: IN_PROGRESS } }) { + edges { + node { + instrumentSessionReference + } + } + } + } + } +`; diff --git a/apps/i15-1/src/mocks/handlers.ts b/apps/i15-1/src/mocks/handlers.ts index 09f5e5e1..fcf89a32 100644 --- a/apps/i15-1/src/mocks/handlers.ts +++ b/apps/i15-1/src/mocks/handlers.ts @@ -167,6 +167,22 @@ const fakeContainersForInstrument: { }, }; +const fakeInstrumentSession = { + data: { + instrumentByKey: { + instrumentSessions: { + edges: [ + { + node: { + instrumentSessionReference: "CM44163-4", + }, + }, + ], + }, + }, + }, +}; + function setWorkerState(new_state: string) { workerStatus.status = new_state; } @@ -753,6 +769,10 @@ export const handlers = [ } } + if (body.operationName === "InstrumentSession") { + return HttpResponse.json(fakeInstrumentSession); + } + return HttpResponse.json(fakeExperiments); }), diff --git a/apps/i15-1/src/routes/Dashboard.tsx b/apps/i15-1/src/routes/Dashboard.tsx index fca281af..62f5d994 100644 --- a/apps/i15-1/src/routes/Dashboard.tsx +++ b/apps/i15-1/src/routes/Dashboard.tsx @@ -4,12 +4,14 @@ import PrecisionManufacturingIcon from "@mui/icons-material/PrecisionManufacturi import QueueIcon from "@mui/icons-material/Queue"; import { useUserAuth } from "../context/userAuth/useUserAuth.ts"; import { User } from "@diamondlightsource/sci-react-ui"; +import { InstrumentSessionButton } from "../components/getInstrumentSessionButton.tsx"; function Dashboard() { const user = useUserAuth(); const handleLogIn = () => window.location.assign("/oauth2/sign_in"); const handleLogOut = () => window.location.assign("/oauth2/sign_out"); + return ( <> @@ -26,6 +28,7 @@ function Dashboard() { : { fedid: user.person } } /> + + + + ); + } else if ( + instrumentSessionList && + instrumentSessionList.length == 1 && + !instrumentSession + ) { + return ( +
+ +
+ ); + } else if (menuDisabled && instrumentSession) { return (
Available Sessions - {sessionsList.map((option, index) => ( + {instrumentSessionList?.map((option, index) => (