-
-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new component to set pilot wire mode in scene
- Loading branch information
1 parent
b41977e
commit c9e87df
Showing
7 changed files
with
102 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Component } from 'preact'; | ||
import { Text } from 'preact-i18n'; | ||
import Select from 'react-select'; | ||
import get from 'get-value'; | ||
|
||
import { PILOT_WIRE_MODE } from '../../../../server/utils/constants'; | ||
import withIntlAsProp from '../../utils/withIntlAsProp'; | ||
|
||
class SelectPilotWireMode extends Component { | ||
handleValueChange = ({ value }) => { | ||
this.props.updateValue(value); | ||
}; | ||
|
||
getOptions = () => { | ||
const deviceFeatureOptions = Object.keys(PILOT_WIRE_MODE).map(key => { | ||
const value = PILOT_WIRE_MODE[key]; | ||
return { | ||
label: get(this.props.intl.dictionary, `deviceFeatureValue.category.heater.pilot-wire-mode.${value}`, { | ||
default: value | ||
}), | ||
value | ||
}; | ||
}); | ||
|
||
this.setState({ deviceFeatureOptions }); | ||
}; | ||
|
||
getSelectedOption = () => { | ||
const value = this.props.value; | ||
|
||
if (value !== undefined) { | ||
return { | ||
label: get(this.props.intl.dictionary, `deviceFeatureValue.category.heater.pilot-wire-mode.${value}`, { | ||
default: value | ||
}), | ||
value | ||
}; | ||
} else { | ||
return; | ||
} | ||
}; | ||
|
||
componentDidMount() { | ||
this.getOptions(); | ||
} | ||
|
||
render(props, { deviceFeatureOptions }) { | ||
const selectedOption = this.getSelectedOption(); | ||
return ( | ||
<Select | ||
class="select-device-feature" | ||
defaultValue={''} | ||
value={selectedOption} | ||
onChange={this.handleValueChange} | ||
options={deviceFeatureOptions} | ||
placeholder={<Text id="global.selectPlaceholder" />} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default withIntlAsProp(SelectPilotWireMode); |
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
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
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