From 59c821db8d0f43dcda9bcada3f7c8f9636968d0a Mon Sep 17 00:00:00 2001 From: Chaiwat Ekkaewnumchai Date: Tue, 17 Mar 2020 10:05:27 -0700 Subject: [PATCH] (Server) Add Context to Manipulate Route State Summary: This diff added dummy state handler for route, which appeared in the next diffs. Routes will be used to render components for mocking handler and determine data on the client side. State and other variables will appear on the next diffs. Note: - This is a part of this PR: https://github.com/facebook/flipper/pull/488 Reviewed By: mweststrate Differential Revision: D20440150 fbshipit-source-id: d441ae1d53caf7280bef78d937aaa71617e2da9f --- desktop/plugins/network/index.tsx | 49 +++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/desktop/plugins/network/index.tsx b/desktop/plugins/network/index.tsx index efe9bd0ad..8526924b5 100644 --- a/desktop/plugins/network/index.tsx +++ b/desktop/plugins/network/index.tsx @@ -9,7 +9,7 @@ import {TableHighlightedRows, TableRows, TableBodyRow} from 'flipper'; import {padStart} from 'lodash'; -import React from 'react'; +import React, {createContext} from 'react'; import {MenuItemConstructorOptions} from 'electron'; import { @@ -25,7 +25,7 @@ import { SearchableTable, FlipperPlugin, } from 'flipper'; -import {Request, RequestId, Response} from './types'; +import {Request, RequestId, Response, Route} from './types'; import {convertRequestToCurlCommand, getHeaderValue, decodeBody} from './utils'; import RequestDetails from './RequestDetails'; import {clipboard} from 'electron'; @@ -90,12 +90,27 @@ const TextEllipsis = styled(Text)({ paddingTop: 4, }); +// State management +export interface NetworkRouteManager { + addRoute(): void; + modifyRoute(id: string, routeChange: Partial): void; + removeRoute(id: string): void; +} +const nullNetworkRouteManager: NetworkRouteManager = { + addRoute() {}, + modifyRoute(_id: string, _routeChange: Partial) {}, + removeRoute(_id: string) {}, +}; +export const NetworkRouteContext = createContext( + nullNetworkRouteManager, +); + export default class extends FlipperPlugin { static keyboardActions: Array = ['clear']; static subscribed = []; static defaultPersistedState = { - requests: new Map(), - responses: new Map(), + requests: {}, + responses: {}, }; static metricsReducer(persistedState: PersistedState) { @@ -238,18 +253,20 @@ export default class extends FlipperPlugin { return ( - - {this.renderSidebar()} + + + {this.renderSidebar()} + ); }