Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust component tree #34

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified extension/public/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 38 additions & 28 deletions extension/src/components/Tree.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
import React, { useCallback, useState, useEffect } from "react";
import Tree from "react-d3-tree";
import "../css/styles.css";
import DownloadIcon from "@mui/icons-material/Download";
import React, { useCallback, useState, useEffect } from 'react';
import Tree from 'react-d3-tree';
import '../css/styles.css';
import DownloadIcon from '@mui/icons-material/Download';
import IconButton from '@mui/material/IconButton';
import {
customStringify,
sendData,
saveJSON,
} from "../functions/treeHelperFuncs";
} from '../functions/treeHelperFuncs';

interface ComponentTreeProps {
fiberTree: any; // Replace 'any' with the actual type of fiberTree
}

// set up a centered tree visualization
function ComponentTree({ fiberTree }: ComponentTreeProps) {
const useCenteredTree = (defaultTranslate: { x: number; y: number } = { x: 0, y: 0 }) => {
const useCenteredTree = (
defaultTranslate: { x: number; y: number } = { x: 0, y: 0 }
) => {
const [translate, setTranslate] = useState(defaultTranslate);
const [dimensions, setDimensions] = useState<{ width: number; height: number } | undefined>();

const [dimensions, setDimensions] = useState<
{ width: number; height: number } | undefined
>();

const containerRef = useCallback((containerElem: HTMLDivElement | null) => {
if (containerElem !== null) {
const { width, height } = containerElem.getBoundingClientRect();
setDimensions({ width, height });
setTranslate({ x: width / 2, y: height / 12 });
}
}, []);

return [dimensions, translate, containerRef] as const;
};

const [dimensions, translate, containerRef] = useCenteredTree();
const [recButton, setRecButton] = useState<string>("START PROFILING");
const [recButton, setRecButton] = useState<string>('START PROFILING');
const [idk, setIdk] = useState<any[]>([]);
//state for navigating between tree and charts
//const [view, setView] = useState<string>("treeView");
Expand All @@ -50,55 +54,61 @@ function ComponentTree({ fiberTree }: ComponentTreeProps) {
});
}

//update recButton according to recStat
useEffect(() => {
//update recButton according to recStat
useEffect(() => {
if (!recStat) {
setRecButton("Start profiling");
setRecButton('Start profiling');
sendMessageToContentScript({
message: `Hello from popup! ${idk.length}`,
});
setChartData([...idk]);
} else {
setRecButton("Stop profiling");
setRecButton('Stop profiling');
sendMessageToContentScript({
message: `Hello from popup! ${idk.length}`,
});
}
}, [recStat]);

const stringifiedResult = customStringify(fiberTree);

return (
<>
{fiberTree ? (
<div style={{ width: "100vw", height: "100vh" }}>
<IconButton aria-label="delete" onClick={() => saveJSON(fiberTree, "parseTreeData")}>
<DownloadIcon />
</IconButton>
<div style={{ width: '100%', height: '100%' }}>
<IconButton
aria-label='delete'
onClick={() => saveJSON(fiberTree, 'parseTreeData')}
>
<DownloadIcon />
</IconButton>
<div
id="treeWrapper"
id='treeWrapper'
style={{
width: "100%",
height: "100%",
width: '100%',
height: '100%',
}}
ref={containerRef}
>
<Tree
data={fiberTree}
orientation="vertical"
rootNodeClassName="node__root"
branchNodeClassName="node__branch"
leafNodeClassName="node__leaf"
orientation='vertical'
rootNodeClassName='node__root'
branchNodeClassName='node__branch'
leafNodeClassName='node__leaf'
enableLegacyTransitions
translate={translate}
/>
</div>
</div>
) : (
<p>COMPONENT TREE - if your component tree isn't rendering, make sure you have React DevTools installed and try again!</p>
<p>
COMPONENT TREE - if your component tree isn't rendering, make sure you
have React DevTools installed and try again!
</p>
)}
</>
);
}

export default ComponentTree;
export default ComponentTree;
4 changes: 1 addition & 3 deletions extension/src/containers/MetricsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,14 @@ const MetricsTab = ({ queryEvents }: BasicTabsProps) => {
}, [recStat]);

return (
<Box sx={{ display: 'flex', flexDirection: 'column', width: '100%', marginTop: '1rem' }}>
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
<Box sx={{ display: 'flex', flexDirection: 'column', width: '100%', height: '100%', marginTop: '1rem' }}>
<ProfilingToggle onClick={() => setStatus()}>
{recButton}
</ProfilingToggle>
<div className='ct'></div>
{view === 'treeView' && (
<ComponentTree fiberTree={idk[idk.length - 1]} />
)}
</div>
</Box>
);
};
Expand Down
91 changes: 91 additions & 0 deletions package/examples/example-2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package/examples/example-2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"license": "ISC",
"devDependencies": {
"npm-run-all": "^4.1.5"
},
"dependencies": {
"react-query-rewind": "^1.0.1"
}
}
2 changes: 1 addition & 1 deletion package/examples/example-2/server/models/postsOne.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"posts": [
{
"text": "hi",
"liked": true,
"liked": false,
"comments": [
"new",
"hello"
Expand Down