Skip to content

Commit a593286

Browse files
committed
chore: show the sample ESI in the Review page of the Experiment Safety form to the User
1 parent 1d530a3 commit a593286

2 files changed

Lines changed: 94 additions & 18 deletions

File tree

apps/frontend/src/components/experimentSafety/ExperimentSafetyDetails.tsx

Lines changed: 90 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,109 @@
1+
import { Box, Button, DialogActions, DialogContent } from '@mui/material';
12
import List from '@mui/material/List';
23
import ListItem from '@mui/material/ListItem';
3-
import React from 'react';
4+
import React, { useState } from 'react';
5+
import { Link } from 'react-router-dom';
46

7+
import StyledDialog from 'components/common/StyledDialog';
58
import UOLoader from 'components/common/UOLoader';
69
import QuestionaryDetails, {
710
TableRowData,
811
} from 'components/questionary/QuestionaryDetails';
912
import { useExperimentSafety } from 'hooks/experimentSafety/useExperimentSafety';
1013

1114
interface ExperimentSafetyDetailsProps {
12-
esiId: number;
15+
experimentSafetyPk: number;
16+
}
17+
18+
function ExperimentSampleLists({
19+
samples,
20+
}: {
21+
samples: {
22+
sampleId: number;
23+
sample: { title: string };
24+
sampleEsiQuestionaryId: number;
25+
}[];
26+
}) {
27+
const [selectedSampleId, setSelectedSampleId] = useState<number | null>(null);
28+
29+
return (
30+
<>
31+
<List
32+
sx={{
33+
listStyle: 'none',
34+
padding: 0,
35+
}}
36+
>
37+
{samples.map((sample) => (
38+
<ListItem key={`sample-${sample.sampleId}`}>
39+
<Link
40+
to="#"
41+
onClick={() => setSelectedSampleId(sample.sampleId)}
42+
style={{ cursor: 'pointer' }}
43+
>
44+
{sample.sample.title || `Sample ${sample.sampleId}`}
45+
</Link>
46+
</ListItem>
47+
))}
48+
</List>
49+
{/* Sample Details Modal */}
50+
<StyledDialog
51+
maxWidth="lg"
52+
fullWidth
53+
open={selectedSampleId !== null}
54+
onClose={() => setSelectedSampleId(null)}
55+
title={
56+
selectedSampleId
57+
? (() => {
58+
const selectedSample = samples?.find(
59+
(sample) => sample.sampleId === selectedSampleId
60+
);
61+
62+
return `Sample Safety Input - ${
63+
selectedSample?.sample.title || `Sample ${selectedSampleId}`
64+
}`;
65+
})()
66+
: 'Sample Safety Input'
67+
}
68+
>
69+
<DialogContent>
70+
{selectedSampleId
71+
? (() => {
72+
const selectedSample = samples?.find(
73+
(sample) => sample.sampleId === selectedSampleId
74+
);
75+
76+
return selectedSample?.sampleEsiQuestionaryId ? (
77+
<QuestionaryDetails
78+
questionaryId={selectedSample.sampleEsiQuestionaryId}
79+
/>
80+
) : (
81+
<Box>No questionary found for this sample</Box>
82+
);
83+
})()
84+
: null}
85+
</DialogContent>
86+
<DialogActions>
87+
<Button
88+
type="button"
89+
variant="outlined"
90+
onClick={() => setSelectedSampleId(null)}
91+
data-cy="close-sample-dialog"
92+
>
93+
Close
94+
</Button>
95+
</DialogActions>
96+
</StyledDialog>
97+
</>
98+
);
1399
}
14100

15101
function ExperimentSafetyDetails(props: ExperimentSafetyDetailsProps) {
16-
const { experimentSafety } = useExperimentSafety(props.esiId);
102+
const { experimentSafety } = useExperimentSafety(props.experimentSafetyPk);
17103

18104
if (!experimentSafety) {
19105
return <UOLoader />;
20106
}
21-
22107
const additionalDetails: TableRowData[] = [
23108
{
24109
label: 'Proposal ID',
@@ -27,18 +112,7 @@ function ExperimentSafetyDetails(props: ExperimentSafetyDetailsProps) {
27112
{ label: 'Proposal Title', value: experimentSafety?.proposal.title || '' },
28113
{
29114
label: 'Samples for the experiment',
30-
value: (
31-
<List
32-
sx={{
33-
listStyle: 'none',
34-
padding: 0,
35-
}}
36-
>
37-
{experimentSafety.samples.map((sample) => (
38-
<ListItem key={sample.sampleId}>{sample.sample.title}</ListItem>
39-
))}
40-
</List>
41-
),
115+
value: <ExperimentSampleLists samples={experimentSafety.samples} />,
42116
},
43117
];
44118

apps/frontend/src/components/experimentSafety/ExperimentSafetyReview.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { FunctionType } from 'utils/utilTypes';
1515
import withConfirm, { WithConfirmType } from 'utils/withConfirm';
1616

1717
import { ExperimentSafetyContextType } from './ExperimentSafetyContainer';
18-
import ProposalEsiDetails from './ExperimentSafetyDetails';
18+
import ExperimentSafetyDetails from './ExperimentSafetyDetails';
1919

2020
type ExperimentSafetyReviewProps = {
2121
onComplete?: FunctionType<void>;
@@ -62,7 +62,9 @@ function ExperimentSafetyReview({ confirm }: ExperimentSafetyReviewProps) {
6262

6363
return (
6464
<>
65-
<ProposalEsiDetails esiId={state.experimentSafety.experimentSafetyPk} />
65+
<ExperimentSafetyDetails
66+
experimentSafetyPk={state.experimentSafety.experimentSafetyPk}
67+
/>
6668
<NavigationFragment isLoading={isExecutingCall}>
6769
<NavigButton
6870
onClick={() =>

0 commit comments

Comments
 (0)