Network plugin - support mocks in imported devices (#2040)

Summary:
It is not currently possible to create mock routes from imported network logs.  This PR will provide that functionality.

See this issue for more details: https://github.com/facebook/flipper/issues/1988

## Changelog

Network plugin - create mocks from imported network logs

Pull Request resolved: https://github.com/facebook/flipper/pull/2040

Test Plan:
Use sample app to create network activity
Export network activity
Import network activity
Create mocks from imported network activity
Verify that mocks work using sample app

Reviewed By: mweststrate

Differential Revision: D26947187

Pulled By: passy

fbshipit-source-id: 5e4e0197c49bb7a8227a70e574613381815e6d30
This commit is contained in:
bizzguy
2021-03-11 03:05:43 -08:00
committed by Facebook GitHub Bot
parent 07defebb22
commit f61b5a1a86

View File

@@ -44,7 +44,13 @@ import {clipboard} from 'electron';
import {URL} from 'url';
import {MockResponseDialog} from './MockResponseDialog';
import {combineBase64Chunks} from './chunks';
import {PluginClient, createState, usePlugin, useValue} from 'flipper-plugin';
import {
PluginClient,
Device,
createState,
usePlugin,
useValue,
} from 'flipper-plugin';
import {remote, OpenDialogOptions} from 'electron';
import fs from 'fs';
import electron from 'electron';
@@ -325,8 +331,16 @@ export function plugin(client: PluginClient<Events, Methods>) {
});
}
function supportsMocks(device: Device): Promise<boolean> {
if (device.isArchived) {
return Promise.resolve(true);
} else {
return client.supportsMethod('mockResponses');
}
}
function init() {
client.supportsMethod('mockResponses').then((result) => {
supportsMocks(client.device).then((result) => {
const newRoutes = JSON.parse(
localStorage.getItem(LOCALSTORAGE_MOCK_ROUTE_LIST_KEY + client.appId) ||
'{}',
@@ -552,6 +566,7 @@ export function plugin(client: PluginClient<Events, Methods>) {
JSON.stringify(routesValuesArray),
);
if (!client.device.isArchived) {
try {
await client.send('mockResponses', {
routes: routesValuesArray
@@ -570,6 +585,7 @@ export function plugin(client: PluginClient<Events, Methods>) {
}
}
}
}
return {
selectedIds,