Unifying use of clientID utils
Summary: Fixes a couple of typo's and merges two very similar functions into one. Now that there's a single way to create a clientID, we can get more strict about what it is and what it isn't. Reviewed By: passy Differential Revision: D18809741 fbshipit-source-id: 9a68e45bead38cc2917a6d4cd2cf461c309f3ede
This commit is contained in:
committed by
Facebook Github Bot
parent
e1e2978b19
commit
c95ecf6b3e
@@ -40,7 +40,7 @@ export type State = {
|
||||
androidEmulators: Array<string>;
|
||||
selectedDevice: null | BaseDevice;
|
||||
selectedPlugin: null | string;
|
||||
selectedApp: null | string | undefined;
|
||||
selectedApp: null | string;
|
||||
userPreferredDevice: null | string;
|
||||
userPreferredPlugin: null | string;
|
||||
userPreferredApp: null | string;
|
||||
@@ -229,7 +229,7 @@ const reducer = (state: State = INITAL_STATE, action: Actions): State => {
|
||||
return updateSelection({
|
||||
...state,
|
||||
staticView: null,
|
||||
selectedApp,
|
||||
selectedApp: selectedApp || null,
|
||||
selectedPlugin,
|
||||
userPreferredPlugin: selectedPlugin || state.userPreferredPlugin,
|
||||
});
|
||||
|
||||
@@ -10,44 +10,30 @@
|
||||
import Client from '../Client';
|
||||
import BaseDevice from '../devices/BaseDevice';
|
||||
|
||||
type ClientIdConstituents = {
|
||||
app: string;
|
||||
os: string;
|
||||
device: string;
|
||||
device_id: string;
|
||||
};
|
||||
|
||||
export function currentActiveApps(
|
||||
clients: Array<Client>,
|
||||
selectedDevice: null | BaseDevice,
|
||||
): Array<string> {
|
||||
const currentActiveApps: Array<string> = clients
|
||||
.map(({id}: {id: string}) => {
|
||||
const appName = appNameFromClienID(id) || '';
|
||||
const device = deviceFromClienID(id) || '';
|
||||
return {appName, device};
|
||||
const appName = deconstructClientId(id).app || '';
|
||||
const os = deconstructClientId(id).os || '';
|
||||
return {appName, os};
|
||||
})
|
||||
.filter(
|
||||
({device}: {device: string}) =>
|
||||
device && selectedDevice && device == selectedDevice.os,
|
||||
({os}: {os: string}) => os && selectedDevice && os == selectedDevice.os,
|
||||
)
|
||||
.map(client => client.appName);
|
||||
return currentActiveApps;
|
||||
}
|
||||
|
||||
export function appNameFromClienID(id: string): string | undefined {
|
||||
const arr = id.split('#');
|
||||
const appName = arr[0];
|
||||
return appName;
|
||||
}
|
||||
|
||||
export function deviceFromClienID(id: string): string | undefined {
|
||||
const arr = id.split('#');
|
||||
const device = arr[1];
|
||||
return device;
|
||||
}
|
||||
|
||||
export function getCurrentAppName(client: string | undefined | null): string {
|
||||
if (client) {
|
||||
return appNameFromClienID(client) || '';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
export function buildClientId(clientInfo: {
|
||||
app: string;
|
||||
os: string;
|
||||
@@ -56,3 +42,16 @@ export function buildClientId(clientInfo: {
|
||||
}): string {
|
||||
return `${clientInfo.app}#${clientInfo.os}#${clientInfo.device}#${clientInfo.device_id}`;
|
||||
}
|
||||
|
||||
export function deconstructClientId(clientId: string): ClientIdConstituents {
|
||||
if (!clientId || clientId.split('#').length !== 4) {
|
||||
console.error(`Attempted to deconstruct invalid clientId: "${clientId}"`);
|
||||
}
|
||||
const [app, os, device, device_id] = clientId.split('#');
|
||||
return {
|
||||
app,
|
||||
os,
|
||||
device,
|
||||
device_id,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ import {
|
||||
SupportFormRequestDetailsState,
|
||||
} from '../reducers/supportForm';
|
||||
import {setSelectPluginsToExportActiveSheet} from '../reducers/application';
|
||||
import {getCurrentAppName} from '../utils/clientUtils';
|
||||
import {deconstructClientId} from '../utils/clientUtils';
|
||||
|
||||
export const IMPORT_FLIPPER_TRACE_EVENT = 'import-flipper-trace';
|
||||
export const EXPORT_FLIPPER_TRACE_EVENT = 'export-flipper-trace';
|
||||
@@ -547,7 +547,10 @@ export function exportStore(
|
||||
if (exportData != null) {
|
||||
exportData.supportRequestDetails = {
|
||||
...state.supportForm?.supportFormV2,
|
||||
appName: getCurrentAppName(state.connections.selectedApp),
|
||||
appName:
|
||||
state.connections.selectedApp == null
|
||||
? ''
|
||||
: deconstructClientId(state.connections.selectedApp).app,
|
||||
};
|
||||
|
||||
statusUpdate && statusUpdate('Serializing Flipper data...');
|
||||
|
||||
Reference in New Issue
Block a user