From 76bf2f3603b2fa175b93679eaffd9dd48346e05e Mon Sep 17 00:00:00 2001 From: Chaiwat Ekkaewnumchai Date: Tue, 17 Mar 2020 10:05:27 -0700 Subject: [PATCH] (Server) Add Removing Route Button Summary: - Add a close button when hovering over the component - Remove the route corresponding to it when clicking on closing Note: - This is a part of this PR: https://github.com/facebook/flipper/pull/488 Reviewed By: mweststrate Differential Revision: D20444419 fbshipit-source-id: 5ebe112c542b033a3e10ed10f23d6a04a730c657 --- .../network/ManageMockResponsePanel.tsx | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/desktop/plugins/network/ManageMockResponsePanel.tsx b/desktop/plugins/network/ManageMockResponsePanel.tsx index 771e91e55..1d6d59c8b 100644 --- a/desktop/plugins/network/ManageMockResponsePanel.tsx +++ b/desktop/plugins/network/ManageMockResponsePanel.tsx @@ -95,17 +95,18 @@ function _duplicateIds(routes: {[id: string]: Route}): Array { function _buildRows( routes: {[id: string]: Route}, duplicatedIds: Array, + handleRemoveId: (id: string) => void, ) { return Object.entries(routes).map(([id, route]) => ({ columns: { route: { - value: duplicatedIds.includes(id) ? ( - - - {route.requestUrl} - - ) : ( - {route.requestUrl} + value: ( + handleRemoveId(id)} + /> ), }, }, @@ -113,6 +114,32 @@ function _buildRows( })); } +function RouteRow(props: { + text: string; + showWarning: boolean; + handleRemoveId: () => void; +}) { + const [showCloseButton, setShowCloseButton] = useState(false); + return ( + setShowCloseButton(true)} + onMouseLeave={() => setShowCloseButton(false)}> + + {props.showWarning && ( + + )} + {props.text} + + {showCloseButton && ( + + + + )} + + ); +} + function ManagedMockResponseRightPanel(props: { id: string; route: Route; @@ -173,7 +200,10 @@ export function ManageMockResponsePanel(props: Props) { multiline={true} columnSizes={ColumnSizes} columns={Columns} - rows={_buildRows(routes, duplicatedIds)} + rows={_buildRows(routes, duplicatedIds, id => { + networkRouteManager.removeRoute(id); + setSelectedId(null); + })} stickyBottom={true} autoHeight={false} floating={false}