@@ -9,11 +9,29 @@ import PropTypes from 'prop-types';
9
9
import CellLineName from 'src/apps/mydb/elements/details/cellLines/propertiesTab/CellLineName' ;
10
10
import Amount from 'src/apps/mydb/elements/details/cellLines/propertiesTab/Amount' ;
11
11
import InvalidPropertyWarning from 'src/apps/mydb/elements/details/cellLines/propertiesTab/InvalidPropertyWarning' ;
12
+ import UserStore from 'src/stores/alt/stores/UserStore' ;
12
13
13
14
class GeneralProperties extends React . Component {
14
15
// eslint-disable-next-line react/static-property-placement
15
16
static contextType = StoreContext ;
16
17
18
+ // eslint-disable-next-line class-methods-use-this
19
+ checkPermission ( attributeName ) {
20
+ const readonlyAttributes = [
21
+ 'Disease' , 'Organism' , 'Tissue' , 'Growth medium' , 'Mutation' , 'Variant' , 'Biosafety level' ,
22
+ 'Cryopreservation medium' , 'Opt. growth temperature' , 'Gender' , 'Cell type' , 'Material Description'
23
+ ] ;
24
+ const { item } = this . props ;
25
+ const { currentUser } = UserStore . getState ( ) ;
26
+ if ( item . created_by == null ) {
27
+ const { cellLineDetailsStore } = this . context ;
28
+ const cellLine = cellLineDetailsStore . cellLines ( item . id ) ;
29
+ return readonlyAttributes . includes ( attributeName )
30
+ && cellLine . created_by !== '' && cellLine . created_by !== currentUser . id . toString ( ) ;
31
+ }
32
+ return readonlyAttributes . includes ( attributeName ) && item . created_by !== currentUser . id ;
33
+ }
34
+
17
35
renderOptionalAttribute ( attributeName , defaultValue , onChangeCallBack ) {
18
36
return this . renderAttribute ( attributeName , defaultValue , onChangeCallBack , true ) ;
19
37
}
@@ -43,7 +61,7 @@ class GeneralProperties extends React.Component {
43
61
< Form . Label column sm = { 3 } > { attributeName } </ Form . Label >
44
62
< Col sm = { 9 } >
45
63
< Form . Control
46
- disabled = { readOnly }
64
+ disabled = { readOnly || this . checkPermission ( attributeName ) }
47
65
className = { styleClass }
48
66
type = "text"
49
67
value = { defaultValue }
@@ -69,10 +87,10 @@ class GeneralProperties extends React.Component {
69
87
< Form . Label column sm = { 3 } > Biosafety level</ Form . Label >
70
88
< Col sm = { 9 } >
71
89
< Select
72
- isDisabled = { readOnly }
90
+ isDisabled = { readOnly || this . checkPermission ( 'Biosafety level' ) }
73
91
options = { options }
74
92
isClearable = { false }
75
- value = { options . find ( ( { value} ) => value === item . bioSafetyLevel ) }
93
+ value = { options . find ( ( { value } ) => value === item . bioSafetyLevel ) }
76
94
onChange = { ( e ) => { cellLineDetailsStore . changeBioSafetyLevel ( item . id , e . value ) ; } }
77
95
/>
78
96
</ Col >
@@ -117,7 +135,7 @@ class GeneralProperties extends React.Component {
117
135
< Amount
118
136
cellLineId = { item . id }
119
137
initialValue = { item . amount }
120
- readOnly = { readOnly }
138
+ readOnly = { readOnly || this . checkPermission ( 'Amount' ) }
121
139
/>
122
140
</ Col >
123
141
< Col sm = { 3 } className = "amount-unit" >
@@ -187,7 +205,7 @@ class GeneralProperties extends React.Component {
187
205
{ this . renderOptionalAttribute ( 'Cell type' , cellLineItem . cellType , ( e ) => {
188
206
cellLineDetailsStore . changeCellType ( cellLineId , e . target . value ) ;
189
207
} ) }
190
- { this . renderOptionalAttribute ( 'Description' , cellLineItem . materialDescription , ( e ) => {
208
+ { this . renderOptionalAttribute ( 'Material Description' , cellLineItem . materialDescription , ( e ) => {
191
209
cellLineDetailsStore . changeMaterialDescription ( cellLineId , e . target . value ) ;
192
210
} ) }
193
211
</ Accordion . Body >
@@ -209,7 +227,7 @@ class GeneralProperties extends React.Component {
209
227
{ this . renderOptionalAttribute ( 'Name of specific probe' , cellLineItem . itemName , ( e ) => {
210
228
cellLineDetailsStore . changeItemName ( cellLineId , e . target . value ) ;
211
229
} ) }
212
- { this . renderOptionalAttribute ( 'Description' , cellLineItem . itemDescription , ( e ) => {
230
+ { this . renderOptionalAttribute ( 'Sample Description' , cellLineItem . itemDescription , ( e ) => {
213
231
cellLineDetailsStore . changeItemDescription ( cellLineId , e . target . value ) ;
214
232
} ) }
215
233
</ Accordion . Body >
@@ -224,6 +242,8 @@ export default observer(GeneralProperties);
224
242
GeneralProperties . propTypes = {
225
243
readOnly : PropTypes . bool . isRequired ,
226
244
item : PropTypes . shape ( {
227
- id : PropTypes . string . isRequired
245
+ id : PropTypes . string . isRequired ,
246
+ can_update : PropTypes . bool ,
247
+ created_by : PropTypes . number
228
248
} ) . isRequired
229
249
} ;
0 commit comments