summaryrefslogtreecommitdiff
path: root/src/components/map/groups/TileGroup.js
blob: 3de712d146f45ee4458a34e667b7b0e9b58af970 (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
import PropTypes from "prop-types";
import React from "react";
import {Group} from "react-konva";
import {ROOM_DEFAULT_COLOR, ROOM_IN_CONSTRUCTION_COLOR} from "../../../colors/index";
import RackContainer from "../../../containers/map/RackContainer";
import Shapes from "../../../shapes/index";
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) {
        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;