Skip to content

Commit

Permalink
[native] Improve device labels on device list screen
Browse files Browse the repository at this point in the history
Summary:
Resolves [[ https://linear.app/comm/issue/ENG-9136/rethink-device-description-if-current-device-is-primary | ENG-9136 ]]

The previous label for current primary device looked weird with two parentheses:
```
someDeviceID (primary) (this device)
```

Depends on D13262

Test Plan:
- Opened devices screen on native and verified they're now displayed correctly
{F3000688}
- JS playground:
```
lang=js
function getLabel(deviceID, isPrimary, isThisDevice) {
  // contents of useMemo
}

getLabel('123456789', false, false) // '1234567'
getLabel('123456789', false, true)  // '1234567 (this device)'
getLabel('123456789', true, false)  // '1234567 (primary)'
getLabel('123456789', true, true)   // '1234567 (primary, this device)'
```

Reviewers: ashoat, varun

Reviewed By: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D13747
  • Loading branch information
barthap committed Nov 8, 2024
1 parent 89cbd85 commit 085f43d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions native/profile/linked-devices-list-item.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,21 @@ function LinkedDevicesListItem(props: Props): React.Node {

const label = React.useMemo(() => {
const baseLabel = deviceID.substr(0, 7);
let finalLabel = baseLabel;

const labelAttributes = [];
if (isPrimary) {
finalLabel += ' (primary)';
labelAttributes.push('primary');
}

if (isThisDevice) {
finalLabel += ' (this device)';
labelAttributes.push('this device');
}

if (labelAttributes.length === 0) {
return baseLabel;
}

const joinedAttributes = labelAttributes.join(', ');
const finalLabel = `${baseLabel} (${joinedAttributes})`;
return finalLabel;
}, [deviceID, isPrimary, isThisDevice]);

Expand Down

0 comments on commit 085f43d

Please sign in to comment.