summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/components/app/sidebars
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-05-13 13:00:00 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-05-17 17:06:49 +0200
commit24147cba0f5723be3525e8f40d1954144841629b (patch)
treed44727504f7a9c579219616cbdba5e965543561a /opendc-web/opendc-web-ui/src/components/app/sidebars
parent4397a959e806bf476be4c81bc804616adf58b969 (diff)
ui: Address technical dept in frontend
Diffstat (limited to 'opendc-web/opendc-web-ui/src/components/app/sidebars')
-rw-r--r--opendc-web/opendc-web-ui/src/components/app/sidebars/project/PortfolioListComponent.js106
-rw-r--r--opendc-web/opendc-web-ui/src/components/app/sidebars/project/ScenarioListComponent.js105
-rw-r--r--opendc-web/opendc-web-ui/src/components/app/sidebars/project/TopologyListComponent.js91
-rw-r--r--opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddComponent.js56
-rw-r--r--opendc-web/opendc-web-ui/src/components/app/sidebars/topology/rack/MachineComponent.js4
5 files changed, 174 insertions, 188 deletions
diff --git a/opendc-web/opendc-web-ui/src/components/app/sidebars/project/PortfolioListComponent.js b/opendc-web/opendc-web-ui/src/components/app/sidebars/project/PortfolioListComponent.js
index b714a7d2..d002b473 100644
--- a/opendc-web/opendc-web-ui/src/components/app/sidebars/project/PortfolioListComponent.js
+++ b/opendc-web/opendc-web-ui/src/components/app/sidebars/project/PortfolioListComponent.js
@@ -1,67 +1,65 @@
import PropTypes from 'prop-types'
import React from 'react'
-import Shapes from '../../../../shapes'
+import { Portfolio } from '../../../../shapes'
import Link from 'next/link'
import FontAwesome from 'react-fontawesome'
import ScenarioListContainer from '../../../../containers/app/sidebars/project/ScenarioListContainer'
-class PortfolioListComponent extends React.Component {
- static propTypes = {
- portfolios: PropTypes.arrayOf(Shapes.Portfolio),
- currentProjectId: PropTypes.string.isRequired,
- currentPortfolioId: PropTypes.string,
- onNewPortfolio: PropTypes.func.isRequired,
- onChoosePortfolio: PropTypes.func.isRequired,
- onDeletePortfolio: PropTypes.func.isRequired,
- }
+function PortfolioListComponent({
+ portfolios,
+ currentProjectId,
+ currentPortfolioId,
+ onNewPortfolio,
+ onChoosePortfolio,
+ onDeletePortfolio,
+}) {
+ return (
+ <div className="pb-3">
+ <h2>
+ Portfolios
+ <button className="btn btn-outline-primary float-right" onClick={(e) => onNewPortfolio(e)}>
+ <FontAwesome name="plus" />
+ </button>
+ </h2>
- onDelete(id) {
- this.props.onDeletePortfolio(id)
- }
-
- render() {
- return (
- <div className="pb-3">
- <h2>
- Portfolios
- <button
- className="btn btn-outline-primary float-right"
- onClick={this.props.onNewPortfolio.bind(this)}
- >
- <FontAwesome name="plus" />
- </button>
- </h2>
-
- {this.props.portfolios.map((portfolio, idx) => (
- <div key={portfolio._id}>
- <div className="row mb-1">
- <div
- className={
- 'col-7 align-self-center ' +
- (portfolio._id === this.props.currentPortfolioId ? 'font-weight-bold' : '')
- }
- >
- {portfolio.name}
- </div>
- <div className="col-5 text-right">
- <Link href={`/projects/${this.props.currentProjectId}/portfolios/${portfolio._id}`}>
- <a
- className="btn btn-outline-primary mr-1 fa fa-play"
- onClick={() => this.props.onChoosePortfolio(portfolio._id)}
- />
- </Link>
- <span
- className="btn btn-outline-danger fa fa-trash"
- onClick={() => this.onDelete(portfolio._id)}
+ {portfolios.map((portfolio, idx) => (
+ <div key={portfolio._id}>
+ <div className="row mb-1">
+ <div
+ className={
+ 'col-7 align-self-center ' +
+ (portfolio._id === currentPortfolioId ? 'font-weight-bold' : '')
+ }
+ >
+ {portfolio.name}
+ </div>
+ <div className="col-5 text-right">
+ <Link href={`/projects/${currentProjectId}/portfolios/${portfolio._id}`}>
+ <a
+ className="btn btn-outline-primary mr-1 fa fa-play"
+ onClick={() => onChoosePortfolio(portfolio._id)}
/>
- </div>
+ </Link>
+ <span
+ className="btn btn-outline-danger fa fa-trash"
+ onClick={() => onDeletePortfolio(portfolio._id)}
+ />
</div>
- <ScenarioListContainer portfolioId={portfolio._id} />
</div>
- ))}
- </div>
- )
- }
+ <ScenarioListContainer portfolioId={portfolio._id} />
+ </div>
+ ))}
+ </div>
+ )
+}
+
+PortfolioListComponent.propTypes = {
+ portfolios: PropTypes.arrayOf(Portfolio),
+ currentProjectId: PropTypes.string.isRequired,
+ currentPortfolioId: PropTypes.string,
+ onNewPortfolio: PropTypes.func.isRequired,
+ onChoosePortfolio: PropTypes.func.isRequired,
+ onDeletePortfolio: PropTypes.func.isRequired,
}
export default PortfolioListComponent
diff --git a/opendc-web/opendc-web-ui/src/components/app/sidebars/project/ScenarioListComponent.js b/opendc-web/opendc-web-ui/src/components/app/sidebars/project/ScenarioListComponent.js
index 4efa99ef..26543d12 100644
--- a/opendc-web/opendc-web-ui/src/components/app/sidebars/project/ScenarioListComponent.js
+++ b/opendc-web/opendc-web-ui/src/components/app/sidebars/project/ScenarioListComponent.js
@@ -1,65 +1,64 @@
import PropTypes from 'prop-types'
import React from 'react'
-import Shapes from '../../../../shapes'
+import { Scenario } from '../../../../shapes'
import Link from 'next/link'
import FontAwesome from 'react-fontawesome'
-class ScenarioListComponent extends React.Component {
- static propTypes = {
- scenarios: PropTypes.arrayOf(Shapes.Scenario),
- portfolioId: PropTypes.string,
- currentProjectId: PropTypes.string.isRequired,
- currentScenarioId: PropTypes.string,
- onNewScenario: PropTypes.func.isRequired,
- onChooseScenario: PropTypes.func.isRequired,
- onDeleteScenario: PropTypes.func.isRequired,
- }
-
- onDelete(id) {
- this.props.onDeleteScenario(id)
- }
-
- render() {
- return (
- <>
- {this.props.scenarios.map((scenario, idx) => (
- <div key={scenario._id} className="row mb-1">
- <div
- className={
- 'col-7 pl-5 align-self-center ' +
- (scenario._id === this.props.currentScenarioId ? 'font-weight-bold' : '')
- }
- >
- {scenario.name}
- </div>
- <div className="col-5 text-right">
- <Link
- href={`/projects/${this.props.currentProjectId}/portfolios/${scenario.portfolioId}/scenarios/${scenario._id}`}
- >
- <a
- className="btn btn-outline-primary mr-1 fa fa-play disabled"
- onClick={() => this.props.onChooseScenario(scenario.portfolioId, scenario._id)}
- />
- </Link>
- <span
- className={'btn btn-outline-danger fa fa-trash ' + (idx === 0 ? 'disabled' : '')}
- onClick={() => (idx !== 0 ? this.onDelete(scenario._id) : undefined)}
- />
- </div>
- </div>
- ))}
- <div className="pl-4 mb-2">
+function ScenarioListComponent({
+ scenarios,
+ portfolioId,
+ currentProjectId,
+ currentScenarioId,
+ onNewScenario,
+ onChooseScenario,
+ onDeleteScenario,
+}) {
+ return (
+ <>
+ {scenarios.map((scenario, idx) => (
+ <div key={scenario._id} className="row mb-1">
<div
- className="btn btn-outline-primary"
- onClick={() => this.props.onNewScenario(this.props.portfolioId)}
+ className={
+ 'col-7 pl-5 align-self-center ' +
+ (scenario._id === currentScenarioId ? 'font-weight-bold' : '')
+ }
>
- <FontAwesome name="plus" className="mr-1" />
- New scenario
+ {scenario.name}
</div>
+ <div className="col-5 text-right">
+ <Link
+ href={`/projects/${currentProjectId}/portfolios/${scenario.portfolioId}/scenarios/${scenario._id}`}
+ >
+ <a
+ className="btn btn-outline-primary mr-1 fa fa-play disabled"
+ onClick={() => onChooseScenario(scenario.portfolioId, scenario._id)}
+ />
+ </Link>
+ <span
+ className={'btn btn-outline-danger fa fa-trash ' + (idx === 0 ? 'disabled' : '')}
+ onClick={() => (idx !== 0 ? onDeleteScenario(scenario._id) : undefined)}
+ />
+ </div>
+ </div>
+ ))}
+ <div className="pl-4 mb-2">
+ <div className="btn btn-outline-primary" onClick={() => onNewScenario(this.props.portfolioId)}>
+ <FontAwesome name="plus" className="mr-1" />
+ New scenario
</div>
- </>
- )
- }
+ </div>
+ </>
+ )
+}
+
+ScenarioListComponent.propTypes = {
+ scenarios: PropTypes.arrayOf(Scenario),
+ portfolioId: PropTypes.string,
+ currentProjectId: PropTypes.string.isRequired,
+ currentScenarioId: PropTypes.string,
+ onNewScenario: PropTypes.func.isRequired,
+ onChooseScenario: PropTypes.func.isRequired,
+ onDeleteScenario: PropTypes.func.isRequired,
}
export default ScenarioListComponent
diff --git a/opendc-web/opendc-web-ui/src/components/app/sidebars/project/TopologyListComponent.js b/opendc-web/opendc-web-ui/src/components/app/sidebars/project/TopologyListComponent.js
index 2f42f7e4..a7d78c4a 100644
--- a/opendc-web/opendc-web-ui/src/components/app/sidebars/project/TopologyListComponent.js
+++ b/opendc-web/opendc-web-ui/src/components/app/sidebars/project/TopologyListComponent.js
@@ -1,60 +1,49 @@
import PropTypes from 'prop-types'
import React from 'react'
-import Shapes from '../../../../shapes'
+import { Topology } from '../../../../shapes'
import FontAwesome from 'react-fontawesome'
-class TopologyListComponent extends React.Component {
- static propTypes = {
- topologies: PropTypes.arrayOf(Shapes.Topology),
- currentTopologyId: PropTypes.string,
- onChooseTopology: PropTypes.func.isRequired,
- onNewTopology: PropTypes.func.isRequired,
- onDeleteTopology: PropTypes.func.isRequired,
- }
+function TopologyListComponent({ topologies, currentTopologyId, onChooseTopology, onNewTopology, onDeleteTopology }) {
+ return (
+ <div className="pb-3">
+ <h2>
+ Topologies
+ <button className="btn btn-outline-primary float-right" onClick={onNewTopology}>
+ <FontAwesome name="plus" />
+ </button>
+ </h2>
- onChoose(id) {
- this.props.onChooseTopology(id)
- }
-
- onDelete(id) {
- this.props.onDeleteTopology(id)
- }
-
- render() {
- return (
- <div className="pb-3">
- <h2>
- Topologies
- <button className="btn btn-outline-primary float-right" onClick={this.props.onNewTopology}>
- <FontAwesome name="plus" />
- </button>
- </h2>
-
- {this.props.topologies.map((topology, idx) => (
- <div key={topology._id} className="row mb-1">
- <div
- className={
- 'col-7 align-self-center ' +
- (topology._id === this.props.currentTopologyId ? 'font-weight-bold' : '')
- }
- >
- {topology.name}
- </div>
- <div className="col-5 text-right">
- <span
- className="btn btn-outline-primary mr-1 fa fa-play"
- onClick={() => this.onChoose(topology._id)}
- />
- <span
- className={'btn btn-outline-danger fa fa-trash ' + (idx === 0 ? 'disabled' : '')}
- onClick={() => (idx !== 0 ? this.onDelete(topology._id) : undefined)}
- />
- </div>
+ {topologies.map((topology, idx) => (
+ <div key={topology._id} className="row mb-1">
+ <div
+ className={
+ 'col-7 align-self-center ' + (topology._id === currentTopologyId ? 'font-weight-bold' : '')
+ }
+ >
+ {topology.name}
</div>
- ))}
- </div>
- )
- }
+ <div className="col-5 text-right">
+ <span
+ className="btn btn-outline-primary mr-1 fa fa-play"
+ onClick={() => onChooseTopology(topology._id)}
+ />
+ <span
+ className={'btn btn-outline-danger fa fa-trash ' + (idx === 0 ? 'disabled' : '')}
+ onClick={() => (idx !== 0 ? onDeleteTopology(topology._id) : undefined)}
+ />
+ </div>
+ </div>
+ ))}
+ </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
diff --git a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddComponent.js b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddComponent.js
index 4e9dbc7e..f80fccc8 100644
--- a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddComponent.js
+++ b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddComponent.js
@@ -1,35 +1,35 @@
import PropTypes from 'prop-types'
-import React from 'react'
+import React, { useRef } from 'react'
-class UnitAddComponent extends React.Component {
- static propTypes = {
- units: PropTypes.array.isRequired,
- onAdd: PropTypes.func.isRequired,
- }
+function UnitAddComponent({ units, onAdd }) {
+ const unitSelect = useRef(null)
- render() {
- return (
- <div className="form-inline">
- <div className="form-group w-100">
- <select className="form-control w-70 mr-1" ref={(unitSelect) => (this.unitSelect = unitSelect)}>
- {this.props.units.map((unit) => (
- <option value={unit._id} key={unit._id}>
- {unit.name}
- </option>
- ))}
- </select>
- <button
- type="submit"
- className="btn btn-outline-primary"
- onClick={() => this.props.onAdd(this.unitSelect.value)}
- >
- <span className="fa fa-plus mr-2" />
- Add
- </button>
- </div>
+ return (
+ <div className="form-inline">
+ <div className="form-group w-100">
+ <select className="form-control w-70 mr-1" ref={unitSelect}>
+ {units.map((unit) => (
+ <option value={unit._id} key={unit._id}>
+ {unit.name}
+ </option>
+ ))}
+ </select>
+ <button
+ type="submit"
+ className="btn btn-outline-primary"
+ onClick={() => onAdd(unitSelect.current.value)}
+ >
+ <span className="fa fa-plus mr-2" />
+ Add
+ </button>
</div>
- )
- }
+ </div>
+ )
+}
+
+UnitAddComponent.propTypes = {
+ units: PropTypes.array.isRequired,
+ onAdd: PropTypes.func.isRequired,
}
export default UnitAddComponent
diff --git a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/rack/MachineComponent.js b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/rack/MachineComponent.js
index caa3dc04..4db0e7fe 100644
--- a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/rack/MachineComponent.js
+++ b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/rack/MachineComponent.js
@@ -1,5 +1,5 @@
import React from 'react'
-import Shapes from '../../../../../shapes'
+import { Machine } from '../../../../../shapes'
const UnitIcon = ({ id, type }) => (
<div>
@@ -37,7 +37,7 @@ const MachineComponent = ({ position, machine, onClick }) => {
}
MachineComponent.propTypes = {
- machine: Shapes.Machine,
+ machine: Machine,
}
export default MachineComponent