Skip to content

Commit 87467d6

Browse files
authored
Merge pull request #28 from DiamondLightSource/add_jsonmap_macros_on_screenload
Add JsonMap macros on navigation between screens
2 parents a68efe2 + 73ea727 commit 87467d6

File tree

8 files changed

+474
-139
lines changed

8 files changed

+474
-139
lines changed

Dockerfile

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,7 @@ COPY *.json ./
1919
RUN npm run build:nolint
2020

2121
# Create image for deployment
22-
FROM nginxinc/nginx-unprivileged:stable AS deployment
23-
24-
25-
# Update package lists and upgrade libpng1.6 (libpng16-16 runtime)
26-
# to fix a security vulnerability (CVE-2025-64720)
27-
USER root
28-
ENV DEBIAN_FRONTEND=noninteractive
29-
30-
RUN set -eux; \
31-
apt-get update; \
32-
apt-get install -y --no-install-recommends libpng16-16=1.6.39-2+deb12u1; \
33-
rm -rf /var/lib/apt/lists/*
22+
FROM nginxinc/nginx-unprivileged:1.29-alpine AS deployment
3423

3524
USER nginx
3625
COPY nginx.conf /etc/nginx/nginx.conf

src/components/BeamlineSelect.tsx

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { MenuItem as MuiMenuItem, styled } from "@mui/material";
33
import FormControl from "@mui/material/FormControl";
44
import Select, { SelectChangeEvent } from "@mui/material/Select";
55
import { useContext } from "react";
6-
import { FileContext, executeAction } from "@diamondlightsource/cs-web-lib";
6+
import { FileContext } from "@diamondlightsource/cs-web-lib";
77
import { CHANGE_BEAMLINE } from "../store";
88
import { Tooltip } from "@mui/material";
99
import { BeamlineTreeStateContext } from "../App";
10-
import { buildUrl } from "../utils/urlUtils";
10+
import { executeOpenPageActionWithFileGuid } from "../utils/csWebLibActions";
1111

1212
const MenuItem = styled(MuiMenuItem)({
1313
"&.Mui-disabled": {
@@ -24,28 +24,14 @@ export default function BeamlineSelect() {
2424
type: CHANGE_BEAMLINE,
2525
payload: { beamline: event.target.value }
2626
});
27-
// Load the toplevel screen for the beamline on click
28-
executeAction(
29-
{
30-
type: "OPEN_PAGE",
31-
dynamicInfo: {
32-
name: state.beamlines[event.target.value].topLevelScreen,
33-
location: "main",
34-
description: undefined,
35-
file: {
36-
path: buildUrl(
37-
state.beamlines[event.target.value].host,
38-
state.beamlines[event.target.value].topLevelScreen
39-
),
40-
macros: {},
41-
defaultProtocol: "ca"
42-
}
43-
}
44-
},
45-
fileContext,
46-
undefined,
47-
{},
48-
`/synoptic/${event.target.value}`
27+
28+
const beamlineState = state.beamlines[event.target.value];
29+
30+
executeOpenPageActionWithFileGuid(
31+
beamlineState,
32+
beamlineState.topLevelScreen,
33+
event.target.value,
34+
fileContext
4935
);
5036
};
5137

src/components/ScreenTreeView.tsx

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { RichTreeView } from "@mui/x-tree-view/RichTreeView";
22
import { useContext, useEffect, useMemo, useState } from "react";
33
import { TreeViewBaseItem, TreeViewItemId } from "@mui/x-tree-view";
4-
import { executeAction, FileContext } from "@diamondlightsource/cs-web-lib";
4+
import { FileContext } from "@diamondlightsource/cs-web-lib";
55
import { BeamlineTreeStateContext } from "../App";
66
import { MenuContext } from "../routes/MainPage";
7-
import { buildUrl } from "../utils/urlUtils";
7+
import { executeOpenPageActionWithFileGuid } from "../utils/csWebLibActions";
88

99
export default function ScreenTreeView() {
1010
const { state } = useContext(BeamlineTreeStateContext);
@@ -17,31 +17,14 @@ export default function ScreenTreeView() {
1717
};
1818

1919
const handleClick = (itemId: string) => {
20-
const fileMetadata =
21-
state.beamlines[state.currentBeamline].filePathIds[itemId];
22-
const newScreen = buildUrl(
23-
state.beamlines[state.currentBeamline].host,
24-
fileMetadata.file
25-
);
20+
const selectedBeamlineId = state.currentBeamline;
21+
const beamlineState = state.beamlines[selectedBeamlineId];
2622

27-
executeAction(
28-
{
29-
type: "OPEN_PAGE",
30-
dynamicInfo: {
31-
name: newScreen,
32-
location: "main",
33-
description: undefined,
34-
file: {
35-
path: newScreen,
36-
macros: {},
37-
defaultProtocol: "ca"
38-
}
39-
}
40-
},
41-
fileContext,
42-
undefined,
43-
{},
44-
`/synoptic/${state.currentBeamline}/${state.beamlines[state.currentBeamline].filePathIds[itemId].urlId}`
23+
executeOpenPageActionWithFileGuid(
24+
beamlineState,
25+
itemId,
26+
selectedBeamlineId,
27+
fileContext
4528
);
4629
};
4730

src/components/SynopticBreadcrumbs.tsx

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import Typography from "@mui/material/Typography";
22
import NavigateNextIcon from "@mui/icons-material/NavigateNext";
33
import { ReactNode, useContext } from "react";
44
import { Breadcrumbs, Link } from "@mui/material";
5-
import { executeAction, FileContext } from "@diamondlightsource/cs-web-lib";
5+
import { FileContext } from "@diamondlightsource/cs-web-lib";
66
import { BeamlineStateProperties } from "../store";
77
import { BeamlineTreeStateContext } from "../App";
8-
import { buildUrl } from "../utils/urlUtils";
8+
import { executeOpenPageActionWithUrlId } from "../utils/csWebLibActions";
99

1010
export const SynopticBreadcrumbs = () => {
1111
const { state } = useContext(BeamlineTreeStateContext);
@@ -18,7 +18,11 @@ export const SynopticBreadcrumbs = () => {
1818

1919
return (
2020
<Breadcrumbs
21-
onClick={handleClick(state.beamlines[state.currentBeamline], fileContext)}
21+
onClick={handleClick(
22+
state.currentBeamline,
23+
state.beamlines[state.currentBeamline],
24+
fileContext
25+
)}
2226
separator={<NavigateNextIcon fontSize="small" />}
2327
aria-label="breadcrumb"
2428
sx={{
@@ -37,37 +41,23 @@ export const SynopticBreadcrumbs = () => {
3741
};
3842

3943
const handleClick =
40-
(currentBeamlineState: BeamlineStateProperties, fileContext: any) =>
44+
(
45+
selectedBeamlineId: string,
46+
beamlineState: BeamlineStateProperties,
47+
fileContext: any
48+
) =>
4149
(event: any) => {
4250
if (event.target.pathname) {
4351
event.preventDefault();
4452
const urlId = decodeURI(event.target.pathname)
4553
.split("/")
4654
.at(-1) as string;
4755

48-
const fileMetadata = Object.values(currentBeamlineState.filePathIds).find(
49-
x => x.urlId === urlId
50-
);
51-
const newScreen = buildUrl(currentBeamlineState.host, fileMetadata?.file);
52-
53-
executeAction(
54-
{
55-
type: "OPEN_PAGE",
56-
dynamicInfo: {
57-
name: newScreen,
58-
location: "main",
59-
description: undefined,
60-
file: {
61-
path: newScreen,
62-
macros: {},
63-
defaultProtocol: "ca"
64-
}
65-
}
66-
},
67-
fileContext,
68-
undefined,
69-
{},
70-
event.target.pathname
56+
executeOpenPageActionWithUrlId(
57+
beamlineState,
58+
urlId,
59+
selectedBeamlineId,
60+
fileContext
7161
);
7262
}
7363
};

src/routes/EditorPage.tsx

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import {
88
reducer
99
} from "../store";
1010
import { parseScreenTree } from "../utils/parser";
11-
import { executeAction, FileContext } from "@diamondlightsource/cs-web-lib";
11+
import { FileContext } from "@diamondlightsource/cs-web-lib";
1212
import Editor from "../components/Editor";
1313
import { useParams } from "react-router-dom";
14-
import { buildUrl } from "../utils/urlUtils";
14+
import { executeOpenPageActionWithUrlId } from "../utils/csWebLibActions";
1515

1616
/**
1717
* Displays a mock editor page with palette and Phoebus
@@ -59,29 +59,14 @@ export function EditorPage() {
5959
loadScreen: params.screenUrlId
6060
}
6161
});
62-
if (params.beamline) {
62+
if (params.beamline && params.screenUrlId) {
6363
// If we navigated directly to a beamline and/or screen, load in display
64-
const newBeamlineState = newBeamlines[params.beamline];
65-
const newScreen = params.screenUrlId
66-
? newBeamlineState.filePathIds[params.screenUrlId].file
67-
: buildUrl(newBeamlineState.host, newBeamlineState.topLevelScreen);
68-
executeAction(
69-
{
70-
type: "OPEN_PAGE",
71-
dynamicInfo: {
72-
name: newScreen,
73-
location: "main",
74-
description: undefined,
75-
file: {
76-
path: newScreen,
77-
macros: {},
78-
defaultProtocol: "ca"
79-
}
80-
}
81-
},
82-
fileContext,
83-
undefined,
84-
{}
64+
const beamlineState = newBeamlines[params.beamline];
65+
executeOpenPageActionWithUrlId(
66+
beamlineState,
67+
params.screenUrlId,
68+
params.beamline,
69+
fileContext
8570
);
8671
}
8772
}, []);

src/routes/MainPage.tsx

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import { CHANGE_BEAMLINE, CHANGE_SCREEN, LOAD_SCREENS } from "../store";
1111
import DLSAppBar from "../components/AppBar";
1212
import ScreenDisplay from "../components/ScreenDisplay";
1313
import { parseScreenTree } from "../utils/parser";
14-
import { executeAction, FileContext } from "@diamondlightsource/cs-web-lib";
14+
import { FileContext } from "@diamondlightsource/cs-web-lib";
1515
import { RotatingLines } from "react-loader-spinner";
1616
import { SynopticBreadcrumbs } from "../components/SynopticBreadcrumbs";
1717
import { BeamlineTreeStateContext } from "../App";
1818
import { useParams } from "react-router-dom";
1919
import { buildUrl } from "../utils/urlUtils";
20+
import { executeOpenPageActionWithUrlId } from "../utils/csWebLibActions";
2021

2122
export const MenuContext = createContext<{
2223
menuOpen: boolean;
@@ -79,32 +80,12 @@ export function MainPage() {
7980
if (params.beamline) {
8081
// If we navigated directly to a beamline and/or screen, load in display
8182
const newBeamlineState = newBeamlines[params.beamline];
82-
const filepath = Object.values(newBeamlineState.filePathIds).find(
83-
x => x.urlId === params.screenUrlId
84-
)?.file;
8583

86-
const newScreen = buildUrl(
87-
newBeamlineState.host,
88-
filepath ?? newBeamlineState.topLevelScreen
89-
);
90-
91-
executeAction(
92-
{
93-
type: "OPEN_PAGE",
94-
dynamicInfo: {
95-
name: newScreen,
96-
location: "main",
97-
description: undefined,
98-
file: {
99-
path: newScreen,
100-
macros: {},
101-
defaultProtocol: "ca"
102-
}
103-
}
104-
},
105-
fileContext,
106-
undefined,
107-
{}
84+
executeOpenPageActionWithUrlId(
85+
newBeamlineState,
86+
params.screenUrlId,
87+
params.beamline,
88+
fileContext
10889
);
10990
}
11091
}, []);

0 commit comments

Comments
 (0)