summaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-07-22 14:31:03 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:48:19 +0200
commitd8eb2d7fd4cf15706bced6c6ceca320cfaecb2f7 (patch)
treecc883f95b5580a4f399e665bcda16d52aa04bb32 /frontend
parent92ce9387f5c3ce54b4077ef6a5f604fc2cfe6ade (diff)
Implement topology duplication
Diffstat (limited to 'frontend')
-rw-r--r--frontend/public/index.html4
-rw-r--r--frontend/src/actions/topologies.js5
-rw-r--r--frontend/src/components/modals/custom-components/NewTopologyModalComponent.js3
-rw-r--r--frontend/src/containers/modals/NewTopologyModal.js7
-rw-r--r--frontend/src/sagas/objects.js20
-rw-r--r--frontend/src/sagas/topology.js11
6 files changed, 30 insertions, 20 deletions
diff --git a/frontend/public/index.html b/frontend/public/index.html
index b19fdbda..ec8cd964 100644
--- a/frontend/public/index.html
+++ b/frontend/public/index.html
@@ -61,8 +61,8 @@
</noscript>
<div id="root"></div>
-<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
- integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
+<script src="https://code.jquery.com/jquery-3.5.1.min.js"
+ integrity="sha384-ZvpUoO/+PpLXR1lu4jmpXWu80pZlYUAfxl5NsBMWOEPSjUn/6Z/hRTt8+pR6L4N2"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
diff --git a/frontend/src/actions/topologies.js b/frontend/src/actions/topologies.js
index c80ef6b2..dcce3b7d 100644
--- a/frontend/src/actions/topologies.js
+++ b/frontend/src/actions/topologies.js
@@ -1,10 +1,11 @@
export const ADD_TOPOLOGY = 'ADD_TOPOLOGY'
export const DELETE_TOPOLOGY = 'DELETE_TOPOLOGY'
-export function addTopology(topology) {
+export function addTopology(name, duplicateId) {
return {
type: ADD_TOPOLOGY,
- topology,
+ name,
+ duplicateId,
}
}
diff --git a/frontend/src/components/modals/custom-components/NewTopologyModalComponent.js b/frontend/src/components/modals/custom-components/NewTopologyModalComponent.js
index bbec9ebb..a244b730 100644
--- a/frontend/src/components/modals/custom-components/NewTopologyModalComponent.js
+++ b/frontend/src/components/modals/custom-components/NewTopologyModalComponent.js
@@ -31,7 +31,7 @@ class NewTopologyModalComponent extends React.Component {
}
onDuplicate() {
- this.props.onCreateTopology(this.textInput.value, this.originTopology.value)
+ this.props.onDuplicateTopology(this.textInput.value, this.originTopology.value)
this.reset()
}
@@ -67,7 +67,6 @@ class NewTopologyModalComponent extends React.Component {
<label className="form-control-label">Topology to duplicate (not supported yet)</label>
<select
className="form-control"
- disabled
ref={(originTopology) => (this.originTopology = originTopology)}
>
<option value={-1} key={-1}>
diff --git a/frontend/src/containers/modals/NewTopologyModal.js b/frontend/src/containers/modals/NewTopologyModal.js
index 99c42367..0acf6cf2 100644
--- a/frontend/src/containers/modals/NewTopologyModal.js
+++ b/frontend/src/containers/modals/NewTopologyModal.js
@@ -21,14 +21,13 @@ const mapDispatchToProps = (dispatch) => {
return {
onCreateTopology: (name) => {
if (name) {
- dispatch(addTopology({ name, rooms: [] }))
+ dispatch(addTopology(name, undefined))
}
dispatch(closeNewTopologyModal())
},
- onDuplicateTopology: (name) => {
+ onDuplicateTopology: (name, id) => {
if (name) {
- // TODO different handling here
- dispatch(addTopology({ name, rooms: [] }))
+ dispatch(addTopology(name, id))
}
dispatch(closeNewTopologyModal())
},
diff --git a/frontend/src/sagas/objects.js b/frontend/src/sagas/objects.js
index 1dbc7903..9dc65be1 100644
--- a/frontend/src/sagas/objects.js
+++ b/frontend/src/sagas/objects.js
@@ -142,6 +142,12 @@ const generateIdIfNotPresent = (obj) => {
}
export const updateTopologyOnServer = function* (id) {
+ const topology = yield getTopologyAsObject(id, true)
+
+ yield call(updateTopology, topology)
+}
+
+export const getTopologyAsObject = function* (id, keepIds) {
const topologyStore = yield select(OBJECT_SELECTORS['topology'])
const roomStore = yield select(OBJECT_SELECTORS['room'])
const tileStore = yield select(OBJECT_SELECTORS['tile'])
@@ -152,27 +158,27 @@ export const updateTopologyOnServer = function* (id) {
const memoryStore = yield select(OBJECT_SELECTORS['memory'])
const storageStore = yield select(OBJECT_SELECTORS['storage'])
- const topology = {
- _id: id,
+ return {
+ _id: keepIds ? id : undefined,
name: topologyStore[id].name,
rooms: topologyStore[id].roomIds.map((roomId) => ({
- _id: roomId,
+ _id: keepIds ? roomId : undefined,
name: roomStore[roomId].name,
tiles: roomStore[roomId].tileIds.map((tileId) => ({
- _id: tileId,
+ _id: keepIds ? tileId : undefined,
positionX: tileStore[tileId].positionX,
positionY: tileStore[tileId].positionY,
rack: !tileStore[tileId].rackId
? undefined
: {
- _id: rackStore[tileStore[tileId].rackId]._id,
+ _id: keepIds ? rackStore[tileStore[tileId].rackId]._id : undefined,
name: rackStore[tileStore[tileId].rackId].name,
capacity: rackStore[tileStore[tileId].rackId].capacity,
powerCapacityW: rackStore[tileStore[tileId].rackId].powerCapacityW,
machines: rackStore[tileStore[tileId].rackId].machineIds
.filter((m) => m !== null)
.map((machineId) => ({
- _id: machineId,
+ _id: keepIds ? machineId : undefined,
position: machineStore[machineId].position,
cpus: machineStore[machineId].cpuIds.map((id) => cpuStore[id]),
gpus: machineStore[machineId].gpuIds.map((id) => gpuStore[id]),
@@ -183,8 +189,6 @@ export const updateTopologyOnServer = function* (id) {
})),
})),
}
-
- yield call(updateTopology, topology)
}
export const fetchAndStoreAllTraces = () => fetchAndStoreObjects('trace', call(getAllTraces))
diff --git a/frontend/src/sagas/topology.js b/frontend/src/sagas/topology.js
index 14c1ed2d..8b67c196 100644
--- a/frontend/src/sagas/topology.js
+++ b/frontend/src/sagas/topology.js
@@ -16,7 +16,7 @@ import {
DEFAULT_RACK_SLOT_CAPACITY,
MAX_NUM_UNITS_PER_MACHINE,
} from '../components/app/map/MapConstants'
-import { fetchAndStoreTopology, updateTopologyOnServer } from './objects'
+import { fetchAndStoreTopology, getTopologyAsObject, updateTopologyOnServer } from './objects'
import { uuid } from 'uuidv4'
import { addTopology, deleteTopology } from '../api/routes/topologies'
@@ -40,9 +40,16 @@ export function* onAddTopology(action) {
try {
const currentProjectId = yield select((state) => state.currentProjectId)
+ let topologyToBeCreated
+ if (action.duplicateId) {
+ topologyToBeCreated = yield getTopologyAsObject(action.duplicateId, false)
+ } else {
+ topologyToBeCreated = { name: action.name, rooms: [] }
+ }
+
const topology = yield call(
addTopology,
- Object.assign({}, action.topology, {
+ Object.assign({}, topologyToBeCreated, {
projectId: currentProjectId,
})
)