From 2b56289490d68aa6d9d366e1d3cfacfd55bb2872 Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Tue, 1 Aug 2023 06:59:08 -0700 Subject: [PATCH] Sidebar only visible when necessary Summary: Sidebar should only show if the entry requires one. In this case, only shell commands have details to be displayed in the sidebar. Reviewed By: antonk52 Differential Revision: D47952535 fbshipit-source-id: ae657032504dbb80900a534d2d357c9316b67cd9 --- .../src/chrome/ConnectivityLogs.tsx | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/desktop/flipper-ui-core/src/chrome/ConnectivityLogs.tsx b/desktop/flipper-ui-core/src/chrome/ConnectivityLogs.tsx index b27d7ce3f..fc93f82e0 100644 --- a/desktop/flipper-ui-core/src/chrome/ConnectivityLogs.tsx +++ b/desktop/flipper-ui-core/src/chrome/ConnectivityLogs.tsx @@ -8,7 +8,7 @@ */ import {Layout, Panel} from '../ui'; -import React, {CSSProperties, useState} from 'react'; +import React, {CSSProperties, useCallback, useState} from 'react'; import { createDataSource, DataFormatter, @@ -135,27 +135,32 @@ const Placeholder = styled(Layout.Container)({ fontSize: 18, }); +function isShellCommand( + entry: ConnectionRecordEntry, +): entry is CommandRecordEntry { + return 'cmd' in entry; +} + function Sidebar({selection}: {selection: undefined | ConnectionRecordEntry}) { const content: JSX.Element[] = []; if (selection) { - if ('cmd' in selection) { - const cmd = selection as CommandRecordEntry; + if (isShellCommand(selection)) { content.push( - {cmd.cmd} + {selection.cmd} , - {cmd.description} + {selection.description} , - {cmd.stdout} + {selection.stdout} , - {cmd.stderr} + {selection.stderr} , - {cmd.troubleshoot} + {selection.troubleshoot} , ); } @@ -195,17 +200,28 @@ export const ConnectivityLogs = () => { ); + const onSelection = useCallback( + (entry: ConnectionRecordEntry) => { + if (isShellCommand(entry)) { + setSelection(entry); + } else { + setSelection(undefined); + } + }, + [setSelection], + ); + return ( - + dataSource={rows} columns={columns} enableAutoScroll onRowStyle={getRowStyle} - onSelect={setSelection} + onSelect={onSelection} extraActions={clearButton} /> - + {selection && } ); };