Skip to content

Commit

Permalink
fix: Resolve SonarCloud warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
toxophilist committed Aug 29, 2024
1 parent 3111787 commit f1b6890
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@

import { CompartmentPickerProps, QueryDialogProps } from "../../types/Dialogs"
import { OciApiFacade } from "../../facade/OciApiFacade"
import { useContext, useState } from "react"
// import { OciCompartment } from "../../model/provider/oci/resources"
import React, { useContext, useState } from "react"
import { OciModelResources } from '@ocd/model'
import { OcdDocument } from "../OcdDocument"
import { OcdUtils } from '@ocd/core'
import { ActiveFileContext, ConsoleConfigContext } from "../../pages/OcdConsole"
import React from "react"

export const OcdQueryDialog = ({ocdDocument, setOcdDocument}: QueryDialogProps): JSX.Element => {
const {activeFile, setActiveFile} = useContext(ActiveFileContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,26 @@
** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
*/

import { CompartmentPickerProps, QueryDialogProps } from "../../types/Dialogs"
import { QueryDialogProps } from "../../types/Dialogs"
import { OciApiFacade } from "../../facade/OciApiFacade"
import { useContext, useState } from "react"
// import { OciCompartment } from "../../model/provider/oci/resources"
import { OciModelResources } from '@ocd/model'
import { OcdDocument } from "../OcdDocument"
import { OcdUtils } from '@ocd/core'
import { ActiveFileContext, CacheContext, ConsoleConfigContext } from "../../pages/OcdConsole"
import React from "react"
import React, { useContext, useState } from "react"
import { CacheContext, ConsoleConfigContext } from "../../pages/OcdConsole"
import OcdConsoleConfig from "../OcdConsoleConfiguration"
import { OcdCacheData } from "../OcdCache"

export const OcdReferenceDataQueryDialog = ({ocdDocument, setOcdDocument}: QueryDialogProps): JSX.Element => {
const {activeFile, setActiveFile} = useContext(ActiveFileContext)
const {ocdConsoleConfig, setOcdConsoleConfig} = useContext(ConsoleConfigContext)
const {ocdCache, setOcdCache} = useContext(CacheContext)
const loadingState = '......Reading OCI Config'
const regionsLoading = {id: 'Select Valid Profile', displayName: 'Select Valid Profile'}
const [className, setClassName] = useState(`ocd-reference-data-query-dialog`)
const className = `ocd-reference-data-query-dialog`
const [workingClassName, setWorkingClassName] = useState(`ocd-query-wrapper hidden`)
const [cursor, setCursor] = useState('default')
const [profiles, setProfiles] = useState([loadingState])
const [profilesLoaded, setProfilesLoaded] = useState(false)
const [regions, setRegions] = useState([regionsLoading])
const [compartments, setCompartments] = useState([] as OciModelResources.OciCompartment[])
const [selectedProfile, setSelectedProfile] = useState('DEFAULT')
const [selectedRegion, setSelectedRegion] = useState('')
const [selectedCompartmentIds, setSelectedCompartmentIds] = useState([])
const [hierarchy, setHierarchy] = useState('')
const refs: Record<string, React.RefObject<any>> = compartments.reduce((acc, value: OciModelResources.OciCompartment) => {
acc[value.hierarchy] = React.createRef();
return acc;
}, {} as Record<string, React.RefObject<any>>);

if (!profilesLoaded) OciApiFacade.loadOCIConfigProfileNames().then((results) => {
setProfilesLoaded(true)
setProfiles(results)
Expand Down Expand Up @@ -82,20 +69,6 @@ export const OcdReferenceDataQueryDialog = ({ocdDocument, setOcdDocument}: Query
setCursor('default')
console.debug('OcdReferenceDataQueryDialog: Cache', ocdCache)
})
// // setClassName(`${className} ocd-busy-cursor`)
// OciApiFacade.queryDropdown(selectedProfile, selectedRegion).then((results) => {
// // @ts-ignore
// console.debug('OcdReferenceDataQueryDialog: Query Dropdown', JSON.stringify(results, null, 2))
// const clone = OcdConsoleConfig.clone(ocdConsoleConfig)
// console.debug('OcdReferenceDataQueryDialog: Cache', ocdCache)
// ocdCache.cache.dropdownData[selectedProfile] = {all: results}
// ocdCache.cache.profile = selectedProfile
// console.debug('OcdReferenceDataQueryDialog: Cache', ocdCache)
// clone.queryReferenceData = !ocdConsoleConfig.queryReferenceData
// setOcdConsoleConfig(clone)
// setAndSaveOcdCache(OcdCacheData.clone(ocdCache))
// setCursor('default')
// })
}

return (
Expand Down
4 changes: 2 additions & 2 deletions ocd/packages/model/src/layout/OcdCommonLayoutEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export class OcdCommonLayoutEngine {
return coords.filter(c => c.pgid === '') // Only Coords Without Parent
}

layout(detailed: boolean = true, coords: OcdViewCoords[]): OcdViewCoords[] {
layout(detailed: boolean, coords: OcdViewCoords[]): OcdViewCoords[] {
const rootCoords = coords ? this.createCoordsHierarchy(coords) : this.createCoordsHierarchy(this.coords)
rootCoords.filter((c) => c.container).forEach((p) => this.layoutChildren(detailed, p))
this.layoutRoot(detailed, rootCoords)
return rootCoords
}

layoutChildren(detailed: boolean = true, parent: OcdViewCoords): OcdViewCoords {
layoutChildren(detailed: boolean, parent: OcdViewCoords): OcdViewCoords {
if (parent.coords) {
// Reset Width & Height
parent.w = this.spacing
Expand Down
12 changes: 6 additions & 6 deletions ocd/packages/model/src/layout/OcdOkitWebLayoutEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { OcdDesign, OcdViewCoords } from "../OcdDesign"
import { OcdCommonLayoutEngine } from "./OcdCommonLayoutEngine"
import { OciResource, OciModelResources } from "../index"
import { OciResource } from "../index"

export class OcdOkitWebLayoutEngine extends OcdCommonLayoutEngine {
moveToChild: Record<string, string[]> = {'oci-subnet': ['oci-dhcp-option', 'oci-route-table', 'oci-security-list']}
Expand Down Expand Up @@ -78,7 +78,7 @@ export class OcdOkitWebLayoutEngine extends OcdCommonLayoutEngine {
return rootCoords
}

layoutChildren(detailed: boolean = true, parent: OcdViewCoords): OcdViewCoords {
layoutChildren(detailed: boolean, parent: OcdViewCoords): OcdViewCoords {
if (parent.coords) {
// Reset Width & Height
parent.w = this.spacing
Expand All @@ -104,7 +104,7 @@ export class OcdOkitWebLayoutEngine extends OcdCommonLayoutEngine {
child.x = childX
child.y = childY
// Add Spacing
childX += (this.spacing + (detailed ? this.detailedWidth : this.simpleWidth) as number)
childX += (this.spacing + (detailed ? this.detailedWidth : this.simpleWidth))
// Size Container
parent.w = Math.max(parent.w, (childX + this.spacing))
parent.h = childY + this.spacing + this.simpleHeight
Expand All @@ -131,7 +131,7 @@ export class OcdOkitWebLayoutEngine extends OcdCommonLayoutEngine {
return parent
}

layoutTopEdgeChildren(detailed: boolean = true, parent: OcdViewCoords, edge: string[]): OcdViewCoords {
layoutTopEdgeChildren(detailed: boolean, parent: OcdViewCoords, edge: string[]): OcdViewCoords {
console.debug('OcdOkitWebLayoutEngine: layoutTopEdgeChildren:', parent.class, edge)
let childX = this.spacing + this.detailedWidth
let childY = ((this.simpleHeight/2) * -1) - this.edgeAdjustment
Expand All @@ -140,15 +140,15 @@ export class OcdOkitWebLayoutEngine extends OcdCommonLayoutEngine {
child.x = childX
child.y = childY
// Add Spacing
childX += (this.spacing + (detailed ? this.detailedWidth : this.simpleWidth) as number)
childX += (this.spacing + (detailed ? this.detailedWidth : this.simpleWidth))
// Size Container
parent.w = Math.max(parent.w, (childX + this.spacing))
})

return parent
}

layoutRightEdgeChildren(detailed: boolean = true, parent: OcdViewCoords, edge: string[]): OcdViewCoords {
layoutRightEdgeChildren(detailed: boolean, parent: OcdViewCoords, edge: string[]): OcdViewCoords {
console.debug('OcdOkitWebLayoutEngine: layoutRightEdgeChildren:', parent.class, edge)
let childX = parent.w - this.simpleWidth - this.edgeAdjustment
let childY = this.spacing + this.simpleHeight
Expand Down

0 comments on commit f1b6890

Please sign in to comment.