Summary: _typescript_

Reviewed By: priteshrnandgaonkar

Differential Revision: D16828108

fbshipit-source-id: ca04853242b2f6511ecf28250add78bbbf79ba05
This commit is contained in:
Daniel Büchele
2019-08-20 03:18:32 -07:00
committed by Facebook Github Bot
parent 6e19315e48
commit c1b718db8f
3 changed files with 39 additions and 42 deletions

View File

@@ -4,52 +4,50 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
* @format * @format
*/ */
import {Component} from 'react'; import React, {Component} from 'react';
import { import CodeBlock from './CodeBlock';
CodeBlock, import {colors} from './colors';
colors, import ManagedTable from './table/ManagedTable';
ManagedTable, import FlexColumn from './FlexColumn';
FlexColumn, import Text from './Text';
Text, import ManagedDataInspector from './data-inspector/ManagedDataInspector';
ManagedDataInspector, import Input from './Input';
Input, import View from './View';
View, import styled from 'react-emotion';
} from '../index'; import {TableBodyRow, TableRows} from './table/types';
import styled from '../styled/index'; import {PluginClient} from '../../plugin';
import type {TableBodyRow, TableRows} from 'flipper';
import type {PluginClient} from '../../plugin.tsx';
type ValueWithType = {| type ValueWithType = {
type: string, type: string;
value: any, value: any;
|}; };
type SuccessResult = {| type SuccessResult = {
isSuccess: true, isSuccess: true;
value: ValueWithType, value: ValueWithType;
|}; };
type FailedResult = {| type FailedResult = {
isSuccess: false, isSuccess: false;
error: string, error: string;
|}; };
type CommandResult = SuccessResult | FailedResult; type CommandResult = SuccessResult | FailedResult;
type Props = { type Props = {
client: PluginClient, client: PluginClient;
getContext: () => string, getContext: () => string;
}; };
type State = { type State = {
isConsoleEnabled: boolean, isConsoleEnabled: boolean;
script: string, script: string;
previousExecutions: Array<{ previousExecutions: Array<{
command: string, command: string;
result: CommandResult, result: CommandResult;
}>, }>;
}; };
class ConsoleError extends Component<{ class ConsoleError extends Component<{
error: Error | string | void, error: Error | string | void;
className?: string, className?: string;
}> { }> {
static Container = styled(CodeBlock)({ static Container = styled(CodeBlock)({
backgroundColor: colors.redTint, backgroundColor: colors.redTint,
@@ -62,10 +60,9 @@ class ConsoleError extends Component<{
render() { render() {
const {className, error} = this.props; const {className, error} = this.props;
return ( return (
<ConsoleError.Container className={className}> <ConsoleError.Container className={className}>
{error} {(error || '').toString()}
</ConsoleError.Container> </ConsoleError.Container>
); );
} }
@@ -133,11 +130,11 @@ export class Console extends Component<Props, State> {
}); });
}; };
onInputChange = (event: SyntheticInputEvent<>) => { onInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
this.setState({script: event.target.value}); this.setState({script: event.target.value});
}; };
onSubmit = (event: SyntheticEvent<>) => { onSubmit = (event: React.FormEvent) => {
if (this.state.script != '') { if (this.state.script != '') {
this.executeScriptOnDevice(); this.executeScriptOnDevice();
} }
@@ -166,7 +163,7 @@ export class Console extends Component<Props, State> {
collapsed={true} collapsed={true}
/> />
) : ( ) : (
<ConsoleError error={result.error} /> <ConsoleError error={(result as FailedResult).error} />
), ),
}, },
}, },

View File

@@ -12,7 +12,7 @@ import type {Logger} from '../../../fb-interfaces/Logger.js';
import Panel from '../Panel.js'; import Panel from '../Panel.js';
import ManagedDataInspector from '../data-inspector/ManagedDataInspector.js'; import ManagedDataInspector from '../data-inspector/ManagedDataInspector.js';
import {Component} from 'react'; import {Component} from 'react';
import {Console} from '../console'; import {Console} from '../console.tsx';
import GK from '../../../fb-stubs/GK.tsx'; import GK from '../../../fb-stubs/GK.tsx';
const deepEqual = require('deep-equal'); const deepEqual = require('deep-equal');

View File

@@ -180,6 +180,6 @@ export {
} from './components/elements-inspector/ElementsInspector.js'; } from './components/elements-inspector/ElementsInspector.js';
export {InspectorSidebar} from './components/elements-inspector/sidebar.js'; export {InspectorSidebar} from './components/elements-inspector/sidebar.js';
export {Console} from './components/console.js'; export {Console} from './components/console.tsx';
export {default as Sheet} from './components/Sheet.js'; export {default as Sheet} from './components/Sheet.js';