summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/components/app/sidebars/project/TopologyListComponent.js
blob: d5627abc3155f79798336a059d0d9a34e9882a60 (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
import PropTypes from 'prop-types'
import React from 'react'
import { Topology } from '../../../../shapes'
import FontAwesome from 'react-fontawesome'
import { Button, Col, Row } from 'reactstrap'
import classNames from 'classnames'

function TopologyListComponent({ topologies, currentTopologyId, onChooseTopology, onNewTopology, onDeleteTopology }) {
    return (
        <div className="pb-3">
            <h2>
                Topologies
                <Button color="primary" outline className="float-right" onClick={onNewTopology}>
                    <FontAwesome name="plus" />
                </Button>
            </h2>

            {topologies.map((topology, idx) => (
                <Row key={topology._id} className="mb-1">
                    <Col
                        xs="7"
                        className={classNames('align-self-center', {
                            'font-weight-bold': topology._id === currentTopologyId,
                        })}
                    >
                        {topology.name}
                    </Col>
                    <Col xs="5" className="text-right">
                        <Button
                            color="primary"
                            outline
                            className="mr-1 fa fa-play"
                            onClick={() => onChooseTopology(topology._id)}
                        />
                        <Button
                            color="danger"
                            outline
                            className="fa fa-trash"
                            disable={idx === 0}
                            onClick={() => (idx !== 0 ? onDeleteTopology(topology._id) : undefined)}
                        />
                    </Col>
                </Row>
            ))}
        </div>
    )
}

TopologyListComponent.propTypes = {
    topologies: PropTypes.arrayOf(Topology),
    currentTopologyId: PropTypes.string,
    onChooseTopology: PropTypes.func.isRequired,
    onNewTopology: PropTypes.func.isRequired,
    onDeleteTopology: PropTypes.func.isRequired,
}

export default TopologyListComponent