Add padding and refactor our controls component
Summary: also made the controls component full width to push down the visualiser Reviewed By: lblasa Differential Revision: D41548665 fbshipit-source-id: 2bca527e70c92bc0ded120e51a0880f76f7cca87
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a93d571dc0
commit
b214806325
46
desktop/plugins/public/ui-debugger/components/Controls.tsx
Normal file
46
desktop/plugins/public/ui-debugger/components/Controls.tsx
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
* 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 {plugin} from '../index';
|
||||||
|
import {Button, Input, Tooltip} from 'antd';
|
||||||
|
import {PauseCircleOutlined, PlayCircleOutlined} from '@ant-design/icons';
|
||||||
|
import {usePlugin, useValue, Layout} from 'flipper-plugin';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const Controls: React.FC = () => {
|
||||||
|
const instance = usePlugin(plugin);
|
||||||
|
const searchTerm = useValue(instance.uiState.searchTerm);
|
||||||
|
const isPaused = useValue(instance.uiState.isPaused);
|
||||||
|
return (
|
||||||
|
<Layout.Horizontal pad="small" gap="small">
|
||||||
|
<Input
|
||||||
|
value={searchTerm}
|
||||||
|
onChange={(e) => instance.uiState.searchTerm.set(e.target.value)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="default"
|
||||||
|
shape="circle"
|
||||||
|
onClick={() => instance.setPlayPause(!instance.uiState.isPaused.get())}
|
||||||
|
icon={
|
||||||
|
<Tooltip
|
||||||
|
title={isPaused ? 'Resume live updates' : 'Pause incoming updates'}>
|
||||||
|
{isPaused ? <PlayCircleOutlined /> : <PauseCircleOutlined />}
|
||||||
|
</Tooltip>
|
||||||
|
}></Button>
|
||||||
|
</Layout.Horizontal>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -17,8 +17,8 @@ import {Tree} from './Tree';
|
|||||||
import {Visualization2D} from './Visualization2D';
|
import {Visualization2D} from './Visualization2D';
|
||||||
import {useKeyboardModifiers} from '../hooks/useKeyboardModifiers';
|
import {useKeyboardModifiers} from '../hooks/useKeyboardModifiers';
|
||||||
import {Inspector} from './sidebar/Inspector';
|
import {Inspector} from './sidebar/Inspector';
|
||||||
import {Button, Input, Spin, Tooltip} from 'antd';
|
import {Spin} from 'antd';
|
||||||
import {PauseCircleOutlined, PlayCircleOutlined} from '@ant-design/icons';
|
import {Controls} from './Controls';
|
||||||
|
|
||||||
export function Component() {
|
export function Component() {
|
||||||
const instance = usePlugin(plugin);
|
const instance = usePlugin(plugin);
|
||||||
@@ -31,10 +31,8 @@ export function Component() {
|
|||||||
|
|
||||||
useHotkeys('ctrl+i', () => setShowPerfStats((show) => !show));
|
useHotkeys('ctrl+i', () => setShowPerfStats((show) => !show));
|
||||||
|
|
||||||
const searchTerm = useValue(instance.uiState.searchTerm);
|
|
||||||
const {ctrlPressed} = useKeyboardModifiers();
|
const {ctrlPressed} = useKeyboardModifiers();
|
||||||
|
|
||||||
const isPaused = useValue(instance.uiState.isPaused);
|
|
||||||
function renderSidebar(
|
function renderSidebar(
|
||||||
node: UINode | undefined,
|
node: UINode | undefined,
|
||||||
metadata: Map<MetadataId, Metadata>,
|
metadata: Map<MetadataId, Metadata>,
|
||||||
@@ -53,46 +51,31 @@ export function Component() {
|
|||||||
|
|
||||||
if (rootId) {
|
if (rootId) {
|
||||||
return (
|
return (
|
||||||
<Layout.Horizontal grow>
|
<Layout.Container grow padh="small" padv="medium">
|
||||||
<Layout.Container grow pad="medium" gap="small">
|
<Controls />
|
||||||
<Layout.Horizontal padh="small" gap="small">
|
<Layout.Horizontal grow pad="small" gap="small">
|
||||||
<Input
|
<Layout.Container grow gap="small">
|
||||||
value={searchTerm}
|
<Layout.ScrollContainer>
|
||||||
onChange={(e) => instance.uiState.searchTerm.set(e.target.value)}
|
<Tree
|
||||||
/>
|
selectedNode={selectedNode}
|
||||||
<Button
|
onSelectNode={setSelectedNode}
|
||||||
type="default"
|
nodes={nodes}
|
||||||
shape="circle"
|
rootId={rootId}
|
||||||
onClick={() =>
|
/>
|
||||||
instance.setPlayPause(!instance.uiState.isPaused.get())
|
</Layout.ScrollContainer>
|
||||||
}
|
</Layout.Container>
|
||||||
icon={
|
|
||||||
<Tooltip
|
<Visualization2D
|
||||||
title={
|
rootId={rootId}
|
||||||
isPaused ? 'Resume live updates' : 'Pause incoming updates'
|
nodes={nodes}
|
||||||
}>
|
selectedNode={selectedNode}
|
||||||
{isPaused ? <PlayCircleOutlined /> : <PauseCircleOutlined />}
|
onSelectNode={setSelectedNode}
|
||||||
</Tooltip>
|
modifierPressed={ctrlPressed}
|
||||||
}></Button>
|
/>
|
||||||
</Layout.Horizontal>
|
|
||||||
<Layout.ScrollContainer>
|
{selectedNode && renderSidebar(nodes.get(selectedNode), metadata)}
|
||||||
<Tree
|
</Layout.Horizontal>
|
||||||
selectedNode={selectedNode}
|
</Layout.Container>
|
||||||
onSelectNode={setSelectedNode}
|
|
||||||
nodes={nodes}
|
|
||||||
rootId={rootId}
|
|
||||||
/>
|
|
||||||
</Layout.ScrollContainer>
|
|
||||||
</Layout.Container>
|
|
||||||
<Visualization2D
|
|
||||||
rootId={rootId}
|
|
||||||
nodes={nodes}
|
|
||||||
selectedNode={selectedNode}
|
|
||||||
onSelectNode={setSelectedNode}
|
|
||||||
modifierPressed={ctrlPressed}
|
|
||||||
/>
|
|
||||||
{selectedNode && renderSidebar(nodes.get(selectedNode), metadata)}
|
|
||||||
</Layout.Horizontal>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,15 @@ type LiveClientState = {
|
|||||||
nodes: Map<Id, UINode>;
|
nodes: Map<Id, UINode>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type UIState = {
|
||||||
|
isPaused: Atom<boolean>;
|
||||||
|
searchTerm: Atom<string>;
|
||||||
|
isContextMenuOpen: Atom<boolean>;
|
||||||
|
hoveredNodes: Atom<Id[]>;
|
||||||
|
focusedNode: Atom<Id | undefined>;
|
||||||
|
treeState: Atom<TreeState>;
|
||||||
|
};
|
||||||
|
|
||||||
export function plugin(client: PluginClient<Events>) {
|
export function plugin(client: PluginClient<Events>) {
|
||||||
const rootId = createState<Id | undefined>(undefined);
|
const rootId = createState<Id | undefined>(undefined);
|
||||||
const metadata = createState<Map<MetadataId, Metadata>>(new Map());
|
const metadata = createState<Map<MetadataId, Metadata>>(new Map());
|
||||||
@@ -63,7 +72,7 @@ export function plugin(client: PluginClient<Events>) {
|
|||||||
const nodes = createState<Map<Id, UINode>>(new Map());
|
const nodes = createState<Map<Id, UINode>>(new Map());
|
||||||
const snapshot = createState<SnapshotInfo | null>(null);
|
const snapshot = createState<SnapshotInfo | null>(null);
|
||||||
|
|
||||||
const uiState = {
|
const uiState: UIState = {
|
||||||
//used to disabled hover effects which cause rerenders and mess up the existing context menu
|
//used to disabled hover effects which cause rerenders and mess up the existing context menu
|
||||||
isContextMenuOpen: createState<boolean>(false),
|
isContextMenuOpen: createState<boolean>(false),
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user