Skip to content

Commit

Permalink
Bugfix/tagging rerender (#66)
Browse files Browse the repository at this point in the history
* Fix tag re-render bug

Had to prop drill rather than update a context variable.

* Improve analysis window performance
  • Loading branch information
tubarao312 authored Feb 8, 2024
1 parent 2876abf commit 9dd5093
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
8 changes: 2 additions & 6 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
Expand All @@ -32,4 +28,4 @@
"port": 5000
}
}
}
}
3 changes: 1 addition & 2 deletions src/components/graph/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ interface GraphContextProps {
getNodeCount: () => number;
setShowTutorial: (show: boolean) => void;
addNewAddressToCenter: (address: string) => void;
storedSetNodeCustomTags: null | ((tags: string[]) => void);
storeSetNodeCustomTags: (setter: (tags: string[]) => void) => void;
addMultipleDifferentPaths: (pathArgs: PathExpansionArgs[]) => void;
focusedAddressData: AddressAnalysis | null;
Expand Down Expand Up @@ -692,7 +691,6 @@ const GraphProvided: FC<GraphProvidedProps> = ({
setShowTutorial,
addNewAddressToCenter,
addMultipleDifferentPaths,
storedSetNodeCustomTags,
storeSetNodeCustomTags,
focusedAddressData,
};
Expand All @@ -704,6 +702,7 @@ const GraphProvided: FC<GraphProvidedProps> = ({
<MemoedDraggableWindow
analysisData={focusedAddressData}
onExit={onAddressFocusOff}
setNodeCustomTags={storedSetNodeCustomTags}
/>
<ReactFlow
nodes={nodes}
Expand Down
11 changes: 7 additions & 4 deletions src/components/graph/analysis_window/AnalysisWindow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, createContext, useRef, useState, useEffect } from "react";
import { FC, createContext, memo, useRef, useState, useEffect } from "react";
import clsx from "clsx";
import {
PresentationChartLineIcon,
Expand Down Expand Up @@ -39,23 +39,24 @@ export const AnalysisModes: AnalysisMode[] = [
{
name: AnalysisModeNames.Overview,
icon: EyeIcon,
component: Overview,
component: memo(Overview),
},
{
name: AnalysisModeNames.Transactions,
icon: ArrowsRightLeftIcon,
component: Transactions,
component: memo(Transactions),
},
{
name: AnalysisModeNames.Advanced,
icon: PresentationChartLineIcon,
component: Advanced,
component: memo(Advanced),
},
];

interface DraggableWindowProps {
analysisData: AddressAnalysis | null;
onExit: () => void;
setNodeCustomTags: null | ((tags: string[]) => void);
}

/** The draggable window that appears when an address is clicked on.
Expand All @@ -74,6 +75,7 @@ interface DraggableWindowProps {
const DraggableWindow: FC<DraggableWindowProps> = ({
analysisData,
onExit,
setNodeCustomTags,
}) => {
const [hasBeenHovered, setHasBeenHovered] = useState<boolean>(false);
const [analysisMode, setAnalysisMode] = useState<AnalysisMode>(
Expand Down Expand Up @@ -159,6 +161,7 @@ const DraggableWindow: FC<DraggableWindowProps> = ({
onExit={onExit}
setAnalysisMode={setAnalysisMode}
analysisMode={analysisMode}
setNodeCustomTags={setNodeCustomTags}
/>
</div>
<div className="relative flex-auto overflow-hidden">
Expand Down
15 changes: 10 additions & 5 deletions src/components/graph/analysis_window/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,12 @@ function getCategoryRisk(category: string): number {

// Label + Tag + Tag Input Wrapped Component

const LabelsAndTags: FC = () => {
interface LabelsAndTagsProps {
setNodeCustomTags: null | ((tags: string[]) => void);
}

const LabelsAndTags: FC<LabelsAndTagsProps> = ({ setNodeCustomTags }) => {
const { analysisData, address } = useContext(AnalysisContext);
const { storedSetNodeCustomTags } = useContext(GraphContext);

// Labels get displayed first in the flex-wrap
const labels = analysisData!.labels;
Expand Down Expand Up @@ -198,8 +201,8 @@ const LabelsAndTags: FC = () => {
);

useEffect(() => {
if (storedSetNodeCustomTags && addressCustomTags !== null) {
storedSetNodeCustomTags(addressCustomTags);
if (setNodeCustomTags && addressCustomTags !== null) {
setNodeCustomTags(addressCustomTags);
}
}, [addressCustomTags]);

Expand Down Expand Up @@ -234,12 +237,14 @@ interface HeaderProps {
onExit: () => void;
setAnalysisMode: (mode: AnalysisMode) => void;
analysisMode: AnalysisMode;
setNodeCustomTags: null | ((tags: string[]) => void);
}

const Header: FC<HeaderProps> = ({
onExit,
setAnalysisMode,
analysisMode,
setNodeCustomTags,
}: HeaderProps) => {
// Extract analysisData from context
const { addMultipleDifferentPaths } = useContext(GraphContext);
Expand Down Expand Up @@ -349,7 +354,7 @@ const Header: FC<HeaderProps> = ({
</span>
<span className="flex flex-row items-center justify-start gap-x-1.5">
{/* List of labels using Badges shown underneath the address. */}
<LabelsAndTags />
<LabelsAndTags setNodeCustomTags={setNodeCustomTags} />
</span>
</div>
</span>
Expand Down

0 comments on commit 9dd5093

Please sign in to comment.