-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor dashboard devices-in-room box (#1138)
- Loading branch information
Showing
4 changed files
with
42 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,32 @@ | ||
import { createElement } from 'preact'; | ||
import { DEVICE_FEATURE_TYPES } from '../../../../../server/utils/constants'; | ||
|
||
import BinaryDeviceFeature from './device-features/BinaryDeviceFeature'; | ||
import ColorDeviceFeature from './device-features/ColorDeviceFeature'; | ||
import SensorDeviceFeature from './device-features/SensorDeviceFeature'; | ||
import MultilevelDeviceFeature from './device-features/MultiLevelDeviceFeature'; | ||
import BrightnessDeviceFeature from './device-features/BrightnessDeviceFeature'; | ||
import MultiLevelDeviceFeature from './device-features/MultiLevelDeviceFeature'; | ||
|
||
const ROW_TYPE_BY_FEATURE_TYPE = { | ||
[DEVICE_FEATURE_TYPES.LIGHT.BINARY]: BinaryDeviceFeature, | ||
[DEVICE_FEATURE_TYPES.LIGHT.COLOR]: ColorDeviceFeature, | ||
[DEVICE_FEATURE_TYPES.SWITCH.DIMMER]: MultiLevelDeviceFeature, | ||
[DEVICE_FEATURE_TYPES.LIGHT.BRIGHTNESS]: MultiLevelDeviceFeature | ||
}; | ||
|
||
const DeviceRow = ({ children, ...props }) => { | ||
// if device is a sensor, we display the sensor deviceFeature | ||
if (props.deviceFeature.read_only) { | ||
return <SensorDeviceFeature user={props.user} deviceFeature={props.deviceFeature} />; | ||
} | ||
|
||
// else, it's not a sensor | ||
// if it's a binary | ||
if (props.deviceFeature.type === 'binary') { | ||
return ( | ||
<BinaryDeviceFeature | ||
x={props.x} | ||
y={props.y} | ||
device={props.device} | ||
deviceFeature={props.deviceFeature} | ||
roomIndex={props.roomIndex} | ||
deviceIndex={props.deviceIndex} | ||
deviceFeatureIndex={props.deviceFeatureIndex} | ||
updateValue={props.updateValue} | ||
/> | ||
); | ||
} | ||
if (props.deviceFeature.type === 'color') { | ||
return ( | ||
<ColorDeviceFeature | ||
x={props.x} | ||
y={props.y} | ||
device={props.device} | ||
deviceFeature={props.deviceFeature} | ||
roomIndex={props.roomIndex} | ||
deviceIndex={props.deviceIndex} | ||
deviceFeatureIndex={props.deviceFeatureIndex} | ||
updateValue={props.updateValue} | ||
/> | ||
); | ||
} | ||
if (props.deviceFeature.type === 'dimmer') { | ||
return ( | ||
<MultilevelDeviceFeature | ||
x={props.x} | ||
y={props.y} | ||
device={props.device} | ||
deviceFeature={props.deviceFeature} | ||
roomIndex={props.roomIndex} | ||
deviceIndex={props.deviceIndex} | ||
deviceFeatureIndex={props.deviceFeatureIndex} | ||
updateValue={props.updateValue} | ||
/> | ||
); | ||
} | ||
if (props.deviceFeature.type === 'brightness') { | ||
return ( | ||
<BrightnessDeviceFeature | ||
x={props.x} | ||
y={props.y} | ||
device={props.device} | ||
deviceFeature={props.deviceFeature} | ||
roomIndex={props.roomIndex} | ||
deviceIndex={props.deviceIndex} | ||
deviceFeatureIndex={props.deviceFeatureIndex} | ||
updateValue={props.updateValue} | ||
/> | ||
); | ||
const elementType = ROW_TYPE_BY_FEATURE_TYPE[props.deviceFeature.type]; | ||
|
||
if (!elementType) { | ||
// if no related components, we return nothing | ||
return null; | ||
} | ||
// if not, we return nothing | ||
return null; | ||
|
||
return createElement(elementType, props); | ||
}; | ||
|
||
export default DeviceRow; |
43 changes: 0 additions & 43 deletions
43
front/src/components/boxs/device-in-room/device-features/BrightnessDeviceFeature.jsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters