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>;
|
androidEmulators: Array<string>;
|
||||||
selectedDevice: null | BaseDevice;
|
selectedDevice: null | BaseDevice;
|
||||||
selectedPlugin: null | string;
|
selectedPlugin: null | string;
|
||||||
selectedApp: null | string | undefined;
|
selectedApp: null | string;
|
||||||
userPreferredDevice: null | string;
|
userPreferredDevice: null | string;
|
||||||
userPreferredPlugin: null | string;
|
userPreferredPlugin: null | string;
|
||||||
userPreferredApp: null | string;
|
userPreferredApp: null | string;
|
||||||
@@ -229,7 +229,7 @@ const reducer = (state: State = INITAL_STATE, action: Actions): State => {
|
|||||||
return updateSelection({
|
return updateSelection({
|
||||||
...state,
|
...state,
|
||||||
staticView: null,
|
staticView: null,
|
||||||
selectedApp,
|
selectedApp: selectedApp || null,
|
||||||
selectedPlugin,
|
selectedPlugin,
|
||||||
userPreferredPlugin: selectedPlugin || state.userPreferredPlugin,
|
userPreferredPlugin: selectedPlugin || state.userPreferredPlugin,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,44 +10,30 @@
|
|||||||
import Client from '../Client';
|
import Client from '../Client';
|
||||||
import BaseDevice from '../devices/BaseDevice';
|
import BaseDevice from '../devices/BaseDevice';
|
||||||
|
|
||||||
|
type ClientIdConstituents = {
|
||||||
|
app: string;
|
||||||
|
os: string;
|
||||||
|
device: string;
|
||||||
|
device_id: string;
|
||||||
|
};
|
||||||
|
|
||||||
export function currentActiveApps(
|
export function currentActiveApps(
|
||||||
clients: Array<Client>,
|
clients: Array<Client>,
|
||||||
selectedDevice: null | BaseDevice,
|
selectedDevice: null | BaseDevice,
|
||||||
): Array<string> {
|
): Array<string> {
|
||||||
const currentActiveApps: Array<string> = clients
|
const currentActiveApps: Array<string> = clients
|
||||||
.map(({id}: {id: string}) => {
|
.map(({id}: {id: string}) => {
|
||||||
const appName = appNameFromClienID(id) || '';
|
const appName = deconstructClientId(id).app || '';
|
||||||
const device = deviceFromClienID(id) || '';
|
const os = deconstructClientId(id).os || '';
|
||||||
return {appName, device};
|
return {appName, os};
|
||||||
})
|
})
|
||||||
.filter(
|
.filter(
|
||||||
({device}: {device: string}) =>
|
({os}: {os: string}) => os && selectedDevice && os == selectedDevice.os,
|
||||||
device && selectedDevice && device == selectedDevice.os,
|
|
||||||
)
|
)
|
||||||
.map(client => client.appName);
|
.map(client => client.appName);
|
||||||
return currentActiveApps;
|
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: {
|
export function buildClientId(clientInfo: {
|
||||||
app: string;
|
app: string;
|
||||||
os: string;
|
os: string;
|
||||||
@@ -56,3 +42,16 @@ export function buildClientId(clientInfo: {
|
|||||||
}): string {
|
}): string {
|
||||||
return `${clientInfo.app}#${clientInfo.os}#${clientInfo.device}#${clientInfo.device_id}`;
|
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,
|
SupportFormRequestDetailsState,
|
||||||
} from '../reducers/supportForm';
|
} from '../reducers/supportForm';
|
||||||
import {setSelectPluginsToExportActiveSheet} from '../reducers/application';
|
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 IMPORT_FLIPPER_TRACE_EVENT = 'import-flipper-trace';
|
||||||
export const EXPORT_FLIPPER_TRACE_EVENT = 'export-flipper-trace';
|
export const EXPORT_FLIPPER_TRACE_EVENT = 'export-flipper-trace';
|
||||||
@@ -547,7 +547,10 @@ export function exportStore(
|
|||||||
if (exportData != null) {
|
if (exportData != null) {
|
||||||
exportData.supportRequestDetails = {
|
exportData.supportRequestDetails = {
|
||||||
...state.supportForm?.supportFormV2,
|
...state.supportForm?.supportFormV2,
|
||||||
appName: getCurrentAppName(state.connections.selectedApp),
|
appName:
|
||||||
|
state.connections.selectedApp == null
|
||||||
|
? ''
|
||||||
|
: deconstructClientId(state.connections.selectedApp).app,
|
||||||
};
|
};
|
||||||
|
|
||||||
statusUpdate && statusUpdate('Serializing Flipper data...');
|
statusUpdate && statusUpdate('Serializing Flipper data...');
|
||||||
|
|||||||
Reference in New Issue
Block a user