@@ -9,10 +9,11 @@ import { RemixUIGridView } from '@remix-ui/remix-ui-grid-view'
9
9
import { RemixUIGridSection } from '@remix-ui/remix-ui-grid-section'
10
10
import { RemixUIGridCell } from '@remix-ui/remix-ui-grid-cell'
11
11
import isElectron from 'is-electron'
12
- import type { TemplateGroup } from '@remix-ui/workspace'
12
+ import type { Template , TemplateGroup } from '@remix-ui/workspace'
13
13
import './templates-selection-plugin.css'
14
14
import { templates } from './templates'
15
15
import { TEMPLATE_METADATA } from '@remix-ui/workspace'
16
+ import { TemplateType } from 'libs/remix-ui/workspace/src/lib/types'
16
17
17
18
//@ts -ignore
18
19
const _paq = ( window . _paq = window . _paq || [ ] )
@@ -88,27 +89,54 @@ export class TemplatesSelectionPlugin extends ViewPlugin {
88
89
89
90
}
90
91
91
- const createWorkspace = async ( item , templateName : string ) => {
92
+ const createWorkspace = async ( item : Template , templateGroup : TemplateGroup ) => {
92
93
const defaultName = await this . call ( 'filePanel' , 'getAvailableWorkspaceName' , item . displayName )
93
94
const username = await this . call ( 'settings' , 'get' , 'settings/github-user-name' )
94
95
const email = await this . call ( 'settings' , 'get' , 'settings/github-email' )
95
96
const gitNotSet = ! username || ! email
96
97
let workspaceName = defaultName
97
98
let initGit = false
99
+ this . opts = { }
98
100
const modal : AppModal = {
99
101
id : 'TemplatesSelection' ,
100
102
title : window . _intl . formatMessage ( { id : ! isElectron ( ) ? 'filePanel.workspace.create' : 'filePanel.workspace.create.desktop' } ) ,
101
- message : await createModalMessage ( defaultName , gitNotSet , ( value ) => workspaceName = value , ( value ) => initGit = ! ! value , ( event ) => setCheckBoxRefs ( event ) , ( event ) => setRadioRefs ( event ) , templateName ) ,
103
+ message : await createModalMessage (
104
+ item ,
105
+ templateGroup ,
106
+ defaultName ,
107
+ gitNotSet ,
108
+ ( value ) => workspaceName = value ,
109
+ ( value ) => initGit = ! ! value ,
110
+ ( event ) => setCheckBoxRefs ( event ) ,
111
+ ( event ) => setRadioRefs ( event ) ,
112
+ ) ,
102
113
okLabel : window . _intl . formatMessage ( { id : ! isElectron ( ) ? 'filePanel.ok' : 'filePanel.selectFolder' } ) ,
103
114
}
115
+
104
116
const modalResult = await this . call ( 'notification' , 'modal' , modal )
117
+ console . log ( 'Creating workspace with template' , item , this . opts )
105
118
if ( ! modalResult ) return
106
119
_paq . push ( [ 'trackEvent' , 'template-selection' , 'createWorkspace' , item . value ] )
107
120
this . emit ( 'createWorkspaceReducerEvent' , workspaceName , item . value , this . opts , false , errorCallback , initGit )
108
121
}
109
122
110
- const addToCurrentWorkspace = async ( item ) => {
123
+ const addToCurrentWorkspace = async ( item : Template , templateGroup : TemplateGroup ) => {
124
+ this . opts = { }
111
125
_paq . push ( [ 'trackEvent' , 'template-selection' , 'addToCurrentWorkspace' , item . value ] )
126
+ if ( templateGroup . hasOptions ) {
127
+ const modal : AppModal = {
128
+ id : 'TemplatesSelection' ,
129
+ title : window . _intl . formatMessage ( { id : 'filePanel.customizeTemplate' } ) ,
130
+ message : createOptionsModal (
131
+ ( event ) => setCheckBoxRefs ( event ) ,
132
+ ( event ) => setRadioRefs ( event ) , ) ,
133
+ okLabel : window . _intl . formatMessage ( { id : 'filePanel.ok' } ) ,
134
+ cancelLabel : window . _intl . formatMessage ( { id : 'filePanel.cancel' } )
135
+ }
136
+ const modalResult = await this . call ( 'notification' , 'modal' , modal )
137
+ if ( ! modalResult ) return
138
+ }
139
+ console . log ( 'Adding template to current workspace' , item , this . opts )
112
140
this . emit ( 'addTemplateToWorkspaceReducerEvent' , item . value , this . opts , false , async ( e , data ) => {
113
141
if ( e ) {
114
142
const modal : AppModal = {
@@ -208,7 +236,7 @@ export class TemplatesSelectionPlugin extends ViewPlugin {
208
236
< span
209
237
data-id = { `create-${ item . value } ${ item . opts ? JSON . stringify ( item . opts ) : '' } ` }
210
238
onClick = { async ( ) => {
211
- createWorkspace ( item , template . name )
239
+ createWorkspace ( item , template )
212
240
} }
213
241
className = "btn btn-sm mr-2 border border-primary"
214
242
>
@@ -223,7 +251,7 @@ export class TemplatesSelectionPlugin extends ViewPlugin {
223
251
>
224
252
< span
225
253
data-id = { `add-${ item . value } ` }
226
- onClick = { async ( ) => addToCurrentWorkspace ( item ) }
254
+ onClick = { async ( ) => addToCurrentWorkspace ( item , template ) }
227
255
className = "btn btn-sm border"
228
256
>
229
257
Add to current
@@ -257,13 +285,14 @@ export class TemplatesSelectionPlugin extends ViewPlugin {
257
285
}
258
286
259
287
const createModalMessage = async (
288
+ template : Template ,
289
+ templateGroup : TemplateGroup ,
260
290
defaultName : string ,
261
291
gitConfigNotSet : boolean ,
262
292
onChangeTemplateName : ( name : string ) => void ,
263
293
onChangeInitGit : ( name : string ) => void ,
264
294
onChangeCheckBoxRefs : ( event : any ) => void ,
265
295
onChangeRadioRefs : ( event : any ) => void ,
266
- templateName ?: string
267
296
) => {
268
297
return (
269
298
< >
@@ -278,57 +307,7 @@ const createModalMessage = async (
278
307
onChange = { ( e ) => onChangeTemplateName ( e . target . value ) }
279
308
onInput = { ( e ) => onChangeTemplateName ( ( e . target as any ) . value ) }
280
309
/>
281
- { templateName ?. includes ( 'OpenZeppelin' ) ? (
282
- < div id = "ozcustomization" data-id = "ozCustomization" style = { { display : 'block' } } className = "mb-2" >
283
- < label className = "form-check-label d-block mb-2" style = { { fontWeight : 'bolder' } } >
284
- < FormattedMessage id = "filePanel.customizeTemplate" />
285
- </ label >
286
-
287
- < label id = "wsName" className = "form-check-label d-block mb-1" >
288
- < FormattedMessage id = "filePanel.features" />
289
- </ label >
290
- < div className = "mb-2" >
291
- < div className = "d-flex ml-2 custom-control custom-checkbox" >
292
- < input className = "custom-control-input" type = "checkbox" name = "feature" value = "mintable" id = "mintable" onChange = { onChangeCheckBoxRefs } />
293
- < label className = "form-check-label custom-control-label" htmlFor = "mintable" data-id = "featureTypeMintable" >
294
- < FormattedMessage id = "filePanel.mintable" />
295
- </ label >
296
- </ div >
297
- < div className = "d-flex ml-2 custom-control custom-checkbox" >
298
- < input className = "custom-control-input" type = "checkbox" name = "feature" value = "burnable" id = "burnable" onChange = { onChangeCheckBoxRefs } />
299
- < label className = "form-check-label custom-control-label" htmlFor = "burnable" data-id = "featureTypeBurnable" >
300
- < FormattedMessage id = "filePanel.burnable" />
301
- </ label >
302
- </ div >
303
- < div className = "d-flex ml-2 custom-control custom-checkbox" >
304
- < input className = "custom-control-input" type = "checkbox" name = "feature" value = "pausable" id = "pausable" onChange = { onChangeCheckBoxRefs } />
305
- < label className = "form-check-label custom-control-label" htmlFor = "pausable" data-id = "featureTypePausable" >
306
- < FormattedMessage id = "filePanel.pausable" />
307
- </ label >
308
- </ div >
309
- </ div >
310
-
311
- < label id = "wsName" className = "form-check-label d-block mb-1" >
312
- < FormattedMessage id = "filePanel.upgradeability" />
313
- </ label >
314
- < div >
315
- < div className = "d-flex ml-2 custom-control custom-radio" >
316
- < input className = "custom-control-input" type = "radio" name = "upgradeability" value = "transparent" id = "transparent" onChange = { onChangeRadioRefs } />
317
- < label className = "form-check-label custom-control-label" htmlFor = "transparent" data-id = "upgradeTypeTransparent" >
318
- < FormattedMessage id = "filePanel.transparent" />
319
- </ label >
320
- </ div >
321
- < div className = "d-flex ml-2 custom-control custom-radio" >
322
- < input className = "custom-control-input" type = "radio" name = "upgradeability" value = "uups" id = "uups" onChange = { onChangeRadioRefs } />
323
- < label className = "form-check-label custom-control-label" htmlFor = "uups" data-id = "upgradeTypeUups" >
324
- UUPS
325
- </ label >
326
- </ div >
327
- </ div >
328
- </ div >
329
- ) : (
330
- < > </ >
331
- ) }
310
+ { templateGroup . hasOptions ? createOptionsModal ( onChangeCheckBoxRefs , onChangeRadioRefs ) : null }
332
311
< div className = "d-flex py-2 align-items-center custom-control custom-checkbox" >
333
312
< input
334
313
id = "initGitRepository"
@@ -359,3 +338,42 @@ const createModalMessage = async (
359
338
)
360
339
}
361
340
341
+ const createOptionsModal = (
342
+ onChangeCheckBoxRefs : ( event : any ) => void ,
343
+ onChangeRadioRefs : ( event : any ) => void
344
+ ) => (
345
+ < div id = "ozcustomization" data-id = "ozCustomization" style = { { display : 'block' } } className = "mb-2" >
346
+ < label className = "form-check-label d-block mb-2" style = { { fontWeight : 'bolder' } } >
347
+ < FormattedMessage id = "filePanel.customizeTemplate" />
348
+ </ label >
349
+
350
+ < label className = "form-check-label d-block mb-1" >
351
+ < FormattedMessage id = "filePanel.features" />
352
+ </ label >
353
+ < div className = "mb-2" >
354
+ { [ 'mintable' , 'burnable' , 'pausable' ] . map ( ( feature ) => (
355
+ < div key = { feature } className = "d-flex ml-2 custom-control custom-checkbox" >
356
+ < input className = "custom-control-input" type = "checkbox" name = "feature" value = { feature } id = { feature } onChange = { onChangeCheckBoxRefs } />
357
+ < label className = "form-check-label custom-control-label" htmlFor = { feature } data-id = { `featureType${ feature . charAt ( 0 ) . toUpperCase ( ) + feature . slice ( 1 ) } ` } >
358
+ < FormattedMessage id = { `filePanel.${ feature } ` } />
359
+ </ label >
360
+ </ div >
361
+ ) ) }
362
+ </ div >
363
+
364
+ < label className = "form-check-label d-block mb-1" >
365
+ < FormattedMessage id = "filePanel.upgradeability" />
366
+ </ label >
367
+ < div >
368
+ { [ 'transparent' , 'uups' ] . map ( ( type ) => (
369
+ < div key = { type } className = "d-flex ml-2 custom-control custom-radio" >
370
+ < input className = "custom-control-input" type = "radio" name = "upgradeability" value = { type } id = { type } onChange = { onChangeRadioRefs } />
371
+ < label className = "form-check-label custom-control-label" htmlFor = { type } data-id = { `upgradeType${ type . charAt ( 0 ) . toUpperCase ( ) + type . slice ( 1 ) } ` } >
372
+ { type . toUpperCase ( ) }
373
+ </ label >
374
+ </ div >
375
+ ) ) }
376
+ </ div >
377
+ </ div >
378
+ )
379
+
0 commit comments