Migrate DataDescription from js to tsx

Summary: As per title

Reviewed By: danielbuechele

Differential Revision: D16770503

fbshipit-source-id: f8e4fddeb84aefef469a97f65dd65f951dd55e22
This commit is contained in:
Pritesh Nandgaonkar
2019-08-20 06:18:58 -07:00
committed by Facebook Github Bot
parent d84900aa8c
commit 0c87a82804
5 changed files with 60 additions and 56 deletions

View File

@@ -96,7 +96,7 @@ export {
} from './ui/components/data-inspector/ManagedDataInspector.tsx'; } from './ui/components/data-inspector/ManagedDataInspector.tsx';
export { export {
default as DataDescription, default as DataDescription,
} from './ui/components/data-inspector/DataDescription.js'; } from './ui/components/data-inspector/DataDescription.tsx';
export {default as Tabs} from './ui/components/Tabs.tsx'; export {default as Tabs} from './ui/components/Tabs.tsx';
export {default as Tab} from './ui/components/Tab.tsx'; export {default as Tab} from './ui/components/Tab.tsx';
export {default as Input} from './ui/components/Input.tsx'; export {default as Input} from './ui/components/Input.tsx';

View File

@@ -4,15 +4,16 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
* @format * @format
*/ */
import Link from '../Link.tsx'; import Link from '../Link';
import type {DataInspectorSetValue} from './DataInspector.tsx'; import {DataInspectorSetValue} from './DataInspector';
import {PureComponent} from 'react'; import {PureComponent} from 'react';
import styled from '../../styled/index.js'; import styled from '../../styled/index.js';
import {SketchPicker} from 'react-color'; import {SketchPicker} from 'react-color';
import {Component, Fragment} from 'react'; import {Component, Fragment} from 'react';
import Popover from '../Popover.tsx'; import Popover from '../Popover';
import {colors} from '../colors.tsx'; import {colors} from '../colors';
import Input from '../Input.tsx'; import Input from '../Input';
import React, {KeyboardEvent} from 'react';
const NullValue = styled('span')({ const NullValue = styled('span')({
color: 'rgb(128, 128, 128)', color: 'rgb(128, 128, 128)',
@@ -38,7 +39,7 @@ const NumberValue = styled('span')({
color: colors.tealDark1, color: colors.tealDark1,
}); });
const ColorBox = styled('span')(props => ({ const ColorBox = styled('span')((props: {color: string}) => ({
backgroundColor: props.color, backgroundColor: props.color,
boxShadow: 'inset 0 0 1px rgba(0, 0, 0, 1)', boxShadow: 'inset 0 0 1px rgba(0, 0, 0, 1)',
display: 'inline-block', display: 'inline-block',
@@ -62,27 +63,27 @@ const ColorPickerDescription = styled('div')({
position: 'relative', position: 'relative',
}); });
type DataDescriptionProps = {| type DataDescriptionProps = {
path?: Array<string>, path?: Array<string>;
type: string, type: string;
value: any, value: any;
setValue: ?DataInspectorSetValue, setValue: DataInspectorSetValue | null | undefined;
|}; };
type DescriptionCommitOptions = {| type DescriptionCommitOptions = {
value: any, value: any;
keep: boolean, keep: boolean;
clear: boolean, clear: boolean;
set: boolean, set: boolean;
|}; };
class NumberTextEditor extends PureComponent<{ class NumberTextEditor extends PureComponent<{
commit: (opts: DescriptionCommitOptions) => void, commit: (opts: DescriptionCommitOptions) => void;
type: string, type: string;
value: any, value: any;
origValue: any, origValue: any;
}> { }> {
onNumberTextInputChange = (e: SyntheticInputEvent<HTMLInputElement>) => { onNumberTextInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const val = const val =
this.props.type === 'number' this.props.type === 'number'
? parseFloat(e.target.value) ? parseFloat(e.target.value)
@@ -95,7 +96,7 @@ class NumberTextEditor extends PureComponent<{
}); });
}; };
onNumberTextInputKeyDown = (e: SyntheticKeyboardEvent<*>) => { onNumberTextInputKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Enter') { if (e.key === 'Enter') {
const val = const val =
this.props.type === 'number' this.props.type === 'number'
@@ -112,7 +113,7 @@ class NumberTextEditor extends PureComponent<{
} }
}; };
onNumberTextRef = (ref: ?HTMLElement) => { onNumberTextRef = (ref: HTMLElement | undefined | null) => {
if (ref) { if (ref) {
ref.focus(); ref.focus();
} }
@@ -128,7 +129,7 @@ class NumberTextEditor extends PureComponent<{
}; };
render() { render() {
const extraProps: Object = {}; const extraProps: any = {};
if (this.props.type === 'number') { if (this.props.type === 'number') {
// render as a HTML number input // render as a HTML number input
extraProps.type = 'number'; extraProps.type = 'number';
@@ -153,15 +154,15 @@ class NumberTextEditor extends PureComponent<{
} }
} }
type DataDescriptionState = {| type DataDescriptionState = {
editing: boolean, editing: boolean;
origValue: any, origValue: any;
value: any, value: any;
|}; };
export default class DataDescription extends PureComponent< export default class DataDescription extends PureComponent<
DataDescriptionProps, DataDescriptionProps,
DataDescriptionState, DataDescriptionState
> { > {
constructor(props: DataDescriptionProps, context: Object) { constructor(props: DataDescriptionProps, context: Object) {
super(props, context); super(props, context);
@@ -256,8 +257,8 @@ export default class DataDescription extends PureComponent<
} }
class ColorEditor extends Component<{ class ColorEditor extends Component<{
value: any, value: any;
commit: (opts: DescriptionCommitOptions) => void, commit: (opts: DescriptionCommitOptions) => void;
}> { }> {
onBlur = () => { onBlur = () => {
this.props.commit({ this.props.commit({
@@ -272,8 +273,8 @@ class ColorEditor extends Component<{
hex, hex,
rgb: {a, b, g, r}, rgb: {a, b, g, r},
}: { }: {
hex: string, hex: string;
rgb: {a: number, b: number, g: number, r: number}, rgb: {a: number; b: number; g: number; r: number};
}) => { }) => {
const prev = this.props.value; const prev = this.props.value;
@@ -349,11 +350,11 @@ class ColorEditor extends Component<{
} }
class DataDescriptionPreview extends Component<{ class DataDescriptionPreview extends Component<{
type: string, type: string;
value: any, value: any;
editable: boolean, editable: boolean;
commit: (opts: DescriptionCommitOptions) => void, commit: (opts: DescriptionCommitOptions) => void;
onEdit?: () => void, onEdit?: () => void;
}> { }> {
onClick = () => { onClick = () => {
const {onEdit} = this.props; const {onEdit} = this.props;
@@ -389,12 +390,15 @@ class DataDescriptionPreview extends Component<{
function parseColor( function parseColor(
val: string | number, val: string | number,
): ?{| ):
r: number, | {
g: number, r: number;
b: number, g: number;
a: number, b: number;
|} { a: number;
}
| undefined
| null {
if (typeof val === 'number') { if (typeof val === 'number') {
const a = ((val >> 24) & 0xff) / 255; const a = ((val >> 24) & 0xff) / 255;
const r = (val >> 16) & 0xff; const r = (val >> 16) & 0xff;
@@ -444,12 +448,12 @@ function parseColor(
} }
class DataDescriptionContainer extends Component<{ class DataDescriptionContainer extends Component<{
type: string, type: string;
value: any, value: any;
editable: boolean, editable: boolean;
commit: (opts: DescriptionCommitOptions) => void, commit: (opts: DescriptionCommitOptions) => void;
}> { }> {
onChangeCheckbox = (e: SyntheticInputEvent<HTMLInputElement>) => { onChangeCheckbox = (e: React.ChangeEvent<HTMLInputElement>) => {
this.props.commit({ this.props.commit({
clear: true, clear: true,
keep: true, keep: true,

View File

@@ -5,7 +5,7 @@
* @format * @format
*/ */
import DataDescription from './DataDescription.js'; import DataDescription from './DataDescription';
import {Component} from 'react'; import {Component} from 'react';
import ContextMenu from '../ContextMenu'; import ContextMenu from '../ContextMenu';
import Tooltip from '../Tooltip'; import Tooltip from '../Tooltip';

View File

@@ -6,7 +6,7 @@
*/ */
import {DataValueExtractor, InspectorName} from './DataInspector'; import {DataValueExtractor, InspectorName} from './DataInspector';
import DataDescription from './DataDescription.js'; import DataDescription from './DataDescription';
import styled from 'react-emotion'; import styled from 'react-emotion';
import {getSortedKeys} from './utils.js'; import {getSortedKeys} from './utils.js';
import {PureComponent} from 'react'; import {PureComponent} from 'react';

View File

@@ -64,7 +64,7 @@ export {
} from './components/data-inspector/ManagedDataInspector.tsx'; } from './components/data-inspector/ManagedDataInspector.tsx';
export { export {
default as DataDescription, default as DataDescription,
} from './components/data-inspector/DataDescription.js'; } from './components/data-inspector/DataDescription.tsx';
// tabs // tabs
export {default as Tabs} from './components/Tabs.tsx'; export {default as Tabs} from './components/Tabs.tsx';