Refactor export data functions and exportpersistedstate function to just expect state

Summary: This diff refactors the `exportpersistedstate` and few of the functions in exportData.tsx to just expect the Redux State instead the store object.

Reviewed By: mweststrate

Differential Revision: D18733011

fbshipit-source-id: 56739917b49142ba4b6e79e7c16378fe60d6ac3b
This commit is contained in:
Pritesh Nandgaonkar
2019-11-28 03:47:32 -08:00
committed by Facebook Github Bot
parent bf85da17ab
commit ca53f35875
9 changed files with 32 additions and 30 deletions

View File

@@ -11,7 +11,7 @@ import os from 'os';
import path from 'path';
import electron from 'electron';
import {getInstance as getLogger} from '../fb-stubs/Logger';
import {Store, MiddlewareAPI} from '../reducers';
import {Store, State as ReduxState} from '../reducers';
import {DeviceExport} from '../devices/BaseDevice';
import {State as PluginStatesState} from '../reducers/pluginStates';
import {PluginNotification} from '../reducers/notifications';
@@ -397,13 +397,13 @@ export async function fetchMetadata(
clients: Client[],
pluginStates: PluginStatesState,
pluginsMap: Map<string, typeof FlipperDevicePlugin | typeof FlipperPlugin>,
store: MiddlewareAPI,
state: ReduxState,
statusUpdate?: (msg: string) => void,
idler?: Idler,
): Promise<{pluginStates: PluginStatesState; errorArray: Array<Error>}> {
const newPluginState = {...pluginStates};
const errorArray: Array<Error> = [];
const selectedDevice = store.getState().connections.selectedDevice;
const selectedDevice = state.connections.selectedDevice;
for (const client of clients) {
if (
!selectedDevice ||
@@ -412,7 +412,7 @@ export async function fetchMetadata(
) {
continue;
}
const selectedPlugins = store.getState().plugins.selectedPlugins;
const selectedPlugins = state.plugins.selectedPlugins;
const selectedFilteredPlugins =
selectedPlugins.length > 0
? client.plugins.filter(plugin => selectedPlugins.includes(plugin))
@@ -436,7 +436,7 @@ export async function fetchMetadata(
exportState(
callClient(client, plugin),
newPluginState[key],
store,
state,
idler,
statusUpdate,
),
@@ -462,18 +462,17 @@ export async function fetchMetadata(
}
export async function getStoreExport(
store: MiddlewareAPI,
state: ReduxState,
statusUpdate?: (msg: string) => void,
idler?: Idler,
): Promise<{exportData: ExportType | null; errorArray: Array<Error>}> {
const state = store.getState();
const {clients} = state.connections;
const client = clients.find(
client => client.id === state.connections.selectedApp,
);
const {pluginStates} = state;
const {plugins} = state;
const {selectedDevice} = store.getState().connections;
const {selectedDevice} = state.connections;
if (!selectedDevice) {
throw new Error('Please select a device before exporting data.');
}
@@ -500,18 +499,18 @@ export async function getStoreExport(
[client],
pluginStates,
pluginsMap,
store,
state,
statusUpdate,
idler,
);
getLogger().trackTimeSince(fetchMetaDataMarker, fetchMetaDataMarker, {
plugins: store.getState().plugins.selectedPlugins,
plugins: state.plugins.selectedPlugins,
});
const {errorArray} = metadata;
const newPluginState = metadata.pluginStates;
const {activeNotifications} = store.getState().notifications;
const {devicePlugins, clientPlugins} = store.getState().plugins;
const {activeNotifications} = state.notifications;
const {devicePlugins, clientPlugins} = state.plugins;
const exportData = await processStore(
{
activeNotifications,
@@ -521,7 +520,7 @@ export async function getStoreExport(
devicePlugins,
clientPlugins,
salt: uuid.v4(),
selectedPlugins: store.getState().plugins.selectedPlugins,
selectedPlugins: state.plugins.selectedPlugins,
statusUpdate,
},
idler,
@@ -530,7 +529,7 @@ export async function getStoreExport(
}
export function exportStore(
store: MiddlewareAPI,
state: ReduxState,
idler?: Idler,
statusUpdate?: (msg: string) => void,
): Promise<{serializedString: string; errorArray: Array<Error>}> {
@@ -540,12 +539,12 @@ export function exportStore(
try {
statusUpdate && statusUpdate('Preparing to export Flipper data...');
const {exportData, errorArray} = await getStoreExport(
store,
state,
statusUpdate,
idler,
);
if (exportData != null) {
exportData.supportRequestDetails = store.getState().supportForm?.supportFormV2;
exportData.supportRequestDetails = state.supportForm?.supportFormV2;
statusUpdate && statusUpdate('Serializing Flipper data...');
const serializedString = JSON.stringify(exportData);
if (serializedString.length <= 0) {
@@ -555,7 +554,7 @@ export function exportStore(
EXPORT_FLIPPER_TRACE_TIME_SERIALIZATION_EVENT,
EXPORT_FLIPPER_TRACE_TIME_SERIALIZATION_EVENT,
{
plugins: store.getState().plugins.selectedPlugins,
plugins: state.plugins.selectedPlugins,
},
);
resolve({serializedString, errorArray});
@@ -575,7 +574,7 @@ export const exportStoreToFile = (
idler?: Idler,
statusUpdate?: (msg: string) => void,
): Promise<{errorArray: Array<Error>}> => {
return exportStore(store, idler, statusUpdate).then(
return exportStore(store.getState(), idler, statusUpdate).then(
({serializedString, errorArray}) => {
return promisify(fs.writeFile)(exportFilePath, serializedString).then(
() => {