From 31ea15132dd3d60a69c4b48da67ca0180b7f9850 Mon Sep 17 00:00:00 2001 From: Tamoor Shahid Date: Fri, 24 Oct 2025 11:43:21 +0100 Subject: [PATCH 1/5] Moved useContainerDimensions into separate file --- src/components/OavVideoStream.tsx | 25 +------------------------ src/components/OavVideoStreamHelper.tsx | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 24 deletions(-) create mode 100644 src/components/OavVideoStreamHelper.tsx diff --git a/src/components/OavVideoStream.tsx b/src/components/OavVideoStream.tsx index 904fa33..133d434 100644 --- a/src/components/OavVideoStream.tsx +++ b/src/components/OavVideoStream.tsx @@ -7,30 +7,7 @@ import { useParsedPvConnection, } from "../pv/util"; import React from "react"; - -export const useContainerDimensions = ( - ref: React.MutableRefObject -) => { - 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) diff --git a/src/components/OavVideoStreamHelper.tsx b/src/components/OavVideoStreamHelper.tsx new file mode 100644 index 0000000..0d55099 --- /dev/null +++ b/src/components/OavVideoStreamHelper.tsx @@ -0,0 +1,25 @@ +import { useState, useEffect } from "react"; + +export const useContainerDimensions = ( + ref: React.MutableRefObject +) => { + 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; +}; From 327736e13507e9a03ace4063454d2d540b269e61 Mon Sep 17 00:00:00 2001 From: Tamoor Shahid Date: Fri, 24 Oct 2025 11:47:30 +0100 Subject: [PATCH 2/5] Blueapi Helpers moved to separate file --- src/blueapi/BlueapiComponents.tsx | 41 ++----------------------------- src/blueapi/BlueapiHelpers.tsx | 39 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 39 deletions(-) create mode 100644 src/blueapi/BlueapiHelpers.tsx diff --git a/src/blueapi/BlueapiComponents.tsx b/src/blueapi/BlueapiComponents.tsx index 864e5a7..4012be2 100644 --- a/src/blueapi/BlueapiComponents.tsx +++ b/src/blueapi/BlueapiComponents.tsx @@ -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"; @@ -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(false); const [msg, setMsg] = React.useState("Running plan..."); @@ -203,3 +165,4 @@ export function AbortButton() { ); } +export { parseInstrumentSession, readVisitFromPv }; diff --git a/src/blueapi/BlueapiHelpers.tsx b/src/blueapi/BlueapiHelpers.tsx new file mode 100644 index 0000000..a099add --- /dev/null +++ b/src/blueapi/BlueapiHelpers.tsx @@ -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; +} From a88d6278a7895ea63997d4e083618c5d942a3997 Mon Sep 17 00:00:00 2001 From: Tamoor Shahid Date: Mon, 27 Oct 2025 15:15:23 +0000 Subject: [PATCH 3/5] Changed helper.tsx to .ts --- src/blueapi/{BlueapiHelpers.tsx => BlueapiHelpers.ts} | 0 .../{OavVideoStreamHelper.tsx => OavVideoStreamHelper.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/blueapi/{BlueapiHelpers.tsx => BlueapiHelpers.ts} (100%) rename src/components/{OavVideoStreamHelper.tsx => OavVideoStreamHelper.ts} (100%) diff --git a/src/blueapi/BlueapiHelpers.tsx b/src/blueapi/BlueapiHelpers.ts similarity index 100% rename from src/blueapi/BlueapiHelpers.tsx rename to src/blueapi/BlueapiHelpers.ts diff --git a/src/components/OavVideoStreamHelper.tsx b/src/components/OavVideoStreamHelper.ts similarity index 100% rename from src/components/OavVideoStreamHelper.tsx rename to src/components/OavVideoStreamHelper.ts From aa00f06b81cf4842dc96b33e55f9753840764803 Mon Sep 17 00:00:00 2001 From: Tamoor Shahid Date: Mon, 27 Oct 2025 15:22:46 +0000 Subject: [PATCH 4/5] Prettier fix --- src/blueapi/BlueapiHelpers.ts | 2 +- src/components/OavVideoStreamHelper.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/blueapi/BlueapiHelpers.ts b/src/blueapi/BlueapiHelpers.ts index a099add..ff96356 100644 --- a/src/blueapi/BlueapiHelpers.ts +++ b/src/blueapi/BlueapiHelpers.ts @@ -31,7 +31,7 @@ export function parseInstrumentSession(visit: string): string { 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" + "Unable to run plan as something appears to be wrong with visit path", ); } } diff --git a/src/components/OavVideoStreamHelper.ts b/src/components/OavVideoStreamHelper.ts index 0d55099..284d5dc 100644 --- a/src/components/OavVideoStreamHelper.ts +++ b/src/components/OavVideoStreamHelper.ts @@ -1,7 +1,7 @@ import { useState, useEffect } from "react"; export const useContainerDimensions = ( - ref: React.MutableRefObject + ref: React.MutableRefObject, ) => { const [dimensions, setDimensions] = useState({ width: 0, height: 0 }); useEffect(() => { From 6c75526f4d3313d38ea9b44c758ad5d42d76572c Mon Sep 17 00:00:00 2001 From: Tamoor Shahid Date: Tue, 28 Oct 2025 13:56:36 +0000 Subject: [PATCH 5/5] Fixed PR --- src/blueapi/BlueapiComponents.tsx | 3 +-- src/blueapi/BlueapiHelpers.ts | 39 ------------------------------- 2 files changed, 1 insertion(+), 41 deletions(-) delete mode 100644 src/blueapi/BlueapiHelpers.ts diff --git a/src/blueapi/BlueapiComponents.tsx b/src/blueapi/BlueapiComponents.tsx index d948cb1..f29b330 100644 --- a/src/blueapi/BlueapiComponents.tsx +++ b/src/blueapi/BlueapiComponents.tsx @@ -8,7 +8,7 @@ import { Tooltip, Typography, } from "@mui/material"; -import { parseInstrumentSession, readVisitFromPv } from "./BlueapiHelpers"; +import { parseInstrumentSession, readVisitFromPv } from "./visit"; type SeverityLevel = "success" | "info" | "warning" | "error"; type VariantChoice = "outlined" | "contained"; @@ -165,4 +165,3 @@ export function AbortButton() { ); } -export { parseInstrumentSession, readVisitFromPv }; diff --git a/src/blueapi/BlueapiHelpers.ts b/src/blueapi/BlueapiHelpers.ts deleted file mode 100644 index ff96356..0000000 --- a/src/blueapi/BlueapiHelpers.ts +++ /dev/null @@ -1,39 +0,0 @@ -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; -}