From 8bbc03e13853c87da6df8d3673feb72f3605ba29 Mon Sep 17 00:00:00 2001 From: Benjamin Elo Date: Mon, 12 Aug 2019 05:49:44 -0700 Subject: [PATCH] Migrate MainSidebar from JS to TS Summary: Migrated MainSidebar.js to MainSidebar.tsx Reviewed By: passy Differential Revision: D16731621 fbshipit-source-id: 57be95bf96c63105d05562cf0175e46c7f83aafa --- src/App.js | 2 +- .../{MainSidebar.js => MainSidebar.tsx} | 100 ++++++++++-------- 2 files changed, 54 insertions(+), 48 deletions(-) rename src/chrome/{MainSidebar.js => MainSidebar.tsx} (82%) diff --git a/src/App.js b/src/App.js index f45a0d7bf..a7c1dce98 100644 --- a/src/App.js +++ b/src/App.js @@ -10,7 +10,7 @@ import {FlexColumn, FlexRow} from 'flipper'; import {connect} from 'react-redux'; import WelcomeScreen from './chrome/WelcomeScreen.tsx'; import TitleBar from './chrome/TitleBar.tsx'; -import MainSidebar from './chrome/MainSidebar.js'; +import MainSidebar from './chrome/MainSidebar.tsx'; import BugReporterDialog from './chrome/BugReporterDialog.tsx'; import ErrorBar from './chrome/ErrorBar.tsx'; import ShareSheet from './chrome/ShareSheet.js'; diff --git a/src/chrome/MainSidebar.js b/src/chrome/MainSidebar.tsx similarity index 82% rename from src/chrome/MainSidebar.js rename to src/chrome/MainSidebar.tsx index f32d1a682..94f0b0a16 100644 --- a/src/chrome/MainSidebar.js +++ b/src/chrome/MainSidebar.tsx @@ -5,17 +5,16 @@ * @format */ -import {FlipperBasePlugin} from '../plugin.tsx'; -import config from '../fb-stubs/config.tsx'; -import type BaseDevice from '../devices/BaseDevice.tsx'; -import type Client from '../Client.tsx'; -import type {UninitializedClient} from '../UninitializedClient.tsx'; -import type {PluginNotification} from '../reducers/notifications.tsx'; -import type {ActiveSheet} from '../reducers/application.tsx'; +import config from '../fb-stubs/config'; +import BaseDevice from '../devices/BaseDevice'; +import Client from '../Client'; +import {UninitializedClient} from '../UninitializedClient'; +import {FlipperBasePlugin} from '../plugin'; +import {PluginNotification} from '../reducers/notifications'; +import {ActiveSheet} from '../reducers/application'; +import {State as Store} from '../reducers'; import { - PureComponent, - Component, Sidebar, FlexBox, colors, @@ -29,11 +28,11 @@ import { FlipperDevicePlugin, LoadingIndicator, } from 'flipper'; -import React from 'react'; +import React, {Component, PureComponent} from 'react'; import NotificationsHub from '../NotificationsHub.js'; -import {selectPlugin} from '../reducers/connections.tsx'; -import {setActiveSheet} from '../reducers/application.tsx'; -import UserAccount from './UserAccount.tsx'; +import {selectPlugin} from '../reducers/connections'; +import {setActiveSheet} from '../reducers/application'; +import UserAccount from './UserAccount'; import {connect} from 'react-redux'; const ListItem = styled('div')(({active}) => ({ @@ -123,10 +122,10 @@ function PluginIcon({ name, color, }: { - isActive: boolean, - backgroundColor?: string, - name: string, - color: string, + isActive: boolean; + backgroundColor?: string; + name: string; + color: string; }) { return ( @@ -136,10 +135,10 @@ function PluginIcon({ } class PluginSidebarListItem extends Component<{ - onClick: () => void, - isActive: boolean, - plugin: Class>, - app?: ?string, + onClick: () => void; + isActive: boolean; + plugin: typeof FlipperBasePlugin; + app?: string | null | undefined; }> { render() { const {isActive, plugin} = this.props; @@ -189,29 +188,36 @@ function centerInSidebar(component) { }); } -type MainSidebarProps = {| - selectedPlugin: ?string, - selectedApp: ?string, - selectedDevice: ?BaseDevice, - windowIsFocused: boolean, - selectPlugin: (payload: {| - selectedPlugin: ?string, - selectedApp: ?string, - deepLinkPayload: ?string, - |}) => void, - clients: Array, - uninitializedClients: Array<{ - client: UninitializedClient, - deviceId?: string, - errorMessage?: string, - }>, - numNotifications: number, - devicePlugins: Map>>, - clientPlugins: Map>>, - setActiveSheet: (activeSheet: ActiveSheet) => void, -|}; +type OwnProps = {}; -class MainSidebar extends PureComponent { +type StateFromProps = { + numNotifications: number; + windowIsFocused: boolean; + selectedDevice: BaseDevice | null | undefined; + selectedPlugin: string | null | undefined; + selectedApp: string | null | undefined; + clients: Array; + uninitializedClients: Array<{ + client: UninitializedClient; + deviceId?: string; + errorMessage?: string; + }>; + devicePlugins: Map; + clientPlugins: Map; +}; + +type DispatchFromProps = { + selectPlugin: (payload: { + selectedPlugin: string | null | undefined; + selectedApp: string | null | undefined; + deepLinkPayload: string | null | undefined; + }) => void; + + setActiveSheet: (activeSheet: ActiveSheet) => void; +}; + +type Props = OwnProps & StateFromProps & DispatchFromProps; +class MainSidebar extends PureComponent { render() { const { selectedDevice, @@ -273,7 +279,7 @@ class MainSidebar extends PureComponent { Array.from(this.props.devicePlugins.values()) .filter(plugin => plugin.supportsDevice(selectedDevice)) .sort(byPluginNameOrId) - .map((plugin: Class>) => ( + .map((plugin: typeof FlipperDevicePlugin) => ( { {client.query.app} {Array.from(this.props.clientPlugins.values()) .filter( - (p: Class>) => + (p: typeof FlipperDevicePlugin) => client.plugins.indexOf(p.id) > -1, ) .sort(byPluginNameOrId) - .map((plugin: Class>) => ( + .map((plugin: typeof FlipperDevicePlugin) => ( { } } -export default connect( +export default connect( ({ application: {windowIsFocused}, connections: {