Skip to content

Commit

Permalink
Nightly Merge Wed 19 Feb 2025 11:39:29 GMT
Browse files Browse the repository at this point in the history
  • Loading branch information
toxophilist committed Feb 19, 2025
2 parents 8d0cb76 + faa6c3a commit e7e02ef
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 33 deletions.
1 change: 1 addition & 0 deletions ocd/packages/core/src/OcdNoneVisualResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Resources that will be excluded from None OpenTofu exports
export const ociNoneVisualResources: string[] = [
'network_security_group_security_rule',
'volume_attachment',
'vnic_attachment'
]
export const azureNoneVisualResources: string[] = []
Expand Down
77 changes: 46 additions & 31 deletions ocd/packages/react/src/components/Menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,42 +220,57 @@ export const menuItems: MenuItem[] = [
saveFile(ocdDocument).then((resp) => console.info('Saved', resp))
}
},
// {
// label: 'OpenTofu (Terraform)',
// click: (ocdDocument: OcdDocument, setOcdDocument: Function) => { // Convert to call to Electron API
// const writeTerraformFile = async (dirHandle: FileSystemDirectoryHandle, filename: string, contents: string[]) => {
// const fileHandle: FileSystemFileHandle = await dirHandle.getFileHandle(filename, {create: true})
// // @ts-ignore
// const writable = await fileHandle.createWritable()
// await writable.write(contents.join('\n'))
// await writable.close()
// return writable
// }
// const saveFile = async (ocdDocument: OcdDocument) => {
// try {
// // @ts-ignore
// const handle = await showDirectoryPicker()
// // const writable = await handle.createWritable()
// const exporter = new OcdTerraformExporter()
// const terraform = exporter.export(ocdDocument.design)
// const fileWriters = Object.entries(terraform).map(([k, v]) => writeTerraformFile(handle, k, v))
// return Promise.all(fileWriters)
// } catch (err: any) {
// console.error(err.name, err.message);
// }
// }
// saveFile(ocdDocument).then((resp) => console.info('Saved', resp))
// }
// },
{
label: 'Resource Manager',
click: (ocdDocument: OcdDocument, setOcdDocument: Function, ocdConsoleConfig: OcdConsoleConfig, setOcdConsoleConfig: Function, activeFile: Record<string, any>, setActiveFile: Function) => {
const clone = OcdDocument.clone(ocdDocument)
clone.dialog.resourceManager = true
console.debug('Menu: Setting Resource Manager', ocdDocument, clone)
setOcdDocument(clone)
}
},
{
label: 'OpenTofu (Terraform)',
click: (ocdDocument: OcdDocument, setOcdDocument: Function) => { // Convert to call to Electron API
const writeTerraformFile = async (dirHandle: FileSystemDirectoryHandle, filename: string, contents: string[]) => {
const fileHandle: FileSystemFileHandle = await dirHandle.getFileHandle(filename, {create: true})
// @ts-ignore
const writable = await fileHandle.createWritable()
await writable.write(contents.join('\n'))
await writable.close()
return writable
}
const saveFile = async (ocdDocument: OcdDocument) => {
try {
// @ts-ignore
const handle = await showDirectoryPicker()
// const writable = await handle.createWritable()
const exporter = new OcdTerraformExporter()
const terraform = exporter.export(ocdDocument.design)
const fileWriters = Object.entries(terraform).map(([k, v]) => writeTerraformFile(handle, k, v))
return Promise.all(fileWriters)
} catch (err: any) {
console.error(err.name, err.message);
click: (ocdDocument: OcdDocument, setOcdDocument: Function, ocdConsoleConfig: OcdConsoleConfig, setOcdConsoleConfig: Function, activeFile: Record<string, any>, setActiveFile: Function) => {
const suggestedFilename = activeFile.name.replaceAll('.okit', '.xlsx')
const design = JSON.parse(JSON.stringify(ocdDocument.design)) // Resolve cloning issue when design changed
console.debug('Export Excel Design:', design)
OcdDesignFacade.exportToTerraform(design, suggestedFilename).then((results) => {
if (!results.canceled) {
console.debug('Design Exported to OpenTofu')
} else {
console.debug('Design Exported to OpenTofu Cancelled')
}
}
saveFile(ocdDocument).then((resp) => console.info('Saved', resp))
}).catch((resp) => {console.warn('Save Design Failed with', resp)})
}
},
// {
// label: 'Resource Manager',
// click: (ocdDocument: OcdDocument, setOcdDocument: Function, ocdConsoleConfig: OcdConsoleConfig, setOcdConsoleConfig: Function, activeFile: Record<string, any>, setActiveFile: Function) => {
// const clone = OcdDocument.clone(ocdDocument)
// clone.dialog.resourceManager = true
// console.debug('Menu: Setting Resource Manager', ocdDocument, clone)
// setOcdDocument(clone)
// }
// },
{
label: 'Excel',
click: (ocdDocument: OcdDocument, setOcdDocument: Function, ocdConsoleConfig: OcdConsoleConfig, setOcdConsoleConfig: Function, activeFile: Record<string, any>, setActiveFile: Function) => {
Expand Down
4 changes: 2 additions & 2 deletions ocd/packages/react/src/pages/OcdTabular.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { useState } from "react"
import { ConsolePageProps } from "../types/Console"
import { OcdUtils } from "@ocd/core"
import { OcdUtils, ociNoneVisualResources } from "@ocd/core"
import { OciDefault } from "../components/tabular/provider/oci/OciTabularContents"
import * as ociTabularResources from '../components/tabular/provider/oci/resources'
import { OcdDesignFacade } from "../facade/OcdDesignFacade"
Expand Down Expand Up @@ -35,7 +35,7 @@ const OcdTabular = ({ ocdConsoleConfig, setOcdConsoleConfig, ocdDocument, setOcd
return (
<div className='ocd-tabular-view'>
<div id='ocd_resources_bar' className='ocd-designer-canvas-layers'>
{Object.keys(ociResources).sort(OcdUtils.simpleSort).map((k: string) => {
{Object.keys(ociResources).filter((k: string) => !ociNoneVisualResources.includes(k)).sort(OcdUtils.simpleSort).map((k: string) => {
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>
})}
</div>
Expand Down

0 comments on commit e7e02ef

Please sign in to comment.