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
This commit is contained in:
Lorenzo Blasa
2023-08-01 06:59:08 -07:00
committed by Facebook GitHub Bot
parent 1394a41599
commit 2b56289490

View File

@@ -8,7 +8,7 @@
*/ */
import {Layout, Panel} from '../ui'; import {Layout, Panel} from '../ui';
import React, {CSSProperties, useState} from 'react'; import React, {CSSProperties, useCallback, useState} from 'react';
import { import {
createDataSource, createDataSource,
DataFormatter, DataFormatter,
@@ -135,27 +135,32 @@ const Placeholder = styled(Layout.Container)({
fontSize: 18, fontSize: 18,
}); });
function isShellCommand(
entry: ConnectionRecordEntry,
): entry is CommandRecordEntry {
return 'cmd' in entry;
}
function Sidebar({selection}: {selection: undefined | ConnectionRecordEntry}) { function Sidebar({selection}: {selection: undefined | ConnectionRecordEntry}) {
const content: JSX.Element[] = []; const content: JSX.Element[] = [];
if (selection) { if (selection) {
if ('cmd' in selection) { if (isShellCommand(selection)) {
const cmd = selection as CommandRecordEntry;
content.push( content.push(
<Panel key="cmd" heading="CMD"> <Panel key="cmd" heading="CMD">
{cmd.cmd} {selection.cmd}
</Panel>, </Panel>,
<Panel key="description" heading="Description"> <Panel key="description" heading="Description">
{cmd.description} {selection.description}
</Panel>, </Panel>,
<Panel key="stdout" heading="STDOUT"> <Panel key="stdout" heading="STDOUT">
{cmd.stdout} {selection.stdout}
</Panel>, </Panel>,
<Panel key="stderr" heading="STDERR"> <Panel key="stderr" heading="STDERR">
{cmd.stderr} {selection.stderr}
</Panel>, </Panel>,
<Panel key="troubleshoot" heading="Troubleshooting Tips"> <Panel key="troubleshoot" heading="Troubleshooting Tips">
{cmd.troubleshoot} {selection.troubleshoot}
</Panel>, </Panel>,
); );
} }
@@ -195,17 +200,28 @@ export const ConnectivityLogs = () => {
</Button> </Button>
); );
const onSelection = useCallback(
(entry: ConnectionRecordEntry) => {
if (isShellCommand(entry)) {
setSelection(entry);
} else {
setSelection(undefined);
}
},
[setSelection],
);
return ( return (
<Layout.Right resizable width={400}> <Layout.Right resizable width={selection ? 400 : 0}>
<DataTable<ConnectionRecordEntry> <DataTable<ConnectionRecordEntry>
dataSource={rows} dataSource={rows}
columns={columns} columns={columns}
enableAutoScroll enableAutoScroll
onRowStyle={getRowStyle} onRowStyle={getRowStyle}
onSelect={setSelection} onSelect={onSelection}
extraActions={clearButton} extraActions={clearButton}
/> />
<Sidebar selection={selection} /> {selection && <Sidebar selection={selection} />}
</Layout.Right> </Layout.Right>
); );
}; };