Move the logic to show archived info in the object creation

Summary:
Write now the logic to append (Imported) and (Offline) text for archived devices is scattered at multiple places. Due to which we had the following bug

{F227484749}

Reviewed By: mweststrate

Differential Revision: D19663506

fbshipit-source-id: 1f5c0060825d8b246c94da85ac4a18cc4ff040d2
This commit is contained in:
Pritesh Nandgaonkar
2020-02-03 10:06:07 -08:00
committed by Facebook Github Bot
parent 041a347fd3
commit 9369033d99
4 changed files with 15 additions and 14 deletions

View File

@@ -77,15 +77,13 @@ class DevicesButton extends Component<Props> {
let icon = 'minus-circle'; let icon = 'minus-circle';
if (selectedDevice && selectedDevice.isArchived) { if (selectedDevice && selectedDevice.isArchived) {
buttonLabel = `${selectedDevice.title || 'Unknown device'} ${ buttonLabel = `${selectedDevice.displayTitle() || 'Unknown device'}`;
selectedDevice.source ? '(imported)' : '(offline)'
}`;
icon = 'box'; icon = 'box';
} else if (selectedDevice && selectedDevice.deviceType === 'physical') { } else if (selectedDevice && selectedDevice.deviceType === 'physical') {
buttonLabel = selectedDevice.title || 'Unknown device'; buttonLabel = selectedDevice.displayTitle() || 'Unknown device';
icon = 'mobile'; icon = 'mobile';
} else if (selectedDevice && selectedDevice.deviceType === 'emulator') { } else if (selectedDevice && selectedDevice.deviceType === 'emulator') {
buttonLabel = selectedDevice.title || 'Unknown emulator'; buttonLabel = selectedDevice.displayTitle() || 'Unknown emulator';
icon = 'desktop'; icon = 'desktop';
} }
@@ -102,7 +100,7 @@ class DevicesButton extends Component<Props> {
.map((device: BaseDevice) => ({ .map((device: BaseDevice) => ({
click: () => selectDevice(device), click: () => selectDevice(device),
checked: device === selectedDevice, checked: device === selectedDevice,
label: `📱 ${device.title}`, label: `📱 ${device.displayTitle()}`,
type: 'checkbox', type: 'checkbox',
})), })),
]; ];
@@ -120,7 +118,7 @@ class DevicesButton extends Component<Props> {
.map((device: BaseDevice) => ({ .map((device: BaseDevice) => ({
click: () => selectDevice(device), click: () => selectDevice(device),
checked: device === selectedDevice, checked: device === selectedDevice,
label: device.title, label: device.displayTitle(),
type: 'checkbox', type: 'checkbox',
})), })),
]; ];
@@ -138,9 +136,7 @@ class DevicesButton extends Component<Props> {
.map((device: BaseDevice) => ({ .map((device: BaseDevice) => ({
click: () => selectDevice(device), click: () => selectDevice(device),
checked: device === selectedDevice, checked: device === selectedDevice,
label: `📦 ${device.title} ${ label: `📦 ${device.displayTitle()}`,
device.source ? '(imported)' : '(offline)'
}`,
type: 'checkbox', type: 'checkbox',
})), })),
]; ];

View File

@@ -250,12 +250,9 @@ class MainSidebar2 extends PureComponent<Props, State> {
selectedDevice, selectedDevice,
} = this.props; } = this.props;
const clients = getAvailableClients(device, this.props.clients); const clients = getAvailableClients(device, this.props.clients);
return ( return (
<SidebarSection <SidebarSection
title={`${device.title} ${ title={device.displayTitle()}
device.isArchived ? (device.source ? '(imported)' : '(offline)') : ''
}`}
key={device.serial} key={device.serial}
level={1} level={1}
defaultCollapsed={!canBeDefaultDevice(device)}> defaultCollapsed={!canBeDefaultDevice(device)}>

View File

@@ -41,6 +41,10 @@ export default class ArchivedDevice extends BaseDevice {
isArchived = true; isArchived = true;
displayTitle(): string {
return `${this.title} ${this.source ? '(Imported)' : '(Offline)'}`;
}
supportRequestDetails?: SupportFormRequestDetailsState; supportRequestDetails?: SupportFormRequestDetailsState;
getLogs() { getLogs() {

View File

@@ -90,6 +90,10 @@ export default class BaseDevice {
return os.toLowerCase() === this.os.toLowerCase(); return os.toLowerCase() === this.os.toLowerCase();
} }
displayTitle(): string {
return this.title;
}
toJSON(): DeviceExport { toJSON(): DeviceExport {
return { return {
os: this.os, os: this.os,