Skip to content

Commit fcec0ff

Browse files
authored
RSDEV-279 Additional subsample count label (#60)
This change adds an additional label on the subsample form informing the user of how many siblings the subsample has. Currently, the subsamples quantity field provides a link to the search for all of the parent sample's subsamples, with a link text that specifies the number of subsamples minus one -- the number of siblings the subsample has. Given that the quantity field is in the details section, it may appear below the fold when the vertical dimension of the viewport is low or it may not be visible due to the details section being collapsed. This change duplicates this label by adding it to the overview section's parent sample field also, where it is more likely to be seen at first glance.
1 parent f15a0e6 commit fcec0ff

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

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

+13-6
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,19 @@ function QuantityField<
162162
);
163163
}}
164164
>
165-
There {parentSample.subSamplesCount === 2 ? "is" : "are"}{" "}
166-
{parentSample.subSamplesCount - 1} other{" "}
167-
{parentSample.subSamplesCount === 2
168-
? parentSample.subSampleAlias.alias
169-
: parentSample.subSampleAlias.plural}
170-
.
165+
{parentSample.subSamplesCount === 1 ? (
166+
`The parent sample only has one ${parentSample.subSampleAlias.alias}.`
167+
) : (
168+
<>
169+
There{" "}
170+
{parentSample.subSamplesCount === 2 ? "is" : "are"}{" "}
171+
{parentSample.subSamplesCount - 1} other{" "}
172+
{parentSample.subSamplesCount === 2
173+
? parentSample.subSampleAlias.alias
174+
: parentSample.subSampleAlias.plural}
175+
.
176+
</>
177+
)}
171178
</Link>
172179
</Typography>
173180
)}

src/main/webapp/ui/src/Inventory/components/Fields/Sample.js

+37-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { type Sample } from "../../../stores/definitions/Sample";
66
import { RecordLink } from "../RecordLink";
77
import FormField from "../../../components/Inputs/FormField";
88
import Box from "@mui/material/Box";
9+
import Link from "@mui/material/Link";
10+
import Typography from "@mui/material/Typography";
11+
import NavigateContext from "../../../stores/contexts/Navigate";
912

1013
export default function SampleField<
1114
Fields: {
@@ -15,16 +18,47 @@ export default function SampleField<
1518
FieldOwner: HasUneditableFields<Fields>
1619
>({ fieldOwner }: {| fieldOwner: FieldOwner |}): Node {
1720
const sample = fieldOwner.fieldValues.sample;
21+
const { useNavigate } = React.useContext(NavigateContext);
22+
const navigate = useNavigate();
1823

1924
return (
2025
<FormField
2126
value={void 0}
2227
label="Parent Sample"
2328
disabled
2429
renderInput={() => (
25-
<Box>
26-
<RecordLink record={sample} />
27-
</Box>
30+
<>
31+
<Box>
32+
<RecordLink record={sample} />
33+
</Box>
34+
{sample.globalId && (
35+
<Typography variant="caption">
36+
<Link
37+
href={`/inventory/search?parentGlobalId=${sample.globalId}`}
38+
onClick={(e) => {
39+
e.preventDefault();
40+
if (sample.globalId)
41+
navigate(
42+
`/inventory/search?parentGlobalId=${sample.globalId}`
43+
);
44+
}}
45+
>
46+
{sample.subSamplesCount === 1 ? (
47+
`The parent sample only has one ${sample.subSampleAlias.alias}.`
48+
) : (
49+
<>
50+
There {sample.subSamplesCount === 2 ? "is" : "are"}{" "}
51+
{sample.subSamplesCount - 1} other{" "}
52+
{sample.subSamplesCount === 2
53+
? sample.subSampleAlias.alias
54+
: sample.subSampleAlias.plural}
55+
.
56+
</>
57+
)}
58+
</Link>
59+
</Typography>
60+
)}
61+
</>
2862
)}
2963
/>
3064
);

0 commit comments

Comments
 (0)