diff --git a/desktop/plugins/network/ManageMockResponsePanel.tsx b/desktop/plugins/network/ManageMockResponsePanel.tsx index 8f7427ce9..0174d9116 100644 --- a/desktop/plugins/network/ManageMockResponsePanel.tsx +++ b/desktop/plugins/network/ManageMockResponsePanel.tsx @@ -20,13 +20,18 @@ import { } from 'flipper'; import React, {useContext, useState, useMemo, useEffect} from 'react'; -import {Route} from './types'; +import {Route, Request, Response} from './types'; import {MockResponseDetails} from './MockResponseDetails'; import {NetworkRouteContext} from './index'; import {RequestId} from './types'; -type Props = {routes: {[id: string]: Route}}; +type Props = { + routes: {[id: string]: Route}; + highlightedRows: Set | null | undefined; + requests: {[id: string]: Request}; + responses: {[id: string]: Response}; +}; const ColumnSizes = {route: 'flex'}; @@ -35,7 +40,17 @@ const Columns = {route: {value: 'Route', resizable: false}}; const AddRouteButton = styled(FlexBox)({ color: colors.blackAlpha50, alignItems: 'center', - padding: 10, + padding: 5, + flexShrink: 0, + whiteSpace: 'nowrap', + overflow: 'hidden', + textOverflow: 'ellipsis', +}); + +const CopyHighlightedCallsButton = styled(FlexBox)({ + color: colors.blueDark, + alignItems: 'center', + padding: 5, flexShrink: 0, whiteSpace: 'nowrap', overflow: 'hidden', @@ -119,12 +134,11 @@ function RouteRow(props: { showWarning: boolean; handleRemoveId: () => void; }) { - const [showCloseButton, setShowCloseButton] = useState(false); return ( - setShowCloseButton(true)} - onMouseLeave={() => setShowCloseButton(false)}> + + + + {props.showWarning && ( @@ -137,11 +151,6 @@ function RouteRow(props: { {props.text} )} - {showCloseButton && ( - - - - )} ); } @@ -171,21 +180,20 @@ function ManagedMockResponseRightPanel(props: { export function ManageMockResponsePanel(props: Props) { const networkRouteManager = useContext(NetworkRouteContext); const [selectedId, setSelectedId] = useState(null); - const [currentRouteSize, setCurrentRouteSize] = useState(0); - const {routes} = props; useEffect(() => { - const keys = Object.keys(routes); - const routeSize = keys.length; - if (currentRouteSize === routeSize) { - return; - } - if (routeSize > 0 && routeSize > currentRouteSize) { - setSelectedId(keys[routeSize - 1]); - } - setCurrentRouteSize(routeSize); - }, [routes]); - const duplicatedIds = useMemo(() => _duplicateIds(routes), [routes]); + setSelectedId((selectedId) => { + const keys = Object.keys(props.routes); + return keys.length === 0 + ? null + : selectedId === null || !keys.includes(selectedId) + ? keys[keys.length - 1] + : selectedId; + }); + }, [props.routes]); + const duplicatedIds = useMemo(() => _duplicateIds(props.routes), [ + props.routes, + ]); return ( @@ -201,12 +209,28 @@ export function ManageMockResponsePanel(props: Props) { />  Add Route + { + networkRouteManager.copyHighlightedCalls( + props.highlightedRows as Set, + props.requests, + props.responses, + ); + }}> + +  Copy Highlighted Calls + { + rows={_buildRows(props.routes, duplicatedIds, (id) => { networkRouteManager.removeRoute(id); setSelectedId(null); })} @@ -223,10 +247,10 @@ export function ManageMockResponsePanel(props: Props) { /> - {selectedId && routes.hasOwnProperty(selectedId) && ( + {selectedId && props.routes.hasOwnProperty(selectedId) && ( )} diff --git a/desktop/plugins/network/MockResponseDialog.tsx b/desktop/plugins/network/MockResponseDialog.tsx index 243ad1013..a484c8b0d 100644 --- a/desktop/plugins/network/MockResponseDialog.tsx +++ b/desktop/plugins/network/MockResponseDialog.tsx @@ -10,12 +10,15 @@ import {FlexColumn, Button, styled} from 'flipper'; import {ManageMockResponsePanel} from './ManageMockResponsePanel'; -import {Route} from './types'; +import {Route, Request, Response} from './types'; import React from 'react'; type Props = { routes: {[id: string]: Route}; onHide: () => void; + highlightedRows: Set | null | undefined; + requests: {[id: string]: Request}; + responses: {[id: string]: Response}; }; const Title = styled('div')({ @@ -39,7 +42,12 @@ export function MockResponseDialog(props: Props) { return ( Mock Network Responses - +