blob: 69367b5f744ff0ec69256e7291aeec29ce6259b7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
import React, { useState } from 'react'
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 { addTopology, deleteTopology } from '../../../../redux/actions/topologies'
import NewTopologyModalComponent from '../../../../components/modals/custom-components/NewTopologyModalComponent'
import { useActiveTopology, useProjectTopologies } from '../../../../data/topology'
const TopologyListContainer = () => {
const dispatch = useDispatch()
const router = useRouter()
const { project: currentProjectId } = router.query
const topologies = useProjectTopologies()
const currentTopologyId = useActiveTopology()?._id
const [isVisible, setVisible] = useState(false)
const onChooseTopology = async (id) => {
dispatch(setCurrentTopology(id))
await router.push(`/projects/${currentProjectId}/topologies/${id}`)
}
const onDeleteTopology = async (id) => {
if (id) {
dispatch(deleteTopology(id))
dispatch(setCurrentTopology(state.objects.project[currentProjectId].topologyIds[0]))
await router.push(`/projects/${currentProjectId}`)
}
}
const onCreateTopology = (name) => {
if (name) {
dispatch(addTopology(currentProjectId, name, undefined))
}
setVisible(false)
}
const onDuplicateTopology = (name, id) => {
if (name) {
dispatch(addTopology(currentProjectId, name, id))
}
setVisible(false)
}
const onCancel = () => setVisible(false)
return (
<>
<TopologyListComponent
topologies={topologies}
currentTopologyId={currentTopologyId}
onChooseTopology={onChooseTopology}
onNewTopology={() => setVisible(true)}
onDeleteTopology={onDeleteTopology}
/>
<NewTopologyModalComponent
show={isVisible}
topologies={topologies}
onCreateTopology={onCreateTopology}
onDuplicateTopology={onDuplicateTopology}
onCancel={onCancel}
/>
</>
)
}
export default TopologyListContainer
|