Skip to content

Commit 81f513d

Browse files
authored
RSDEV-282 By default, hide all but the most recent two notes on subsamples (#64)
If subsamples have lots of notes then it could make the UI quite cumbersome, especially where the subsample notes are now shown on the sample page they are no longer at the very foot of the page as they are on the subsample page. This change hides all but the two most recent notes by default, with the rest hidden behind a "Show more" button. The new note field is placed at the top of the list, where it appears before the most recent note and is readily available even when the list of notes is long. This change also improves the aesthetics of the notes somewhat, utilising the theme colour of the subsamples to make it clear that the notes are associated with the physical quantity of the sample, and not the grouping that forms the whole sample.
1 parent 490b820 commit 81f513d

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

src/main/webapp/ui/src/Inventory/Subsample/Fields/Notes/NoteItem.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,34 @@ import TextField from "../../../../components/Inputs/TextField";
99
import { type Note } from "../../../../stores/models/SubSampleModel";
1010
import Box from "@mui/material/Box";
1111
import Typography from "@mui/material/Typography";
12+
import { styled, darken } from "@mui/material/styles";
13+
import { chipClasses } from "@mui/material/Chip";
1214

1315
type NoteItemArgs = {|
1416
note: Note,
1517
|};
1618

19+
const CustomListItem = styled(ListItem)(({ theme }) => ({
20+
borderLeft: `4px solid ${theme.palette.record.subSample.bg}`,
21+
backgroundColor: theme.palette.hover.tableRow,
22+
color: darken(theme.palette.record.subSample.bg, 0.9),
23+
padding: theme.spacing(0, 1),
24+
marginBottom: theme.spacing(1),
25+
"& p": {
26+
marginBlockStart: theme.spacing(0.25),
27+
marginBlockEnd: theme.spacing(0.25),
28+
marginLeft: theme.spacing(2),
29+
fontSize: "0.85rem",
30+
},
31+
[`& .${chipClasses.root}`]: {
32+
background: "transparent",
33+
border: `2px solid ${theme.palette.record.subSample.bg}`,
34+
},
35+
}));
36+
1737
export default function NoteItem({ note }: NoteItemArgs): Node {
1838
return (
19-
<ListItem alignItems="flex-start" divider>
39+
<CustomListItem alignItems="flex-start">
2040
<ListItemText
2141
disableTypography
2242
primary={
@@ -37,6 +57,6 @@ export default function NoteItem({ note }: NoteItemArgs): Node {
3757
<TextField value={note.content} disabled={true} variant="standard" />
3858
}
3959
/>
40-
</ListItem>
60+
</CustomListItem>
4161
);
4262
}

src/main/webapp/ui/src/Inventory/Subsample/Fields/Notes/Notes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ function Notes({
2222
return (
2323
<FormControl>
2424
{!hideLabel && <FormLabel>Notes</FormLabel>}
25-
{record.isFieldVisible("notes") && <NotesList record={record} />}
26-
{record.isFieldVisible("notes") && (
25+
{record.isFieldEditable("notes") && record.isFieldVisible("notes") && (
2726
<NewNote record={record} onErrorStateChange={onErrorStateChange} />
2827
)}
28+
{record.isFieldVisible("notes") && <NotesList record={record} />}
2929
</FormControl>
3030
);
3131
}

src/main/webapp/ui/src/Inventory/Subsample/Fields/Notes/NotesList.js

+29-7
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,43 @@ import { observer } from "mobx-react-lite";
55
import NoteItem from "./NoteItem";
66
import List from "@mui/material/List";
77
import SubSampleModel from "../../../../stores/models/SubSampleModel";
8+
import Button from "@mui/material/Button";
9+
import Collapse from "@mui/material/Collapse";
10+
import Divider from "@mui/material/Divider";
811

912
type NotesListArgs = {|
1013
record: SubSampleModel,
1114
|};
1215

1316
function NotesList({ record }: NotesListArgs): Node {
17+
const [firstNote, secondNote, ...restOfNotes] = record.notes.toReversed();
18+
const [open, setOpen] = React.useState(false);
19+
20+
if (record.loading) return null;
21+
if (record.notes.length === 0) return null;
22+
1423
return (
15-
!record.loading &&
16-
record.notes.length > 0 && (
17-
<List disablePadding>
18-
{record.notes.map((note, i) => (
19-
<NoteItem key={i} note={note} />
24+
<List disablePadding sx={{ mt: 1 }}>
25+
{firstNote && <NoteItem key={0} note={firstNote} />}
26+
{secondNote && <NoteItem key={1} note={secondNote} />}
27+
{restOfNotes.length > 0 && (
28+
<Divider textAlign="center" sx={{ backgroundColor: "white", mb: 1 }}>
29+
<Button
30+
size="small"
31+
onClick={() => {
32+
setOpen(!open);
33+
}}
34+
>
35+
{open ? "Show fewer" : "Show more"}
36+
</Button>
37+
</Divider>
38+
)}
39+
<Collapse in={open}>
40+
{restOfNotes.map((note, i) => (
41+
<NoteItem key={i + 2} note={note} />
2042
))}
21-
</List>
22-
)
43+
</Collapse>
44+
</List>
2345
);
2446
}
2547

0 commit comments

Comments
 (0)