From 07c4470ab97b350ed278fd84bc65c791eb533e39 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Wed, 7 Apr 2021 07:52:47 -0700 Subject: [PATCH] Stricter types for DataDescription Summary: Made datatypes used by DataInspector more strictly typed (in the hope to be able to drop some, but all are still in use, although the distinction between different elements isn't always clear). Reviewed By: passy Differential Revision: D27266825 fbshipit-source-id: 6a1c74b0ae3daff6299ca598b18a205d17c42e22 --- desktop/app/src/index.tsx | 5 +++- .../data-inspector/DataDescription.tsx | 27 ++++++++++++++++--- .../components/data-inspector/DataPreview.tsx | 4 +-- desktop/plugins/leak_canary/index.tsx | 3 ++- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/desktop/app/src/index.tsx b/desktop/app/src/index.tsx index 68a12dfa6..adeefc670 100644 --- a/desktop/app/src/index.tsx +++ b/desktop/app/src/index.tsx @@ -99,7 +99,10 @@ export { export {default as DataInspector} from './ui/components/data-inspector/DataInspector'; export {default as ManagedDataInspector} from './ui/components/data-inspector/ManagedDataInspector'; export {default as SearchableDataInspector} from './ui/components/data-inspector/SearchableDataInspector'; -export {default as DataDescription} from './ui/components/data-inspector/DataDescription'; +export { + default as DataDescription, + DataDescriptionType, +} from './ui/components/data-inspector/DataDescription'; export {HighlightManager} from './ui/components/Highlight'; export {default as Tabs} from './ui/components/Tabs'; export {default as Tab} from './ui/components/Tab'; diff --git a/desktop/app/src/ui/components/data-inspector/DataDescription.tsx b/desktop/app/src/ui/components/data-inspector/DataDescription.tsx index 374425622..90d764e21 100644 --- a/desktop/app/src/ui/components/data-inspector/DataDescription.tsx +++ b/desktop/app/src/ui/components/data-inspector/DataDescription.tsx @@ -85,9 +85,28 @@ const EmptyObjectValue = styled.span({ }); EmptyObjectValue.displayName = 'DataDescription:EmptyObjectValue'; +export type DataDescriptionType = + | 'number' + | 'string' + | 'boolean' + | 'undefined' + | 'null' + | 'object' + | 'array' + | 'date' + | 'symbol' + | 'function' + | 'bigint' + | 'text' // deprecated, please use string + | 'enum' // unformatted string + | 'color' + | 'picker' // multiple choise item like an, eehhh, enum + | 'timeline' + | 'color_lite'; // color with limited palette, specific for fblite; + type DataDescriptionProps = { path?: Array; - type: string; + type: DataDescriptionType; value: any; extra?: any; setValue: DataInspectorSetValue | null | undefined; @@ -102,7 +121,7 @@ type DescriptionCommitOptions = { class NumberTextEditor extends PureComponent<{ commit: (opts: DescriptionCommitOptions) => void; - type: string; + type: DataDescriptionType; value: any; origValue: any; }> { @@ -447,7 +466,7 @@ class ColorEditor extends PureComponent<{ } class DataDescriptionPreview extends PureComponent<{ - type: string; + type: DataDescriptionType; value: any; extra?: any; editable: boolean; @@ -551,7 +570,7 @@ type Picker = { }; class DataDescriptionContainer extends PureComponent<{ - type: string; + type: DataDescriptionType; value: any; editable: boolean; commit: (opts: DescriptionCommitOptions) => void; diff --git a/desktop/app/src/ui/components/data-inspector/DataPreview.tsx b/desktop/app/src/ui/components/data-inspector/DataPreview.tsx index ea900b383..0ddefe44c 100755 --- a/desktop/app/src/ui/components/data-inspector/DataPreview.tsx +++ b/desktop/app/src/ui/components/data-inspector/DataPreview.tsx @@ -7,7 +7,7 @@ * @format */ -import DataDescription from './DataDescription'; +import DataDescription, {DataDescriptionType} from './DataDescription'; import styled from '@emotion/styled'; import {getSortedKeys} from './utils'; import {PureComponent} from 'react'; @@ -21,7 +21,7 @@ export type DataValueExtractor = ( ) => | { mutable: boolean; - type: string; + type: DataDescriptionType; value: any; extra?: any; } diff --git a/desktop/plugins/leak_canary/index.tsx b/desktop/plugins/leak_canary/index.tsx index 0d97ab5f5..f1990c614 100644 --- a/desktop/plugins/leak_canary/index.tsx +++ b/desktop/plugins/leak_canary/index.tsx @@ -20,6 +20,7 @@ import { FlipperPlugin, Button, styled, + DataDescriptionType, } from 'flipper'; import {Element} from 'flipper'; import {processLeaks} from './processLeakString'; @@ -163,7 +164,7 @@ export default class LeakCanary extends FlipperPlugin< _extractValue( value: any, _: number, // depth - ): {mutable: boolean; type: string; value: any} { + ): {mutable: boolean; type: DataDescriptionType; value: any} { if (!isNaN(value)) { return {mutable: false, type: 'number', value: value}; } else if (value == 'true' || value == 'false') {