Layout plugin: Add option to Expand/collapse recursively

Summary:
Uses a slightly modified version of the deep expansion. In testing, there were a few issues due to the function in Inspector::onElementExpanded is essentially a toggle. I added an optional parameter to override this toggle behavior for child elements, and also flipped the order of root and child actions during collapsing, as the child state otherwise didn't persist properly (due to the component being unmounted, would be my guess?) This change should be non-breaking to other uses of the method that don't use the `deep: true` parameter
close https://github.com/facebook/flipper/issues/223

Reviewed By: passy

Differential Revision: D18225057

fbshipit-source-id: 53e840f07bf648249b5a4b36d115918dba215ff8
This commit is contained in:
Gijs Weterings
2019-10-31 08:40:04 -07:00
committed by Facebook Github Bot
parent e90cff1b82
commit 96162f40cb
2 changed files with 26 additions and 9 deletions

View File

@@ -303,15 +303,24 @@ export default class Inspector extends Component<Props> {
}),
);
onElementExpanded = (id: ElementID, deep: boolean) => {
const expanded = !this.elements()[id].expanded;
this.updateElement(id, {expanded});
if (expanded) {
this.getChildren(id, {}).then(children => {
if (deep) {
children.forEach(child => this.onElementExpanded(child.id, deep));
}
});
onElementExpanded = (
id: ElementID,
deep: boolean,
forceExpand: boolean = false,
) => {
const shouldExpand = forceExpand || !this.elements()[id].expanded;
if (shouldExpand) {
this.updateElement(id, {expanded: shouldExpand});
}
this.getChildren(id, {}).then(children => {
if (deep) {
children.forEach(child =>
this.onElementExpanded(child.id, deep, shouldExpand),
);
}
});
if (!shouldExpand) {
this.updateElement(id, {expanded: shouldExpand});
}
};

View File

@@ -253,6 +253,14 @@ class ElementsRow extends PureComponent<ElementsRowProps, ElementsRowState> {
this.props.onElementExpanded(this.props.id, false);
},
},
{
label: props.element.expanded
? 'Collapse all child elements'
: 'Expand all child elements',
click: () => {
this.props.onElementExpanded(this.props.id, true);
},
},
];
for (const extension of props.contextMenuExtensions) {