From 966d748aceb2f50e47ab74cf9b29bbaa283856eb Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Thu, 22 Oct 2020 09:37:26 -0700 Subject: [PATCH] Some fixes in rendering legacy plugins Summary: Some exploratory testing on all iOS and Android plugins, to see how they behave inside Sandy, and fixed some layout glitches (some were also present without Sandy) General fixes: * Introduced some niceties like searchbox resizing properly, and toolbars wrapping automatically in Sandy, rather than buttons becoming invisible * Containers don't grow anymore by default, but take size of contents * ScrollContainer child is now a Layout.Vertical. Layout.Vertical should be used as default container everywhere (e.g. Tabs, Panels) in the future * Fixed layout issue if a split container had only 1 visible child * DetailsSidebar now scrolls vertically by default * Details sidebar would sometimes render content in-place rather than in the reserved area * AppSelector dropdown and Plugin list will now properly ellipse (...) if there is not enough space Plugin fixes: * Long database / table names in Database plugin would break layout Also fixes https://github.com/facebook/flipper/issues/1611 Reviewed By: passy Differential Revision: D24454188 fbshipit-source-id: c60c867270900a1d4f28587d47067c6ec1072ede --- desktop/app/src/PluginContainer.tsx | 3 +- desktop/app/src/chrome/DetailSidebar.tsx | 36 +++++++-- .../PluginInstaller.node.tsx.snap | 8 +- desktop/app/src/reducers/connections.tsx | 4 +- .../app/src/sandy-chrome/ContentContainer.tsx | 1 + desktop/app/src/sandy-chrome/LeftSidebar.tsx | 4 +- .../sandy-chrome/appinspect/AppSelector.tsx | 18 ++++- .../sandy-chrome/appinspect/PluginList.tsx | 4 + desktop/app/src/ui/components/Layout.tsx | 76 ++++++++++--------- desktop/app/src/ui/components/Panel.tsx | 9 ++- desktop/app/src/ui/components/Select.tsx | 16 +++- desktop/app/src/ui/components/Tabs.tsx | 1 + desktop/app/src/ui/components/Toolbar.tsx | 10 ++- .../ui/components/searchable/Searchable.tsx | 15 ++-- desktop/plugins/databases/index.tsx | 2 + desktop/plugins/network/index.tsx | 20 ++--- desktop/static/icons.json | 7 ++ 17 files changed, 155 insertions(+), 79 deletions(-) diff --git a/desktop/app/src/PluginContainer.tsx b/desktop/app/src/PluginContainer.tsx index a43efbb6b..ca7f7a6bc 100644 --- a/desktop/app/src/PluginContainer.tsx +++ b/desktop/app/src/PluginContainer.tsx @@ -49,6 +49,7 @@ import {ToggleButton, SmallText, Layout} from './ui'; import {SandyPluginRenderer} from 'flipper-plugin'; import {isDevicePluginDefinition} from './utils/pluginUtils'; import ArchivedDevice from './devices/ArchivedDevice'; +import {ContentContainer} from './sandy-chrome/ContentContainer'; const Container = styled(FlexColumn)({ width: 0, @@ -436,7 +437,7 @@ class PluginContainer extends PureComponent { heading={`Plugin "${ activePlugin.title || 'Unknown' }" encountered an error during render`}> - {pluginElement} + {pluginElement} diff --git a/desktop/app/src/chrome/DetailSidebar.tsx b/desktop/app/src/chrome/DetailSidebar.tsx index 83701c30e..9960db5f4 100644 --- a/desktop/app/src/chrome/DetailSidebar.tsx +++ b/desktop/app/src/chrome/DetailSidebar.tsx @@ -7,14 +7,14 @@ * @format */ -import React, {useEffect, useMemo, useContext} from 'react'; +import React, {useEffect, useState} from 'react'; import ReactDOM from 'react-dom'; -import {ReactReduxContext} from 'react-redux'; import Sidebar from '../ui/components/Sidebar'; import {toggleRightSidebarAvailable} from '../reducers/application'; import {useDispatch, useStore} from '../utils/useStore'; import {useIsSandy} from '../sandy-chrome/SandyContext'; import {ContentContainer} from '../sandy-chrome/ContentContainer'; +import {Layout} from '../ui'; type OwnProps = { children: any; @@ -24,12 +24,13 @@ type OwnProps = { /* eslint-disable react-hooks/rules-of-hooks */ export default function DetailSidebar({children, width, minWidth}: OwnProps) { - const reduxContext = useContext(ReactReduxContext); - const domNode = useMemo(() => document.getElementById('detailsSidebar'), []); + const [domNode, setDomNode] = useState( + document.getElementById('detailsSidebar'), + ); - if (!reduxContext || !domNode) { + if (typeof jest !== 'undefined') { // For unit tests, make sure to render elements inline - return
{children}
; + return
{children}
; } const isSandy = useIsSandy(); @@ -49,6 +50,19 @@ export default function DetailSidebar({children, width, minWidth}: OwnProps) { [children, rightSidebarAvailable, dispatch], ); + // If the plugin container is mounting and rendering a sidbar immediately, the domNode might not yet be available + useEffect(() => { + if (!domNode) { + const newDomNode = document.getElementById('detailsSidebar'); + if (!newDomNode) { + // if after layouting domNode is still not available, something is wrong... + console.error('Failed to obtain detailsSidebar node'); + } else { + setDomNode(newDomNode); + } + } + }, [domNode]); + return ( (children && rightSidebarVisible && @@ -59,7 +73,15 @@ export default function DetailSidebar({children, width, minWidth}: OwnProps) { width={width || 300} position="right" gutter={isSandy}> - {isSandy ? {children} : children} + {isSandy ? ( + + + {children} + + + ) : ( + children + )} , domNode, )) || diff --git a/desktop/app/src/chrome/plugin-manager/__tests__/__snapshots__/PluginInstaller.node.tsx.snap b/desktop/app/src/chrome/plugin-manager/__tests__/__snapshots__/PluginInstaller.node.tsx.snap index 8886f7cb4..36cefb7c8 100644 --- a/desktop/app/src/chrome/plugin-manager/__tests__/__snapshots__/PluginInstaller.node.tsx.snap +++ b/desktop/app/src/chrome/plugin-manager/__tests__/__snapshots__/PluginInstaller.node.tsx.snap @@ -9,10 +9,10 @@ exports[`load PluginInstaller list 1`] = ` class="css-1qqef1i-View-FlexBox-FlexRow-ToolbarContainer e13mj6h80" >