summaryrefslogtreecommitdiff
path: root/frontend/src/components/app/map/groups/TileGroup.js
blob: 49e2e52bae265d128a242e6528356932e9a23713 (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
import PropTypes from 'prop-types'
import React from 'react'
import { Group } from 'react-konva'
import RackContainer from '../../../../containers/app/map/RackContainer'
import Shapes from '../../../../shapes/index'
import { ROOM_DEFAULT_COLOR, ROOM_IN_CONSTRUCTION_COLOR } from '../../../../util/colors'
import { convertLoadToSimulationColor } from '../../../../util/simulation-load'
import RoomTile from '../elements/RoomTile'

const TileGroup = ({ tile, newTile, inSimulation, roomLoad, onClick }) => {
    let tileObject
    switch (tile.objectType) {
        case 'RACK':
            tileObject = <RackContainer tile={tile}/>
            break
        default:
            tileObject = null
    }

    let color = ROOM_DEFAULT_COLOR
    if (newTile) {
        color = ROOM_IN_CONSTRUCTION_COLOR
    } else if (inSimulation && roomLoad >= 0) {
        color = convertLoadToSimulationColor(roomLoad)
    }

    return (
        <Group onClick={() => onClick(tile)}>
            <RoomTile tile={tile} color={color}/>
            {tileObject}
        </Group>
    )
}

TileGroup.propTypes = {
    tile: Shapes.Tile,
    newTile: PropTypes.bool,
}

export default TileGroup