Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support displaying multiple serialports and board version of a device #262

Merged
merged 1 commit into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions lib/windows/app/components/DeviceSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ import Dropdown from '../../../components/HotkeyedDropdown';

// Stateless, templating-only component. Used only from ../containers/DeviceSelectorContainer
export default class DeviceSelector extends React.Component {
/**
* Returns an array of JSX that corresponds to the list of serialports
* of a device definition from nrf-device-lister
*
* @param {Object} device The device to render as a menu item.
* @returns {*} Array of 'serialport: ...' JSX item
*/
static mapSerialPortsToListItems(device) {
return Object.keys(device)
.filter(key => key.startsWith('serialport'))
.map(key => <li key={device[key].comName}>Serial port: {device[key].comName}</li>);
}

componentDidMount() {
this.props.onMount();
}
Expand Down Expand Up @@ -98,11 +111,12 @@ export default class DeviceSelector extends React.Component {
className={menuItemCssClass}
onSelect={() => onSelect(device)}
>
<div>{ device.serialNumber }</div>
<div>
{ device.serialNumber }
<span>{ device.boardVersion }</span>
</div>
<ul className={menuItemDetailsCssClass}>
{ device.serialport ?
(<li>Serial port: {device.serialport.comName}</li>)
: null }
{ DeviceSelector.mapSerialPortsToListItems(device) }
{ device.usb ?
(<li>USB: {device.usb.manufacturer} {device.usb.product}</li>)
: null }
Expand Down Expand Up @@ -190,4 +204,3 @@ DeviceSelector.defaultProps = {
onMount: () => {},
onUnmount: () => {},
};

4 changes: 4 additions & 0 deletions lib/windows/app/components/__tests__/DeviceSelector-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ describe('DeviceSelector', () => {
serialport: {
comName: '/dev/ttyACM0',
},
'serialport.1': {
comName: '/dev/ttyACM1',
},
usb: {
manufacturer: 'Nordic Semiconductor',
product: 'nRF52 USB',
},
boardVersion: 'PCA42424',
traits: ['serialport', 'nordicUsb', 'jlink'],
},
]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ exports[`DeviceSelector should render one device with serialport, usb, and jlink
>
<div>
123456789
<span>
PCA42424
</span>
</div>
<ul
className="core-device-selector-item-details"
Expand All @@ -53,6 +56,10 @@ exports[`DeviceSelector should render one device with serialport, usb, and jlink
Serial port:
/dev/ttyACM0
</li>
<li>
Serial port:
/dev/ttyACM1
</li>
<li>
USB:
Nordic Semiconductor
Expand Down
5 changes: 5 additions & 0 deletions resources/css/app.less
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ html, body, #webapp {

.core-device-selector-item {
padding-left: 5px;

// board version
> a > div:nth-child(1) > span {
margin-left: 20px;
}
}

ul.core-device-selector-item-details {
Expand Down