Migrate MainSidebar from JS to TS

Summary: Migrated MainSidebar.js to MainSidebar.tsx

Reviewed By: passy

Differential Revision: D16731621

fbshipit-source-id: 57be95bf96c63105d05562cf0175e46c7f83aafa
This commit is contained in:
Benjamin Elo
2019-08-12 05:49:44 -07:00
committed by Facebook Github Bot
parent 46b032d5ed
commit 8bbc03e138
2 changed files with 54 additions and 48 deletions

View File

@@ -10,7 +10,7 @@ import {FlexColumn, FlexRow} from 'flipper';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import WelcomeScreen from './chrome/WelcomeScreen.tsx'; import WelcomeScreen from './chrome/WelcomeScreen.tsx';
import TitleBar from './chrome/TitleBar.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 BugReporterDialog from './chrome/BugReporterDialog.tsx';
import ErrorBar from './chrome/ErrorBar.tsx'; import ErrorBar from './chrome/ErrorBar.tsx';
import ShareSheet from './chrome/ShareSheet.js'; import ShareSheet from './chrome/ShareSheet.js';

View File

@@ -5,17 +5,16 @@
* @format * @format
*/ */
import {FlipperBasePlugin} from '../plugin.tsx'; import config from '../fb-stubs/config';
import config from '../fb-stubs/config.tsx'; import BaseDevice from '../devices/BaseDevice';
import type BaseDevice from '../devices/BaseDevice.tsx'; import Client from '../Client';
import type Client from '../Client.tsx'; import {UninitializedClient} from '../UninitializedClient';
import type {UninitializedClient} from '../UninitializedClient.tsx'; import {FlipperBasePlugin} from '../plugin';
import type {PluginNotification} from '../reducers/notifications.tsx'; import {PluginNotification} from '../reducers/notifications';
import type {ActiveSheet} from '../reducers/application.tsx'; import {ActiveSheet} from '../reducers/application';
import {State as Store} from '../reducers';
import { import {
PureComponent,
Component,
Sidebar, Sidebar,
FlexBox, FlexBox,
colors, colors,
@@ -29,11 +28,11 @@ import {
FlipperDevicePlugin, FlipperDevicePlugin,
LoadingIndicator, LoadingIndicator,
} from 'flipper'; } from 'flipper';
import React from 'react'; import React, {Component, PureComponent} from 'react';
import NotificationsHub from '../NotificationsHub.js'; import NotificationsHub from '../NotificationsHub.js';
import {selectPlugin} from '../reducers/connections.tsx'; import {selectPlugin} from '../reducers/connections';
import {setActiveSheet} from '../reducers/application.tsx'; import {setActiveSheet} from '../reducers/application';
import UserAccount from './UserAccount.tsx'; import UserAccount from './UserAccount';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
const ListItem = styled('div')(({active}) => ({ const ListItem = styled('div')(({active}) => ({
@@ -123,10 +122,10 @@ function PluginIcon({
name, name,
color, color,
}: { }: {
isActive: boolean, isActive: boolean;
backgroundColor?: string, backgroundColor?: string;
name: string, name: string;
color: string, color: string;
}) { }) {
return ( return (
<PluginShape backgroundColor={backgroundColor}> <PluginShape backgroundColor={backgroundColor}>
@@ -136,10 +135,10 @@ function PluginIcon({
} }
class PluginSidebarListItem extends Component<{ class PluginSidebarListItem extends Component<{
onClick: () => void, onClick: () => void;
isActive: boolean, isActive: boolean;
plugin: Class<FlipperBasePlugin<>>, plugin: typeof FlipperBasePlugin;
app?: ?string, app?: string | null | undefined;
}> { }> {
render() { render() {
const {isActive, plugin} = this.props; const {isActive, plugin} = this.props;
@@ -189,29 +188,36 @@ function centerInSidebar(component) {
}); });
} }
type MainSidebarProps = {| type OwnProps = {};
selectedPlugin: ?string,
selectedApp: ?string,
selectedDevice: ?BaseDevice,
windowIsFocused: boolean,
selectPlugin: (payload: {|
selectedPlugin: ?string,
selectedApp: ?string,
deepLinkPayload: ?string,
|}) => void,
clients: Array<Client>,
uninitializedClients: Array<{
client: UninitializedClient,
deviceId?: string,
errorMessage?: string,
}>,
numNotifications: number,
devicePlugins: Map<string, Class<FlipperDevicePlugin<>>>,
clientPlugins: Map<string, Class<FlipperPlugin<>>>,
setActiveSheet: (activeSheet: ActiveSheet) => void,
|};
class MainSidebar extends PureComponent<MainSidebarProps> { type StateFromProps = {
numNotifications: number;
windowIsFocused: boolean;
selectedDevice: BaseDevice | null | undefined;
selectedPlugin: string | null | undefined;
selectedApp: string | null | undefined;
clients: Array<Client>;
uninitializedClients: Array<{
client: UninitializedClient;
deviceId?: string;
errorMessage?: string;
}>;
devicePlugins: Map<string, typeof FlipperDevicePlugin>;
clientPlugins: Map<string, typeof FlipperPlugin>;
};
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<Props> {
render() { render() {
const { const {
selectedDevice, selectedDevice,
@@ -273,7 +279,7 @@ class MainSidebar extends PureComponent<MainSidebarProps> {
Array.from(this.props.devicePlugins.values()) Array.from(this.props.devicePlugins.values())
.filter(plugin => plugin.supportsDevice(selectedDevice)) .filter(plugin => plugin.supportsDevice(selectedDevice))
.sort(byPluginNameOrId) .sort(byPluginNameOrId)
.map((plugin: Class<FlipperDevicePlugin<>>) => ( .map((plugin: typeof FlipperDevicePlugin) => (
<PluginSidebarListItem <PluginSidebarListItem
key={plugin.id} key={plugin.id}
isActive={plugin.id === selectedPlugin} isActive={plugin.id === selectedPlugin}
@@ -301,11 +307,11 @@ class MainSidebar extends PureComponent<MainSidebarProps> {
<SidebarHeader>{client.query.app}</SidebarHeader> <SidebarHeader>{client.query.app}</SidebarHeader>
{Array.from(this.props.clientPlugins.values()) {Array.from(this.props.clientPlugins.values())
.filter( .filter(
(p: Class<FlipperPlugin<>>) => (p: typeof FlipperDevicePlugin) =>
client.plugins.indexOf(p.id) > -1, client.plugins.indexOf(p.id) > -1,
) )
.sort(byPluginNameOrId) .sort(byPluginNameOrId)
.map((plugin: Class<FlipperPlugin<>>) => ( .map((plugin: typeof FlipperDevicePlugin) => (
<PluginSidebarListItem <PluginSidebarListItem
key={plugin.id} key={plugin.id}
isActive={ isActive={
@@ -352,7 +358,7 @@ class MainSidebar extends PureComponent<MainSidebarProps> {
} }
} }
export default connect<MainSidebarProps, {||}, _, _, _, _>( export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
({ ({
application: {windowIsFocused}, application: {windowIsFocused},
connections: { connections: {