1
1
import React , { useEffect , useState } from "react" ;
2
- import { Col , Table , Typography , Alert , Row } from "antd" ;
2
+ import { Col , Table , Typography , Alert , Row , Button , Tabs , Modal , Form , Input } from "antd" ;
3
3
import axios from "axios" ;
4
4
import Title from "antd/es/typography/Title" ;
5
5
6
6
const TemplateStore = ( ) => {
7
7
const [ templates , setTemplates ] = useState ( [ ] ) ;
8
- const [ error , setError ] = useState ( {
8
+ const [ newTemplateModal , setNewTemplateModal ] = useState ( false )
9
+ const [ confirmLoading , setConfirmLoading ] = useState ( false ) ;
10
+ const [ error , setError ] = useState ( {
9
11
message : "" ,
10
12
description : "" ,
11
13
} ) ;
12
14
13
- useEffect ( ( ) => {
15
+ const [ form ] = Form . useForm ( ) ;
16
+
17
+ useEffect ( ( ) => {
14
18
axios
15
19
. get ( `/api/templates/store` )
16
20
. then ( ( res ) => {
@@ -32,6 +36,41 @@ const TemplateStore = () => {
32
36
} ) ;
33
37
} , [ ] ) ;
34
38
39
+ const handleOK = ( ) => {
40
+ form . submit ( ) ;
41
+ }
42
+
43
+ const handleSubmit = ( values : any ) => {
44
+ setConfirmLoading ( true ) ;
45
+
46
+ axios
47
+ . put ( `/api/templates/store` , values )
48
+ . then ( ( res ) => {
49
+ setNewTemplateModal ( false ) ;
50
+ setConfirmLoading ( true ) ;
51
+ window . location . href = "/templates" ;
52
+ } )
53
+ . catch ( ( error ) => {
54
+ if ( error . response === undefined ) {
55
+ setError ( {
56
+ message : String ( error ) ,
57
+ description :
58
+ "Check if Cyclops backend is available on: " +
59
+ window . __RUNTIME_CONFIG__ . REACT_APP_CYCLOPS_CTRL_HOST ,
60
+ } ) ;
61
+ } else {
62
+ setError ( {
63
+ message : error . message ,
64
+ description : error . response . data ,
65
+ } ) ;
66
+ }
67
+ } ) ;
68
+ }
69
+
70
+ const handleCancelModal = ( ) => {
71
+ setNewTemplateModal ( false ) ;
72
+ }
73
+
35
74
return (
36
75
< div >
37
76
{ error . message . length !== 0 && (
@@ -53,6 +92,15 @@ const TemplateStore = () => {
53
92
< Col span = { 18 } >
54
93
< Title level = { 2 } > Templates: { templates . length } </ Title >
55
94
</ Col >
95
+ < Col span = { 6 } >
96
+ < Button
97
+ type = { "primary" }
98
+ block
99
+ onClick = { ( ) => { setNewTemplateModal ( true ) }
100
+ } >
101
+ Add template reference
102
+ </ Button >
103
+ </ Col >
56
104
</ Row >
57
105
< Col span = { 24 } style = { { overflowX : "auto" } } >
58
106
< Table dataSource = { templates } >
@@ -72,6 +120,52 @@ const TemplateStore = () => {
72
120
< Table . Column title = "Version" dataIndex = { [ "ref" , "version" ] } width = { "10%" } />
73
121
</ Table >
74
122
</ Col >
123
+ < Modal
124
+ title = "Add template ref"
125
+ open = { newTemplateModal }
126
+ onOk = { handleOK }
127
+ onCancel = { handleCancelModal }
128
+ confirmLoading = { confirmLoading }
129
+ width = { "60%" }
130
+ >
131
+ < Form
132
+ onFinish = { handleSubmit }
133
+ form = { form }
134
+ initialValues = { { remember : true } }
135
+ labelCol = { { span : 6 } }
136
+ >
137
+ < Form . Item
138
+ label = "Template ref name"
139
+ name = { "name" }
140
+ rules = { [ { required : true , message : 'Template ref is required' } ] }
141
+ >
142
+ < Input />
143
+ </ Form . Item >
144
+
145
+ < Form . Item
146
+ label = "Repository URL"
147
+ name = { [ "ref" , "repo" ] }
148
+ rules = { [ { required : true , message : 'Repo URL is required' } ] }
149
+ >
150
+ < Input />
151
+ </ Form . Item >
152
+
153
+ < Form . Item
154
+ label = "Path"
155
+ name = { [ "ref" , "path" ] }
156
+ rules = { [ { required : true , message : 'Path is required' } ] }
157
+ >
158
+ < Input />
159
+ </ Form . Item >
160
+
161
+ < Form . Item
162
+ label = "Version"
163
+ name = { [ "ref" , "version" ] }
164
+ >
165
+ < Input />
166
+ </ Form . Item >
167
+ </ Form >
168
+ </ Modal >
75
169
</ div >
76
170
) ;
77
171
} ;
0 commit comments