debugger icon indicating copy to clipboard operation
debugger copied to clipboard

[Component] Remove Prototype from Component Pane

Open mmcote opened this issue 8 years ago • 1 comments

Within the props and state of the component pane, the prototype should not be able to be seen.

To get the component pane to appear simply pause inside a react component. The example used in the image below is from pausing in the App component from: https://ahfarmer.github.io/emoji-search/.

image

Not a 100% sure if this will be any help but to get and filter out the <prototype>, here is some code. I was hoping to simply wrap the newly filtered children in a their respective roots of either state or props to present in the pane.

diff --git a/src/components/SecondaryPanes/FrameworkComponent.js b/src/components/SecondaryPanes/FrameworkComponent.js
index e03e0ef8..5dfb06d2 100644
--- a/src/components/SecondaryPanes/FrameworkComponent.js
+++ b/src/components/SecondaryPanes/FrameworkComponent.js
@@ -17,7 +17,7 @@ import { isReactComponent } from "../../utils/preview";
 
 import type { Frame } from "../../types";
 
-const { createNode, getChildren } = ObjectInspectorUtils.node;
+const { createNode, getChildren, NODE_TYPES } = ObjectInspectorUtils.node;
 const { loadItemProperties } = ObjectInspectorUtils.loadProperties;
 
 type Props = {
@@ -27,29 +27,55 @@ type Props = {
 };

 class FrameworkComponent extends PureComponent<Props> {
-  async componentWillMount() {
-    const expression = "this;";
-    const { selectedFrame, setPopupObjectProperties } = this.props;
+  getRoot() {
+    const expression = "this";
+    const { selectedFrame } = this.props;
     const value = selectedFrame.this;
 
-    const root = createNode({ name: expression, contents: { value } });
+    return createNode({
+      name: expression,
+      path: expression,
+      contents: { value }
+    });
+  }
+
+  async componentWillMount() {
+    const { setPopupObjectProperties } = this.props;
+    const root = this.getRoot();
+
     const properties = await loadItemProperties(root, createObjectClient);
     if (properties) {
-      setPopupObjectProperties(value, properties);
+      setPopupObjectProperties(root.contents.value, properties);
+
+      const roots = getChildren({
+        item: root,
+        loadedProperties: new Map([[root.path, properties]])
+      });
+
+      const stateRoot = roots.find(r => r.name == "state");
+      const stateProps = await loadItemProperties(
+        stateRoot,
+        createObjectClient
+      );
+      if (stateProps) {
+        setPopupObjectProperties(stateRoot.contents.value, stateProps);
+      }
+
+      const propsRoot = roots.find(r => r.name == "props");
+      const props = await loadItemProperties(propsRoot, createObjectClient);
+      if (props) {
+        setPopupObjectProperties(propsRoot.contents.value, props);
+      }
     }
   }
 
   renderReactComponent() {
-    const { selectedFrame, popupObjectProperties } = this.props;
-    const expression = "this;";
-    const value = selectedFrame.this;
-    const root = {
-      name: expression,
-      path: expression,
-      contents: { value }
-    };
+    const { popupObjectProperties } = this.props;
+    const root = this.getRoot();
+
+    const loadedRootProperties =
+      popupObjectProperties[root.contents.value.actor];
 
-    const loadedRootProperties = popupObjectProperties[value.actor];
     if (!loadedRootProperties) {
       return null;
     }
@@ -59,8 +85,32 @@ class FrameworkComponent extends PureComponent<Props> {
       loadedProperties: new Map([[root.path, loadedRootProperties]])
     });
 
-    roots = roots.filter(r => ["state", "props"].includes(r.name));
+    const stateRoot = roots.find(r => r.name == "state");
+    const stateProperties =
+      popupObjectProperties[stateRoot.contents.value.actor];
+
+    const propsRoot = roots.find(r => r.name == "props");
+    const propsProperties =
+      popupObjectProperties[propsRoot.contents.value.actor];
+
+    if (!stateProperties || !propsProperties) {
+      return null;
+    }
+
+    let stateRoots = getChildren({
+      item: stateRoot,
+      loadedProperties: new Map([[stateRoot.path, stateProperties]])
+    });
+
+    let propsRoots = getChildren({
+      item: propsRoot,
+      loadedProperties: new Map([[propsRoot.path, propsProperties]])
+    });
+
+    stateRoots = stateRoots.filter(r => r.type != NODE_TYPES.PROTOTYPE);
+    propsRoots = propsRoots.filter(r => r.type != NODE_TYPES.PROTOTYPE);

+    roots = roots.filter(r => r.name == "state" || r.name == "props");
     return (
       <div className="pane framework-component">
         <ObjectInspector

mmcote avatar Apr 20 '18 21:04 mmcote

this is a nice to have, which we can wait on. so moving to the icebox.

jasonLaster avatar May 23 '18 21:05 jasonLaster