14
14
// You should have received a copy of the GNU Affero General Public License
15
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
17
- import React , { Fragment , useEffect , useState } from "react" ;
17
+ import React , { Fragment } from "react" ;
18
18
import { Theme } from "@mui/material/styles" ;
19
19
import createStyles from "@mui/styles/createStyles" ;
20
- import withStyles from "@mui/styles/withStyles" ;
21
20
import {
22
21
formFieldStyles ,
23
22
modalStyleUtils ,
24
23
} from "../../../../Common/FormComponents/common/styleLibrary" ;
25
24
import Grid from "@mui/material/Grid" ;
26
- import { generatePoolName , niceBytes } from "../../../../../../common/utils" ;
25
+ import { niceBytes } from "../../../../../../common/utils" ;
27
26
import { LinearProgress } from "@mui/material" ;
28
- import { IAddPoolRequest } from "../../../ListTenants/types" ;
29
27
import PageHeader from "../../../../Common/PageHeader/PageHeader" ;
30
28
import PageLayout from "../../../../Common/Layout/PageLayout" ;
31
29
import GenericWizard from "../../../../Common/GenericWizard/GenericWizard" ;
@@ -39,20 +37,12 @@ import { AppState } from "../../../../../../store";
39
37
import { useDispatch , useSelector } from "react-redux" ;
40
38
import PoolConfiguration from "./PoolConfiguration" ;
41
39
import PoolPodPlacement from "./PoolPodPlacement" ;
42
- import { ErrorResponseHandler } from "../../../../../../common/types" ;
43
- import { getDefaultAffinity , getNodeSelector } from "../../utils" ;
44
- import api from "../../../../../../common/api" ;
45
40
import BackLink from "../../../../../../common/BackLink" ;
46
- import { setErrorSnackMessage } from "../../../../../../systemSlice" ;
47
- import { resetPoolForm , setTenantDetailsLoad } from "../../../tenantsSlice" ;
41
+ import { resetPoolForm } from "./addPoolSlice" ;
42
+ import AddPoolCreateButton from "./AddPoolCreateButton" ;
43
+ import makeStyles from "@mui/styles/makeStyles" ;
48
44
49
- interface IAddPoolProps {
50
- classes : any ;
51
- open : boolean ;
52
- match : any ;
53
- }
54
-
55
- const styles = ( theme : Theme ) =>
45
+ const useStyles = makeStyles ( ( theme : Theme ) =>
56
46
createStyles ( {
57
47
bottomContainer : {
58
48
display : "flex" ,
@@ -77,136 +67,20 @@ const styles = (theme: Theme) =>
77
67
} ,
78
68
...formFieldStyles ,
79
69
...modalStyleUtils ,
80
- } ) ;
81
-
82
- const requiredPages = [ "setup" , "affinity" , "configure" ] ;
70
+ } )
71
+ ) ;
83
72
84
- const AddPool = ( { classes , open , match } : IAddPoolProps ) => {
73
+ const AddPool = ( ) => {
85
74
const dispatch = useDispatch ( ) ;
75
+ const classes = useStyles ( ) ;
86
76
87
- const tenant = useSelector (
88
- ( state : AppState ) => state . tenants . tenantDetails . tenantInfo
89
- ) ;
90
- const selectedStorageClass = useSelector (
91
- ( state : AppState ) => state . tenants . addPool . fields . setup . storageClass
92
- ) ;
93
- const validPages = useSelector (
94
- ( state : AppState ) => state . tenants . addPool . validPages
95
- ) ;
96
- const numberOfNodes = useSelector (
97
- ( state : AppState ) => state . tenants . addPool . fields . setup . numberOfNodes
98
- ) ;
99
- const volumeSize = useSelector (
100
- ( state : AppState ) => state . tenants . addPool . fields . setup . volumeSize
101
- ) ;
102
- const volumesPerServer = useSelector (
103
- ( state : AppState ) => state . tenants . addPool . fields . setup . volumesPerServer
104
- ) ;
105
- const affinityType = useSelector (
106
- ( state : AppState ) => state . tenants . addPool . fields . affinity . podAffinity
107
- ) ;
108
- const nodeSelectorLabels = useSelector (
109
- ( state : AppState ) =>
110
- state . tenants . addPool . fields . affinity . nodeSelectorLabels
111
- ) ;
112
- const withPodAntiAffinity = useSelector (
113
- ( state : AppState ) =>
114
- state . tenants . addPool . fields . affinity . withPodAntiAffinity
115
- ) ;
116
- const tolerations = useSelector (
117
- ( state : AppState ) => state . tenants . addPool . fields . tolerations
118
- ) ;
119
- const securityContextEnabled = useSelector (
120
- ( state : AppState ) =>
121
- state . tenants . addPool . fields . configuration . securityContextEnabled
122
- ) ;
123
- const securityContext = useSelector (
124
- ( state : AppState ) =>
125
- state . tenants . addPool . fields . configuration . securityContext
126
- ) ;
127
-
128
- const [ addSending , setAddSending ] = useState < boolean > ( false ) ;
77
+ const tenant = useSelector ( ( state : AppState ) => state . tenants . tenantInfo ) ;
78
+ const sending = useSelector ( ( state : AppState ) => state . addPool . sending ) ;
129
79
130
80
const poolsURL = `/namespaces/${ tenant ?. namespace || "" } /tenants/${
131
81
tenant ?. name || ""
132
82
} /pools`;
133
83
134
- useEffect ( ( ) => {
135
- if ( addSending && tenant ) {
136
- const poolName = generatePoolName ( tenant . pools ) ;
137
-
138
- let affinityObject = { } ;
139
-
140
- switch ( affinityType ) {
141
- case "default" :
142
- affinityObject = {
143
- affinity : getDefaultAffinity ( tenant . name , poolName ) ,
144
- } ;
145
- break ;
146
- case "nodeSelector" :
147
- affinityObject = {
148
- affinity : getNodeSelector (
149
- nodeSelectorLabels ,
150
- withPodAntiAffinity ,
151
- tenant . name ,
152
- poolName
153
- ) ,
154
- } ;
155
- break ;
156
- }
157
-
158
- const tolerationValues = tolerations . filter (
159
- ( toleration ) => toleration . key . trim ( ) !== ""
160
- ) ;
161
-
162
- const data : IAddPoolRequest = {
163
- name : poolName ,
164
- servers : numberOfNodes ,
165
- volumes_per_server : volumesPerServer ,
166
- volume_configuration : {
167
- size : volumeSize * 1073741824 ,
168
- storage_class_name : selectedStorageClass ,
169
- labels : null ,
170
- } ,
171
- tolerations : tolerationValues ,
172
- securityContext : securityContextEnabled ? securityContext : null ,
173
- ...affinityObject ,
174
- } ;
175
-
176
- api
177
- . invoke (
178
- "POST" ,
179
- `/api/v1/namespaces/${ tenant . namespace } /tenants/${ tenant . name } /pools` ,
180
- data
181
- )
182
- . then ( ( ) => {
183
- setAddSending ( false ) ;
184
- dispatch ( resetPoolForm ( ) ) ;
185
- dispatch ( setTenantDetailsLoad ( true ) ) ;
186
- history . push ( poolsURL ) ;
187
- } )
188
- . catch ( ( err : ErrorResponseHandler ) => {
189
- setAddSending ( false ) ;
190
- dispatch ( setErrorSnackMessage ( err ) ) ;
191
- } ) ;
192
- }
193
- } , [
194
- addSending ,
195
- poolsURL ,
196
- affinityType ,
197
- nodeSelectorLabels ,
198
- numberOfNodes ,
199
- securityContext ,
200
- securityContextEnabled ,
201
- selectedStorageClass ,
202
- tenant ,
203
- tolerations ,
204
- volumeSize ,
205
- volumesPerServer ,
206
- withPodAntiAffinity ,
207
- dispatch ,
208
- ] ) ;
209
-
210
84
const cancelButton = {
211
85
label : "Cancel" ,
212
86
type : "other" ,
@@ -218,15 +92,7 @@ const AddPool = ({ classes, open, match }: IAddPoolProps) => {
218
92
} ;
219
93
220
94
const createButton = {
221
- label : "Create" ,
222
- type : "submit" ,
223
- enabled :
224
- ! addSending &&
225
- selectedStorageClass !== "" &&
226
- requiredPages . every ( ( v ) => validPages . includes ( v ) ) ,
227
- action : ( ) => {
228
- setAddSending ( true ) ;
229
- } ,
95
+ componentRender : < AddPoolCreateButton key = { "add-pool-crate" } /> ,
230
96
} ;
231
97
232
98
const wizardSteps : IWizardElement [ ] = [
@@ -272,8 +138,7 @@ const AddPool = ({ classes, open, match }: IAddPoolProps) => {
272
138
}
273
139
/>
274
140
</ Grid >
275
-
276
- { addSending && (
141
+ { sending && (
277
142
< Grid item xs = { 12 } >
278
143
< LinearProgress />
279
144
</ Grid >
@@ -287,4 +152,4 @@ const AddPool = ({ classes, open, match }: IAddPoolProps) => {
287
152
) ;
288
153
} ;
289
154
290
- export default withStyles ( styles ) ( AddPool ) ;
155
+ export default AddPool ;
0 commit comments