Files
flipper/desktop/plugins/public/ui-debugger/plugin/ClientDataUtils.tsx
Luke De Feo 795d1de10d 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
2023-08-01 10:32:29 -07:00

51 lines
1.1 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 {ClientNode, Id} from '../ClientTypes';
import {UIState} from '../DesktopTypes';
export function checkFocusedNodeStillActive(
uiState: UIState,
nodes: Map<Id, ClientNode>,
) {
const focusedNodeId = uiState.focusedNode.get();
const focusedNode = focusedNodeId != null && nodes.get(focusedNodeId);
if (!focusedNode || !isFocusedNodeAncestryAllActive(focusedNode, nodes)) {
uiState.focusedNode.set(undefined);
}
}
function isFocusedNodeAncestryAllActive(
focused: ClientNode,
nodes: Map<Id, ClientNode>,
): boolean {
let node = focused;
while (node != null) {
if (node.parent == null) {
return true;
}
const parent = nodes.get(node.parent);
if (parent == null) {
//should also never happen
return false;
}
if (parent.activeChild != null && parent.activeChild !== node.id) {
return false;
}
node = parent;
}
//wont happen
return false;
}