From b902bebf071bba88833d090189debed007b69f9b Mon Sep 17 00:00:00 2001 From: Jessica V Date: Thu, 4 Jun 2026 17:35:58 +0100 Subject: [PATCH 1/4] Add types --- frontend/i14/src/types/APIresponse.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 frontend/i14/src/types/APIresponse.ts diff --git a/frontend/i14/src/types/APIresponse.ts b/frontend/i14/src/types/APIresponse.ts new file mode 100644 index 00000000..bf0ec35b --- /dev/null +++ b/frontend/i14/src/types/APIresponse.ts @@ -0,0 +1,24 @@ +type ProposalCategory = "mg" | "cm" | "nt" | "nr" | "jm" | "bi" | "si"; + +interface InstrumentSession { + startTime: string; + endTime: string; + instrumentSessionNumber: number; +} + +interface Proposal { + proposalNumber: number; + proposalCategory: ProposalCategory; + title: string; + instrumentSessions: InstrumentSession[]; +} + +export type ApiVisitSchema = { + data: { + account: { + proposalRoles: { + proposal: Proposal; + }[]; + }; + }; +}; From 79110eba6c32722bbe58aed67efaf5da6c1d9f59 Mon Sep 17 00:00:00 2001 From: Jessica V Date: Thu, 4 Jun 2026 17:53:05 +0100 Subject: [PATCH 2/4] Update WorkflowForm --- .../src/components/workflows/WorkflowForm.tsx | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/frontend/i14/src/components/workflows/WorkflowForm.tsx b/frontend/i14/src/components/workflows/WorkflowForm.tsx index 90c20cc5..fb95dbff 100644 --- a/frontend/i14/src/components/workflows/WorkflowForm.tsx +++ b/frontend/i14/src/components/workflows/WorkflowForm.tsx @@ -9,11 +9,12 @@ import { Stack, Typography, } from "@mui/material"; -import { visitRegex } from "@diamondlightsource/sci-react-ui"; import { initialData } from "../../data/form"; -import { templateOptions } from "../../data/templates"; import OptionSelect from "./OptionSelect"; +import { dataToOptions } from "../../api/services"; +import { templateOptions } from "../../data/templates"; +import visitArray from "../../data/visits.json"; import type { WorkflowFormData, Option } from "../../types/workflowFields"; @@ -23,18 +24,18 @@ export const WorkflowForm: FC = () => { const getFilteredTemplates = (toggle: ToggleGroup): Option[] => { return (templateOptions ?? []).filter((o) => o.value.includes(toggle)); }; + const visitOptions: Option[] = useMemo(() => dataToOptions(visitArray), []); const [data, setData] = useState(() => { const defaultTechnique = techniques.find((t) => initialData.template.includes(t)) ?? techniques[0]; return { ...initialData, + visit: visitOptions[0]?.value ?? initialData.visit, technique: defaultTechnique, }; }); - const visitMatch = visitRegex.exec(data.visit); - const filteredTemplateOptions: Option[] = getFilteredTemplates( data.technique ); @@ -93,21 +94,13 @@ export const WorkflowForm: FC = () => { setData((prev) => ({ ...prev, template: e.target.value })) } /> - - ) => { - const value = e.target.value; - setData((prev) => ({ ...prev, visit: value })); - }} - helperText={visitMatch ? "" : "Expected format: xx12345-1"} - error={!visitMatch} + options={visitOptions} + onChange={(e) => + setData((prev) => ({ ...prev, visit: e.target.value })) + } /> { }} /> - From 0a312f314b669c6382214a7a01a2d538aecbb555 Mon Sep 17 00:00:00 2001 From: Jessica V Date: Fri, 5 Jun 2026 04:53:31 +0100 Subject: [PATCH 3/4] Separate api processing --- frontend/i14/src/api/services.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 frontend/i14/src/api/services.ts diff --git a/frontend/i14/src/api/services.ts b/frontend/i14/src/api/services.ts new file mode 100644 index 00000000..62442381 --- /dev/null +++ b/frontend/i14/src/api/services.ts @@ -0,0 +1,29 @@ +import type { ApiVisitSchema, Proposal } from "../../types/APIresponse"; +import type { Option } from "../../types/workflowFields"; + +const formatDate = (d: Date): string => + `${d.toLocaleString("en-GB", { month: "long" })} ${d.getFullYear()}`; + +const makeVisitId = (proposal: Proposal, sessionNumber: number): string => + `${String(proposal.proposalCategory).toLowerCase()}${proposal.proposalNumber}-${sessionNumber}`; + +const makeLabel = ( + proposal: Proposal, + sessionNumber: number, + d: string +): string => { + const visit = makeVisitId(proposal, sessionNumber); + const date = formatDate(new Date(d)); + return `${visit} - ${date}`; +}; + +export const dataToOptions = (d: ApiVisitSchema): Option[] => + d.visitArray.account.proposalRoles?.flatMap((r) => + (r.proposal?.instrumentSessions ?? []) + .filter((s) => s?.startTime) + .map((s) => ({ + desc: r.proposal?.title ?? "", + label: makeLabel(r.proposal, s.instrumentSessionNumber, s.startTime), + value: makeVisitId(r.proposal, s.instrumentSessionNumber), + })) + ) ?? []; From cf8d076820251b844251de3d52fca1316fcf6032 Mon Sep 17 00:00:00 2001 From: Jessica V Date: Fri, 5 Jun 2026 06:35:21 +0100 Subject: [PATCH 4/4] Reorder visit options and filter to most recent five --- frontend/i14/src/api/services.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/frontend/i14/src/api/services.ts b/frontend/i14/src/api/services.ts index 62442381..15143fbc 100644 --- a/frontend/i14/src/api/services.ts +++ b/frontend/i14/src/api/services.ts @@ -18,12 +18,18 @@ const makeLabel = ( }; export const dataToOptions = (d: ApiVisitSchema): Option[] => - d.visitArray.account.proposalRoles?.flatMap((r) => - (r.proposal?.instrumentSessions ?? []) - .filter((s) => s?.startTime) - .map((s) => ({ - desc: r.proposal?.title ?? "", - label: makeLabel(r.proposal, s.instrumentSessionNumber, s.startTime), - value: makeVisitId(r.proposal, s.instrumentSessionNumber), - })) - ) ?? []; + d.visitArray.account.proposalRoles + ?.flatMap((r) => + (r.proposal?.instrumentSessions ?? []) + .filter((s) => s?.startTime) + .map((s) => ({ + desc: r.proposal?.title ?? "", + label: makeLabel(r.proposal, s.instrumentSessionNumber, s.startTime), + value: makeVisitId(r.proposal, s.instrumentSessionNumber), + _ts: Date.parse(s.startTime), + })) + ) + .filter((o) => !Number.isNaN(o._ts)) + .sort((a, b) => b._ts - a._ts) + .slice(0, 5) + .map(({ _ts, ...rest }) => rest);