Convert multiple arguments as options for the helper functions
Summary: With the each addition of the CLI arguments, there were addition in the arguments to the helper functions for exportStore. To control it, I have moved those arguments into an object Reviewed By: jknoxville Differential Revision: D16378511 fbshipit-source-id: e620bc0d4863aa6029a57771aa970aebb7294ba9
This commit is contained in:
committed by
Facebook Github Bot
parent
aeee96c050
commit
23d4327f69
@@ -150,20 +150,28 @@ test('test generateNotifications helper function', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('test processStore function for empty state', () => {
|
test('test processStore function for empty state', () => {
|
||||||
const json = processStore([], null, {}, [], new Map(), 'salt', []);
|
const json = processStore({
|
||||||
|
activeNotifications: [],
|
||||||
|
device: null,
|
||||||
|
pluginStates: {},
|
||||||
|
clients: [],
|
||||||
|
devicePlugins: new Map(),
|
||||||
|
salt: 'salt',
|
||||||
|
selectedPlugins: [],
|
||||||
|
});
|
||||||
expect(json).resolves.toBeNull();
|
expect(json).resolves.toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('test processStore function for an iOS device connected', async () => {
|
test('test processStore function for an iOS device connected', async () => {
|
||||||
const json = await processStore(
|
const json = await processStore({
|
||||||
[],
|
activeNotifications: [],
|
||||||
new ArchivedDevice('serial', 'emulator', 'TestiPhone', 'iOS', []),
|
device: new ArchivedDevice('serial', 'emulator', 'TestiPhone', 'iOS', []),
|
||||||
{},
|
pluginStates: {},
|
||||||
[],
|
clients: [],
|
||||||
new Map(),
|
devicePlugins: new Map(),
|
||||||
'salt',
|
salt: 'salt',
|
||||||
[],
|
selectedPlugins: [],
|
||||||
);
|
});
|
||||||
expect(json).toBeDefined();
|
expect(json).toBeDefined();
|
||||||
// $FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
// $FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
||||||
const {device, clients} = json;
|
const {device, clients} = json;
|
||||||
@@ -188,15 +196,15 @@ test('test processStore function for an iOS device connected with client plugin
|
|||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
const clientIdentifier = generateClientIdentifier(device, 'testapp');
|
const clientIdentifier = generateClientIdentifier(device, 'testapp');
|
||||||
const json = await processStore(
|
const json = await processStore({
|
||||||
[],
|
activeNotifications: [],
|
||||||
device,
|
device,
|
||||||
{[clientIdentifier]: {msg: 'Test plugin'}},
|
pluginStates: {[clientIdentifier]: {msg: 'Test plugin'}},
|
||||||
[generateClientFromDevice(device, 'testapp')],
|
clients: [generateClientFromDevice(device, 'testapp')],
|
||||||
new Map(),
|
devicePlugins: new Map(),
|
||||||
'salt',
|
salt: 'salt',
|
||||||
[],
|
selectedPlugins: [],
|
||||||
);
|
});
|
||||||
expect(json).toBeDefined();
|
expect(json).toBeDefined();
|
||||||
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
||||||
const {pluginStates} = json.store;
|
const {pluginStates} = json.store;
|
||||||
@@ -236,11 +244,10 @@ test('test processStore function to have only the client for the selected device
|
|||||||
selectedDevice,
|
selectedDevice,
|
||||||
'testapp',
|
'testapp',
|
||||||
);
|
);
|
||||||
|
const json = await processStore({
|
||||||
const json = await processStore(
|
activeNotifications: [],
|
||||||
[],
|
device: selectedDevice,
|
||||||
selectedDevice,
|
pluginStates: {
|
||||||
{
|
|
||||||
[unselectedDeviceClientIdentifier + '#testapp']: {
|
[unselectedDeviceClientIdentifier + '#testapp']: {
|
||||||
msg: 'Test plugin unselected device',
|
msg: 'Test plugin unselected device',
|
||||||
},
|
},
|
||||||
@@ -248,14 +255,14 @@ test('test processStore function to have only the client for the selected device
|
|||||||
msg: 'Test plugin selected device',
|
msg: 'Test plugin selected device',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[
|
clients: [
|
||||||
selectedDeviceClient,
|
selectedDeviceClient,
|
||||||
generateClientFromDevice(unselectedDevice, 'testapp'),
|
generateClientFromDevice(unselectedDevice, 'testapp'),
|
||||||
],
|
],
|
||||||
new Map(),
|
devicePlugins: new Map(),
|
||||||
'salt',
|
salt: 'salt',
|
||||||
[],
|
selectedPlugins: [],
|
||||||
);
|
});
|
||||||
|
|
||||||
expect(json).toBeDefined();
|
expect(json).toBeDefined();
|
||||||
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already added
|
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already added
|
||||||
@@ -294,10 +301,10 @@ test('test processStore function to have multiple clients for the selected devic
|
|||||||
const client1 = generateClientFromDevice(selectedDevice, 'testapp1');
|
const client1 = generateClientFromDevice(selectedDevice, 'testapp1');
|
||||||
const client2 = generateClientFromDevice(selectedDevice, 'testapp2');
|
const client2 = generateClientFromDevice(selectedDevice, 'testapp2');
|
||||||
|
|
||||||
const json = await processStore(
|
const json = await processStore({
|
||||||
[],
|
activeNotifications: [],
|
||||||
selectedDevice,
|
device: selectedDevice,
|
||||||
{
|
pluginStates: {
|
||||||
[clientIdentifierApp1 + '#testapp1']: {
|
[clientIdentifierApp1 + '#testapp1']: {
|
||||||
msg: 'Test plugin App1',
|
msg: 'Test plugin App1',
|
||||||
},
|
},
|
||||||
@@ -305,14 +312,14 @@ test('test processStore function to have multiple clients for the selected devic
|
|||||||
msg: 'Test plugin App2',
|
msg: 'Test plugin App2',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[
|
clients: [
|
||||||
generateClientFromDevice(selectedDevice, 'testapp1'),
|
generateClientFromDevice(selectedDevice, 'testapp1'),
|
||||||
generateClientFromDevice(selectedDevice, 'testapp2'),
|
generateClientFromDevice(selectedDevice, 'testapp2'),
|
||||||
],
|
],
|
||||||
new Map(),
|
devicePlugins: new Map(),
|
||||||
'salt',
|
salt: 'salt',
|
||||||
[],
|
selectedPlugins: [],
|
||||||
);
|
});
|
||||||
expect(json).toBeDefined();
|
expect(json).toBeDefined();
|
||||||
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already added
|
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already added
|
||||||
const {clients} = json;
|
const {clients} = json;
|
||||||
@@ -343,19 +350,19 @@ test('test processStore function for device plugin state and no clients', async
|
|||||||
'iOS',
|
'iOS',
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
const json = await processStore(
|
const json = await processStore({
|
||||||
[],
|
activeNotifications: [],
|
||||||
selectedDevice,
|
device: selectedDevice,
|
||||||
{
|
pluginStates: {
|
||||||
'serial#TestDevicePlugin': {
|
'serial#TestDevicePlugin': {
|
||||||
msg: 'Test Device plugin',
|
msg: 'Test Device plugin',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[],
|
clients: [],
|
||||||
new Map([['TestDevicePlugin', TestDevicePlugin]]),
|
devicePlugins: new Map([['TestDevicePlugin', TestDevicePlugin]]),
|
||||||
'salt',
|
salt: 'salt',
|
||||||
[],
|
selectedPlugins: [],
|
||||||
);
|
});
|
||||||
expect(json).toBeDefined();
|
expect(json).toBeDefined();
|
||||||
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
||||||
const {pluginStates} = json.store;
|
const {pluginStates} = json.store;
|
||||||
@@ -376,19 +383,19 @@ test('test processStore function for unselected device plugin state and no clien
|
|||||||
'iOS',
|
'iOS',
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
const json = await processStore(
|
const json = await processStore({
|
||||||
[],
|
activeNotifications: [],
|
||||||
selectedDevice,
|
device: selectedDevice,
|
||||||
{
|
pluginStates: {
|
||||||
'unselectedDeviceIdentifier#TestDevicePlugin': {
|
'unselectedDeviceIdentifier#TestDevicePlugin': {
|
||||||
msg: 'Test Device plugin',
|
msg: 'Test Device plugin',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[],
|
clients: [],
|
||||||
new Map([['TestDevicePlugin', TestDevicePlugin]]),
|
devicePlugins: new Map([['TestDevicePlugin', TestDevicePlugin]]),
|
||||||
'salt',
|
salt: 'salt',
|
||||||
[],
|
selectedPlugins: [],
|
||||||
);
|
});
|
||||||
expect(json).toBeDefined();
|
expect(json).toBeDefined();
|
||||||
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
||||||
const {pluginStates} = json.store;
|
const {pluginStates} = json.store;
|
||||||
@@ -418,16 +425,15 @@ test('test processStore function for notifications for selected device', async (
|
|||||||
notification,
|
notification,
|
||||||
client: client.id,
|
client: client.id,
|
||||||
};
|
};
|
||||||
|
const json = await processStore({
|
||||||
const json = await processStore(
|
activeNotifications: [activeNotification],
|
||||||
[activeNotification],
|
device: selectedDevice,
|
||||||
selectedDevice,
|
pluginStates: {},
|
||||||
{},
|
clients: [client],
|
||||||
[client],
|
devicePlugins: new Map([['TestDevicePlugin', TestDevicePlugin]]),
|
||||||
new Map([['TestDevicePlugin', TestDevicePlugin]]),
|
salt: 'salt',
|
||||||
'salt',
|
selectedPlugins: [],
|
||||||
[],
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(json).toBeDefined();
|
expect(json).toBeDefined();
|
||||||
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
||||||
@@ -477,15 +483,15 @@ test('test processStore function for notifications for unselected device', async
|
|||||||
notification,
|
notification,
|
||||||
client: unselectedclient.id,
|
client: unselectedclient.id,
|
||||||
};
|
};
|
||||||
const json = await processStore(
|
const json = await processStore({
|
||||||
[activeNotification],
|
activeNotifications: [activeNotification],
|
||||||
selectedDevice,
|
device: selectedDevice,
|
||||||
{},
|
pluginStates: {},
|
||||||
[client, unselectedclient],
|
clients: [client, unselectedclient],
|
||||||
new Map(),
|
devicePlugins: new Map(),
|
||||||
'salt',
|
salt: 'salt',
|
||||||
[],
|
selectedPlugins: [],
|
||||||
);
|
});
|
||||||
expect(json).toBeDefined();
|
expect(json).toBeDefined();
|
||||||
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
||||||
const {pluginStates} = json.store;
|
const {pluginStates} = json.store;
|
||||||
@@ -514,15 +520,15 @@ test('test processStore function for selected plugins', async () => {
|
|||||||
msg: 'Test plugin2',
|
msg: 'Test plugin2',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const json = await processStore(
|
const json = await processStore({
|
||||||
[],
|
activeNotifications: [],
|
||||||
selectedDevice,
|
device: selectedDevice,
|
||||||
pluginstates,
|
pluginStates: pluginstates,
|
||||||
[client],
|
clients: [client],
|
||||||
new Map(),
|
devicePlugins: new Map(),
|
||||||
'salt',
|
salt: 'salt',
|
||||||
['plugin2'],
|
selectedPlugins: ['plugin2'],
|
||||||
);
|
});
|
||||||
expect(json).toBeDefined();
|
expect(json).toBeDefined();
|
||||||
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
||||||
const {pluginStates} = json.store;
|
const {pluginStates} = json.store;
|
||||||
@@ -557,15 +563,16 @@ test('test processStore function for no selected plugins', async () => {
|
|||||||
msg: 'Test plugin2',
|
msg: 'Test plugin2',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const json = await processStore(
|
const json = await processStore({
|
||||||
[],
|
activeNotifications: [],
|
||||||
selectedDevice,
|
device: selectedDevice,
|
||||||
pluginstates,
|
pluginStates: pluginstates,
|
||||||
[client],
|
clients: [client],
|
||||||
new Map(),
|
devicePlugins: new Map(),
|
||||||
'salt',
|
salt: 'salt',
|
||||||
[],
|
selectedPlugins: [],
|
||||||
);
|
});
|
||||||
|
|
||||||
expect(json).toBeDefined();
|
expect(json).toBeDefined();
|
||||||
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
||||||
const {pluginStates} = json.store;
|
const {pluginStates} = json.store;
|
||||||
|
|||||||
@@ -39,6 +39,32 @@ export type ExportType = {|
|
|||||||
},
|
},
|
||||||
|};
|
|};
|
||||||
|
|
||||||
|
type ProcessPluginStatesOptions = {|
|
||||||
|
clients: Array<ClientExport>,
|
||||||
|
serial: string,
|
||||||
|
allPluginStates: PluginStatesState,
|
||||||
|
devicePlugins: Map<string, Class<FlipperDevicePlugin<>>>,
|
||||||
|
selectedPlugins: Array<string>,
|
||||||
|
statusUpdate?: (msg: string) => void,
|
||||||
|
|};
|
||||||
|
|
||||||
|
type ProcessNotificationStatesOptions = {
|
||||||
|
clients: Array<ClientExport>,
|
||||||
|
serial: string,
|
||||||
|
allActiveNotifications: Array<PluginNotification>,
|
||||||
|
devicePlugins: Map<string, Class<FlipperDevicePlugin<>>>,
|
||||||
|
statusUpdate?: (msg: string) => void,
|
||||||
|
};
|
||||||
|
|
||||||
|
type AddSaltToDeviceSerialOptions = {
|
||||||
|
salt: string,
|
||||||
|
device: BaseDevice,
|
||||||
|
clients: Array<ClientExport>,
|
||||||
|
pluginStates: PluginStatesState,
|
||||||
|
pluginNotification: Array<PluginNotification>,
|
||||||
|
statusUpdate?: (msg: string) => void,
|
||||||
|
};
|
||||||
|
|
||||||
export function processClients(
|
export function processClients(
|
||||||
clients: Array<ClientExport>,
|
clients: Array<ClientExport>,
|
||||||
serial: string,
|
serial: string,
|
||||||
@@ -69,13 +95,17 @@ export function pluginsClassMap(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function processPluginStates(
|
export function processPluginStates(
|
||||||
clients: Array<ClientExport>,
|
options: ProcessPluginStatesOptions,
|
||||||
serial: string,
|
|
||||||
allPluginStates: PluginStatesState,
|
|
||||||
devicePlugins: Map<string, Class<FlipperDevicePlugin<>>>,
|
|
||||||
selectedPlugins: Array<string>,
|
|
||||||
statusUpdate?: (msg: string) => void,
|
|
||||||
): PluginStatesState {
|
): PluginStatesState {
|
||||||
|
const {
|
||||||
|
clients,
|
||||||
|
serial,
|
||||||
|
allPluginStates,
|
||||||
|
devicePlugins,
|
||||||
|
selectedPlugins,
|
||||||
|
statusUpdate,
|
||||||
|
} = options;
|
||||||
|
|
||||||
let pluginStates = {};
|
let pluginStates = {};
|
||||||
statusUpdate &&
|
statusUpdate &&
|
||||||
statusUpdate('Filtering the plugin states for the filtered Clients...');
|
statusUpdate('Filtering the plugin states for the filtered Clients...');
|
||||||
@@ -101,12 +131,15 @@ export function processPluginStates(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function processNotificationStates(
|
export function processNotificationStates(
|
||||||
clients: Array<ClientExport>,
|
options: ProcessNotificationStatesOptions,
|
||||||
serial: string,
|
|
||||||
allActiveNotifications: Array<PluginNotification>,
|
|
||||||
devicePlugins: Map<string, Class<FlipperDevicePlugin<>>>,
|
|
||||||
statusUpdate?: (msg: string) => void,
|
|
||||||
): Array<PluginNotification> {
|
): Array<PluginNotification> {
|
||||||
|
const {
|
||||||
|
clients,
|
||||||
|
serial,
|
||||||
|
allActiveNotifications,
|
||||||
|
devicePlugins,
|
||||||
|
statusUpdate,
|
||||||
|
} = options;
|
||||||
statusUpdate &&
|
statusUpdate &&
|
||||||
statusUpdate('Filtering the notifications for the filtered Clients...');
|
statusUpdate('Filtering the notifications for the filtered Clients...');
|
||||||
const activeNotifications = allActiveNotifications.filter(notif => {
|
const activeNotifications = allActiveNotifications.filter(notif => {
|
||||||
@@ -122,13 +155,16 @@ export function processNotificationStates(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const addSaltToDeviceSerial = async (
|
const addSaltToDeviceSerial = async (
|
||||||
salt: string,
|
options: AddSaltToDeviceSerialOptions,
|
||||||
device: BaseDevice,
|
|
||||||
clients: Array<ClientExport>,
|
|
||||||
pluginStates: PluginStatesState,
|
|
||||||
pluginNotification: Array<PluginNotification>,
|
|
||||||
statusUpdate?: (msg: string) => void,
|
|
||||||
): Promise<ExportType> => {
|
): Promise<ExportType> => {
|
||||||
|
const {
|
||||||
|
salt,
|
||||||
|
device,
|
||||||
|
clients,
|
||||||
|
pluginStates,
|
||||||
|
pluginNotification,
|
||||||
|
statusUpdate,
|
||||||
|
} = options;
|
||||||
const {serial} = device;
|
const {serial} = device;
|
||||||
const newSerial = salt + '-' + serial;
|
const newSerial = salt + '-' + serial;
|
||||||
const newDevice = new ArchivedDevice(
|
const newDevice = new ArchivedDevice(
|
||||||
@@ -191,7 +227,7 @@ const addSaltToDeviceSerial = async (
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const processStore = async (
|
type ProcessStoreOptions = {|
|
||||||
activeNotifications: Array<PluginNotification>,
|
activeNotifications: Array<PluginNotification>,
|
||||||
device: ?BaseDevice,
|
device: ?BaseDevice,
|
||||||
pluginStates: PluginStatesState,
|
pluginStates: PluginStatesState,
|
||||||
@@ -200,34 +236,49 @@ export const processStore = async (
|
|||||||
salt: string,
|
salt: string,
|
||||||
selectedPlugins: Array<string>,
|
selectedPlugins: Array<string>,
|
||||||
statusUpdate?: (msg: string) => void,
|
statusUpdate?: (msg: string) => void,
|
||||||
|
|};
|
||||||
|
|
||||||
|
export const processStore = async (
|
||||||
|
options: ProcessStoreOptions,
|
||||||
): Promise<?ExportType> => {
|
): Promise<?ExportType> => {
|
||||||
|
const {
|
||||||
|
activeNotifications,
|
||||||
|
device,
|
||||||
|
pluginStates,
|
||||||
|
clients,
|
||||||
|
devicePlugins,
|
||||||
|
salt,
|
||||||
|
selectedPlugins,
|
||||||
|
statusUpdate,
|
||||||
|
} = options;
|
||||||
|
|
||||||
if (device) {
|
if (device) {
|
||||||
const {serial} = device;
|
const {serial} = device;
|
||||||
const processedClients = processClients(clients, serial, statusUpdate);
|
const processedClients = processClients(clients, serial, statusUpdate);
|
||||||
const processedPluginStates = processPluginStates(
|
const processedPluginStates = processPluginStates({
|
||||||
processedClients,
|
clients: processedClients,
|
||||||
serial,
|
serial,
|
||||||
pluginStates,
|
allPluginStates: pluginStates,
|
||||||
devicePlugins,
|
devicePlugins,
|
||||||
selectedPlugins,
|
selectedPlugins,
|
||||||
statusUpdate,
|
statusUpdate,
|
||||||
);
|
});
|
||||||
const processedActiveNotifications = processNotificationStates(
|
const processedActiveNotifications = processNotificationStates({
|
||||||
processedClients,
|
clients: processedClients,
|
||||||
serial,
|
serial,
|
||||||
activeNotifications,
|
allActiveNotifications: activeNotifications,
|
||||||
devicePlugins,
|
devicePlugins,
|
||||||
statusUpdate,
|
statusUpdate,
|
||||||
);
|
});
|
||||||
// Adding salt to the device id, so that the device_id in the device list is unique.
|
// Adding salt to the device id, so that the device_id in the device list is unique.
|
||||||
const exportFlipperData = await addSaltToDeviceSerial(
|
const exportFlipperData = await addSaltToDeviceSerial({
|
||||||
salt,
|
salt,
|
||||||
device,
|
device,
|
||||||
processedClients,
|
clients: processedClients,
|
||||||
processedPluginStates,
|
pluginStates: processedPluginStates,
|
||||||
processedActiveNotifications,
|
pluginNotification: processedActiveNotifications,
|
||||||
statusUpdate,
|
statusUpdate,
|
||||||
);
|
});
|
||||||
return exportFlipperData;
|
return exportFlipperData;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -319,16 +370,16 @@ export async function getStoreExport(
|
|||||||
|
|
||||||
const {activeNotifications} = store.getState().notifications;
|
const {activeNotifications} = store.getState().notifications;
|
||||||
const {devicePlugins} = store.getState().plugins;
|
const {devicePlugins} = store.getState().plugins;
|
||||||
const exportData = await processStore(
|
const exportData = await processStore({
|
||||||
activeNotifications,
|
activeNotifications,
|
||||||
selectedDevice,
|
device: selectedDevice,
|
||||||
newPluginState,
|
pluginStates: newPluginState,
|
||||||
clients.map(client => client.toJSON()),
|
clients: clients.map(client => client.toJSON()),
|
||||||
devicePlugins,
|
devicePlugins,
|
||||||
uuid.v4(),
|
salt: uuid.v4(),
|
||||||
store.getState().plugins.selectedPlugins,
|
selectedPlugins: store.getState().plugins.selectedPlugins,
|
||||||
statusUpdate,
|
statusUpdate,
|
||||||
);
|
});
|
||||||
return {exportData, errorArray};
|
return {exportData, errorArray};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user