summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/TopologyListContainer.js
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-07-08 16:08:02 +0200
committerGitHub <noreply@github.com>2021-07-08 16:08:02 +0200
commit1a2416043f0b877f570e89da74e0d0a4aff1d8ae (patch)
tree1bed18bb62d223be954faca87b0736d2a571b443 /opendc-web/opendc-web-ui/src/containers/app/sidebars/project/TopologyListContainer.js
parentdfd2ded56780995cec6d91af37443b710d4ddb3b (diff)
parent2c8d675c2cf140eac05988065a9d20fd2773399a (diff)
ui: Simplify data fetching in frontend
This pull request aims to simplify the data fetching logic in the OpenDC frontend. Previously, the frontend used Redux extensively to sync the server state with the client state, which introduced a lot of unnecessary complexity. With this pull request, we move most of the data fetching logic out of Redux and instead use React Query to perform the logic for fetching and caching API requests. * Move all server data except topologies outside Redux * Use React Query for fetching server data * (De)normalize topology using Normalizr * Remove current ids state from Redux * Combine fetching of project relations
Diffstat (limited to 'opendc-web/opendc-web-ui/src/containers/app/sidebars/project/TopologyListContainer.js')
-rw-r--r--opendc-web/opendc-web-ui/src/containers/app/sidebars/project/TopologyListContainer.js24
1 files changed, 13 insertions, 11 deletions
diff --git a/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/TopologyListContainer.js b/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/TopologyListContainer.js
index 266ca495..a2244a30 100644
--- a/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/TopologyListContainer.js
+++ b/opendc-web/opendc-web-ui/src/containers/app/sidebars/project/TopologyListContainer.js
@@ -3,40 +3,42 @@ import { useDispatch } from 'react-redux'
import TopologyListComponent from '../../../../components/app/sidebars/project/TopologyListComponent'
import { setCurrentTopology } from '../../../../redux/actions/topology/building'
import { useRouter } from 'next/router'
-import { getState } from '../../../../util/state-utils'
-import { addTopology, deleteTopology } from '../../../../redux/actions/topologies'
+import { addTopology } from '../../../../redux/actions/topologies'
import NewTopologyModalComponent from '../../../../components/modals/custom-components/NewTopologyModalComponent'
import { useActiveTopology, useProjectTopologies } from '../../../../data/topology'
+import { useMutation } from 'react-query'
const TopologyListContainer = () => {
const dispatch = useDispatch()
const router = useRouter()
- const topologies = useProjectTopologies()
+ const { project: currentProjectId } = router.query
+ const topologies =
+ useProjectTopologies(currentProjectId).data?.map((topology) => ({ _id: topology._id, name: topology.name })) ??
+ []
const currentTopologyId = useActiveTopology()?._id
const [isVisible, setVisible] = useState(false)
+ const { mutate: deleteTopology } = useMutation('deleteTopology')
+
const onChooseTopology = async (id) => {
dispatch(setCurrentTopology(id))
- const state = await getState(dispatch)
- router.push(`/projects/${state.currentProjectId}`)
+ await router.push(`/projects/${currentProjectId}/topologies/${id}`)
}
const onDeleteTopology = async (id) => {
if (id) {
- const state = await getState(dispatch)
- dispatch(deleteTopology(id))
- dispatch(setCurrentTopology(state.objects.project[state.currentProjectId].topologyIds[0]))
- router.push(`/projects/${state.currentProjectId}`)
+ deleteTopology(id)
+ await router.push(`/projects/${currentProjectId}`)
}
}
const onCreateTopology = (name) => {
if (name) {
- dispatch(addTopology(name, undefined))
+ dispatch(addTopology(currentProjectId, name, undefined))
}
setVisible(false)
}
const onDuplicateTopology = (name, id) => {
if (name) {
- dispatch(addTopology(name, id))
+ dispatch(addTopology(currentProjectId, name, id))
}
setVisible(false)
}