Files
flipper/desktop/plugins/public/ui-debugger/components/main.tsx
Luke De Feo f282a5eb8a Ant tree -> React complex tree
Summary:
Upgraded from ant tree library to the much more capable React complex tree. Added the following:
1. Ability to expand / collapse nodes while automatically expanding / collapsing active/inactive children when they change
2. Keyboard controls of tree all the time
3. Basic search functionality
4. Selecting node in tree focuses and scrolls in the tree
5. Hover state for tree

Reviewed By: lblasa

Differential Revision: D40633876

fbshipit-source-id: 8dcef5ec2c277e476a3eb3cdaef62b15c25323c0
2022-10-25 07:10:38 -07:00

78 lines
2.3 KiB
TypeScript

/**
* 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, {useState} from 'react';
import {plugin} from '../index';
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);
const rootId = useValue(instance.rootId);
const nodes: Map<Id, UINode> = useValue(instance.nodes);
const snapshots: Map<Id, Snapshot> = useValue(instance.snapshots);
const [showPerfStats, setShowPerfStats] = useState(false);
const [selectedNode, setSelectedNode] = useState<Id | undefined>(undefined);
const [hoveredNode, setHoveredNode] = useState<Id | undefined>(undefined);
useHotkeys('ctrl+i', () => setShowPerfStats((show) => !show));
const {ctrlPressed} = useKeyboardModifiers();
function renderSidebar(node: UINode | undefined) {
if (!node) {
return;
}
return (
<DetailSidebar width={350}>
<Inspector node={node} />
</DetailSidebar>
);
}
if (showPerfStats) return <PerfStats events={instance.perfEvents} />;
if (rootId) {
return (
<Layout.Horizontal grow>
<Layout.ScrollContainer>
<Tree
selectedNode={selectedNode}
hoveredNode={hoveredNode}
onSelectNode={setSelectedNode}
onHoveredNode={setHoveredNode}
nodes={nodes}
rootId={rootId}
/>
</Layout.ScrollContainer>
<Visualization2D
rootId={rootId}
nodes={nodes}
snapshots={snapshots}
hoveredNode={hoveredNode}
onHoverNode={setHoveredNode}
selectedNode={selectedNode}
onSelectNode={setSelectedNode}
modifierPressed={ctrlPressed}
/>
{selectedNode && renderSidebar(nodes.get(selectedNode))}
</Layout.Horizontal>
);
}
return <div>Loading...</div>;
}