@@ -5,13 +5,12 @@ import { setNetworkData } from './helpers/network';
5
5
import { setDrivesData } from './helpers/drive' ;
6
6
import { TYPES } from './helpers/general' ;
7
7
8
- const memoryField = ( roles ) => ( {
8
+ const memoryField = ( ) => ( {
9
9
component : 'switch' ,
10
10
name : 'cb_memory' ,
11
11
label : __ ( 'Memory' ) ,
12
12
onText : __ ( 'Yes' ) ,
13
13
offText : __ ( 'No' ) ,
14
- isDisabled : roles . allowMemoryChange === false ,
15
14
} ) ;
16
15
17
16
const memoryValueField = ( ) => ( {
@@ -56,13 +55,12 @@ const memoryFormFields = (memory) => ({
56
55
] ,
57
56
} ) ;
58
57
59
- const processorField = ( roles ) => ( {
58
+ const processorField = ( ) => ( {
60
59
component : 'switch' ,
61
60
name : 'processor' ,
62
61
label : __ ( 'Processor' ) ,
63
62
onText : __ ( 'Yes' ) ,
64
63
offText : __ ( 'No' ) ,
65
- isDisabled : roles . allowCpuChange === false ,
66
64
} ) ;
67
65
68
66
const socketField = ( data , setData , options ) => ( {
@@ -123,6 +121,7 @@ const diskTable = (data, roles, setData, onCellClick, buttonClick) => ({
123
121
formType : TYPES . DISK ,
124
122
addButtonLabel : __ ( 'Add Disk' ) ,
125
123
buttonClick,
124
+ roleAllowed : roles . allowDiskChange ,
126
125
} ) ;
127
126
128
127
const networkTable = ( data , roles , setData , onCellClick , buttonClick ) => ( {
@@ -135,6 +134,7 @@ const networkTable = (data, roles, setData, onCellClick, buttonClick) => ({
135
134
formType : TYPES . NETWORK ,
136
135
addButtonLabel : __ ( 'Add Network Adapter' ) ,
137
136
buttonClick,
137
+ roleAllowed : roles . allowNetworkChange ,
138
138
} ) ;
139
139
140
140
const driveTable = ( data , roles , setData , onCellClick ) => ( {
@@ -147,19 +147,23 @@ const driveTable = (data, roles, setData, onCellClick) => ({
147
147
addButton : false ,
148
148
formType : TYPES . DRIVE ,
149
149
hideField : ! data . dataTable . drives || data . dataTable . drives . length === 0 ,
150
+ roleAllowed : roles . allowCdromsChange ,
150
151
} ) ;
151
152
152
153
const renderDatatables = ( recordId , data , roles , setData , onCellClick , buttonClick ) => [ diskTable ( data , roles , setData , onCellClick , buttonClick ) ,
153
154
networkTable ( data , roles , setData , onCellClick , buttonClick ) ,
154
155
driveTable ( data , roles , setData , onCellClick ) ] ;
155
156
156
157
export const reconfigureFormFields = ( recordId , roles , memory , data , setData , options , onCellClick , buttonClick ) => {
157
- const formFields = [
158
- memoryField ( roles ) ,
159
- memoryFormFields ( memory ) ,
160
- processorField ( roles ) ,
161
- processorFormFields ( data , setData , options , memory . max_cpu ) ,
162
- ] ;
158
+ const formFields = [ ] ;
159
+ if ( roles . allowMemoryChange ) {
160
+ formFields . push ( memoryField ( ) ) ;
161
+ formFields . push ( memoryFormFields ( roles ) ) ;
162
+ }
163
+ if ( roles . allowCpuChange ) {
164
+ formFields . push ( processorField ( ) ) ;
165
+ formFields . push ( processorFormFields ( data , setData , options , memory . max_cpu ) ) ;
166
+ }
163
167
if ( recordId . length === 1 ) {
164
168
formFields . push ( renderDatatables ( recordId , data , roles , setData , onCellClick , buttonClick ) ) ;
165
169
}
0 commit comments