Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #38 from sarbull/react
Browse files Browse the repository at this point in the history
Hide console.log via debug prop parameter
  • Loading branch information
pmarius22 authored Aug 4, 2022
2 parents 518549f + 3a3d306 commit b44c38c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 24 deletions.
1 change: 0 additions & 1 deletion package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function App() {
<div className="container">
<HappiGraph rawData={{...rawData}}
algorithm={""}
debug={false}
graphDirection={"VERTICAL"}
selectedNodeId={"term@68e36496-7167-4af7-abdd-a0cd36e24084:6662c0f2.e1b1ec6c.66k78i6du.uchsna1.rn2epa.rfn2fjqf7h4qvmt5lflm8"}
actions={<HappiGraphActions rawData={{...rawData}}/>} />
Expand Down
17 changes: 9 additions & 8 deletions src/components/HappiGraph/happi-graph-legend.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import {
graphNodesUpdateInLegendData
} from './happi-graph-legend.render';

import { v4 as uuidv4 } from 'uuid';

interface Props {
nodes: any;
links: any;
debug?: boolean;
}

interface State {
nodes: any;
links: any;
isMinimised: boolean;
legendData: any;
debug: boolean;
}

/**
Expand All @@ -37,6 +37,7 @@ class HappiGraphLegend extends React.Component<Props, State> {
super(props);

this.state = {
debug: props.debug ? true : false,
nodes: [...props.nodes],
links: [...props.links],
isMinimised: true,
Expand All @@ -50,7 +51,7 @@ class HappiGraphLegend extends React.Component<Props, State> {
}

componentDidMount() {
const { nodes, links } = this.state;
const { nodes, links, debug } = this.state;

let data = {};

Expand All @@ -59,7 +60,7 @@ class HappiGraphLegend extends React.Component<Props, State> {
...graphNodesUpdateInLegendData(nodes)
};

console.log(data);
debug && console.log(data);

this.setState({
legendData: { ...data }
Expand All @@ -72,25 +73,25 @@ class HappiGraphLegend extends React.Component<Props, State> {
return (<>
<div className="happi-graph-legend">
<div className="toggler">
<MantineSwitch label="Legend" checked={!isMinimised} onClick={() => { this.toggleMinimise() }} />
<MantineSwitch label="Legend" checked={!isMinimised} onChange={() => { this.toggleMinimise() }} />
</div>

<div className="contents">
{ legendData && !isMinimised && getLegendCategories(legendData).map((legendKey: any, legendKeyId: number) => {
return <><div className="icon-title" key={`${uuidv4()}-${legendKeyId}`}>
return <div key={legendKeyId}><div className="icon-title">
<b>{ legendKey }</b>
</div>

<div className="svg-icons">
{ legendData && legendKey && getLegendLabels(legendData, legendKey).map((label: any, labelId: number) => {
return <div className="svg-icon" key={`${uuidv4()}-${labelId}`}>
return <div className="svg-icon" key={`${labelId}`}>
<img src={ `data:image/svg+xml;utf8,${ getIcon(legendKey, label, legendData) }` } alt="icon" />

<span>{ label }</span>
</div>
}) }
</div>
</>}) }
</div>}) }
</div>
</div>
</>);
Expand Down
25 changes: 14 additions & 11 deletions src/components/HappiGraph/happi-graph.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class HappiGraph extends React.Component<Props, State> {
constructor(props: Props) {
super(props);

console.warn('render()');

const mappedNodes = mapNodes(props.rawData.nodes, props.selectedNodeId);
const mappedLinks = mapLinks(props.rawData.edges, mappedNodes);

Expand Down Expand Up @@ -142,26 +140,30 @@ class HappiGraph extends React.Component<Props, State> {
}

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 =
Expand All @@ -174,8 +176,8 @@ class HappiGraph extends React.Component<Props, State> {
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,
Expand Down Expand Up @@ -225,7 +227,8 @@ class HappiGraph extends React.Component<Props, State> {
nodes,
links,
allGroup,
isFullscreen
isFullscreen,
debug
} = this.state;

return (<>
Expand Down Expand Up @@ -298,7 +301,7 @@ class HappiGraph extends React.Component<Props, State> {
</div>

<div className="happi-graph-legend-wrapper">
<HappiGraphLegend nodes={nodes} links={links}/>
<HappiGraphLegend nodes={nodes} links={links} debug={debug}/>
</div>
</div>
</>);
Expand Down
6 changes: 3 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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);

0 comments on commit b44c38c

Please sign in to comment.