From 3a3d3069060fb92bc561e8a84377cf9b76297846 Mon Sep 17 00:00:00 2001 From: Sirbu Nicolae-Cezar Date: Thu, 4 Aug 2022 15:11:44 +0300 Subject: [PATCH] Hide console.log via debug prop parameter Signed-off-by: Sirbu Nicolae-Cezar --- package-lock.json | 1 - package.json | 1 - src/components/App/index.tsx | 1 + .../happi-graph-legend.component.tsx | 17 +++++++------ .../HappiGraph/happi-graph.component.tsx | 25 +++++++++++-------- src/index.tsx | 6 ++--- 6 files changed, 27 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6dce5fb..875ec5c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,6 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-icons": "^4.4.0", - "uuid": "8.3.2", "vis-network": "^9.1.2", "web-vitals": "2.1.4", "web-worker": "1.2.0" diff --git a/package.json b/package.json index 080307d..68ad3bd 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-icons": "^4.4.0", - "uuid": "8.3.2", "vis-network": "^9.1.2", "web-vitals": "2.1.4", "web-worker": "1.2.0" diff --git a/src/components/App/index.tsx b/src/components/App/index.tsx index 1dedf33..ed8dc64 100644 --- a/src/components/App/index.tsx +++ b/src/components/App/index.tsx @@ -20,6 +20,7 @@ export function App() {
} /> diff --git a/src/components/HappiGraph/happi-graph-legend.component.tsx b/src/components/HappiGraph/happi-graph-legend.component.tsx index 7370f37..9043786 100644 --- a/src/components/HappiGraph/happi-graph-legend.component.tsx +++ b/src/components/HappiGraph/happi-graph-legend.component.tsx @@ -10,11 +10,10 @@ import { graphNodesUpdateInLegendData } from './happi-graph-legend.render'; -import { v4 as uuidv4 } from 'uuid'; - interface Props { nodes: any; links: any; + debug?: boolean; } interface State { @@ -22,6 +21,7 @@ interface State { links: any; isMinimised: boolean; legendData: any; + debug: boolean; } /** @@ -37,6 +37,7 @@ class HappiGraphLegend extends React.Component { super(props); this.state = { + debug: props.debug ? true : false, nodes: [...props.nodes], links: [...props.links], isMinimised: true, @@ -50,7 +51,7 @@ class HappiGraphLegend extends React.Component { } componentDidMount() { - const { nodes, links } = this.state; + const { nodes, links, debug } = this.state; let data = {}; @@ -59,7 +60,7 @@ class HappiGraphLegend extends React.Component { ...graphNodesUpdateInLegendData(nodes) }; - console.log(data); + debug && console.log(data); this.setState({ legendData: { ...data } @@ -72,25 +73,25 @@ class HappiGraphLegend extends React.Component { return (<>
- { this.toggleMinimise() }} /> + { this.toggleMinimise() }} />
{ legendData && !isMinimised && getLegendCategories(legendData).map((legendKey: any, legendKeyId: number) => { - return <>
+ return
{ legendKey }
{ legendData && legendKey && getLegendLabels(legendData, legendKey).map((label: any, labelId: number) => { - return
+ return
icon { label }
}) }
- }) } +
}) }
); diff --git a/src/components/HappiGraph/happi-graph.component.tsx b/src/components/HappiGraph/happi-graph.component.tsx index fc3e8ee..e49e53c 100644 --- a/src/components/HappiGraph/happi-graph.component.tsx +++ b/src/components/HappiGraph/happi-graph.component.tsx @@ -54,8 +54,6 @@ class HappiGraph extends React.Component { constructor(props: Props) { super(props); - console.warn('render()'); - const mappedNodes = mapNodes(props.rawData.nodes, props.selectedNodeId); const mappedLinks = mapLinks(props.rawData.edges, mappedNodes); @@ -142,26 +140,30 @@ class HappiGraph extends React.Component { } componentDidMount() { - const { happiGraph } = this.state; + const { happiGraph, debug } = this.state; - console.log("componentDidMount()", this.state); + debug && console.log("componentDidMount()", this.state); this.setState({ svg: d3.select(happiGraph.current) }, () => { this.selectAlgorithm(() => { - console.log('Everything is ready.'); + debug && console.log('Everything is ready.'); this.init(); }); }); } componentDidUpdate() { - console.log("componentDidUpdate()", this.state); + const { debug } = this.state; + + debug && console.log("componentDidUpdate()", this.state); } init() { - console.log('init()'); + const { debug } = this.state; + + debug && console.log('init()'); const { svg, nodes, links, graphDirection } = this.state; const allGroup = @@ -174,8 +176,8 @@ class HappiGraph extends React.Component { let svgWidth = parseInt(svg.style('width')); let svgHeight = parseInt(svg.style('height')); - console.log('svgWitdh = ', svgWidth); - console.log('svgHeight = ', svgHeight); + debug && console.log('svgWitdh = ', svgWidth); + debug && console.log('svgHeight = ', svgHeight); this.setState({ allGroup: allGroup, @@ -225,7 +227,8 @@ class HappiGraph extends React.Component { nodes, links, allGroup, - isFullscreen + isFullscreen, + debug } = this.state; return (<> @@ -298,7 +301,7 @@ class HappiGraph extends React.Component {
- +
); diff --git a/src/index.tsx b/src/index.tsx index dee6399..8163e2e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,6 +1,6 @@ -import React from 'react'; +// import React from 'react'; import ReactDOM from 'react-dom/client'; -import reportWebVitals from './reportWebVitals'; +// import reportWebVitals from './reportWebVitals'; import { App } from './components/App'; @@ -17,4 +17,4 @@ root.render( // If you want to start measuring performance in your app, pass a function // to log results (for example: reportWebVitals(console.log)) // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals -reportWebVitals(console.log); +// reportWebVitals(console.log);