|
| 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