Skip to content

Commit e7e02ef

Browse files
committed
Nightly Merge Wed 19 Feb 2025 11:39:29 GMT
2 parents 8d0cb76 + faa6c3a commit e7e02ef

File tree

3 files changed

+49
-33
lines changed

3 files changed

+49
-33
lines changed

ocd/packages/core/src/OcdNoneVisualResources.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// Resources that will be excluded from None OpenTofu exports
77
export const ociNoneVisualResources: string[] = [
88
'network_security_group_security_rule',
9+
'volume_attachment',
910
'vnic_attachment'
1011
]
1112
export const azureNoneVisualResources: string[] = []

ocd/packages/react/src/components/Menu.ts

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -220,42 +220,57 @@ export const menuItems: MenuItem[] = [
220220
saveFile(ocdDocument).then((resp) => console.info('Saved', resp))
221221
}
222222
},
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+
},
223259
{
224260
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')
245270
}
246-
}
247-
saveFile(ocdDocument).then((resp) => console.info('Saved', resp))
271+
}).catch((resp) => {console.warn('Save Design Failed with', resp)})
248272
}
249273
},
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-
// },
259274
{
260275
label: 'Excel',
261276
click: (ocdDocument: OcdDocument, setOcdDocument: Function, ocdConsoleConfig: OcdConsoleConfig, setOcdConsoleConfig: Function, activeFile: Record<string, any>, setActiveFile: Function) => {

ocd/packages/react/src/pages/OcdTabular.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { useState } from "react"
77
import { ConsolePageProps } from "../types/Console"
8-
import { OcdUtils } from "@ocd/core"
8+
import { OcdUtils, ociNoneVisualResources } from "@ocd/core"
99
import { OciDefault } from "../components/tabular/provider/oci/OciTabularContents"
1010
import * as ociTabularResources from '../components/tabular/provider/oci/resources'
1111
import { OcdDesignFacade } from "../facade/OcdDesignFacade"
@@ -35,7 +35,7 @@ const OcdTabular = ({ ocdConsoleConfig, setOcdConsoleConfig, ocdDocument, setOcd
3535
return (
3636
<div className='ocd-tabular-view'>
3737
<div id='ocd_resources_bar' className='ocd-designer-canvas-layers'>
38-
{Object.keys(ociResources).sort(OcdUtils.simpleSort).map((k: string) => {
38+
{Object.keys(ociResources).filter((k: string) => !ociNoneVisualResources.includes(k)).sort(OcdUtils.simpleSort).map((k: string) => {
3939
return <div className={`ocd-designer-canvas-layer ${k === selected ? 'ocd-layer-selected' : ''}`} key={k}><label id={k} onClick={onClick} aria-hidden>{`${OcdUtils.toTitle(k)} (${ociResources[k].length})`}</label></div>
4040
})}
4141
</div>

0 commit comments

Comments
 (0)