(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
This commit is contained in:
Chaiwat Ekkaewnumchai
2020-03-17 10:05:27 -07:00
committed by Facebook GitHub Bot
parent f3eb695fa6
commit 59c821db8d

View File

@@ -9,7 +9,7 @@
import {TableHighlightedRows, TableRows, TableBodyRow} from 'flipper'; import {TableHighlightedRows, TableRows, TableBodyRow} from 'flipper';
import {padStart} from 'lodash'; import {padStart} from 'lodash';
import React from 'react'; import React, {createContext} from 'react';
import {MenuItemConstructorOptions} from 'electron'; import {MenuItemConstructorOptions} from 'electron';
import { import {
@@ -25,7 +25,7 @@ import {
SearchableTable, SearchableTable,
FlipperPlugin, FlipperPlugin,
} from 'flipper'; } from 'flipper';
import {Request, RequestId, Response} from './types'; import {Request, RequestId, Response, Route} from './types';
import {convertRequestToCurlCommand, getHeaderValue, decodeBody} from './utils'; import {convertRequestToCurlCommand, getHeaderValue, decodeBody} from './utils';
import RequestDetails from './RequestDetails'; import RequestDetails from './RequestDetails';
import {clipboard} from 'electron'; import {clipboard} from 'electron';
@@ -90,12 +90,27 @@ const TextEllipsis = styled(Text)({
paddingTop: 4, paddingTop: 4,
}); });
// State management
export interface NetworkRouteManager {
addRoute(): void;
modifyRoute(id: string, routeChange: Partial<Route>): void;
removeRoute(id: string): void;
}
const nullNetworkRouteManager: NetworkRouteManager = {
addRoute() {},
modifyRoute(_id: string, _routeChange: Partial<Route>) {},
removeRoute(_id: string) {},
};
export const NetworkRouteContext = createContext<NetworkRouteManager>(
nullNetworkRouteManager,
);
export default class extends FlipperPlugin<State, any, PersistedState> { export default class extends FlipperPlugin<State, any, PersistedState> {
static keyboardActions: Array<DefaultKeyboardAction> = ['clear']; static keyboardActions: Array<DefaultKeyboardAction> = ['clear'];
static subscribed = []; static subscribed = [];
static defaultPersistedState = { static defaultPersistedState = {
requests: new Map(), requests: {},
responses: new Map(), responses: {},
}; };
static metricsReducer(persistedState: PersistedState) { static metricsReducer(persistedState: PersistedState) {
@@ -238,18 +253,20 @@ export default class extends FlipperPlugin<State, any, PersistedState> {
return ( return (
<FlexColumn grow={true}> <FlexColumn grow={true}>
<NetworkTable <NetworkRouteContext.Provider value={nullNetworkRouteManager}>
requests={requests || {}} <NetworkTable
responses={responses || {}} requests={requests || {}}
clear={this.clearLogs} responses={responses || {}}
copyRequestCurlCommand={this.copyRequestCurlCommand} clear={this.clearLogs}
onRowHighlighted={this.onRowHighlighted} copyRequestCurlCommand={this.copyRequestCurlCommand}
highlightedRows={ onRowHighlighted={this.onRowHighlighted}
this.state.selectedIds ? new Set(this.state.selectedIds) : null highlightedRows={
} this.state.selectedIds ? new Set(this.state.selectedIds) : null
searchTerm={this.state.searchTerm} }
/> searchTerm={this.state.searchTerm}
<DetailSidebar width={500}>{this.renderSidebar()}</DetailSidebar> />
<DetailSidebar width={500}>{this.renderSidebar()}</DetailSidebar>
</NetworkRouteContext.Provider>
</FlexColumn> </FlexColumn>
); );
} }