Convert Flipper plugin "Sandbox" to TypeScript

Summary: As title

Reviewed By: jknoxville

Differential Revision: D18573661

fbshipit-source-id: 2e26e9feee60543df6155046c52e5a03fa233286
This commit is contained in:
Stephen Tseng
2019-11-21 02:57:51 -08:00
committed by Facebook Github Bot
parent 735a586c37
commit d07993ea6b
2 changed files with 18 additions and 21 deletions

View File

@@ -10,17 +10,18 @@
import {FlipperPlugin} from 'flipper'; import {FlipperPlugin} from 'flipper';
import {FlexColumn} from 'flipper'; import {FlexColumn} from 'flipper';
import {ButtonGroup, Button, styled, colors} from 'flipper'; import {ButtonGroup, Button, styled, colors} from 'flipper';
import React, {ChangeEvent} from 'react';
export type Sandbox = { export type Sandbox = {
name: string, name: string;
value: string, value: string;
}; };
type SandboxState = {| type SandboxState = {
sandboxes: Array<Sandbox>, sandboxes: Array<Sandbox>;
customSandbox: string, customSandbox: string;
showFeedback: boolean, showFeedback: boolean;
|}; };
const BigButton = styled(Button)({ const BigButton = styled(Button)({
flexGrow: 1, flexGrow: 1,
@@ -33,8 +34,12 @@ const ButtonContainer = styled(FlexColumn)({
padding: 20, padding: 20,
}); });
export default class SandboxView extends FlipperPlugin<SandboxState> { export default class SandboxView extends FlipperPlugin<
state = { SandboxState,
any,
unknown
> {
state: SandboxState = {
sandboxes: [], sandboxes: [],
customSandbox: '', customSandbox: '',
showFeedback: false, showFeedback: false,
@@ -66,14 +71,6 @@ export default class SandboxView extends FlipperPlugin<SandboxState> {
marginLeft: 15, marginLeft: 15,
}); });
reducers = {
UpdateSandboxes(state: SandboxState, results: Object) {
return {
sandboxes: results.results,
};
},
};
init() { init() {
this.client.call('getSandbox', {}).then((results: Array<Sandbox>) => { this.client.call('getSandbox', {}).then((results: Array<Sandbox>) => {
this.dispatchAction({results, type: 'UpdateSandboxes'}); this.dispatchAction({results, type: 'UpdateSandboxes'});
@@ -85,7 +82,7 @@ export default class SandboxView extends FlipperPlugin<SandboxState> {
.call('setSandbox', { .call('setSandbox', {
sandbox: sandbox, sandbox: sandbox,
}) })
.then((result: Object) => { .then((result: {result: boolean}) => {
setTimeout(() => { setTimeout(() => {
this.setState({showFeedback: false}); this.setState({showFeedback: false});
}, 3000); }, 3000);
@@ -93,7 +90,7 @@ export default class SandboxView extends FlipperPlugin<SandboxState> {
}); });
}; };
onChangeSandbox = (e: SyntheticInputEvent<>) => { onChangeSandbox = (e: ChangeEvent<HTMLInputElement>) => {
this.setState({customSandbox: e.target.value}); this.setState({customSandbox: e.target.value});
}; };
@@ -101,7 +98,7 @@ export default class SandboxView extends FlipperPlugin<SandboxState> {
return ( return (
<FlexColumn> <FlexColumn>
<SandboxView.TextInputLayout> <SandboxView.TextInputLayout>
<ButtonGroup flexgrow={true}> <ButtonGroup>
<SandboxView.TextInput <SandboxView.TextInput
type="text" type="text"
placeholder="Sandbox URL (e.g. unixname.sb.facebook.com)" placeholder="Sandbox URL (e.g. unixname.sb.facebook.com)"

View File

@@ -2,7 +2,7 @@
"name": "Sandbox", "name": "Sandbox",
"title": "Sandbox", "title": "Sandbox",
"version": "1.0.0", "version": "1.0.0",
"main": "index.js", "main": "index.tsx",
"license": "MIT", "license": "MIT",
"keywords": ["flipper-plugin"], "keywords": ["flipper-plugin"],
"icon": "translate", "icon": "translate",