Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion src/blueapi/BlueapiComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Tooltip,
Typography,
} from "@mui/material";
import { parseInstrumentSession, readVisitFromPv } from "./visit";
import { parseInstrumentSession, readVisitFromPv } from "./BlueapiHelpers";

type SeverityLevel = "success" | "info" | "warning" | "error";
type VariantChoice = "outlined" | "contained";
Expand Down Expand Up @@ -165,3 +165,4 @@
</div>
);
}
export { parseInstrumentSession, readVisitFromPv };

Check warning on line 168 in src/blueapi/BlueapiComponents.tsx

View workflow job for this annotation

GitHub Actions / lint / lint

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components

Check warning on line 168 in src/blueapi/BlueapiComponents.tsx

View workflow job for this annotation

GitHub Actions / lint / lint

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components

Check warning on line 168 in src/blueapi/BlueapiComponents.tsx

View workflow job for this annotation

GitHub Actions / lint / lint

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components

Check warning on line 168 in src/blueapi/BlueapiComponents.tsx

View workflow job for this annotation

GitHub Actions / lint / lint

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components
39 changes: 39 additions & 0 deletions src/blueapi/BlueapiHelpers.ts
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.ts
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;
};