@@ -5,10 +5,11 @@ import {
55 Button ,
66 Snackbar ,
77 SnackbarCloseReason ,
8- styled ,
98 Tooltip ,
109 Typography ,
1110} from "@mui/material" ;
11+ import { ReadPvRawValue } from "../pv/util" ;
12+ import { RawValue } from "../pv/types" ;
1213
1314type SeverityLevel = "success" | "info" | "warning" | "error" ;
1415type VariantChoice = "outlined" | "contained" ;
@@ -36,11 +37,35 @@ type RunPlanButtonProps = {
3637// This will be another PR
3738// See https://github.com/DiamondLightSource/mx-daq-ui/issues/71
3839
40+ function readInstrumentSessionFromVisitPv ( ) : string {
41+ const fullVisitPath : RawValue = ReadPvRawValue ( {
42+ label : "visit" ,
43+ pv : "ca://ME14E-MO-IOC-01:GP100" ,
44+ } ) ;
45+ let visitString : string ;
46+ if ( fullVisitPath === "not connected" || ! fullVisitPath ) {
47+ const msg : string =
48+ "Unable to run plan as instrument session not set. Please check visit PV." ;
49+ console . log ( msg ) ;
50+ // throw new Error(msg);
51+ } else {
52+ visitString = fullVisitPath . toString ( ) ;
53+ }
54+ const instrumentSession = visitString . toString ( ) . split ( "/" ) . at ( - 1 ) ;
55+ if ( ! instrumentSession ) {
56+ console . log ( "Something seems to be wrong with visit path" ) ;
57+ // throw new Error("Something seems to be wrong with visit path");
58+ }
59+ return instrumentSession ;
60+ }
61+
3962export function RunPlanButton ( props : RunPlanButtonProps ) {
4063 const [ openSnackbar , setOpenSnackbar ] = React . useState < boolean > ( false ) ;
4164 const [ msg , setMsg ] = React . useState < string > ( "Running plan..." ) ;
4265 const [ severity , setSeverity ] = React . useState < SeverityLevel > ( "info" ) ;
4366
67+ const instrumentSession = readInstrumentSessionFromVisitPv ( ) ;
68+
4469 const params = props . planParams ? props . planParams : { } ;
4570 const variant = props . btnVariant ? props . btnVariant : "outlined" ;
4671 const size = props . btnSize ? props . btnSize : "medium" ;
@@ -50,6 +75,7 @@ export function RunPlanButton(props: RunPlanButtonProps) {
5075 submitAndRunPlanImmediately ( {
5176 planName : props . planName ,
5277 planParams : params ,
78+ instrumentSession : instrumentSession ,
5379 } ) . catch ( ( error ) => {
5480 setSeverity ( "error" ) ;
5581 setMsg (
0 commit comments