Files
flipper/desktop/plugins/public/ui-debugger/components/main.tsx
Luke De Feo c7f24eb469 Refactor UI
Summary: Split our the mega component into separate parts in preparation for the visualizer

Reviewed By: lblasa

Differential Revision: D39509406

fbshipit-source-id: 0f867c1f8a91b7592673ae47ba2b5db4f3500732
2022-09-21 07:02:48 -07:00

71 lines
1.7 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 {
DataInspector,
DetailSidebar,
Layout,
usePlugin,
useValue,
} from 'flipper-plugin';
import {Typography} from 'antd';
import {useHotkeys} from 'react-hotkeys-hook';
import {Id, UINode} from '../types';
import {PerfStats} from './PerfStats';
import {Tree} from './Tree';
export function Component() {
const instance = usePlugin(plugin);
const rootId = useValue(instance.rootId);
const nodes: Map<Id, UINode> = useValue(instance.nodes);
const [showPerfStats, setShowPerfStats] = useState(false);
const [selectedNode, setSelectedNode] = useState<Id | undefined>(undefined);
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} expandRoot />
</Layout.Container>
</DetailSidebar>
</>
);
}
if (showPerfStats) return <PerfStats events={instance.perfEvents} />;
if (rootId) {
return (
<>
<Layout.ScrollContainer>
<Tree
setSelectedNode={setSelectedNode}
nodes={nodes}
rootId={rootId}
/>
</Layout.ScrollContainer>
{selectedNode && renderAttributesInspector(nodes.get(selectedNode))}
</>
);
}
return <div>Nothing yet</div>;
}