summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine')
-rw-r--r--opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/DeleteMachine.js8
-rw-r--r--opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/MachineSidebar.js (renamed from opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/MachineSidebarComponent.js)17
-rw-r--r--opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/MachineSidebarContainer.js37
-rw-r--r--opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddContainer.js5
-rw-r--r--opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitListComponent.js4
-rw-r--r--opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitListContainer.js15
-rw-r--r--opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitTabsComponent.js23
7 files changed, 41 insertions, 68 deletions
diff --git a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/DeleteMachine.js b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/DeleteMachine.js
index a7bf3719..75d458b6 100644
--- a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/DeleteMachine.js
+++ b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/DeleteMachine.js
@@ -21,18 +21,20 @@
*/
import React, { useState } from 'react'
-import { useDispatch } from 'react-redux'
+import { useDispatch, useSelector } from 'react-redux'
import { deleteMachine } from '../../../../../redux/actions/topology/machine'
import { Button } from '@patternfly/react-core'
import TrashIcon from '@patternfly/react-icons/dist/js/icons/trash-icon'
import ConfirmationModal from '../../../../modals/ConfirmationModal'
-const DeleteMachine = () => {
+function DeleteMachine() {
const dispatch = useDispatch()
const [isVisible, setVisible] = useState(false)
+ const rackId = useSelector((state) => state.objects.tile[state.interactionLevel.tileId].rack)
+ const position = useSelector((state) => state.interactionLevel.position)
const callback = (isConfirmed) => {
if (isConfirmed) {
- dispatch(deleteMachine())
+ dispatch(deleteMachine(rackId, position))
}
setVisible(false)
}
diff --git a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/MachineSidebarComponent.js b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/MachineSidebar.js
index d3d4a8cf..0c3dea98 100644
--- a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/MachineSidebarComponent.js
+++ b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/MachineSidebar.js
@@ -12,8 +12,12 @@ import {
} from '@patternfly/react-core'
import { useSelector } from 'react-redux'
-const MachineSidebarComponent = ({ machineId }) => {
- const machine = useSelector((state) => state.objects.machine[machineId])
+function MachineSidebar({ tileId, position }) {
+ const machine = useSelector(({ objects }) => {
+ const rack = objects.rack[objects.tile[tileId].rack]
+ return objects.machine[rack.machines[position - 1]]
+ })
+ const machineId = machine._id
return (
<div>
<TextContent>
@@ -31,14 +35,15 @@ const MachineSidebarComponent = ({ machineId }) => {
<Title headingLevel="h2">Units</Title>
</TextContent>
<div className="pf-u-h-100">
- <UnitTabsComponent />
+ <UnitTabsComponent machineId={machineId} />
</div>
</div>
)
}
-MachineSidebarComponent.propTypes = {
- machineId: PropTypes.string,
+MachineSidebar.propTypes = {
+ tileId: PropTypes.string.isRequired,
+ position: PropTypes.number.isRequired,
}
-export default MachineSidebarComponent
+export default MachineSidebar
diff --git a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/MachineSidebarContainer.js b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/MachineSidebarContainer.js
deleted file mode 100644
index 94d9f2c3..00000000
--- a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/MachineSidebarContainer.js
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-import React from 'react'
-import { useSelector } from 'react-redux'
-import MachineSidebarComponent from './MachineSidebarComponent'
-
-const MachineSidebarContainer = (props) => {
- const machineId = useSelector(
- (state) =>
- state.objects.rack[state.objects.tile[state.interactionLevel.tileId].rack].machines[
- state.interactionLevel.position - 1
- ]
- )
- return <MachineSidebarComponent {...props} machineId={machineId} />
-}
-
-export default MachineSidebarContainer
diff --git a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddContainer.js b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddContainer.js
index 8a6680e6..cc226d46 100644
--- a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddContainer.js
+++ b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddContainer.js
@@ -26,16 +26,17 @@ import { useDispatch, useSelector } from 'react-redux'
import { addUnit } from '../../../../../redux/actions/topology/machine'
import UnitAddComponent from './UnitAddComponent'
-const UnitAddContainer = ({ unitType }) => {
+function UnitAddContainer({ machineId, unitType }) {
const units = useSelector((state) => Object.values(state.objects[unitType]))
const dispatch = useDispatch()
- const onAdd = (id) => dispatch(addUnit(unitType, id))
+ const onAdd = (id) => dispatch(addUnit(machineId, unitType, id))
return <UnitAddComponent onAdd={onAdd} units={units} />
}
UnitAddContainer.propTypes = {
+ machineId: PropTypes.string.isRequired,
unitType: PropTypes.string.isRequired,
}
diff --git a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitListComponent.js b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitListComponent.js
index 9c3c08fd..16ebd708 100644
--- a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitListComponent.js
+++ b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitListComponent.js
@@ -21,7 +21,7 @@ import {
} from '@patternfly/react-core'
import { CubesIcon, InfoIcon, TrashIcon } from '@patternfly/react-icons'
-const UnitInfo = ({ unit, unitType }) => {
+function UnitInfo({ unit, unitType }) {
if (unitType === 'cpu' || unitType === 'gpu') {
return (
<DescriptionList>
@@ -64,7 +64,7 @@ UnitInfo.propTypes = {
unit: PropTypes.oneOfType([ProcessingUnit, StorageUnit]).isRequired,
}
-const UnitListComponent = ({ unitType, units, onDelete }) => {
+function UnitListComponent({ unitType, units, onDelete }) {
if (units.length === 0) {
return (
<EmptyState>
diff --git a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitListContainer.js b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitListContainer.js
index 2d994f97..f76684a5 100644
--- a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitListContainer.js
+++ b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitListContainer.js
@@ -33,23 +33,20 @@ const unitMapping = {
storage: 'storages',
}
-const UnitListContainer = ({ unitType, ...props }) => {
+function UnitListContainer({ machineId, unitType }) {
const dispatch = useDispatch()
const units = useSelector((state) => {
- const machine =
- state.objects.machine[
- state.objects.rack[state.objects.tile[state.interactionLevel.tileId].rack].machines[
- state.interactionLevel.position - 1
- ]
- ]
+ const machine = state.objects.machine[machineId]
return machine[unitMapping[unitType]].map((id) => state.objects[unitType][id])
})
- const onDelete = (unit, unitType) => dispatch(deleteUnit(unitType, unit._id))
- return <UnitListComponent {...props} units={units} unitType={unitType} onDelete={onDelete} />
+ const onDelete = (unit) => dispatch(deleteUnit(machineId, unitType, unit._id))
+
+ return <UnitListComponent units={units} unitType={unitType} onDelete={onDelete} />
}
UnitListContainer.propTypes = {
+ machineId: PropTypes.string.isRequired,
unitType: PropTypes.string.isRequired,
}
diff --git a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitTabsComponent.js b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitTabsComponent.js
index 723ed2e2..6d10d2df 100644
--- a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitTabsComponent.js
+++ b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitTabsComponent.js
@@ -1,31 +1,36 @@
+import PropTypes from 'prop-types'
import React, { useState } from 'react'
import { Tab, Tabs, TabTitleText } from '@patternfly/react-core'
import UnitAddContainer from './UnitAddContainer'
import UnitListContainer from './UnitListContainer'
-const UnitTabsComponent = () => {
+function UnitTabsComponent({ machineId }) {
const [activeTab, setActiveTab] = useState('cpu-units')
return (
<Tabs activeKey={activeTab} onSelect={(_, tab) => setActiveTab(tab)}>
<Tab eventKey="cpu-units" title={<TabTitleText>CPU</TabTitleText>}>
- <UnitAddContainer unitType="cpu" />
- <UnitListContainer unitType="cpu" />
+ <UnitAddContainer machineId={machineId} unitType="cpu" />
+ <UnitListContainer machineId={machineId} unitType="cpu" />
</Tab>
<Tab eventKey="gpu-units" title={<TabTitleText>GPU</TabTitleText>}>
- <UnitAddContainer unitType="gpu" />
- <UnitListContainer unitType="gpu" />
+ <UnitAddContainer machineId={machineId} unitType="gpu" />
+ <UnitListContainer machineId={machineId} unitType="gpu" />
</Tab>
<Tab eventKey="memory-units" title={<TabTitleText>Memory</TabTitleText>}>
- <UnitAddContainer unitType="memory" />
- <UnitListContainer unitType="memory" />
+ <UnitAddContainer machineId={machineId} unitType="memory" />
+ <UnitListContainer machineId={machineId} unitType="memory" />
</Tab>
<Tab eventKey="storage-units" title={<TabTitleText>Storage</TabTitleText>}>
- <UnitAddContainer unitType="storage" />
- <UnitListContainer unitType="storage" />
+ <UnitAddContainer machineId={machineId} unitType="storage" />
+ <UnitListContainer machineId={machineId} unitType="storage" />
</Tab>
</Tabs>
)
}
+UnitTabsComponent.propTypes = {
+ machineId: PropTypes.string.isRequired,
+}
+
export default UnitTabsComponent