@@ -220,42 +220,57 @@ export const menuItems: MenuItem[] = [
220
220
saveFile ( ocdDocument ) . then ( ( resp ) => console . info ( 'Saved' , resp ) )
221
221
}
222
222
} ,
223
+ // {
224
+ // label: 'OpenTofu (Terraform)',
225
+ // click: (ocdDocument: OcdDocument, setOcdDocument: Function) => { // Convert to call to Electron API
226
+ // const writeTerraformFile = async (dirHandle: FileSystemDirectoryHandle, filename: string, contents: string[]) => {
227
+ // const fileHandle: FileSystemFileHandle = await dirHandle.getFileHandle(filename, {create: true})
228
+ // // @ts -ignore
229
+ // const writable = await fileHandle.createWritable()
230
+ // await writable.write(contents.join('\n'))
231
+ // await writable.close()
232
+ // return writable
233
+ // }
234
+ // const saveFile = async (ocdDocument: OcdDocument) => {
235
+ // try {
236
+ // // @ts -ignore
237
+ // const handle = await showDirectoryPicker()
238
+ // // const writable = await handle.createWritable()
239
+ // const exporter = new OcdTerraformExporter()
240
+ // const terraform = exporter.export(ocdDocument.design)
241
+ // const fileWriters = Object.entries(terraform).map(([k, v]) => writeTerraformFile(handle, k, v))
242
+ // return Promise.all(fileWriters)
243
+ // } catch (err: any) {
244
+ // console.error(err.name, err.message);
245
+ // }
246
+ // }
247
+ // saveFile(ocdDocument).then((resp) => console.info('Saved', resp))
248
+ // }
249
+ // },
250
+ {
251
+ label : 'Resource Manager' ,
252
+ click : ( ocdDocument : OcdDocument , setOcdDocument : Function , ocdConsoleConfig : OcdConsoleConfig , setOcdConsoleConfig : Function , activeFile : Record < string , any > , setActiveFile : Function ) => {
253
+ const clone = OcdDocument . clone ( ocdDocument )
254
+ clone . dialog . resourceManager = true
255
+ console . debug ( 'Menu: Setting Resource Manager' , ocdDocument , clone )
256
+ setOcdDocument ( clone )
257
+ }
258
+ } ,
223
259
{
224
260
label : 'OpenTofu (Terraform)' ,
225
- click : ( ocdDocument : OcdDocument , setOcdDocument : Function ) => { // Convert to call to Electron API
226
- const writeTerraformFile = async ( dirHandle : FileSystemDirectoryHandle , filename : string , contents : string [ ] ) => {
227
- const fileHandle : FileSystemFileHandle = await dirHandle . getFileHandle ( filename , { create : true } )
228
- // @ts -ignore
229
- const writable = await fileHandle . createWritable ( )
230
- await writable . write ( contents . join ( '\n' ) )
231
- await writable . close ( )
232
- return writable
233
- }
234
- const saveFile = async ( ocdDocument : OcdDocument ) => {
235
- try {
236
- // @ts -ignore
237
- const handle = await showDirectoryPicker ( )
238
- // const writable = await handle.createWritable()
239
- const exporter = new OcdTerraformExporter ( )
240
- const terraform = exporter . export ( ocdDocument . design )
241
- const fileWriters = Object . entries ( terraform ) . map ( ( [ k , v ] ) => writeTerraformFile ( handle , k , v ) )
242
- return Promise . all ( fileWriters )
243
- } catch ( err : any ) {
244
- console . error ( err . name , err . message ) ;
261
+ click : ( ocdDocument : OcdDocument , setOcdDocument : Function , ocdConsoleConfig : OcdConsoleConfig , setOcdConsoleConfig : Function , activeFile : Record < string , any > , setActiveFile : Function ) => {
262
+ const suggestedFilename = activeFile . name . replaceAll ( '.okit' , '.xlsx' )
263
+ const design = JSON . parse ( JSON . stringify ( ocdDocument . design ) ) // Resolve cloning issue when design changed
264
+ console . debug ( 'Export Excel Design:' , design )
265
+ OcdDesignFacade . exportToTerraform ( design , suggestedFilename ) . then ( ( results ) => {
266
+ if ( ! results . canceled ) {
267
+ console . debug ( 'Design Exported to OpenTofu' )
268
+ } else {
269
+ console . debug ( 'Design Exported to OpenTofu Cancelled' )
245
270
}
246
- }
247
- saveFile ( ocdDocument ) . then ( ( resp ) => console . info ( 'Saved' , resp ) )
271
+ } ) . catch ( ( resp ) => { console . warn ( 'Save Design Failed with' , resp ) } )
248
272
}
249
273
} ,
250
- // {
251
- // label: 'Resource Manager',
252
- // click: (ocdDocument: OcdDocument, setOcdDocument: Function, ocdConsoleConfig: OcdConsoleConfig, setOcdConsoleConfig: Function, activeFile: Record<string, any>, setActiveFile: Function) => {
253
- // const clone = OcdDocument.clone(ocdDocument)
254
- // clone.dialog.resourceManager = true
255
- // console.debug('Menu: Setting Resource Manager', ocdDocument, clone)
256
- // setOcdDocument(clone)
257
- // }
258
- // },
259
274
{
260
275
label : 'Excel' ,
261
276
click : ( ocdDocument : OcdDocument , setOcdDocument : Function , ocdConsoleConfig : OcdConsoleConfig , setOcdConsoleConfig : Function , activeFile : Record < string , any > , setActiveFile : Function ) => {
0 commit comments