1+ import React , { useContext , useState , useEffect } from 'react'
2+
3+ import { pluginAPI } from 'api'
4+ import { AlertContext } from 'layouts/Admin'
5+
6+ import {
7+ Button ,
8+ ButtonText ,
9+ Checkbox ,
10+ CheckboxIcon ,
11+ CheckboxIndicator ,
12+ CheckboxLabel ,
13+ FormControl ,
14+ FormControlHelper ,
15+ FormControlHelperText ,
16+ FormControlLabel ,
17+ FormControlLabelText ,
18+ Input ,
19+ InputField ,
20+ VStack ,
21+ HStack ,
22+ Text
23+ } from '@gluestack-ui/themed'
24+
25+ const EditPlugin = ( { plugin, onClose, notifyChange, ...props } ) => {
26+ const contextType = useContext ( AlertContext )
27+
28+ const [ Name , setName ] = useState ( plugin . Name || '' )
29+ const [ URI , setURI ] = useState ( plugin . URI || '' )
30+ const [ UnixPath , setUnixPath ] = useState ( plugin . UnixPath || '' )
31+ const [ ComposeFilePath , setComposeFilePath ] = useState ( plugin . ComposeFilePath || '' )
32+ const [ Enabled , setEnabled ] = useState ( plugin . Enabled || false )
33+ const [ GitURL , setGitURL ] = useState ( plugin . GitURL || '' )
34+ const [ HasUI , setHasUI ] = useState ( plugin . HasUI || false )
35+ const [ InstallTokenPath , setInstallTokenPath ] = useState ( plugin . InstallTokenPath || '' )
36+ const [ ScopedPaths , setScopedPaths ] = useState ( plugin . ScopedPaths ? plugin . ScopedPaths . join ( ', ' ) : '' )
37+
38+ const handleChange = ( name , value ) => {
39+ if ( name == 'Name' ) {
40+ setName ( value )
41+ }
42+ if ( name == 'URI' ) {
43+ setURI ( value )
44+ }
45+ if ( name == 'UnixPath' ) {
46+ setUnixPath ( value )
47+ }
48+ if ( name == 'ComposeFilePath' ) {
49+ setComposeFilePath ( value )
50+ }
51+ if ( name == 'GitURL' ) {
52+ setGitURL ( value )
53+ }
54+ if ( name == 'InstallTokenPath' ) {
55+ setInstallTokenPath ( value )
56+ }
57+ if ( name == 'ScopedPaths' ) {
58+ setScopedPaths ( value )
59+ }
60+ }
61+
62+ const handleSubmit = ( e ) => {
63+ e . preventDefault ( )
64+
65+ // Convert ScopedPaths string to array
66+ const scopedPathsArray = ScopedPaths
67+ ? ScopedPaths . split ( ',' ) . map ( path => path . trim ( ) ) . filter ( path => path . length > 0 )
68+ : [ ]
69+
70+ let updatedPlugin = {
71+ ...plugin ,
72+ Name,
73+ URI ,
74+ UnixPath,
75+ ComposeFilePath,
76+ Enabled,
77+ GitURL,
78+ HasUI,
79+ InstallTokenPath,
80+ ScopedPaths : scopedPathsArray
81+ }
82+
83+ pluginAPI
84+ . update ( updatedPlugin )
85+ . then ( ( res ) => {
86+ contextType . success ( 'Plugin updated successfully' )
87+ if ( notifyChange ) {
88+ notifyChange ( )
89+ }
90+ if ( onClose ) {
91+ onClose ( )
92+ }
93+ } )
94+ . catch ( ( err ) => {
95+ contextType . error ( `Failed to update plugin: ${ err . message } ` )
96+ } )
97+ }
98+
99+ return (
100+ < VStack space = "md" >
101+ < FormControl >
102+ < FormControlLabel >
103+ < FormControlLabelText > Name</ FormControlLabelText >
104+ </ FormControlLabel >
105+
106+ < Input variant = "underlined" >
107+ < InputField
108+ type = "text"
109+ name = "Name"
110+ value = { Name }
111+ onChangeText = { ( value ) => handleChange ( 'Name' , value ) }
112+ />
113+ </ Input >
114+
115+ < FormControlHelper >
116+ < FormControlHelperText >
117+ Plugin identifier name
118+ </ FormControlHelperText >
119+ </ FormControlHelper >
120+ </ FormControl >
121+ < FormControl >
122+ < FormControlLabel >
123+ < FormControlLabelText > URI</ FormControlLabelText >
124+ </ FormControlLabel >
125+
126+ < Input variant = "underlined" >
127+ < InputField
128+ type = "text"
129+ name = "URI"
130+ value = { URI }
131+ onChangeText = { ( value ) => handleChange ( 'URI' , value ) }
132+ />
133+ </ Input >
134+
135+ < FormControlHelper >
136+ < FormControlHelperText >
137+ { 'Plugin will be @ "http://spr/plugins/' + ( URI || 'URI' ) + '"' }
138+ </ FormControlHelperText >
139+ </ FormControlHelper >
140+ </ FormControl >
141+
142+ < FormControl >
143+ < FormControlLabel >
144+ < FormControlLabelText > UNIX Path</ FormControlLabelText >
145+ </ FormControlLabel >
146+
147+ < Input variant = "underlined" >
148+ < InputField
149+ type = "text"
150+ value = { UnixPath }
151+ onChangeText = { ( value ) => handleChange ( 'UnixPath' , value ) }
152+ />
153+ </ Input >
154+
155+ < FormControlHelper >
156+ < FormControlHelperText >
157+ Plugin pathname for unix socket
158+ </ FormControlHelperText >
159+ </ FormControlHelper >
160+ </ FormControl >
161+
162+ < FormControl >
163+ < FormControlLabel >
164+ < FormControlLabelText > ComposeFilePath</ FormControlLabelText >
165+ </ FormControlLabel >
166+
167+ < Input variant = "underlined" >
168+ < InputField
169+ type = "text"
170+ value = { ComposeFilePath }
171+ onChangeText = { ( value ) => handleChange ( 'ComposeFilePath' , value ) }
172+ />
173+ </ Input >
174+
175+ < FormControlHelper >
176+ < FormControlHelperText >
177+ Docker Compose Filepath
178+ </ FormControlHelperText >
179+ </ FormControlHelper >
180+ </ FormControl >
181+
182+ < FormControl >
183+ < FormControlLabel >
184+ < FormControlLabelText > Git URL</ FormControlLabelText >
185+ </ FormControlLabel >
186+
187+ < Input variant = "underlined" >
188+ < InputField
189+ type = "text"
190+ value = { GitURL }
191+ onChangeText = { ( value ) => handleChange ( 'GitURL' , value ) }
192+ />
193+ </ Input >
194+
195+ < FormControlHelper >
196+ < FormControlHelperText >
197+ Git repository URL for the plugin
198+ </ FormControlHelperText >
199+ </ FormControlHelper >
200+ </ FormControl >
201+
202+ < FormControl >
203+ < FormControlLabel >
204+ < FormControlLabelText > Install Token Path</ FormControlLabelText >
205+ </ FormControlLabel >
206+
207+ < Input variant = "underlined" >
208+ < InputField
209+ type = "text"
210+ value = { InstallTokenPath }
211+ onChangeText = { ( value ) => handleChange ( 'InstallTokenPath' , value ) }
212+ />
213+ </ Input >
214+
215+ < FormControlHelper >
216+ < FormControlHelperText >
217+ Path to installation token file
218+ </ FormControlHelperText >
219+ </ FormControlHelper >
220+ </ FormControl >
221+
222+ < FormControl >
223+ < FormControlLabel >
224+ < FormControlLabelText > Scoped Paths</ FormControlLabelText >
225+ </ FormControlLabel >
226+
227+ < Input variant = "underlined" >
228+ < InputField
229+ type = "text"
230+ value = { ScopedPaths }
231+ onChangeText = { ( value ) => handleChange ( 'ScopedPaths' , value ) }
232+ />
233+ </ Input >
234+
235+ < FormControlHelper >
236+ < FormControlHelperText >
237+ Comma-separated list of paths the plugin can access
238+ </ FormControlHelperText >
239+ </ FormControlHelper >
240+ </ FormControl >
241+
242+ < FormControl >
243+ < Checkbox
244+ value = { Enabled }
245+ onChange = { setEnabled }
246+ >
247+ < CheckboxIndicator mr = "$2" >
248+ < CheckboxIcon />
249+ </ CheckboxIndicator >
250+ < CheckboxLabel > Enabled</ CheckboxLabel >
251+ </ Checkbox >
252+
253+ < FormControlHelper >
254+ < FormControlHelperText >
255+ Enable or disable the plugin
256+ </ FormControlHelperText >
257+ </ FormControlHelper >
258+ </ FormControl >
259+
260+ < FormControl >
261+ < Checkbox
262+ value = { HasUI }
263+ onChange = { setHasUI }
264+ >
265+ < CheckboxIndicator mr = "$2" >
266+ < CheckboxIcon />
267+ </ CheckboxIndicator >
268+ < CheckboxLabel > Has UI</ CheckboxLabel >
269+ </ Checkbox >
270+
271+ < FormControlHelper >
272+ < FormControlHelperText >
273+ Plugin provides a user interface
274+ </ FormControlHelperText >
275+ </ FormControlHelper >
276+ </ FormControl >
277+
278+ < HStack space = "md" >
279+ < Button action = "primary" size = "md" onPress = { handleSubmit } >
280+ < ButtonText > Update</ ButtonText >
281+ </ Button >
282+ { onClose && (
283+ < Button action = "secondary" variant = "outline" size = "md" onPress = { onClose } >
284+ < ButtonText > Cancel</ ButtonText >
285+ </ Button >
286+ ) }
287+ </ HStack >
288+ </ VStack >
289+ )
290+ }
291+
292+ export default EditPlugin
0 commit comments