From c46ddf7912dc6e9a859cec462c7a1283bf43144c Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Tue, 25 Oct 2022 03:09:00 -0700 Subject: [PATCH] Foundations for inspector Summary: ^ This laids the foundation for the inspector. It just reorganises a few bits. Reviewed By: LukeDefeo Differential Revision: D40319611 fbshipit-source-id: 8cf9b151c631faa1f26a7a6dfaa86b01abc42fe5 --- .../public/ui-debugger/components/main.tsx | 26 ++--- .../components/sidebar/Inspector.tsx | 63 ++++++++++++ .../sidebar/inspector/AttributesInspector.tsx | 97 +++++++++++++++++++ .../inspector/DocumentationInspector.tsx | 19 ++++ .../sidebar/inspector/IdentityInspector.tsx | 35 +++++++ .../sidebar/inspector/LayoutInspector.tsx | 19 ++++ desktop/plugins/public/ui-debugger/types.tsx | 2 +- desktop/static/icons.json | 8 +- 8 files changed, 248 insertions(+), 21 deletions(-) create mode 100644 desktop/plugins/public/ui-debugger/components/sidebar/Inspector.tsx create mode 100644 desktop/plugins/public/ui-debugger/components/sidebar/inspector/AttributesInspector.tsx create mode 100644 desktop/plugins/public/ui-debugger/components/sidebar/inspector/DocumentationInspector.tsx create mode 100644 desktop/plugins/public/ui-debugger/components/sidebar/inspector/IdentityInspector.tsx create mode 100644 desktop/plugins/public/ui-debugger/components/sidebar/inspector/LayoutInspector.tsx diff --git a/desktop/plugins/public/ui-debugger/components/main.tsx b/desktop/plugins/public/ui-debugger/components/main.tsx index 950c50899..6c87cdd10 100644 --- a/desktop/plugins/public/ui-debugger/components/main.tsx +++ b/desktop/plugins/public/ui-debugger/components/main.tsx @@ -9,21 +9,14 @@ import React, {useState} from 'react'; import {plugin} from '../index'; -import { - DataInspector, - DetailSidebar, - Layout, - usePlugin, - useValue, -} from 'flipper-plugin'; -import {Typography} from 'antd'; - +import {DetailSidebar, Layout, usePlugin, useValue} from 'flipper-plugin'; import {useHotkeys} from 'react-hotkeys-hook'; import {Id, Snapshot, UINode} from '../types'; import {PerfStats} from './PerfStats'; import {Tree} from './Tree'; import {Visualization2D} from './Visualization2D'; import {useKeyboardModifiers} from '../hooks/useKeyboardModifiers'; +import {Inspector} from './sidebar/Inspector'; export function Component() { const instance = usePlugin(plugin); @@ -39,19 +32,14 @@ export function Component() { const {ctrlPressed} = useKeyboardModifiers(); - function renderAttributesInspector(node: UINode | undefined) { + function renderSidebar(node: UINode | undefined) { if (!node) { return; } return ( - <> - - - Attributes Inspector - - - - + + + ); } @@ -81,7 +69,7 @@ export function Component() { /> - {selectedNode && renderAttributesInspector(nodes.get(selectedNode))} + {selectedNode && renderSidebar(nodes.get(selectedNode))} ); } diff --git a/desktop/plugins/public/ui-debugger/components/sidebar/Inspector.tsx b/desktop/plugins/public/ui-debugger/components/sidebar/Inspector.tsx new file mode 100644 index 000000000..03c505011 --- /dev/null +++ b/desktop/plugins/public/ui-debugger/components/sidebar/Inspector.tsx @@ -0,0 +1,63 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +import React from 'react'; +// eslint-disable-next-line rulesdir/no-restricted-imports-clone +import {Glyph} from 'flipper'; +import {Layout, Tab, Tabs} from 'flipper-plugin'; +import {UINode} from '../../types'; +import {IdentityInspector} from './inspector/IdentityInspector'; +import {AttributesInspector} from './inspector/AttributesInspector'; +import {DocumentationInspector} from './inspector/DocumentationInspector'; +import {LayoutInspector} from './inspector/LayoutInspector'; + +type Props = { + node: UINode; +}; + +export const Inspector: React.FC = ({node}) => { + return ( + + + + + + }> + + + + + + }> + + + + + + }> + + + + + + }> + + + + + ); +}; diff --git a/desktop/plugins/public/ui-debugger/components/sidebar/inspector/AttributesInspector.tsx b/desktop/plugins/public/ui-debugger/components/sidebar/inspector/AttributesInspector.tsx new file mode 100644 index 000000000..844cde590 --- /dev/null +++ b/desktop/plugins/public/ui-debugger/components/sidebar/inspector/AttributesInspector.tsx @@ -0,0 +1,97 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +import React from 'react'; +import {Color, Inspectable, InspectableObject, UINode} from '../../../types'; +import {Panel} from 'flipper-plugin'; + +type Props = { + node: UINode; +}; + +const TextAttributeInspector: React.FC<{name: string; value: string}> = ({ + name, + value, +}) => { + return ( +
+ {name}: {value} +
+ ); +}; + +const NumberAttributeInspector: React.FC<{name: string; value: number}> = ({ + name, + value, +}) => { + return ( +
+ {name}: {value} +
+ ); +}; + +const ColorAttributeInspector: React.FC<{name: string; value: Color}> = ({ + name, + value, +}) => { + return ( +
+ {name}: {JSON.stringify(value)} +
+ ); +}; + +const ObjectAttributeInspector: React.FC<{ + name: string; + value: Record; +}> = ({name, value}) => { + return ( +
+ {name}: {JSON.stringify(value)} +
+ ); +}; + +function create(key: string, inspectable: Inspectable) { + switch (inspectable.type) { + case 'text': + return ; + case 'number': + return ; + case 'color': + return ; + case 'object': + return ; + default: + return; + } +} + +function createSection(name: string, inspectable: InspectableObject) { + return ( + + {' '} + {Object.keys(inspectable.fields).map(function (key, _) { + return create(key, inspectable.fields[key]); + })} + + ); +} + +export const AttributesInspector: React.FC = ({node}) => { + // TODO: add raw panel to inspect data as received. + return ( + <> + {Object.keys(node.attributes).map(function (key, _) { + return createSection(key, node.attributes[key] as InspectableObject); + })} + + ); +}; diff --git a/desktop/plugins/public/ui-debugger/components/sidebar/inspector/DocumentationInspector.tsx b/desktop/plugins/public/ui-debugger/components/sidebar/inspector/DocumentationInspector.tsx new file mode 100644 index 000000000..a5bf2ef5b --- /dev/null +++ b/desktop/plugins/public/ui-debugger/components/sidebar/inspector/DocumentationInspector.tsx @@ -0,0 +1,19 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +import React from 'react'; +import {UINode} from '../../../types'; + +type Props = { + node: UINode; +}; + +export const DocumentationInspector: React.FC = () => { + return

Quick Help and Documentation

; +}; diff --git a/desktop/plugins/public/ui-debugger/components/sidebar/inspector/IdentityInspector.tsx b/desktop/plugins/public/ui-debugger/components/sidebar/inspector/IdentityInspector.tsx new file mode 100644 index 000000000..e09b5633b --- /dev/null +++ b/desktop/plugins/public/ui-debugger/components/sidebar/inspector/IdentityInspector.tsx @@ -0,0 +1,35 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +import React from 'react'; +import {Col, Row} from 'antd'; +import {UINode} from '../../../types'; + +type Props = { + node: UINode; +}; + +export const IdentityInspector: React.FC = ({node}) => { + return ( + <> + + +
Name:
+ + {node.name} +
+ + +
Id:
+ + {node.id} +
+ + ); +}; diff --git a/desktop/plugins/public/ui-debugger/components/sidebar/inspector/LayoutInspector.tsx b/desktop/plugins/public/ui-debugger/components/sidebar/inspector/LayoutInspector.tsx new file mode 100644 index 000000000..0044bf9ae --- /dev/null +++ b/desktop/plugins/public/ui-debugger/components/sidebar/inspector/LayoutInspector.tsx @@ -0,0 +1,19 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +import React from 'react'; +import {UINode} from '../../../types'; + +type Props = { + node: UINode; +}; + +export const LayoutInspector: React.FC = () => { + return

Origin and size

; +}; diff --git a/desktop/plugins/public/ui-debugger/types.tsx b/desktop/plugins/public/ui-debugger/types.tsx index 38ba5041a..89a204fcb 100644 --- a/desktop/plugins/public/ui-debugger/types.tsx +++ b/desktop/plugins/public/ui-debugger/types.tsx @@ -82,7 +82,7 @@ export type InspectableNumber = { }; export type InspectableColor = { - type: 'number'; + type: 'color'; value: Color; mutable: boolean; }; diff --git a/desktop/static/icons.json b/desktop/static/icons.json index 00fe6748f..a74dda590 100644 --- a/desktop/static/icons.json +++ b/desktop/static/icons.json @@ -651,5 +651,11 @@ ], "photo-arrows-left-right": [ 16 + ], + "badge": [ + 16 + ], + "square-ruler": [ + 16 ] -} +} \ No newline at end of file