From 9ba93ad26b6fa92be56d4604df3e12d1e85d769b Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Mon, 31 Jul 2023 07:02:16 -0700 Subject: [PATCH] Connectivity Logs moved outside from TroubleshootingHub Summary: Move it to its own space. Reviewed By: antonk52 Differential Revision: D47914495 fbshipit-source-id: 8d655a8f0fc9ed87adbb4c31dfb04e72aa6f5770 --- .../src/chrome/ConnectivityLogs.tsx | 185 ++++++++++++++++++ .../src/chrome/TroubleshootingHub.tsx | 182 +---------------- .../src/startFlipperDesktop.tsx | 2 +- 3 files changed, 190 insertions(+), 179 deletions(-) create mode 100644 desktop/flipper-ui-core/src/chrome/ConnectivityLogs.tsx diff --git a/desktop/flipper-ui-core/src/chrome/ConnectivityLogs.tsx b/desktop/flipper-ui-core/src/chrome/ConnectivityLogs.tsx new file mode 100644 index 000000000..5213eab30 --- /dev/null +++ b/desktop/flipper-ui-core/src/chrome/ConnectivityLogs.tsx @@ -0,0 +1,185 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +import {Layout} from '../ui'; +import React, {CSSProperties, useState} from 'react'; +import { + createDataSource, + DataFormatter, + DataInspector, + DataTable, + DataTableColumn, + theme, + styled, +} from 'flipper-plugin'; +import {CloseCircleFilled, DeleteOutlined} from '@ant-design/icons'; +import { + CommandRecordEntry, + ConnectionRecordEntry, + FlipperServer, +} from 'flipper-common'; +import {Button} from 'antd'; + +const rows = createDataSource([], { + limit: 200000, + persist: 'connectivity-logs', +}); + +export function enableConnectivityHook(flipperServer: FlipperServer) { + flipperServer.on( + 'connectivity-troubleshoot-log', + (entry: ConnectionRecordEntry) => { + rows.append(entry); + }, + ); + flipperServer.on( + 'connectivity-troubleshoot-cmd', + (entry: CommandRecordEntry) => { + rows.append(entry); + }, + ); +} + +const iconStyle = { + fontSize: '16px', +}; + +const baseRowStyle = { + ...theme.monospace, +}; + +const logTypes: { + [level: string]: { + label: string; + icon?: React.ReactNode; + style?: CSSProperties; + enabled: boolean; + }; +} = { + log: { + label: 'Log', + enabled: true, + }, + cmd: { + label: 'Shell', + enabled: true, + style: { + ...baseRowStyle, + color: theme.primaryColor, + }, + icon: , + }, + error: { + label: 'Error', + style: { + ...baseRowStyle, + color: theme.errorColor, + }, + icon: , + enabled: true, + }, +}; + +function createColumnConfig(): DataTableColumn[] { + return [ + { + key: 'time', + title: 'Time', + width: 160, + }, + { + key: 'device', + title: 'Device', + width: 160, + }, + { + key: 'app', + title: 'App', + width: 160, + visible: true, + }, + { + key: 'medium', + title: 'Medium', + width: 80, + visible: true, + }, + { + key: 'message', + title: 'Message', + wrap: true, + formatters: [ + DataFormatter.truncate(400), + DataFormatter.prettyPrintJson, + DataFormatter.linkify, + ], + }, + ]; +} + +const columns = createColumnConfig(); + +function getRowStyle(entry: ConnectionRecordEntry): CSSProperties | undefined { + return (logTypes[entry.type]?.style as any) ?? baseRowStyle; +} + +const Placeholder = styled(Layout.Container)({ + center: true, + color: theme.textColorPlaceholder, + fontSize: 18, +}); + +function Sidebar({selection}: {selection: undefined | ConnectionRecordEntry}) { + return ( + + {selection != null ? ( + + ) : ( + + Select an entry to visualize details + + )} + + ); +} + +function clearMessages() { + rows.clear(); +} + +export const ConnectivityLogs = () => { + const [selection, setSelection] = useState< + ConnectionRecordEntry | undefined + >(); + + const clearButton = ( + + ); + + return ( + + + dataSource={rows} + columns={columns} + enableAutoScroll + onRowStyle={getRowStyle} + onSelect={setSelection} + extraActions={clearButton} + /> + + + ); +}; diff --git a/desktop/flipper-ui-core/src/chrome/TroubleshootingHub.tsx b/desktop/flipper-ui-core/src/chrome/TroubleshootingHub.tsx index d91511f3f..8d5cec0fb 100644 --- a/desktop/flipper-ui-core/src/chrome/TroubleshootingHub.tsx +++ b/desktop/flipper-ui-core/src/chrome/TroubleshootingHub.tsx @@ -8,186 +8,12 @@ */ import {Layout} from '../ui'; -import React, {CSSProperties, useState} from 'react'; -import { - createDataSource, - DataFormatter, - DataInspector, - DataTable, - DataTableColumn, - Tab, - Tabs, - theme, - styled, -} from 'flipper-plugin'; -import {CloseCircleFilled, DeleteOutlined} from '@ant-design/icons'; -import { - CommandRecordEntry, - ConnectionRecordEntry, - FlipperServer, -} from 'flipper-common'; +import React from 'react'; +import {Tab, Tabs} from 'flipper-plugin'; import SetupDoctorScreen from '../sandy-chrome/SetupDoctorScreen'; import {ConsoleLogs} from './ConsoleLogs'; import {FlipperMessages} from './FlipperMessages'; -import {Button} from 'antd'; - -const rows = createDataSource([], { - limit: 200000, - persist: 'connectivity-logs', -}); - -export function enableConnectivityHook(flipperServer: FlipperServer) { - flipperServer.on( - 'connectivity-troubleshoot-log', - (entry: ConnectionRecordEntry) => { - rows.append(entry); - }, - ); - flipperServer.on( - 'connectivity-troubleshoot-cmd', - (entry: CommandRecordEntry) => { - rows.append(entry); - }, - ); -} - -const iconStyle = { - fontSize: '16px', -}; - -const baseRowStyle = { - ...theme.monospace, -}; - -const logTypes: { - [level: string]: { - label: string; - icon?: React.ReactNode; - style?: CSSProperties; - enabled: boolean; - }; -} = { - log: { - label: 'Log', - enabled: true, - }, - cmd: { - label: 'Shell', - enabled: true, - style: { - ...baseRowStyle, - color: theme.primaryColor, - }, - icon: , - }, - error: { - label: 'Error', - style: { - ...baseRowStyle, - color: theme.errorColor, - }, - icon: , - enabled: true, - }, -}; - -function createColumnConfig(): DataTableColumn[] { - return [ - { - key: 'time', - title: 'Time', - width: 160, - }, - { - key: 'device', - title: 'Device', - width: 160, - }, - { - key: 'app', - title: 'App', - width: 160, - visible: true, - }, - { - key: 'medium', - title: 'Medium', - width: 80, - visible: true, - }, - { - key: 'message', - title: 'Message', - wrap: true, - formatters: [ - DataFormatter.truncate(400), - DataFormatter.prettyPrintJson, - DataFormatter.linkify, - ], - }, - ]; -} - -const columns = createColumnConfig(); - -function getRowStyle(entry: ConnectionRecordEntry): CSSProperties | undefined { - return (logTypes[entry.type]?.style as any) ?? baseRowStyle; -} - -const Placeholder = styled(Layout.Container)({ - center: true, - color: theme.textColorPlaceholder, - fontSize: 18, -}); - -function Sidebar({selection}: {selection: undefined | ConnectionRecordEntry}) { - return ( - - {selection != null ? ( - - ) : ( - - Select an entry to visualize details - - )} - - ); -} - -function clearMessages() { - rows.clear(); -} - -const LogView = () => { - const [selection, setSelection] = useState< - ConnectionRecordEntry | undefined - >(); - - const clearButton = ( - - ); - - return ( - - - dataSource={rows} - columns={columns} - enableAutoScroll - onRowStyle={getRowStyle} - onSelect={setSelection} - extraActions={clearButton} - /> - - - ); -}; +import {ConnectivityLogs} from './ConnectivityLogs'; export function TroubleshootingHub() { return ( @@ -197,7 +23,7 @@ export function TroubleshootingHub() { {}} /> - + diff --git a/desktop/flipper-ui-core/src/startFlipperDesktop.tsx b/desktop/flipper-ui-core/src/startFlipperDesktop.tsx index 2ac147243..2e4a9edc3 100644 --- a/desktop/flipper-ui-core/src/startFlipperDesktop.tsx +++ b/desktop/flipper-ui-core/src/startFlipperDesktop.tsx @@ -43,7 +43,7 @@ import {getRenderHostInstance} from 'flipper-frontend-core'; import {startGlobalErrorHandling} from './utils/globalErrorHandling'; import {loadTheme} from './utils/loadTheme'; import {connectFlipperServerToStore} from './dispatcher/flipperServer'; -import {enableConnectivityHook} from './chrome/TroubleshootingHub'; +import {enableConnectivityHook} from './chrome/ConnectivityLogs'; import ReactDOM from 'react-dom'; class AppFrame extends React.Component<