Network Plugin - Disable routes (#1969)
Summary: Mock routes may contain quite a bit of data for header values and response bodies. Currently, to turn off a mock a user must delete the mock and then go through the process of creating it when needed again. This change will allow a user to temporarily disable a mock without deleting it. A checkbox on the Routes list is used to enable/disable mocks. As shown in this screenshot:  ## Changelog Network Plugin - disable/enable mock routes Pull Request resolved: https://github.com/facebook/flipper/pull/1969 Test Plan: Create mocks using sample app Verify that mocks are working as expected Disable the mocks Verify that the client has been updated with mocks (minus the disabled ones) user Flipper Messages plugin Use the sample app to send the disabled requests again and verify that they are not mocked Reviewed By: mweststrate Differential Revision: D26888815 Pulled By: passy fbshipit-source-id: cb8a05a27dd69ba4d2b60085a077efe795a99a7c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c82313b161
commit
d07b74eed0
@@ -127,6 +127,7 @@ export interface NetworkRouteManager {
|
||||
addRoute(): string | null;
|
||||
modifyRoute(id: string, routeChange: Partial<Route>): void;
|
||||
removeRoute(id: string): void;
|
||||
enableRoute(id: string): void;
|
||||
copyHighlightedCalls(
|
||||
highlightedRows: Set<string>,
|
||||
requests: {[id: string]: Request},
|
||||
@@ -142,6 +143,7 @@ const nullNetworkRouteManager: NetworkRouteManager = {
|
||||
},
|
||||
modifyRoute(_id: string, _routeChange: Partial<Route>) {},
|
||||
removeRoute(_id: string) {},
|
||||
enableRoute(_id: string) {},
|
||||
copyHighlightedCalls(
|
||||
_highlightedRows: Set<string>,
|
||||
_requests: {[id: string]: Request},
|
||||
@@ -348,6 +350,7 @@ export function plugin(client: PluginClient<Events, Methods>) {
|
||||
responseData: '',
|
||||
responseHeaders: {},
|
||||
responseStatus: '200',
|
||||
enabled: true,
|
||||
};
|
||||
});
|
||||
nextRouteId.set(newNextRouteId + 1);
|
||||
@@ -370,6 +373,14 @@ export function plugin(client: PluginClient<Events, Methods>) {
|
||||
}
|
||||
informClientMockChange(routes.get());
|
||||
},
|
||||
enableRoute(id: string) {
|
||||
if (routes.get().hasOwnProperty(id)) {
|
||||
routes.update((draft) => {
|
||||
draft[id].enabled = !draft[id].enabled;
|
||||
});
|
||||
}
|
||||
informClientMockChange(routes.get());
|
||||
},
|
||||
copyHighlightedCalls(
|
||||
highlightedRows: Set<string> | null | undefined,
|
||||
requests: {[id: string]: Request},
|
||||
@@ -396,6 +407,7 @@ export function plugin(client: PluginClient<Events, Methods>) {
|
||||
responseData: responseData as string,
|
||||
responseHeaders: headers,
|
||||
responseStatus: responses[row].status.toString(),
|
||||
enabled: true,
|
||||
};
|
||||
});
|
||||
nextRouteId.set(newNextRouteId + 1);
|
||||
@@ -427,6 +439,7 @@ export function plugin(client: PluginClient<Events, Methods>) {
|
||||
responseData: importedRoute.responseData as string,
|
||||
responseHeaders: importedRoute.responseHeaders,
|
||||
responseStatus: importedRoute.responseStatus,
|
||||
enabled: true,
|
||||
};
|
||||
});
|
||||
nextRouteId.set(newNextRouteId + 1);
|
||||
@@ -541,13 +554,16 @@ export function plugin(client: PluginClient<Events, Methods>) {
|
||||
|
||||
try {
|
||||
await client.send('mockResponses', {
|
||||
routes: routesValuesArray.map((route: Route) => ({
|
||||
requestUrl: route.requestUrl,
|
||||
method: route.requestMethod,
|
||||
data: route.responseData,
|
||||
headers: [...Object.values(route.responseHeaders)],
|
||||
status: route.responseStatus,
|
||||
})),
|
||||
routes: routesValuesArray
|
||||
.filter((e) => e.enabled)
|
||||
.map((route: Route) => ({
|
||||
requestUrl: route.requestUrl,
|
||||
method: route.requestMethod,
|
||||
data: route.responseData,
|
||||
headers: [...Object.values(route.responseHeaders)],
|
||||
status: route.responseStatus,
|
||||
enabled: route.enabled,
|
||||
})),
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Failed to mock responses.', e);
|
||||
|
||||
Reference in New Issue
Block a user