Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 2 additions & 39 deletions src/blueapi/BlueapiComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
Tooltip,
Typography,
} from "@mui/material";
import { forceString, ReadPvRawValue } from "../pv/util";
import { RawValue } from "../pv/types";
import { parseInstrumentSession, readVisitFromPv } from "./BlueapiHelpers";

type SeverityLevel = "success" | "info" | "warning" | "error";
type VariantChoice = "outlined" | "contained";
Expand Down Expand Up @@ -37,43 +36,6 @@ type RunPlanButtonProps = {
// This will be another PR
// See https://github.com/DiamondLightSource/mx-daq-ui/issues/71

/**
* Read the full visit path from the visit PV set by the beamline staff.
* @returns {string} the full visit pV /dls/i24/data/{year}/{visit}
*/
export function readVisitFromPv(): string {
const fullVisitPath: RawValue = ReadPvRawValue({
label: "visit",
pv: "ca://BL24I-MO-IOC-13:GP100",
});
const visitString: string = forceString(fullVisitPath);
return visitString;
}

/**
* Parse the full visit path and return only the instrument session.
* An error will be raised if the instrument session value is undefined or
* if the PV is not connected.
* @param {string} visit The full visit path
* @returns {string} Only the instrument session part of the visit path
*/
export function parseInstrumentSession(visit: string): string {
let instrumentSession: string | undefined;
if (visit === "not connected" || visit === "undefined") {
const msg =
"Unable to run plan as instrument session not set. Please check visit PV.";
throw new Error(msg);
} else {
instrumentSession = visit.split("/").filter(Boolean).at(-1);
if (!instrumentSession) {
throw new Error(
"Unable to run plan as something appears to be wrong with visit path"
);
}
}
return instrumentSession;
}

export function RunPlanButton(props: RunPlanButtonProps) {
const [openSnackbar, setOpenSnackbar] = React.useState<boolean>(false);
const [msg, setMsg] = React.useState<string>("Running plan...");
Expand Down Expand Up @@ -203,3 +165,4 @@ export function AbortButton() {
</div>
);
}
export { parseInstrumentSession, readVisitFromPv };
39 changes: 39 additions & 0 deletions src/blueapi/BlueapiHelpers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { RawValue } from "../pv/types";
import { forceString, ReadPvRawValue } from "../pv/util";

/**
* Read the full visit path from the visit PV set by the beamline staff.
* @returns {string} the full visit pV /dls/i24/data/{year}/{visit}
*/
export function readVisitFromPv(): string {
const fullVisitPath: RawValue = ReadPvRawValue({
label: "visit",
pv: "ca://BL24I-MO-IOC-13:GP100",
});
const visitString: string = forceString(fullVisitPath);
return visitString;
}

/**
* Parse the full visit path and return only the instrument session.
* An error will be raised if the instrument session value is undefined or
* if the PV is not connected.
* @param {string} visit The full visit path
* @returns {string} Only the instrument session part of the visit path
*/
export function parseInstrumentSession(visit: string): string {
let instrumentSession: string | undefined;
if (visit === "not connected" || visit === "undefined") {
const msg =
"Unable to run plan as instrument session not set. Please check visit PV.";
throw new Error(msg);
} else {
instrumentSession = visit.split("/").filter(Boolean).at(-1);
if (!instrumentSession) {
throw new Error(
"Unable to run plan as something appears to be wrong with visit path"
);
}
}
return instrumentSession;
}
25 changes: 1 addition & 24 deletions src/components/OavVideoStream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,7 @@ import {
useParsedPvConnection,
} from "../pv/util";
import React from "react";

export const useContainerDimensions = (
ref: React.MutableRefObject<HTMLHeadingElement | null>
) => {
const [dimensions, setDimensions] = React.useState({ width: 0, height: 0 });
React.useEffect(() => {
const getDimensions = () => ({
width: ref.current?.offsetWidth || 0,
height: ref.current?.offsetWidth || 0,
});
const handleResize = () => {
setDimensions(getDimensions());
};
if (ref.current) {
setDimensions(getDimensions());
}
window.addEventListener("resize", handleResize);
return () => {
window.removeEventListener("resize", handleResize);
};
}, [ref]);

return dimensions;
};
import { useContainerDimensions } from "./OavVideoStreamHelper";

/*
* A viewer which allows overlaying a crosshair (takes numbers which could be the values from a react useState hook)
Expand Down
25 changes: 25 additions & 0 deletions src/components/OavVideoStreamHelper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useState, useEffect } from "react";

export const useContainerDimensions = (
ref: React.MutableRefObject<HTMLHeadingElement | null>
) => {
const [dimensions, setDimensions] = useState({ width: 0, height: 0 });
useEffect(() => {
const getDimensions = () => ({
width: ref.current?.offsetWidth || 0,
height: ref.current?.offsetWidth || 0,
});
const handleResize = () => {
setDimensions(getDimensions());
};
if (ref.current) {
setDimensions(getDimensions());
}
window.addEventListener("resize", handleResize);
return () => {
window.removeEventListener("resize", handleResize);
};
}, [ref]);

return dimensions;
};