1+ import { Box , Button , DialogActions , DialogContent } from '@mui/material' ;
12import List from '@mui/material/List' ;
23import 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' ;
58import UOLoader from 'components/common/UOLoader' ;
69import QuestionaryDetails , {
710 TableRowData ,
811} from 'components/questionary/QuestionaryDetails' ;
912import { useExperimentSafety } from 'hooks/experimentSafety/useExperimentSafety' ;
1013
1114interface 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
15101function 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
0 commit comments