From aea04dd0cfccb08a88f0329f8625ae046b169efd Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Thu, 24 Sep 2020 05:56:14 -0700 Subject: [PATCH] Add Flipper logs to leftrail Summary: This adds support for flipper logs in Sandy, including some theme adjustments. Did remove storage and showing of debug messages, as I noticed it tends to crash Flipper after a while since there are so many. Also added a fixed limit of only remembering last 1000 Also converted Toolbar and button with dropdown items to Sandy. Reviewed By: cekkaewnumchai Differential Revision: D23824528 fbshipit-source-id: b89d1182d4f14682251dbb482d93c2c009ddc7a4 --- desktop/app/src/chrome/ConsoleLogs.tsx | 60 +++++++- .../ExportDataPluginSheet.node.tsx.snap | 12 +- .../ShareSheetPendingDialog.node.tsx.snap | 4 +- .../PluginInstaller.node.tsx.snap | 16 +-- desktop/app/src/sandy-chrome/LeftRail.tsx | 28 +++- desktop/app/src/sandy-chrome/SandyApp.tsx | 12 +- desktop/app/src/sandy-chrome/theme.tsx | 13 ++ desktop/app/src/ui/components/Button.tsx | 133 +++++++++++++++--- desktop/app/src/ui/components/ButtonGroup.tsx | 9 +- desktop/app/src/ui/components/Toolbar.tsx | 34 ++++- 10 files changed, 275 insertions(+), 46 deletions(-) diff --git a/desktop/app/src/chrome/ConsoleLogs.tsx b/desktop/app/src/chrome/ConsoleLogs.tsx index 70b3ab7ef..2379e3ef5 100644 --- a/desktop/app/src/chrome/ConsoleLogs.tsx +++ b/desktop/app/src/chrome/ConsoleLogs.tsx @@ -12,8 +12,13 @@ import {Button, Toolbar, ButtonGroup, Layout} from '../ui'; import React from 'react'; import {Console, Hook} from 'console-feed'; import type {Methods} from 'console-feed/lib/definitions/Methods'; +import type {Styles} from 'console-feed/lib/definitions/Styles'; import {createState, useValue} from 'flipper-plugin'; import {useLocalStorage} from '../utils/useLocalStorage'; +import {theme, useIsDarkMode} from '../sandy-chrome/theme'; +import {useIsSandy} from '../sandy-chrome/SandyContext'; + +const MAX_LOG_ITEMS = 1000; const logsAtom = createState([]); export const errorCounterAtom = createState(0); @@ -23,7 +28,12 @@ export function enableConsoleHook() { Hook( window.console, (log) => { - logsAtom.set([...logsAtom.get(), log]); + if (log.method === 'debug') { + return; // See below, skip debug messages which are generated very aggressively by Flipper + } + const newLogs = logsAtom.get().slice(-MAX_LOG_ITEMS); + newLogs.push(log); + logsAtom.set(newLogs); if (log.method === 'error' || log.method === 'assert') { errorCounterAtom.set(errorCounterAtom.get() + 1); } @@ -39,7 +49,8 @@ function clearLogs() { const allLogLevels: Methods[] = [ 'log', - 'debug', + // 'debug', We typically don't want to allow users to enable the debug logs, as they are used very intensively by flipper itself, + // making Flipper / console-feed. For debug level logging, use the Chrome devtools. 'info', 'warn', 'error', @@ -54,6 +65,8 @@ const allLogLevels: Methods[] = [ const defaultLogLevels: Methods[] = ['warn', 'error', 'table', 'assert']; export function ConsoleLogs() { + const isSandy = useIsSandy(); + const isDarkMode = useIsDarkMode(); const logs = useValue(logsAtom); const [logLevels, setLogLevels] = useLocalStorage( 'console-logs-loglevels', @@ -77,6 +90,8 @@ export function ConsoleLogs() { ); }, [logLevels, setLogLevels]); + const styles = useMemo(() => buildTheme(isSandy), [isSandy]); + return ( @@ -87,7 +102,46 @@ export function ConsoleLogs() { - + ); } + +function buildTheme(isSandy: boolean): Styles { + if (!isSandy) { + const bg = '#333'; + return { + BASE_BACKGROUND_COLOR: bg, + BASE_COLOR: 'white', + LOG_BACKGROUND: bg, + }; + } + return { + // See: https://github.com/samdenty/console-feed/blob/master/src/definitions/Styles.d.ts + BASE_BACKGROUND_COLOR: 'transparent', + BASE_COLOR: theme.textColorPrimary, + LOG_COLOR: theme.textColorPrimary, + LOG_BACKGROUND: 'transparent', + LOG_INFO_BACKGROUND: 'transparent', + LOG_COMMAND_BACKGROUND: 'transparent', + LOG_RESULT_BACKGROUND: 'transparent', + LOG_WARN_BACKGROUND: theme.warningColor, + LOG_ERROR_BACKGROUND: theme.errorColor, + LOG_INFO_COLOR: theme.textColorPrimary, + LOG_COMMAND_COLOR: theme.textColorSecondary, + LOG_RESULT_COLOR: theme.textColorSecondary, + LOG_WARN_COLOR: 'white', + LOG_ERROR_COLOR: 'white', + LOG_INFO_BORDER: theme.dividerColor, + LOG_COMMAND_BORDER: theme.dividerColor, + LOG_RESULT_BORDER: theme.dividerColor, + LOG_WARN_BORDER: theme.dividerColor, + LOG_ERROR_BORDER: theme.dividerColor, + LOG_BORDER: theme.dividerColor, + }; +} diff --git a/desktop/app/src/chrome/__tests__/__snapshots__/ExportDataPluginSheet.node.tsx.snap b/desktop/app/src/chrome/__tests__/__snapshots__/ExportDataPluginSheet.node.tsx.snap index f6e5b2d18..588bc3b33 100644 --- a/desktop/app/src/chrome/__tests__/__snapshots__/ExportDataPluginSheet.node.tsx.snap +++ b/desktop/app/src/chrome/__tests__/__snapshots__/ExportDataPluginSheet.node.tsx.snap @@ -43,7 +43,7 @@ exports[`SettingsSheet snapshot with nothing enabled 1`] = ` TestDevicePlugin