Skip to content

Commit

Permalink
Add ability to add collection of Beacon IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Q committed Dec 19, 2018
1 parent c52f1f1 commit 47ee532
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
18 changes: 8 additions & 10 deletions src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import {saveState} from '../utils'

export const updateBeaconId = (state, event) => {
if (event.key === 'Enter') {
const beaconId = event.target.value
console.log('Beacon DevTools: Initializing', beaconId)
window.Beacon('destroy')
window.Beacon('init', beaconId)

return {
beaconId,
open: false,
}
const beaconId = event.target.value
console.log('Beacon DevTools: Initializing', beaconId)
window.Beacon('destroy')
window.Beacon('init', beaconId)

return {
beaconId,
open: false,
}
}

Expand Down
39 changes: 37 additions & 2 deletions src/components/DevTools/DevTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {DevToolsUI, FormBlock, HeaderUI, FooterUI} from './DevTools.css'
export class DevTools extends React.PureComponent {
static defaultProps = {
beaconId: '',
beaconIds: [],
isAutoOpen: false,
toggleDocs: () => undefined,
toggleMessaging: () => undefined,
Expand Down Expand Up @@ -62,6 +63,37 @@ export class DevTools extends React.PureComponent {
window.Beacon('off', 'close', this.props.closeBeacon)
}

handleOnInputUpdateBeaconId = event => {
if (event.key === 'Enter') {
this.props.updateBeaconId(event)
}
}

handleOnSelectUpdateBeaconId = event => {
this.props.updateBeaconId(event)
}

renderBeaconIds() {
const {beaconIds} = this.props
if (!beaconIds.length) return null

return (
<Label>
Beacon ID List
<Select onChange={this.handleOnSelectUpdateBeaconId}>
<option disabled selected>
Select...
</option>
{beaconIds.map(({id, label}) => (
<option value={id} key={id}>
{label}
</option>
))}
</Select>
</Label>
)
}

render() {
const {
chatEnabled,
Expand All @@ -79,7 +111,6 @@ export class DevTools extends React.PureComponent {
toggleOpen,
toggleShowGetInTouch,
toggleTranslation,
updateBeaconId,
updateColor,
updateDisplayText,
updateIconImage,
Expand All @@ -95,7 +126,11 @@ export class DevTools extends React.PureComponent {
<MainModal>
<HeaderUI>
Beacon DevTools
<Input onKeyUp={updateBeaconId} placeholder="Beacon ID" />
<Input
onKeyUp={this.handleOnInputUpdateBeaconId}
placeholder="Beacon ID"
/>
{this.renderBeaconIds()}
</HeaderUI>
<DevToolsUI>
<div>
Expand Down
7 changes: 5 additions & 2 deletions src/components/Label/Label.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import styled from '@helpscout/hsds-react/components/styled'

const LabelUI = styled('label')`
color: #ccc;
display: block;
font-family: inherit;
font-size: 12px;
display: block;
margin-top: 6px;
font-weight: normal;
letter-spacing: 0;
margin-bottom: 10px;
margin-top: 6px;
text-transform: initial;
`

export default LabelUI

0 comments on commit 47ee532

Please sign in to comment.