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:
committed by
Facebook Github Bot
parent
bf85da17ab
commit
ca53f35875
@@ -177,7 +177,9 @@ async function exitActions(
|
||||
);
|
||||
outputAndExit(payload);
|
||||
} else {
|
||||
const {serializedString, errorArray} = await exportStore(store);
|
||||
const {serializedString, errorArray} = await exportStore(
|
||||
store.getState(),
|
||||
);
|
||||
errorArray.forEach(console.error);
|
||||
outputAndExit(serializedString);
|
||||
}
|
||||
@@ -254,7 +256,7 @@ async function startFlipper(userArguments: UserArguments) {
|
||||
errorAndExit(e);
|
||||
});
|
||||
} else {
|
||||
exportStore(store)
|
||||
exportStore(store.getState())
|
||||
.then(({serializedString}) => {
|
||||
outputAndExit(serializedString);
|
||||
})
|
||||
|
||||
@@ -118,7 +118,7 @@ export default class ShareSheetExportUrl extends Component<Props, State> {
|
||||
}
|
||||
};
|
||||
const {serializedString, errorArray} = await reportPlatformFailures(
|
||||
exportStore(store, this.idler, statusUpdate),
|
||||
exportStore(store.getState(), this.idler, statusUpdate),
|
||||
`${EXPORT_FLIPPER_TRACE_EVENT}:UI_LINK`,
|
||||
);
|
||||
const uploadMarker = `${EXPORT_FLIPPER_TRACE_EVENT}:upload`;
|
||||
|
||||
@@ -31,7 +31,7 @@ export {selectPlugin, StaticView} from './reducers/connections';
|
||||
export {writeBufferToFile, bufferToBlob} from './utils/screenshot';
|
||||
export {getPluginKey, getPersistedState} from './utils/pluginUtils';
|
||||
export {Idler} from './utils/Idler';
|
||||
export {Store, MiddlewareAPI} from './reducers/index';
|
||||
export {Store, MiddlewareAPI, State as ReduxState} from './reducers/index';
|
||||
export {default as BaseDevice} from './devices/BaseDevice';
|
||||
export {default as SidebarExtensions} from './fb-stubs/LayoutInspectorSidebarExtensions';
|
||||
export {
|
||||
|
||||
@@ -18,6 +18,7 @@ import BaseDevice from './devices/BaseDevice';
|
||||
import {serialize, deserialize} from './utils/serialization';
|
||||
import {Idler} from './utils/Idler';
|
||||
import {StaticView} from './reducers/connections';
|
||||
import {State as ReduxState} from './reducers';
|
||||
type Parameters = any;
|
||||
|
||||
// This function is intended to be called from outside of the plugin.
|
||||
@@ -103,7 +104,7 @@ export abstract class FlipperBasePlugin<
|
||||
| ((
|
||||
callClient: (method: string, params?: any) => Promise<any>,
|
||||
persistedState: StaticPersistedState | undefined,
|
||||
store: MiddlewareAPI | undefined,
|
||||
store: ReduxState | undefined,
|
||||
idler?: Idler,
|
||||
statusUpdate?: (msg: string) => void,
|
||||
) => Promise<StaticPersistedState | undefined>)
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
} from './api';
|
||||
import {Fragment} from 'react';
|
||||
import {ImagesMap} from './ImagePool';
|
||||
import {MetricType, MiddlewareAPI} from 'flipper';
|
||||
import {MetricType, ReduxState} from 'flipper';
|
||||
import React from 'react';
|
||||
import ImagesCacheOverview from './ImagesCacheOverview';
|
||||
import {
|
||||
@@ -101,7 +101,7 @@ export default class FlipperImagesPlugin extends FlipperPlugin<
|
||||
static exportPersistedState = (
|
||||
callClient: (method: string, params?: any) => Promise<any>,
|
||||
persistedState: PersistedState,
|
||||
store?: MiddlewareAPI,
|
||||
store?: ReduxState,
|
||||
): Promise<PersistedState> => {
|
||||
const defaultPromise = Promise.resolve(persistedState);
|
||||
if (!persistedState) {
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
ElementID,
|
||||
Element,
|
||||
ElementSearchResultSet,
|
||||
MiddlewareAPI,
|
||||
PluginClient,
|
||||
FlexColumn,
|
||||
FlexRow,
|
||||
@@ -27,6 +26,7 @@ import {
|
||||
colors,
|
||||
SupportRequestFormManager,
|
||||
constants,
|
||||
ReduxState,
|
||||
} from 'flipper';
|
||||
import Inspector from './Inspector';
|
||||
import ToolbarIcon from './ToolbarIcon';
|
||||
@@ -97,7 +97,7 @@ export default class Layout extends FlipperPlugin<State, any, PersistedState> {
|
||||
allNodes: PersistedState;
|
||||
}>,
|
||||
persistedState: PersistedState | undefined,
|
||||
store: MiddlewareAPI | undefined,
|
||||
store: ReduxState | undefined,
|
||||
): Promise<PersistedState | undefined> => {
|
||||
if (!store) {
|
||||
return persistedState;
|
||||
|
||||
@@ -15,7 +15,7 @@ import type {State as PluginsState} from '../../reducers/plugins.tsx';
|
||||
import type {State as PluginStatesState} from '../../reducers/pluginStates.tsx';
|
||||
import type {PluginDefinition} from '../../dispatcher/plugins.tsx';
|
||||
import {FlipperBasePlugin} from 'flipper';
|
||||
import type {MiddlewareAPI} from '../../reducers/index.tsx';
|
||||
import type {ReduxState} from '../../reducers/index.tsx';
|
||||
class MockFlipperPluginWithDefaultPersistedState extends FlipperBasePlugin<
|
||||
*,
|
||||
*,
|
||||
@@ -32,7 +32,7 @@ class MockFlipperPluginWithExportPersistedState extends FlipperBasePlugin<
|
||||
static exportPersistedState = (
|
||||
callClient: (string, ?Object) => Promise<Object>,
|
||||
persistedState: ?{msg: string},
|
||||
store: ?MiddlewareAPI,
|
||||
store: ?ReduxState,
|
||||
): Promise<?{msg: string}> => {
|
||||
return Promise.resolve({msg: 'MockFlipperPluginWithExportPersistedState'});
|
||||
};
|
||||
|
||||
@@ -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(
|
||||
() => {
|
||||
|
||||
@@ -68,7 +68,7 @@ export async function exportMetricsWithoutTrace(
|
||||
store.getState().connections.clients,
|
||||
pluginStates,
|
||||
pluginsMap,
|
||||
store,
|
||||
store.getState(),
|
||||
);
|
||||
const newPluginStates = metadata.pluginStates;
|
||||
const {errorArray} = metadata;
|
||||
|
||||
Reference in New Issue
Block a user