diff options
| author | jc0b <j@jc0b.computer> | 2020-07-07 16:55:22 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-08-24 19:47:51 +0200 |
| commit | 223e916997eb641a1662110b6de630a4cdfdf479 (patch) | |
| tree | 90ca4364461f676db45f25e03d8f22fc32f9fdd8 /frontend/src/containers | |
| parent | 9ff1e3c6bae253372a468dbdc9b8369ab8dd2c6f (diff) | |
| parent | b810c4413079bf5aeb5374f1cd20e151a83530d0 (diff) | |
Merge branch 'feature/mongodb-migration' of github.com:atlarge-research/opendc-dev into feature/mongodb-migration
Diffstat (limited to 'frontend/src/containers')
39 files changed, 247 insertions, 465 deletions
diff --git a/frontend/src/containers/app/map/RackContainer.js b/frontend/src/containers/app/map/RackContainer.js index 34e7bbab..40077608 100644 --- a/frontend/src/containers/app/map/RackContainer.js +++ b/frontend/src/containers/app/map/RackContainer.js @@ -1,27 +1,9 @@ import { connect } from 'react-redux' import RackGroup from '../../../components/app/map/groups/RackGroup' -import { getStateLoad } from '../../../util/simulation-load' - -const mapStateToProps = (state, ownProps) => { - const inSimulation = state.currentExperimentId !== '-1' - - let rackLoad = undefined - if (inSimulation) { - if ( - state.states.rack[state.currentTick] && - state.states.rack[state.currentTick][ownProps.tile.rackId] - ) { - rackLoad = getStateLoad( - state.loadMetric, - state.states.rack[state.currentTick][ownProps.tile.rackId], - ) - } - } +const mapStateToProps = (state) => { return { interactionLevel: state.interactionLevel, - inSimulation, - rackLoad, } } diff --git a/frontend/src/containers/app/map/TileContainer.js b/frontend/src/containers/app/map/TileContainer.js index 28289206..ddef097c 100644 --- a/frontend/src/containers/app/map/TileContainer.js +++ b/frontend/src/containers/app/map/TileContainer.js @@ -1,30 +1,13 @@ import { connect } from 'react-redux' import { goFromRoomToRack } from '../../../actions/interaction-level' import TileGroup from '../../../components/app/map/groups/TileGroup' -import { getStateLoad } from '../../../util/simulation-load' const mapStateToProps = (state, ownProps) => { const tile = state.objects.tile[ownProps.tileId] - const inSimulation = state.currentExperimentId !== '-1' - - let roomLoad = undefined - if (inSimulation) { - if ( - state.states.room[state.currentTick] && - state.states.room[state.currentTick][tile.roomId] - ) { - roomLoad = getStateLoad( - state.loadMetric, - state.states.room[state.currentTick][tile.roomId], - ) - } - } return { interactionLevel: state.interactionLevel, tile, - inSimulation, - roomLoad, } } diff --git a/frontend/src/containers/app/sidebars/elements/LoadBarContainer.js b/frontend/src/containers/app/sidebars/elements/LoadBarContainer.js deleted file mode 100644 index 5c423490..00000000 --- a/frontend/src/containers/app/sidebars/elements/LoadBarContainer.js +++ /dev/null @@ -1,32 +0,0 @@ -import { connect } from 'react-redux' -import LoadBarComponent from '../../../../components/app/sidebars/elements/LoadBarComponent' -import { getStateLoad } from '../../../../util/simulation-load' - -const mapStateToProps = (state, ownProps) => { - let percent = 0 - let enabled = false - - const objectStates = state.states[ownProps.objectType] - if ( - objectStates[state.currentTick] && - objectStates[state.currentTick][ownProps.objectId] - ) { - percent = Math.floor( - 100 * - getStateLoad( - state.loadMetric, - objectStates[state.currentTick][ownProps.objectId], - ), - ) - enabled = true - } - - return { - percent, - enabled, - } -} - -const LoadBarContainer = connect(mapStateToProps)(LoadBarComponent) - -export default LoadBarContainer diff --git a/frontend/src/containers/app/sidebars/elements/LoadChartContainer.js b/frontend/src/containers/app/sidebars/elements/LoadChartContainer.js index 49962d57..61f95932 100644 --- a/frontend/src/containers/app/sidebars/elements/LoadChartContainer.js +++ b/frontend/src/containers/app/sidebars/elements/LoadChartContainer.js @@ -1,25 +1,9 @@ import { connect } from 'react-redux' import LoadChartComponent from '../../../../components/app/sidebars/elements/LoadChartComponent' -import { getStateLoad } from '../../../../util/simulation-load' const mapStateToProps = (state, ownProps) => { const data = [] - if (state.lastSimulatedTick !== -1) { - const objectStates = state.states[ownProps.objectType] - Object.keys(objectStates).forEach(tick => { - if (objectStates[tick][ownProps.objectId]) { - data.push({ - x: tick, - y: getStateLoad( - state.loadMetric, - objectStates[tick][ownProps.objectId], - ), - }) - } - }) - } - return { data, currentTick: state.currentTick, diff --git a/frontend/src/containers/app/sidebars/project/ProjectSidebarContainer.js b/frontend/src/containers/app/sidebars/project/ProjectSidebarContainer.js new file mode 100644 index 00000000..ced0b18b --- /dev/null +++ b/frontend/src/containers/app/sidebars/project/ProjectSidebarContainer.js @@ -0,0 +1,5 @@ +import ProjectSidebarComponent from '../../../../components/app/sidebars/project/ProjectSidebarComponent' + +const ProjectSidebarContainer = ProjectSidebarComponent + +export default ProjectSidebarContainer diff --git a/frontend/src/containers/app/sidebars/project/TopologyListContainer.js b/frontend/src/containers/app/sidebars/project/TopologyListContainer.js new file mode 100644 index 00000000..cab47c8d --- /dev/null +++ b/frontend/src/containers/app/sidebars/project/TopologyListContainer.js @@ -0,0 +1,46 @@ +import { connect } from 'react-redux' +import TopologyListComponent from '../../../../components/app/sidebars/project/TopologyListComponent' +import { setCurrentTopology } from '../../../../actions/topology/building' +import { openNewTopologyModal } from '../../../../actions/modals/topology' +import { deleteTopology } from '../../../../actions/topologies' + +const mapStateToProps = state => { + let topologies = state.objects.project[state.currentProjectId] ? state.objects.project[state.currentProjectId].topologyIds.map(t => ( + state.objects.topology[t] + )) : [] + if (topologies.filter(t => !t).length > 0) { + topologies = [] + } + + return { + show: state.modals.changeTopologyModalVisible, + currentTopologyId: state.currentTopologyId, + topologies, + } +} + +const mapDispatchToProps = dispatch => { + return { + onChooseTopology: (id) => { + dispatch( + setCurrentTopology(id), + ) + }, + onNewTopology: () => { + dispatch(openNewTopologyModal()) + }, + onDeleteTopology: (id) => { + if (id) { + dispatch( + deleteTopology(id), + ) + } + }, + } +} + +const TopologyListContainer = connect(mapStateToProps, mapDispatchToProps)( + TopologyListComponent, +) + +export default TopologyListContainer diff --git a/frontend/src/containers/app/sidebars/simulation/ExperimentMetadataContainer.js b/frontend/src/containers/app/sidebars/simulation/ExperimentMetadataContainer.js deleted file mode 100644 index 0dc20ea7..00000000 --- a/frontend/src/containers/app/sidebars/simulation/ExperimentMetadataContainer.js +++ /dev/null @@ -1,38 +0,0 @@ -import { connect } from 'react-redux' -import ExperimentMetadataComponent from '../../../../components/app/sidebars/simulation/ExperimentMetadataComponent' - -const mapStateToProps = state => { - if (!state.objects.experiment[state.currentExperimentId]) { - return { - experimentName: 'Loading experiment', - topologyName: '', - traceName: '', - schedulerName: '', - } - } - - const topology = - state.objects.topology[ - state.objects.experiment[state.currentExperimentId].topologyId - ] - const topologyName = topology.name - - return { - experimentName: state.objects.experiment[state.currentExperimentId].name, - topologyName, - traceName: - state.objects.trace[ - state.objects.experiment[state.currentExperimentId].traceId - ].name, - schedulerName: - state.objects.scheduler[ - state.objects.experiment[state.currentExperimentId].schedulerName - ].name, - } -} - -const ExperimentMetadataContainer = connect(mapStateToProps)( - ExperimentMetadataComponent, -) - -export default ExperimentMetadataContainer diff --git a/frontend/src/containers/app/sidebars/simulation/LoadMetricContainer.js b/frontend/src/containers/app/sidebars/simulation/LoadMetricContainer.js deleted file mode 100644 index a8654698..00000000 --- a/frontend/src/containers/app/sidebars/simulation/LoadMetricContainer.js +++ /dev/null @@ -1,12 +0,0 @@ -import { connect } from 'react-redux' -import LoadMetricComponent from '../../../../components/app/sidebars/simulation/LoadMetricComponent' - -const mapStateToProps = state => { - return { - loadMetric: state.loadMetric, - } -} - -const LoadMetricContainer = connect(mapStateToProps)(LoadMetricComponent) - -export default LoadMetricContainer diff --git a/frontend/src/containers/app/sidebars/topology/TopologySidebar.js b/frontend/src/containers/app/sidebars/topology/TopologySidebarContainer.js index 8e929d3d..f9bc10bf 100644 --- a/frontend/src/containers/app/sidebars/topology/TopologySidebar.js +++ b/frontend/src/containers/app/sidebars/topology/TopologySidebarContainer.js @@ -7,6 +7,6 @@ const mapStateToProps = state => { } } -const TopologySidebar = connect(mapStateToProps)(TopologySidebarComponent) +const TopologySidebarContainer = connect(mapStateToProps)(TopologySidebarComponent) -export default TopologySidebar +export default TopologySidebarContainer diff --git a/frontend/src/containers/app/sidebars/topology/building/BuildingSidebarContainer.js b/frontend/src/containers/app/sidebars/topology/building/BuildingSidebarContainer.js index 8c8cb79b..a0b52e56 100644 --- a/frontend/src/containers/app/sidebars/topology/building/BuildingSidebarContainer.js +++ b/frontend/src/containers/app/sidebars/topology/building/BuildingSidebarContainer.js @@ -1,14 +1,5 @@ -import { connect } from 'react-redux' import BuildingSidebarComponent from '../../../../../components/app/sidebars/topology/building/BuildingSidebarComponent' -const mapStateToProps = state => { - return { - inSimulation: state.currentExperimentId !== '-1', - } -} - -const BuildingSidebarContainer = connect(mapStateToProps)( - BuildingSidebarComponent, -) +const BuildingSidebarContainer = BuildingSidebarComponent export default BuildingSidebarContainer diff --git a/frontend/src/containers/app/sidebars/topology/machine/MachineSidebarContainer.js b/frontend/src/containers/app/sidebars/topology/machine/MachineSidebarContainer.js index 3cff7cd1..868f26da 100644 --- a/frontend/src/containers/app/sidebars/topology/machine/MachineSidebarContainer.js +++ b/frontend/src/containers/app/sidebars/topology/machine/MachineSidebarContainer.js @@ -3,7 +3,6 @@ import MachineSidebarComponent from '../../../../../components/app/sidebars/topo const mapStateToProps = state => { return { - inSimulation: state.currentExperimentId !== '-1', machineId: state.objects.rack[ state.objects.tile[state.interactionLevel.tileId].rackId diff --git a/frontend/src/containers/app/sidebars/topology/machine/UnitContainer.js b/frontend/src/containers/app/sidebars/topology/machine/UnitContainer.js index 7c26b47f..bd629564 100644 --- a/frontend/src/containers/app/sidebars/topology/machine/UnitContainer.js +++ b/frontend/src/containers/app/sidebars/topology/machine/UnitContainer.js @@ -4,7 +4,6 @@ import UnitComponent from '../../../../../components/app/sidebars/topology/machi const mapStateToProps = (state, ownProps) => { return { - inSimulation: state.currentExperimentId !== '-1', unit: state.objects[ownProps.unitType][ownProps.unitId], } } diff --git a/frontend/src/containers/app/sidebars/topology/machine/UnitListContainer.js b/frontend/src/containers/app/sidebars/topology/machine/UnitListContainer.js index 2596c2bd..e3ad77fd 100644 --- a/frontend/src/containers/app/sidebars/topology/machine/UnitListContainer.js +++ b/frontend/src/containers/app/sidebars/topology/machine/UnitListContainer.js @@ -3,11 +3,10 @@ import UnitListComponent from '../../../../../components/app/sidebars/topology/m const mapStateToProps = (state, ownProps) => { return { - inSimulation: state.currentExperimentId !== '-1', unitIds: state.objects.machine[ state.objects.rack[ - state.objects.tile[state.interactionLevel.tileId].rackId + state.objects.tile[state.interactionLevel.tileId].rackId ].machineIds[state.interactionLevel.position - 1] ][ownProps.unitType + 'Ids'], } diff --git a/frontend/src/containers/app/sidebars/topology/machine/UnitTabsContainer.js b/frontend/src/containers/app/sidebars/topology/machine/UnitTabsContainer.js index 5c606de4..00fe4067 100644 --- a/frontend/src/containers/app/sidebars/topology/machine/UnitTabsContainer.js +++ b/frontend/src/containers/app/sidebars/topology/machine/UnitTabsContainer.js @@ -1,12 +1,5 @@ -import { connect } from 'react-redux' import UnitTabsComponent from '../../../../../components/app/sidebars/topology/machine/UnitTabsComponent' -const mapStateToProps = state => { - return { - inSimulation: state.currentExperimentId !== '-1', - } -} - -const UnitTabsContainer = connect(mapStateToProps)(UnitTabsComponent) +const UnitTabsContainer = UnitTabsComponent export default UnitTabsContainer diff --git a/frontend/src/containers/app/sidebars/topology/rack/EmptySlotContainer.js b/frontend/src/containers/app/sidebars/topology/rack/EmptySlotContainer.js index d580a3e0..ab287bac 100644 --- a/frontend/src/containers/app/sidebars/topology/rack/EmptySlotContainer.js +++ b/frontend/src/containers/app/sidebars/topology/rack/EmptySlotContainer.js @@ -2,19 +2,13 @@ import { connect } from 'react-redux' import { addMachine } from '../../../../../actions/topology/rack' import EmptySlotComponent from '../../../../../components/app/sidebars/topology/rack/EmptySlotComponent' -const mapStateToProps = state => { - return { - inSimulation: state.currentExperimentId !== '-1', - } -} - const mapDispatchToProps = (dispatch, ownProps) => { return { onAdd: () => dispatch(addMachine(ownProps.position)), } } -const EmptySlotContainer = connect(mapStateToProps, mapDispatchToProps)( +const EmptySlotContainer = connect(undefined, mapDispatchToProps)( EmptySlotComponent, ) diff --git a/frontend/src/containers/app/sidebars/topology/rack/MachineContainer.js b/frontend/src/containers/app/sidebars/topology/rack/MachineContainer.js index 43558329..6b0f0a04 100644 --- a/frontend/src/containers/app/sidebars/topology/rack/MachineContainer.js +++ b/frontend/src/containers/app/sidebars/topology/rack/MachineContainer.js @@ -1,29 +1,10 @@ import { connect } from 'react-redux' import { goFromRackToMachine } from '../../../../../actions/interaction-level' import MachineComponent from '../../../../../components/app/sidebars/topology/rack/MachineComponent' -import { getStateLoad } from '../../../../../util/simulation-load' const mapStateToProps = (state, ownProps) => { - const machine = state.objects.machine[ownProps.machineId] - const inSimulation = state.currentExperimentId !== '-1' - - let machineLoad = undefined - if (inSimulation) { - if ( - state.states.machine[state.currentTick] && - state.states.machine[state.currentTick][machine._id] - ) { - machineLoad = getStateLoad( - state.loadMetric, - state.states.machine[state.currentTick][machine._id], - ) - } - } - return { - machine, - inSimulation, - machineLoad, + machine: state.objects.machine[ownProps.machineId], } } diff --git a/frontend/src/containers/app/sidebars/topology/rack/RackNameContainer.js b/frontend/src/containers/app/sidebars/topology/rack/RackNameContainer.js index 1eb885fc..4d8e8936 100644 --- a/frontend/src/containers/app/sidebars/topology/rack/RackNameContainer.js +++ b/frontend/src/containers/app/sidebars/topology/rack/RackNameContainer.js @@ -6,7 +6,7 @@ const mapStateToProps = state => { return { rackName: state.objects.rack[ - state.objects.tile[state.interactionLevel.tileId].rackId + state.objects.tile[state.interactionLevel.tileId].rackId ].name, } } diff --git a/frontend/src/containers/app/sidebars/topology/rack/RackSidebarContainer.js b/frontend/src/containers/app/sidebars/topology/rack/RackSidebarContainer.js index 7f931979..d9be1e8b 100644 --- a/frontend/src/containers/app/sidebars/topology/rack/RackSidebarContainer.js +++ b/frontend/src/containers/app/sidebars/topology/rack/RackSidebarContainer.js @@ -4,7 +4,6 @@ import RackSidebarComponent from '../../../../../components/app/sidebars/topolog const mapStateToProps = state => { return { rackId: state.objects.tile[state.interactionLevel.tileId].rackId, - inSimulation: state.currentExperimentId !== '-1', } } diff --git a/frontend/src/containers/app/sidebars/topology/room/RoomSidebarContainer.js b/frontend/src/containers/app/sidebars/topology/room/RoomSidebarContainer.js index 413c8f21..a95e290d 100644 --- a/frontend/src/containers/app/sidebars/topology/room/RoomSidebarContainer.js +++ b/frontend/src/containers/app/sidebars/topology/room/RoomSidebarContainer.js @@ -3,7 +3,6 @@ import RoomSidebarComponent from '../../../../../components/app/sidebars/topolog const mapStateToProps = state => { return { - inSimulation: state.currentExperimentId !== '-1', roomId: state.interactionLevel.roomId, } } diff --git a/frontend/src/containers/app/timeline/PlayButtonContainer.js b/frontend/src/containers/app/timeline/PlayButtonContainer.js deleted file mode 100644 index 9662d753..00000000 --- a/frontend/src/containers/app/timeline/PlayButtonContainer.js +++ /dev/null @@ -1,24 +0,0 @@ -import { connect } from 'react-redux' -import { pauseSimulation, playSimulation } from '../../../actions/simulation/playback' -import PlayButtonComponent from '../../../components/app/timeline/PlayButtonComponent' - -const mapStateToProps = state => { - return { - isPlaying: state.isPlaying, - currentTick: state.currentTick, - lastSimulatedTick: state.lastSimulatedTick, - } -} - -const mapDispatchToProps = dispatch => { - return { - onPlay: () => dispatch(playSimulation()), - onPause: () => dispatch(pauseSimulation()), - } -} - -const PlayButtonContainer = connect(mapStateToProps, mapDispatchToProps)( - PlayButtonComponent, -) - -export default PlayButtonContainer diff --git a/frontend/src/containers/app/timeline/TimelineContainer.js b/frontend/src/containers/app/timeline/TimelineContainer.js deleted file mode 100644 index 9b196a1b..00000000 --- a/frontend/src/containers/app/timeline/TimelineContainer.js +++ /dev/null @@ -1,26 +0,0 @@ -import { connect } from 'react-redux' -import { pauseSimulation } from '../../../actions/simulation/playback' -import { incrementTick } from '../../../actions/simulation/tick' -import TimelineComponent from '../../../components/app/timeline/TimelineComponent' - -const mapStateToProps = state => { - return { - isPlaying: state.isPlaying, - currentTick: state.currentTick, - lastSimulatedTick: state.lastSimulatedTick, - currentTopologyId: state.currentTopologyId, - } -} - -const mapDispatchToProps = dispatch => { - return { - incrementTick: () => dispatch(incrementTick()), - pauseSimulation: () => dispatch(pauseSimulation()), - } -} - -const TimelineContainer = connect(mapStateToProps, mapDispatchToProps)( - TimelineComponent, -) - -export default TimelineContainer diff --git a/frontend/src/containers/app/timeline/TimelineControlsContainer.js b/frontend/src/containers/app/timeline/TimelineControlsContainer.js deleted file mode 100644 index 91aba98d..00000000 --- a/frontend/src/containers/app/timeline/TimelineControlsContainer.js +++ /dev/null @@ -1,22 +0,0 @@ -import { connect } from 'react-redux' -import { goToTick } from '../../../actions/simulation/tick' -import TimelineControlsComponent from '../../../components/app/timeline/TimelineControlsComponent' - -const mapStateToProps = state => { - return { - currentTick: state.currentTick, - lastSimulatedTick: state.lastSimulatedTick, - } -} - -const mapDispatchToProps = dispatch => { - return { - goToTick: tick => dispatch(goToTick(tick)), - } -} - -const TimelineControlsContainer = connect(mapStateToProps, mapDispatchToProps)( - TimelineControlsComponent, -) - -export default TimelineControlsContainer diff --git a/frontend/src/containers/app/timeline/TimelineLabelsContainer.js b/frontend/src/containers/app/timeline/TimelineLabelsContainer.js deleted file mode 100644 index 192d21c3..00000000 --- a/frontend/src/containers/app/timeline/TimelineLabelsContainer.js +++ /dev/null @@ -1,15 +0,0 @@ -import { connect } from 'react-redux' -import TimelineLabelsComponent from '../../../components/app/timeline/TimelineLabelsComponent' - -const mapStateToProps = state => { - return { - currentTick: state.currentTick, - lastSimulatedTick: state.lastSimulatedTick, - } -} - -const TimelineLabelsContainer = connect(mapStateToProps)( - TimelineLabelsComponent, -) - -export default TimelineLabelsContainer diff --git a/frontend/src/containers/experiments/ExperimentListContainer.js b/frontend/src/containers/experiments/ExperimentListContainer.js index fc8f203b..0b3b70ca 100644 --- a/frontend/src/containers/experiments/ExperimentListContainer.js +++ b/frontend/src/containers/experiments/ExperimentListContainer.js @@ -3,8 +3,8 @@ import ExperimentListComponent from '../../components/experiments/ExperimentList const mapStateToProps = state => { if ( - state.currentSimulationId === '-1' || - !('experimentIds' in state.objects.simulation[state.currentSimulationId]) + state.currentProjectId === '-1' || + !('experimentIds' in state.objects.project[state.currentProjectId]) ) { return { loading: true, @@ -13,7 +13,7 @@ const mapStateToProps = state => { } const experimentIds = - state.objects.simulation[state.currentSimulationId].experimentIds + state.objects.project[state.currentProjectId].experimentIds if (experimentIds) { return { experimentIds, diff --git a/frontend/src/containers/experiments/ExperimentRowContainer.js b/frontend/src/containers/experiments/ExperimentRowContainer.js index 523c0747..87d8af67 100644 --- a/frontend/src/containers/experiments/ExperimentRowContainer.js +++ b/frontend/src/containers/experiments/ExperimentRowContainer.js @@ -13,7 +13,7 @@ const mapStateToProps = (state, ownProps) => { return { experiment, - simulationId: state.currentSimulationId, + projectId: state.currentProjectId, } } diff --git a/frontend/src/containers/modals/ChangeTopologyModal.js b/frontend/src/containers/modals/ChangeTopologyModal.js deleted file mode 100644 index a1db9032..00000000 --- a/frontend/src/containers/modals/ChangeTopologyModal.js +++ /dev/null @@ -1,64 +0,0 @@ -import { connect } from 'react-redux' -import ChangeTopologyModalComponent from '../../components/modals/custom-components/ChangeTopologyModalComponent' -import { closeChangeTopologyModal } from '../../actions/modals/topology' -import { addTopology, deleteTopology } from '../../actions/topologies' -import { setCurrentTopology } from '../../actions/topology/building' - -const mapStateToProps = state => { - let topologies = state.objects.simulation[state.currentSimulationId] ? state.objects.simulation[state.currentSimulationId].topologyIds.map(t => ( - state.objects.topology[t] - )) : [] - if (topologies.filter(t => !t).length > 0) { - topologies = [] - } - - return { - show: state.modals.changeTopologyModalVisible, - currentTopologyId: state.currentTopologyId, - topologies, - } -} - -const mapDispatchToProps = dispatch => { - return { - onChooseTopology: (id) => { - dispatch( - setCurrentTopology(id) - ) - dispatch(closeChangeTopologyModal()) - }, - onCreateTopology: (name) => { - if (name) { - dispatch( - addTopology({name, rooms: []}) - ) - } - dispatch(closeChangeTopologyModal()) - }, - onDuplicateTopology: (name) => { - if (name) { - // TODO different handling here - dispatch( - addTopology({name, rooms: []}) - ) - } - dispatch(closeChangeTopologyModal()) - }, - onDeleteTopology: (id) => { - if (id) { - dispatch( - deleteTopology(id) - ) - } - }, - onCancel: () => { - dispatch(closeChangeTopologyModal()) - }, - } -} - -const ChangeTopologyModal = connect(mapStateToProps, mapDispatchToProps)( - ChangeTopologyModalComponent, -) - -export default ChangeTopologyModal diff --git a/frontend/src/containers/modals/EditRackNameModal.js b/frontend/src/containers/modals/EditRackNameModal.js index 495c107b..fb7727f1 100644 --- a/frontend/src/containers/modals/EditRackNameModal.js +++ b/frontend/src/containers/modals/EditRackNameModal.js @@ -20,7 +20,7 @@ const mapStateToProps = state => { previousName: state.interactionLevel.mode === 'RACK' ? state.objects.rack[ - state.objects.tile[state.interactionLevel.tileId].rackId + state.objects.tile[state.interactionLevel.tileId].rackId ].name : '', } diff --git a/frontend/src/containers/modals/NewExperimentModal.js b/frontend/src/containers/modals/NewExperimentModal.js index 2ac5a4b8..f07b53e6 100644 --- a/frontend/src/containers/modals/NewExperimentModal.js +++ b/frontend/src/containers/modals/NewExperimentModal.js @@ -6,7 +6,7 @@ import NewExperimentModalComponent from '../../components/modals/custom-componen const mapStateToProps = state => { return { show: state.modals.newExperimentModalVisible, - topologies: state.objects.simulation[state.currentSimulationId].topologyIds.map(t => ( + topologies: state.objects.project[state.currentProjectId].topologyIds.map(t => ( state.objects.topology[t] )), traces: Object.values(state.objects.trace), diff --git a/frontend/src/containers/modals/NewProjectModal.js b/frontend/src/containers/modals/NewProjectModal.js new file mode 100644 index 00000000..1d0ebbbc --- /dev/null +++ b/frontend/src/containers/modals/NewProjectModal.js @@ -0,0 +1,37 @@ +import React from 'react' +import { connect } from 'react-redux' +import { closeNewProjectModal } from '../../actions/modals/projects' +import { addProject } from '../../actions/projects' +import TextInputModal from '../../components/modals/TextInputModal' + +const NewProjectModalComponent = ({ visible, callback }) => ( + <TextInputModal + title="New Project" + label="Project title" + show={visible} + callback={callback} + /> +) + +const mapStateToProps = state => { + return { + visible: state.modals.newProjectModalVisible, + } +} + +const mapDispatchToProps = dispatch => { + return { + callback: text => { + if (text) { + dispatch(addProject(text)) + } + dispatch(closeNewProjectModal()) + }, + } +} + +const NewProjectModal = connect(mapStateToProps, mapDispatchToProps)( + NewProjectModalComponent, +) + +export default NewProjectModal diff --git a/frontend/src/containers/modals/NewSimulationModal.js b/frontend/src/containers/modals/NewSimulationModal.js deleted file mode 100644 index e95ac4b0..00000000 --- a/frontend/src/containers/modals/NewSimulationModal.js +++ /dev/null @@ -1,37 +0,0 @@ -import React from 'react' -import { connect } from 'react-redux' -import { closeNewSimulationModal } from '../../actions/modals/simulations' -import { addSimulation } from '../../actions/simulations' -import TextInputModal from '../../components/modals/TextInputModal' - -const NewSimulationModalComponent = ({ visible, callback }) => ( - <TextInputModal - title="New Simulation" - label="Simulation title" - show={visible} - callback={callback} - /> -) - -const mapStateToProps = state => { - return { - visible: state.modals.newSimulationModalVisible, - } -} - -const mapDispatchToProps = dispatch => { - return { - callback: text => { - if (text) { - dispatch(addSimulation(text)) - } - dispatch(closeNewSimulationModal()) - }, - } -} - -const NewSimulationModal = connect(mapStateToProps, mapDispatchToProps)( - NewSimulationModalComponent, -) - -export default NewSimulationModal diff --git a/frontend/src/containers/modals/NewTopologyModal.js b/frontend/src/containers/modals/NewTopologyModal.js new file mode 100644 index 00000000..282f0db9 --- /dev/null +++ b/frontend/src/containers/modals/NewTopologyModal.js @@ -0,0 +1,49 @@ +import { connect } from 'react-redux' +import NewTopologyModalComponent from '../../components/modals/custom-components/NewTopologyModalComponent' +import { closeNewTopologyModal } from '../../actions/modals/topology' +import { addTopology } from '../../actions/topologies' + +const mapStateToProps = state => { + let topologies = state.objects.project[state.currentProjectId] ? state.objects.project[state.currentProjectId].topologyIds.map(t => ( + state.objects.topology[t] + )) : [] + if (topologies.filter(t => !t).length > 0) { + topologies = [] + } + + return { + show: state.modals.changeTopologyModalVisible, + topologies, + } +} + +const mapDispatchToProps = dispatch => { + return { + onCreateTopology: (name) => { + if (name) { + dispatch( + addTopology({ name, rooms: [] }), + ) + } + dispatch(closeNewTopologyModal()) + }, + onDuplicateTopology: (name) => { + if (name) { + // TODO different handling here + dispatch( + addTopology({ name, rooms: [] }), + ) + } + dispatch(closeNewTopologyModal()) + }, + onCancel: () => { + dispatch(closeNewTopologyModal()) + }, + } +} + +const NewTopologyModal = connect(mapStateToProps, mapDispatchToProps)( + NewTopologyModalComponent, +) + +export default NewTopologyModal diff --git a/frontend/src/containers/navigation/AppNavbarContainer.js b/frontend/src/containers/navigation/AppNavbarContainer.js new file mode 100644 index 00000000..bba44d77 --- /dev/null +++ b/frontend/src/containers/navigation/AppNavbarContainer.js @@ -0,0 +1,12 @@ +import { connect } from 'react-redux' +import AppNavbarComponent from '../../components/navigation/AppNavbarComponent' + +const mapStateToProps = state => { + return { + project: state.currentProjectId !== '-1' ? state.objects.project[state.currentProjectId] : undefined, + } +} + +const AppNavbarContainer = connect(mapStateToProps)(AppNavbarComponent) + +export default AppNavbarContainer diff --git a/frontend/src/containers/simulations/FilterLink.js b/frontend/src/containers/projects/FilterLink.js index 9eedd549..dfd6affe 100644 --- a/frontend/src/containers/simulations/FilterLink.js +++ b/frontend/src/containers/projects/FilterLink.js @@ -1,10 +1,10 @@ import { connect } from 'react-redux' -import { setAuthVisibilityFilter } from '../../actions/simulations' -import FilterButton from '../../components/simulations/FilterButton' +import { setAuthVisibilityFilter } from '../../actions/projects' +import FilterButton from '../../components/projects/FilterButton' const mapStateToProps = (state, ownProps) => { return { - active: state.simulationList.authVisibilityFilter === ownProps.filter, + active: state.projectList.authVisibilityFilter === ownProps.filter, } } diff --git a/frontend/src/containers/projects/NewProjectButtonContainer.js b/frontend/src/containers/projects/NewProjectButtonContainer.js new file mode 100644 index 00000000..f1d83ea3 --- /dev/null +++ b/frontend/src/containers/projects/NewProjectButtonContainer.js @@ -0,0 +1,15 @@ +import { connect } from 'react-redux' +import { openNewProjectModal } from '../../actions/modals/projects' +import NewProjectButtonComponent from '../../components/projects/NewProjectButtonComponent' + +const mapDispatchToProps = dispatch => { + return { + onClick: () => dispatch(openNewProjectModal()), + } +} + +const NewProjectButtonContainer = connect(undefined, mapDispatchToProps)( + NewProjectButtonComponent, +) + +export default NewProjectButtonContainer diff --git a/frontend/src/containers/projects/ProjectActions.js b/frontend/src/containers/projects/ProjectActions.js new file mode 100644 index 00000000..b9f9a534 --- /dev/null +++ b/frontend/src/containers/projects/ProjectActions.js @@ -0,0 +1,23 @@ +import { connect } from 'react-redux' +import { deleteProject } from '../../actions/projects' +import ProjectActionButtons from '../../components/projects/ProjectActionButtons' + +const mapStateToProps = (state, ownProps) => { + return { + projectId: ownProps.projectId, + } +} + +const mapDispatchToProps = dispatch => { + return { + onViewUsers: id => { + }, // TODO implement user viewing + onDelete: id => dispatch(deleteProject(id)), + } +} + +const ProjectActions = connect(mapStateToProps, mapDispatchToProps)( + ProjectActionButtons, +) + +export default ProjectActions diff --git a/frontend/src/containers/projects/VisibleProjectAuthList.js b/frontend/src/containers/projects/VisibleProjectAuthList.js new file mode 100644 index 00000000..b7ef6d24 --- /dev/null +++ b/frontend/src/containers/projects/VisibleProjectAuthList.js @@ -0,0 +1,42 @@ +import { connect } from 'react-redux' +import ProjectList from '../../components/projects/ProjectAuthList' + +const getVisibleProjectAuths = (projectAuths, filter) => { + switch (filter) { + case 'SHOW_ALL': + return projectAuths + case 'SHOW_OWN': + return projectAuths.filter( + projectAuth => projectAuth.authorizationLevel === 'OWN', + ) + case 'SHOW_SHARED': + return projectAuths.filter( + projectAuth => projectAuth.authorizationLevel !== 'OWN', + ) + default: + return projectAuths + } +} + +const mapStateToProps = state => { + const denormalizedAuthorizations = state.projectList.authorizationsOfCurrentUser.map( + authorizationIds => { + const authorization = state.objects.authorization[authorizationIds] + authorization.user = state.objects.user[authorization.userId] + authorization.project = + state.objects.project[authorization.projectId] + return authorization + }, + ) + + return { + authorizations: getVisibleProjectAuths( + denormalizedAuthorizations, + state.projectList.authVisibilityFilter, + ), + } +} + +const VisibleProjectAuthList = connect(mapStateToProps)(ProjectList) + +export default VisibleProjectAuthList diff --git a/frontend/src/containers/simulations/NewSimulationButtonContainer.js b/frontend/src/containers/simulations/NewSimulationButtonContainer.js deleted file mode 100644 index 2d7c7385..00000000 --- a/frontend/src/containers/simulations/NewSimulationButtonContainer.js +++ /dev/null @@ -1,15 +0,0 @@ -import { connect } from 'react-redux' -import { openNewSimulationModal } from '../../actions/modals/simulations' -import NewSimulationButtonComponent from '../../components/simulations/NewSimulationButtonComponent' - -const mapDispatchToProps = dispatch => { - return { - onClick: () => dispatch(openNewSimulationModal()), - } -} - -const NewSimulationButtonContainer = connect(undefined, mapDispatchToProps)( - NewSimulationButtonComponent, -) - -export default NewSimulationButtonContainer diff --git a/frontend/src/containers/simulations/SimulationActions.js b/frontend/src/containers/simulations/SimulationActions.js deleted file mode 100644 index 6c662912..00000000 --- a/frontend/src/containers/simulations/SimulationActions.js +++ /dev/null @@ -1,23 +0,0 @@ -import { connect } from 'react-redux' -import { deleteSimulation } from '../../actions/simulations' -import SimulationActionButtons from '../../components/simulations/SimulationActionButtons' - -const mapStateToProps = (state, ownProps) => { - return { - simulationId: ownProps.simulationId, - } -} - -const mapDispatchToProps = dispatch => { - return { - onViewUsers: id => { - }, // TODO implement user viewing - onDelete: id => dispatch(deleteSimulation(id)), - } -} - -const SimulationActions = connect(mapStateToProps, mapDispatchToProps)( - SimulationActionButtons, -) - -export default SimulationActions diff --git a/frontend/src/containers/simulations/VisibleSimulationAuthList.js b/frontend/src/containers/simulations/VisibleSimulationAuthList.js deleted file mode 100644 index f2b30542..00000000 --- a/frontend/src/containers/simulations/VisibleSimulationAuthList.js +++ /dev/null @@ -1,42 +0,0 @@ -import { connect } from 'react-redux' -import SimulationList from '../../components/simulations/SimulationAuthList' - -const getVisibleSimulationAuths = (simulationAuths, filter) => { - switch (filter) { - case 'SHOW_ALL': - return simulationAuths - case 'SHOW_OWN': - return simulationAuths.filter( - simulationAuth => simulationAuth.authorizationLevel === 'OWN', - ) - case 'SHOW_SHARED': - return simulationAuths.filter( - simulationAuth => simulationAuth.authorizationLevel !== 'OWN', - ) - default: - return simulationAuths - } -} - -const mapStateToProps = state => { - const denormalizedAuthorizations = state.simulationList.authorizationsOfCurrentUser.map( - authorizationIds => { - const authorization = state.objects.authorization[authorizationIds] - authorization.user = state.objects.user[authorization.userId] - authorization.simulation = - state.objects.simulation[authorization.simulationId] - return authorization - }, - ) - - return { - authorizations: getVisibleSimulationAuths( - denormalizedAuthorizations, - state.simulationList.authVisibilityFilter, - ), - } -} - -const VisibleSimulationAuthList = connect(mapStateToProps)(SimulationList) - -export default VisibleSimulationAuthList |
