Dont auto expand nodes
Summary: Rather than automatically collapsing siblings when using the visualiser instead we take a different approach: 1. The tree starts out fully collapsed 2. Every time you click on the visualiser we expand it and its ancestory chain to expanded nodes. This is exactly how the Dom inspector works. The previous approach of constantly collapsing all siblings when uinsg the visualiser felt too intrusive and taking control from the user. The option is still there but only in the context menu Some ultilities around autocollapsing nodes were removed as they dont make sense anymore that we now send complete frames Changelog: UIDebugger Tree starts collapsed and expands as you click from the visualiser Reviewed By: aigoncharov Differential Revision: D47949843 fbshipit-source-id: 4381d22b12874dde5a89267572bee95f084380e3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ce1fdfdf19
commit
795d1de10d
@@ -98,6 +98,7 @@ export type UIActions = {
|
|||||||
onExpandAllRecursively: (nodeId: Id) => void;
|
onExpandAllRecursively: (nodeId: Id) => void;
|
||||||
onCollapseAllNonAncestors: (nodeId: Id) => void;
|
onCollapseAllNonAncestors: (nodeId: Id) => void;
|
||||||
onCollapseAllRecursively: (nodeId: Id) => void;
|
onCollapseAllRecursively: (nodeId: Id) => void;
|
||||||
|
ensureAncestorsExpanded: (nodeId: Id) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SelectionSource =
|
export type SelectionSource =
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ export const Visualization2D: React.FC<
|
|||||||
const onClickOverlay = () => {
|
const onClickOverlay = () => {
|
||||||
instance.uiActions.onSelectNode(hoveredNodeId, 'visualiser');
|
instance.uiActions.onSelectNode(hoveredNodeId, 'visualiser');
|
||||||
if (hoveredNodeId != null) {
|
if (hoveredNodeId != null) {
|
||||||
instance.uiActions.onCollapseAllNonAncestors(hoveredNodeId);
|
instance.uiActions.ensureAncestorsExpanded(hoveredNodeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetMode.state !== 'disabled') {
|
if (targetMode.state !== 'disabled') {
|
||||||
|
|||||||
@@ -31,10 +31,7 @@ import {
|
|||||||
} from './DesktopTypes';
|
} from './DesktopTypes';
|
||||||
import {getStreamInterceptor} from './fb-stubs/StreamInterceptor';
|
import {getStreamInterceptor} from './fb-stubs/StreamInterceptor';
|
||||||
import {prefetchSourceFileLocation} from './components/fb-stubs/IDEContextMenu';
|
import {prefetchSourceFileLocation} from './components/fb-stubs/IDEContextMenu';
|
||||||
import {
|
import {checkFocusedNodeStillActive} from './plugin/ClientDataUtils';
|
||||||
checkFocusedNodeStillActive,
|
|
||||||
collapseinActiveChildren,
|
|
||||||
} from './plugin/ClientDataUtils';
|
|
||||||
import {uiActions} from './plugin/uiActions';
|
import {uiActions} from './plugin/uiActions';
|
||||||
|
|
||||||
type PendingData = {
|
type PendingData = {
|
||||||
@@ -67,10 +64,6 @@ export function plugin(client: PluginClient<Events>) {
|
|||||||
limit: 10 * 1024,
|
limit: 10 * 1024,
|
||||||
});
|
});
|
||||||
|
|
||||||
//this keeps track of all node ids we have seen so we dont keep reexpanding nodes when they come in again.
|
|
||||||
//Could probably be removed if we refactor the nodes to be expanded by default and only collapsed is toggled on
|
|
||||||
const seenNodes = new Set<Id>();
|
|
||||||
|
|
||||||
//this holds pending any pending data that needs to be applied in the event of a stream interceptor error
|
//this holds pending any pending data that needs to be applied in the event of a stream interceptor error
|
||||||
//while in the error state more metadata or a more recent frame may come in so both cases need to apply the same darta
|
//while in the error state more metadata or a more recent frame may come in so both cases need to apply the same darta
|
||||||
const pendingData: PendingData = {frame: null, metadata: {}};
|
const pendingData: PendingData = {frame: null, metadata: {}};
|
||||||
@@ -279,21 +272,6 @@ export function plugin(client: PluginClient<Events>) {
|
|||||||
}
|
}
|
||||||
mutableLiveClientData.nodes = nodes;
|
mutableLiveClientData.nodes = nodes;
|
||||||
|
|
||||||
uiState.expandedNodes.update((draft) => {
|
|
||||||
for (const node of nodes.values()) {
|
|
||||||
if (!seenNodes.has(node.id)) {
|
|
||||||
draft.add(node.id);
|
|
||||||
}
|
|
||||||
seenNodes.add(node.id);
|
|
||||||
|
|
||||||
if (!uiState.isPaused.get()) {
|
|
||||||
//we need to not do this while paused as you may move to another screen / tab
|
|
||||||
//and it would collapse the tree node for the activity you were paused on.
|
|
||||||
collapseinActiveChildren(node, draft);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!uiState.isPaused.get()) {
|
if (!uiState.isPaused.get()) {
|
||||||
nodesAtom.set(mutableLiveClientData.nodes);
|
nodesAtom.set(mutableLiveClientData.nodes);
|
||||||
snapshot.set(mutableLiveClientData.snapshotInfo);
|
snapshot.set(mutableLiveClientData.snapshotInfo);
|
||||||
|
|||||||
@@ -7,24 +7,9 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Draft} from 'flipper-plugin';
|
|
||||||
import {ClientNode, Id} from '../ClientTypes';
|
import {ClientNode, Id} from '../ClientTypes';
|
||||||
import {UIState} from '../DesktopTypes';
|
import {UIState} from '../DesktopTypes';
|
||||||
|
|
||||||
export function collapseinActiveChildren(
|
|
||||||
node: ClientNode,
|
|
||||||
expandedNodes: Draft<Set<Id>>,
|
|
||||||
) {
|
|
||||||
if (node.activeChild) {
|
|
||||||
expandedNodes.add(node.activeChild);
|
|
||||||
for (const child of node.children) {
|
|
||||||
if (child !== node.activeChild) {
|
|
||||||
expandedNodes.delete(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function checkFocusedNodeStillActive(
|
export function checkFocusedNodeStillActive(
|
||||||
uiState: UIState,
|
uiState: UIState,
|
||||||
nodes: Map<Id, ClientNode>,
|
nodes: Map<Id, ClientNode>,
|
||||||
|
|||||||
@@ -19,10 +19,7 @@ import {
|
|||||||
WireFrameMode,
|
WireFrameMode,
|
||||||
} from '../DesktopTypes';
|
} from '../DesktopTypes';
|
||||||
import {tracker} from '../utils/tracker';
|
import {tracker} from '../utils/tracker';
|
||||||
import {
|
import {checkFocusedNodeStillActive} from './ClientDataUtils';
|
||||||
checkFocusedNodeStillActive,
|
|
||||||
collapseinActiveChildren,
|
|
||||||
} from './ClientDataUtils';
|
|
||||||
|
|
||||||
export function uiActions(
|
export function uiActions(
|
||||||
uiState: UIState,
|
uiState: UIState,
|
||||||
@@ -87,19 +84,19 @@ export function uiActions(
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onCollapseAllNonAncestors = (nodeId: Id) => {
|
const onCollapseAllNonAncestors = (nodeId: Id) => {
|
||||||
//this is not the simplest way to achieve this but on android there is a parent pointer missing for the decor view
|
uiState.expandedNodes.update((draft) => {
|
||||||
//due to the nested obversers.
|
draft.clear();
|
||||||
|
});
|
||||||
|
ensureAncestorsExpanded(nodeId);
|
||||||
|
};
|
||||||
|
|
||||||
|
const ensureAncestorsExpanded = (nodeId: Id) => {
|
||||||
uiState.expandedNodes.update((draft) => {
|
uiState.expandedNodes.update((draft) => {
|
||||||
const nodesMap = nodes.get();
|
const nodesMap = nodes.get();
|
||||||
let prevNode: Id | null = null;
|
|
||||||
let curNode = nodesMap.get(nodeId);
|
let curNode = nodesMap.get(nodeId);
|
||||||
while (curNode != null) {
|
while (curNode != null) {
|
||||||
for (const child of curNode.children) {
|
draft.add(curNode.id);
|
||||||
if (child !== prevNode) {
|
|
||||||
draft.delete(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
prevNode = curNode.id;
|
|
||||||
curNode = nodesMap.get(curNode?.parent ?? 'Nonode');
|
curNode = nodesMap.get(curNode?.parent ?? 'Nonode');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -177,13 +174,6 @@ export function uiActions(
|
|||||||
tracker.track('play-pause-toggled', {paused: isPaused});
|
tracker.track('play-pause-toggled', {paused: isPaused});
|
||||||
uiState.isPaused.set(isPaused);
|
uiState.isPaused.set(isPaused);
|
||||||
if (!isPaused) {
|
if (!isPaused) {
|
||||||
//When going back to play mode then set the atoms to the live state to rerender the latest
|
|
||||||
//Also need to fixed expanded state for any change in active child state
|
|
||||||
uiState.expandedNodes.update((draft) => {
|
|
||||||
liveClientData.nodes.forEach((node) => {
|
|
||||||
collapseinActiveChildren(node, draft);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
nodes.set(liveClientData.nodes);
|
nodes.set(liveClientData.nodes);
|
||||||
snapshot.set(liveClientData.snapshotInfo);
|
snapshot.set(liveClientData.snapshotInfo);
|
||||||
checkFocusedNodeStillActive(uiState, nodes.get());
|
checkFocusedNodeStillActive(uiState, nodes.get());
|
||||||
@@ -216,5 +206,6 @@ export function uiActions(
|
|||||||
onCollapseAllNonAncestors,
|
onCollapseAllNonAncestors,
|
||||||
onExpandAllRecursively,
|
onExpandAllRecursively,
|
||||||
onCollapseAllRecursively,
|
onCollapseAllRecursively,
|
||||||
|
ensureAncestorsExpanded,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user