@samitouri / QOS-React-2 / commits / 4ffdffb598

Fix scrolling to selected row in collapsed mode

Dan Abramov committed Apr 20, 2019 at 16:20 UTC 4ffdffb598cc66b08169f43ebd1f1560592b058b
2 files changed +29
src/devtools/store.js
+15
@@ -429,6 +429,21 @@ export default class Store extends EventEmitter {
429 return null;
430 }
431
432 + isInsideCollapsedSubTree(id: number): boolean {
433 + let current = this._idToElement.get(id);
434 + while (current != null) {
435 + if (current.parentID === 0) {
436 + return false;
437 + } else {
438 + current = this._idToElement.get(current.parentID);
439 + if (current != null && current.isCollapsed) {
440 + return true;
441 + }
442 + }
443 + }
444 + return false;
445 + }
446 +
447 startProfiling(): void {
448 this._bridge.send('startProfiling');
449
src/devtools/views/Components/TreeContext.js
+14
@@ -596,6 +596,20 @@ function TreeContextController({ children, viewElementSource }: Props) {
596 state = reduceTreeState(store, state, action);
597 state = reduceSearchState(store, state, action);
598 state = reduceOwnersState(store, state, action);
599 +
600 + // If the selected ID is in a collapsed subtree, reset the selected index to null.
601 + // We'll know the correct index after the layout effect will toggle the tree,
602 + // and the store tree is mutated to account for that.
603 + if (
604 + state.selectedElementID !== null &&
605 + store.isInsideCollapsedSubTree(state.selectedElementID)
606 + ) {
607 + return {
608 + ...state,
609 + selectedElementIndex: null,
610 + };
611 + }
612 +
613 return state;
614 default:
615 throw new Error(`Unrecognized action "${type}"`);