diff --git a/desktop/app/src/PluginContainer.tsx b/desktop/app/src/PluginContainer.tsx index c688ed495..b38956dee 100644 --- a/desktop/app/src/PluginContainer.tsx +++ b/desktop/app/src/PluginContainer.tsx @@ -44,7 +44,7 @@ import {activateMenuItems} from './MenuBar'; import {Message} from './reducers/pluginMessageQueue'; import {IdlerImpl} from './utils/Idler'; import {processMessageQueue} from './utils/messageQueue'; -import {ToggleButton, SmallText, Layout} from './ui'; +import {Layout} from './ui'; import {theme, TrackingScope, _SandyPluginRenderer} from 'flipper-plugin'; import {isDevicePluginDefinition, isSandyPlugin} from './utils/pluginUtils'; import {ContentContainer} from './sandy-chrome/ContentContainer'; @@ -54,6 +54,7 @@ import semver from 'semver'; import {loadPlugin} from './reducers/pluginManager'; import {produce} from 'immer'; import {reportUsage} from './utils/metrics'; +import PluginInfo from './chrome/PluginInfo'; const {Text, Link} = Typography; @@ -275,7 +276,7 @@ class PluginContainer extends PureComponent { } if (!pluginIsEnabled) { - return this.renderPluginEnabler(); + return this.renderPluginInfo(); } if (!pendingMessages || pendingMessages.length === 0) { return this.renderPlugin(); @@ -283,41 +284,8 @@ class PluginContainer extends PureComponent { return this.renderPluginLoader(); } - renderPluginEnabler() { - const activePlugin = this.props.activePlugin!; - return ( - - - - - - - - - { - this.props.enablePlugin({ - plugin: activePlugin, - selectedApp: (this.props.target as Client)?.query?.app, - }); - }} - large - /> - - - Click to enable this plugin - - - - ); + renderPluginInfo() { + return ; } renderPluginLoader() { diff --git a/desktop/app/src/chrome/PluginInfo.tsx b/desktop/app/src/chrome/PluginInfo.tsx new file mode 100644 index 000000000..47da96de4 --- /dev/null +++ b/desktop/app/src/chrome/PluginInfo.tsx @@ -0,0 +1,98 @@ +/** + * Copyright (c) Facebook, Inc. and its 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 React, {useCallback, useMemo} from 'react'; +import {Label, ToggleButton, SmallText, styled, Layout} from '../ui'; +import {useDispatch, useStore} from '../utils/useStore'; +import {switchPlugin} from '../reducers/pluginManager'; +import {isPluginEnabled} from '../reducers/connections'; +import {theme} from 'flipper-plugin'; +import {PluginDefinition} from '../plugin'; + +const Waiting = styled(Layout.Container)({ + width: '100%', + height: '100%', + flexGrow: 1, + alignItems: 'center', + justifyContent: 'center', + textAlign: 'center', +}); + +export default function PluginInfo() { + const pluginId = useStore((state) => state.connections.selectedPlugin); + const enabledPlugins = useStore((state) => state.connections.enabledPlugins); + const enabledDevicePlugins = useStore( + (state) => state.connections.enabledDevicePlugins, + ); + const activeClient = useStore((state) => state.connections.activeClient); + const clientPlugins = useStore((state) => state.plugins.clientPlugins); + const devicePlugins = useStore((state) => state.plugins.devicePlugins); + const selectedClientId = activeClient?.id ?? null; + const selectedApp = activeClient?.query.app ?? null; + const disabledPlugin = useMemo( + () => + pluginId && + !isPluginEnabled( + enabledPlugins, + enabledDevicePlugins, + selectedClientId, + pluginId, + ) + ? clientPlugins.get(pluginId) ?? devicePlugins.get(pluginId) + : undefined, + [ + pluginId, + enabledPlugins, + enabledDevicePlugins, + selectedClientId, + clientPlugins, + devicePlugins, + ], + ); + return disabledPlugin ? ( + + ) : null; +} + +function PluginEnabler({ + plugin, + selectedApp, +}: { + plugin: PluginDefinition; + selectedApp: string | null; +}) { + const dispatch = useDispatch(); + const enablePlugin = useCallback(() => { + dispatch(switchPlugin({plugin, selectedApp: selectedApp ?? undefined})); + }, [dispatch, plugin, selectedApp]); + return ( + + + + + + + + + + + + Click to enable this plugin + + + + ); +}