Skip to content

Commit

Permalink
refactor: remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
toxophilist committed Dec 2, 2024
1 parent fcaa245 commit cdac999
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
52 changes: 22 additions & 30 deletions ocd/packages/react/src/components/OcdCanvasLayers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,29 @@ const OcdCanvasLayer = ({ ocdDocument, setOcdDocument, layer } : LayerBarLayerPr
)
}

const addLayer = (ocdDocument: OcdDocument, setOcdDocument: React.Dispatch<any>, setMenuVisible: React.Dispatch<any> | undefined) => {
console.debug('Adding Layer')
const compartment = OciModelResources.OciCompartment.newResource()
ocdDocument.design.model.oci.resources.compartment.push(compartment)
// Add Layer
ocdDocument.addLayer(compartment.id)
const page: OcdViewPage = ocdDocument.getActivePage()
page.layers.forEach((l: OcdViewLayer) => l.selected = l.id === compartment.id)
const selectedResource: OcdSelectedResource = {
modelId: compartment.id,
pageId: ocdDocument.getActivePage().id,
coordsId: '',
class: page.layers[0].class
}
ocdDocument.selectedResource = selectedResource
setOcdDocument(OcdDocument.clone(ocdDocument))
if (setMenuVisible) setMenuVisible(false)
}

const OcdCanvasLayers = ({ ocdDocument, setOcdDocument }: LayerBarLayersProps): JSX.Element => {
const onClickAddLayer = () => {
console.debug('OcdCanvasLayers: Adding Layer')
const compartment = OciModelResources.OciCompartment.newResource()
ocdDocument.design.model.oci.resources.compartment.push(compartment)
// Add Layer
ocdDocument.addLayer(compartment.id)
const page: OcdViewPage = ocdDocument.getActivePage()
page.layers.forEach((l: OcdViewLayer) => l.selected = l.id === compartment.id)
const selectedResource: OcdSelectedResource = {
modelId: compartment.id,
pageId: ocdDocument.getActivePage().id,
coordsId: '',
class: page.layers[0].class
}
ocdDocument.selectedResource = selectedResource
setOcdDocument(OcdDocument.clone(ocdDocument))
addLayer(ocdDocument, setOcdDocument, undefined)
}

const page: OcdViewPage = ocdDocument.getActivePage()
Expand Down Expand Up @@ -157,22 +163,8 @@ const OcdLayersThreeDotMenu = ({ocdDocument, setOcdDocument}: LayerBarMenuProps)
setMenuVisible(false)
}
const onAddLayerClick = () => {
console.debug('OcdCanvasLayers: Adding Layer')
const compartment = OciModelResources.OciCompartment.newResource()
ocdDocument.design.model.oci.resources.compartment.push(compartment)
// Add Layer
ocdDocument.addLayer(compartment.id)
const page: OcdViewPage = ocdDocument.getActivePage()
page.layers.forEach((l: OcdViewLayer) => l.selected = l.id === compartment.id)
const selectedResource: OcdSelectedResource = {
modelId: compartment.id,
pageId: ocdDocument.getActivePage().id,
coordsId: '',
class: page.layers[0].class
}
ocdDocument.selectedResource = selectedResource
setOcdDocument(OcdDocument.clone(ocdDocument))
setMenuVisible(false)
console.debug('OcdCanvasLayers: OcdLayersThreeDotMenu: Adding Layer')
addLayer(ocdDocument, setOcdDocument, setMenuVisible)
}
const page: OcdViewPage = ocdDocument.getActivePage()
const layer = page.layers.find((l) => l.selected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export namespace OciSecurityListConfigs {
id: 'egress_security_rules.destination',
properties: {
placeholder: '0.0.0.0/0',
pattern: "^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(3[0-2]|[1-2][0-9]|[0-9]))$)+|^var\.+$",
pattern: String.raw`^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(3[0-2]|[1-2][0-9]|[0-9]))$)+|^var\.+$`,
title: 'IPv4 CIDR block'
},
configs: []
Expand Down Expand Up @@ -44,13 +44,13 @@ export namespace OciSecurityListConfigs {
id: 'ingress_security_rules',
properties: {},
configs: [],
summary: (open: boolean, resource: OcdResource, openValue: string) => open ? openValue : resource && resource.description.trim().length > 0 ? resource.description : openValue
summary: (open: boolean, resource: OcdResource, openValue: string) => open ? openValue : resource?.description.trim().length > 0 ? resource.description : openValue
},
{
id: 'ingress_security_rules.source',
properties: {
placeholder: '0.0.0.0/0',
pattern: "^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(3[0-2]|[1-2][0-9]|[0-9]))$)+|^var\.+$",
pattern: String.raw`^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(3[0-2]|[1-2][0-9]|[0-9]))$)+|^var\.+$`,
title: 'IPv4 CIDR block'
},
configs: []
Expand Down

0 comments on commit cdac999

Please sign in to comment.