Skip to content

Commit 29ea5e1

Browse files
Merge pull request #122 from DiamondLightSource/minimal-session-selector
Add minimal session selector component
2 parents 06f229e + 41cd98e commit 29ea5e1

2 files changed

Lines changed: 68 additions & 5 deletions

File tree

frontend/unified/src/App.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Box, Divider, Grid2 as Grid, Stack, Typography } from "@mui/material";
2+
import { SessionSelector } from "./components/SessionSelector";
23

34
const VERTICAL_SPACING = 2;
45
const HORIZONTAL_SPACING = 2;
@@ -9,11 +10,7 @@ export const App: React.FC = () => {
910
<Grid container spacing={HORIZONTAL_SPACING} columns={2}>
1011
<Stack spacing={VERTICAL_SPACING}>
1112
<Typography variant="h5">Session</Typography>
12-
<PlaceholderComponent
13-
placeholderText="Session selector component placeholder"
14-
height={100}
15-
width={500}
16-
/>
13+
<SessionSelector />
1714
<Divider sx={{ width: "100%" }} />
1815
<Typography variant="h5">Scan</Typography>
1916
<PlaceholderComponent
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import {
2+
Chip,
3+
TextField,
4+
ToggleButton,
5+
ToggleButtonGroup,
6+
Stack,
7+
} from "@mui/material";
8+
import { useState } from "react";
9+
10+
enum SessionSelectionMode {
11+
Latest = "Latest",
12+
Custom = "Custom",
13+
}
14+
15+
export const SessionSelector: React.FC = () => {
16+
// TODO: initial value based on fetching latest session associated with logged-in user
17+
const [session] = useState<string>("latest-session");
18+
// TODO: initial value based on the initial session
19+
const [beamline] = useState<string>("Beamline: depends-on-session");
20+
const [sessionSelectionMode, setSessionSelectionMode] =
21+
useState<SessionSelectionMode>(SessionSelectionMode.Latest);
22+
const [textInputValue, setTextInputValue] = useState<string>("");
23+
24+
return (
25+
<Stack direction="row" spacing={2} alignItems={"center"}>
26+
<ToggleButtonGroup
27+
exclusive
28+
value={sessionSelectionMode}
29+
onChange={(_, toggleButtonLabel: string) => {
30+
if (toggleButtonLabel === SessionSelectionMode.Latest) {
31+
setSessionSelectionMode(SessionSelectionMode.Latest);
32+
} else if (toggleButtonLabel === SessionSelectionMode.Custom) {
33+
setSessionSelectionMode(SessionSelectionMode.Custom);
34+
}
35+
}}
36+
>
37+
<ToggleButton
38+
sx={{ textTransform: "none" }}
39+
value={SessionSelectionMode.Latest}
40+
>
41+
{SessionSelectionMode.Latest}
42+
</ToggleButton>
43+
<ToggleButton
44+
sx={{ textTransform: "none" }}
45+
value={SessionSelectionMode.Custom}
46+
>
47+
{SessionSelectionMode.Custom}
48+
</ToggleButton>
49+
</ToggleButtonGroup>
50+
<TextField
51+
variant="outlined"
52+
label="Session"
53+
disabled={sessionSelectionMode === SessionSelectionMode.Latest}
54+
value={
55+
sessionSelectionMode === SessionSelectionMode.Latest
56+
? session
57+
: textInputValue
58+
}
59+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
60+
setTextInputValue(e.currentTarget.value);
61+
}}
62+
/>
63+
<Chip label={beamline} variant="outlined" color="primary"></Chip>
64+
</Stack>
65+
);
66+
};

0 commit comments

Comments
 (0)