Skip to content

Commit cd33411

Browse files
committed
A first version with plenty of typing and uncaught error annoyances
1 parent 1ae9295 commit cd33411

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/blueapi/BlueapiComponents.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

1314
type SeverityLevel = "success" | "info" | "warning" | "error";
1415
type 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+
3962
export 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(

src/pv/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function pvIntArrayToString(value: RawValue): string {
5959
}
6060
}
6161

62-
function ReadPvRawValue(props: PvDescription): RawValue {
62+
export function ReadPvRawValue(props: PvDescription): RawValue {
6363
const [_effectivePvName, connected, _readonly, latestValue] = useConnection(
6464
props.label,
6565
props.pv

0 commit comments

Comments
 (0)