From 41e02cdab85ba5db92be7f7bea07ae1f20bcbdd9 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Thu, 22 Jul 2021 19:05:58 +0200 Subject: fix(web/ui): Fix creation of topologies This change fixes an issue with the creation of topologies in the frontend. Previously, the frontend relied on Redux to update the state. However, since we removed the reliance on Redux, we also need to create a new topology using the functions from React Query to actually send a request to the API server. --- .../src/components/projects/NewTopology.js | 15 ++++++--- .../projects/[project]/topologies/[topology].js | 13 +++----- .../opendc-web-ui/src/redux/actions/topologies.js | 27 --------------- .../src/redux/actions/topology/index.js | 39 ++++++++++++++++++++++ .../src/redux/reducers/topology/machine.js | 2 +- .../src/redux/reducers/topology/rack.js | 2 +- .../src/redux/reducers/topology/room.js | 2 +- .../src/redux/reducers/topology/tile.js | 2 +- .../src/redux/reducers/topology/topology.js | 2 +- .../opendc-web-ui/src/redux/sagas/topology.js | 2 +- 10 files changed, 61 insertions(+), 45 deletions(-) delete mode 100644 opendc-web/opendc-web-ui/src/redux/actions/topologies.js create mode 100644 opendc-web/opendc-web-ui/src/redux/actions/topology/index.js (limited to 'opendc-web') diff --git a/opendc-web/opendc-web-ui/src/components/projects/NewTopology.js b/opendc-web/opendc-web-ui/src/components/projects/NewTopology.js index bf59e020..77c57d26 100644 --- a/opendc-web/opendc-web-ui/src/components/projects/NewTopology.js +++ b/opendc-web/opendc-web-ui/src/components/projects/NewTopology.js @@ -21,19 +21,26 @@ */ import PropTypes from 'prop-types' +import produce from 'immer' import { PlusIcon } from '@patternfly/react-icons' import { Button } from '@patternfly/react-core' import { useState } from 'react' -import { useDispatch } from 'react-redux' -import { addTopology } from '../../redux/actions/topologies' +import { useMutation } from "react-query"; +import { useProjectTopologies } from "../../data/topology"; import NewTopologyModal from './NewTopologyModal' function NewTopology({ projectId }) { const [isVisible, setVisible] = useState(false) - const dispatch = useDispatch() + const { data: topologies = [] } = useProjectTopologies(projectId) + const { mutate: addTopology } = useMutation('addTopology') const onSubmit = (name, duplicateId) => { - dispatch(addTopology(projectId, name, duplicateId)) + const candidate = topologies.find((topology) => topology._id === duplicateId) || { projectId, rooms: [] } + const topology = produce(candidate, (draft) => { + delete draft._id + draft.name = name + }) + addTopology(topology) setVisible(false) } return ( diff --git a/opendc-web/opendc-web-ui/src/pages/projects/[project]/topologies/[topology].js b/opendc-web/opendc-web-ui/src/pages/projects/[project]/topologies/[topology].js index 858f9b16..f7188d9f 100644 --- a/opendc-web/opendc-web-ui/src/pages/projects/[project]/topologies/[topology].js +++ b/opendc-web/opendc-web-ui/src/pages/projects/[project]/topologies/[topology].js @@ -20,6 +20,7 @@ * SOFTWARE. */ +import dynamic from 'next/dynamic' import { useRouter } from 'next/router' import ContextSelectionSection from '../../../../components/context/ContextSelectionSection' import ProjectSelector from '../../../../components/context/ProjectSelector' @@ -44,9 +45,10 @@ import { TextContent, } from '@patternfly/react-core' import BreadcrumbLink from '../../../../components/util/BreadcrumbLink' -import TopologyMap from '../../../../components/topologies/TopologyMap' import { goToRoom } from '../../../../redux/actions/interaction-level' -import { openTopology } from '../../../../redux/actions/topologies' +import { openTopology } from '../../../../redux/actions/topology' + +const TopologyMap = dynamic(() => import('../../../../components/topologies/TopologyMap')) /** * Page that displays a datacenter topology. @@ -124,12 +126,7 @@ function Topology() { }} /> -