Add a very simple attributes inspector
Summary: Add a very simple attributes inspector Reviewed By: LukeDefeo Differential Revision: D39306728 fbshipit-source-id: 0e46b3efc617253d0b3006e81a46f00fdf8e8457
This commit is contained in:
committed by
Facebook GitHub Bot
parent
2fc1ff9f9c
commit
ccec5a6abe
@@ -10,13 +10,15 @@
|
|||||||
import React, {useState} from 'react';
|
import React, {useState} from 'react';
|
||||||
import {PerfStatsEvent, plugin} from '../index';
|
import {PerfStatsEvent, plugin} from '../index';
|
||||||
import {
|
import {
|
||||||
|
DataInspector,
|
||||||
DataTable,
|
DataTable,
|
||||||
DataTableColumn,
|
DataTableColumn,
|
||||||
|
DetailSidebar,
|
||||||
Layout,
|
Layout,
|
||||||
usePlugin,
|
usePlugin,
|
||||||
useValue,
|
useValue,
|
||||||
} from 'flipper-plugin';
|
} from 'flipper-plugin';
|
||||||
import {Tree} from 'antd';
|
import {Tree, Typography} from 'antd';
|
||||||
import type {DataNode} from 'antd/es/tree';
|
import type {DataNode} from 'antd/es/tree';
|
||||||
import {DownOutlined} from '@ant-design/icons';
|
import {DownOutlined} from '@ant-design/icons';
|
||||||
import {useHotkeys} from 'react-hotkeys-hook';
|
import {useHotkeys} from 'react-hotkeys-hook';
|
||||||
@@ -86,9 +88,28 @@ export function Component() {
|
|||||||
const nodes = useValue(instance.nodes);
|
const nodes = useValue(instance.nodes);
|
||||||
|
|
||||||
const [showPerfStats, setShowPerfStats] = useState(false);
|
const [showPerfStats, setShowPerfStats] = useState(false);
|
||||||
|
const [selectedNode, setSelectedNode] = useState<string | undefined>(
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
|
||||||
useHotkeys('ctrl+i', () => setShowPerfStats((show) => !show));
|
useHotkeys('ctrl+i', () => setShowPerfStats((show) => !show));
|
||||||
|
|
||||||
|
function renderAttributesInspector(node: UINode | undefined) {
|
||||||
|
if (!node) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<DetailSidebar>
|
||||||
|
<Layout.Container gap pad>
|
||||||
|
<Typography.Title level={2}>Attributes Inspector</Typography.Title>
|
||||||
|
<DataInspector data={node.attributes} expandRoot />
|
||||||
|
</Layout.Container>
|
||||||
|
</DetailSidebar>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (showPerfStats)
|
if (showPerfStats)
|
||||||
return (
|
return (
|
||||||
<DataTable<PerfStatsEvent>
|
<DataTable<PerfStatsEvent>
|
||||||
@@ -100,19 +121,22 @@ export function Component() {
|
|||||||
if (rootId) {
|
if (rootId) {
|
||||||
const antTree = nodesToAntTree(rootId, nodes);
|
const antTree = nodesToAntTree(rootId, nodes);
|
||||||
return (
|
return (
|
||||||
<Layout.ScrollContainer>
|
<>
|
||||||
<Tree
|
<Layout.ScrollContainer>
|
||||||
showIcon
|
<Tree
|
||||||
showLine
|
showIcon
|
||||||
onSelect={(selected) => {
|
showLine
|
||||||
console.log(nodes.get(selected[0] as string));
|
onSelect={(selected) => {
|
||||||
}}
|
setSelectedNode(selected[0] as string);
|
||||||
defaultExpandAll
|
}}
|
||||||
expandedKeys={[...nodes.keys()]}
|
defaultExpandAll
|
||||||
switcherIcon={<DownOutlined />}
|
expandedKeys={[...nodes.keys()]}
|
||||||
treeData={[antTree]}
|
switcherIcon={<DownOutlined />}
|
||||||
/>
|
treeData={[antTree]}
|
||||||
</Layout.ScrollContainer>
|
/>
|
||||||
|
</Layout.ScrollContainer>
|
||||||
|
{selectedNode && renderAttributesInspector(nodes.get(selectedNode))}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user