Skip to content

Commit 7f4dc39

Browse files
authored
Merge branch 'dev' into BarGraph
2 parents 5f10872 + 44526ef commit 7f4dc39

File tree

8 files changed

+84
-25
lines changed

8 files changed

+84
-25
lines changed

src/app/RTKslices.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createSlice, current } from '@reduxjs/toolkit';
22
import { InitialStateProps } from './FrontendTypes';
3+
import _ from 'lodash';
34

45
const initialState: InitialStateProps = { // we initialize what our initialState is here
56
port: null,
@@ -470,7 +471,38 @@ export const mainSlice = createSlice({
470471
seriesArray.push(newSeries);
471472
localStorage.setItem('project', JSON.stringify(seriesArray));
472473
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: 'saved' };
474+
},
475+
toggleExpanded: (state, action) => {
476+
const { tabs, currentTab } = state;
477+
// find correct node from currLocation and toggle isExpanded
478+
const checkChildren = (node) => {
479+
if (_.isEqual(node, action.payload))
480+
node.isExpanded = !node.isExpanded;
481+
else if (node.children) {
482+
node.children.forEach(child => {
483+
checkChildren(child);
484+
});
473485
}
486+
};
487+
checkChildren(tabs[currentTab].currLocation.stateSnapshot);
488+
},
489+
490+
deleteSeries: (state) => {
491+
const { tabs, currentTab } = state;
492+
const allStorage = () => {
493+
const keys = Object.keys(localStorage);
494+
let i = keys.length;
495+
while (i--) {
496+
localStorage.removeItem(keys[i]);
497+
}
498+
};
499+
allStorage();
500+
Object.keys(tabs).forEach((tab) => {
501+
tabs[tab] = {
502+
...tabs[tab],
503+
};
504+
});
505+
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: false };
474506
}
475507
},
476508
})
@@ -499,7 +531,9 @@ export const {
499531
tutorialSaveSeriesToggle,
500532
onHover,
501533
onHoverExit,
502-
save
534+
save,
535+
toggleExpanded,
536+
deleteSeries
503537
} = mainSlice.actions
504538

505539

src/app/components/StateRoute/ComponentMap/ComponentMap.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import { useTooltip, useTooltipInPortal, defaultStyles } from '@visx/tooltip';
1818
import LinkControls from './LinkControls';
1919
import getLinkComponent from './getLinkComponent';
2020
import ToolTipDataDisplay from './ToolTipDataDisplay';
21-
import { toggleExpanded, setCurrentTabInApp } from '../../../actions/actions';
22-
import { useStoreContext } from '../../../store';
21+
import { toggleExpanded, setCurrentTabInApp } from '../../../RTKslices';
22+
// import { useStoreContext } from '../../../store';
23+
import { useDispatch } from 'react-redux';
2324
import { LinkTypesProps, DefaultMargin, ToolTipStyles } from '../../../FrontendTypes'
2425

2526
const defaultMargin: DefaultMargin = {
@@ -41,7 +42,8 @@ export default function ComponentMap({
4142
const [linkType, setLinkType] = useState('diagonal'); // We create a local state "linkType" and set it to a string 'diagonal'.
4243
const [stepPercent, setStepPercent] = useState(0.5); // We create a local state "stepPercent" and set it to a number '0.5'. This will be used to scale the Map component's link: Step to 50%
4344
const [selectedNode, setSelectedNode] = useState('root'); // We create a local state "selectedNode" and set it to a string 'root'.
44-
const [, dispatch] = useStoreContext(); // we destructure the returned context object from the invocation of the useStoreContext function to get access to our dispatch function
45+
// const [, dispatch] = useStoreContext(); // we destructure the returned context object from the invocation of the useStoreContext function to get access to our dispatch function
46+
const dispatch = useDispatch();
4547

4648
const toolTipTimeoutID = useRef(null); //useRef stores stateful data that’s not needed for rendering.
4749

src/app/components/StateRoute/PerformanceVisx/BarGraphComparison.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import MenuItem from '@mui/material/MenuItem';
1515
import FormControl from '@mui/material/FormControl';
1616
import { useTheme } from '@mui/material/styles';
1717
import { Button, InputLabel } from '@mui/material';
18-
import { onHover, onHoverExit, deleteSeries, setCurrentTabInApp } from '../../../actions/actions';
19-
import { useStoreContext } from '../../../store';
18+
import { onHover, onHoverExit, deleteSeries, setCurrentTabInApp } from '../../../RTKslices';
19+
// import { useStoreContext } from '../../../store';
20+
//importing useSelector and useDispatch for rtk conversion
21+
import { useSelector, useDispatch } from 'react-redux';
2022
import {
2123
snapshot,
2224
TooltipData,
@@ -46,7 +48,12 @@ const tooltipStyles = {
4648
};
4749

4850
const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
49-
const [{ tabs, currentTab }, dispatch] = useStoreContext();
51+
//commented out line 51 to add hooks for RTK transition
52+
// const [{ tabs, currentTab }, dispatch] = useStoreContext();
53+
const dispatch = useDispatch();
54+
const tabs = useSelector(state => state.main.tabs);
55+
const currentTab = useSelector(state => state.main.currentTab);
56+
5057
const {
5158
width, // from ParentSize provided in StateRoute
5259
height, // from ParentSize provided in StateRoute

src/app/components/StateRoute/PerformanceVisx/BarGraphComparisonActions.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import MenuItem from '@mui/material/MenuItem';
1414
import FormControl from '@mui/material/FormControl';
1515
import { useTheme } from '@mui/material/styles';
1616
import { Button } from '@mui/material';
17-
import { deleteSeries, setCurrentTabInApp } from '../../../actions/actions';
18-
import { useStoreContext } from '../../../store';
17+
import { deleteSeries, setCurrentTabInApp } from '../../../RTKslices';
18+
// import { useStoreContext } from '../../../store';
19+
//importing useSelector and useDispatch for rtk conversion
20+
import { useDispatch } from 'react-redux';
1921
import { TooltipData, Margin, BarGraphComparisonAction, ActionObj } from '../../../FrontendTypes';
2022

2123
/* DEFAULTS */
@@ -38,7 +40,9 @@ const tooltipStyles = {
3840
};
3941

4042
const BarGraphComparisonActions = (props: BarGraphComparisonAction) => {
41-
const [dispatch] = useStoreContext(); // used to get the dispatch function from our storeContext
43+
//commented out line 44 to add hooks for RTK transition
44+
// const [dispatch] = useStoreContext(); // used to get the dispatch function from our storeContext
45+
const dispatch = useDispatch();
4246
const {
4347
width, // from ParentSize provided in StateRoute
4448
height, // from ParentSize provided in StateRoute

src/app/components/StateRoute/PerformanceVisx/PerformanceVisx.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import RenderingFrequency from './RenderingFrequency';
88
import BarGraph from './BarGraph';
99
import BarGraphComparison from './BarGraphComparison';
1010
import BarGraphComparisonActions from './BarGraphComparisonActions';
11-
import { useStoreContext } from '../../../store';
12-
import { setCurrentTabInApp } from '../../../actions/actions';
11+
// import { useStoreContext } from '../../../store';
12+
import { useDispatch, useSelector } from 'react-redux';
13+
import { setCurrentTabInApp } from '../../../RTKslices';
1314
import { PerfData, Series, PerformanceVisxProps } from '../../../FrontendTypes';
1415

1516
const collectNodes = (snaps, componentName) => {
@@ -177,7 +178,9 @@ const PerformanceVisx = (props: PerformanceVisxProps): JSX.Element => {
177178
snapshots, // from 'tabs[currentTab]' object in 'MainContainer'
178179
hierarchy // from 'tabs[currentTab]' object in 'MainContainer'
179180
} = props;
180-
const [{ currentTabInApp }, dispatch] = useStoreContext();
181+
// const [{ currentTabInApp }, dispatch] = useStoreContext();
182+
const dispatch = useDispatch();
183+
const { currentTabInApp } = useSelector((state: any) => state.main);
181184
const NO_STATE_MSG = 'No state change detected. Trigger an event to change state';
182185
const data = getPerfMetrics(snapshots, getSnapshotIds(hierarchy));
183186
const [series, setSeries] = useState(true);

src/app/components/StateRoute/PerformanceVisx/RenderingFrequency.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
/* eslint-disable jsx-a11y/no-static-element-interactions */
33
/* eslint-disable react/prop-types */
44
import React, { useState, useEffect } from 'react';
5-
import { onHover, onHoverExit, setCurrentTabInApp } from '../../../actions/actions';
6-
import { useStoreContext } from '../../../store';
5+
// import { onHover, onHoverExit, setCurrentTabInApp } from '../../../actions/actions';
6+
import { setCurrentTabInApp } from '../../../RTKslices';
7+
// import { useStoreContext } from '../../../store';
8+
import { useDispatch, useSelector } from 'react-redux';
79

810
/*
911
1012
*/
1113

1214
const RenderingFrequency = (props) => {
1315
const perfData = props.data;
14-
const [store, dispatch] = useStoreContext();
15-
16+
// const [store, dispatch] = useStoreContext();
17+
const dispatch = useDispatch();
1618
useEffect(() => {
1719
dispatch(setCurrentTabInApp('performance-comparison')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'performance-comparison' to facilitate render.
1820
}, []);
@@ -41,7 +43,9 @@ const RenderingFrequency = (props) => {
4143

4244
const ComponentCard = (props): JSX.Element => {
4345
const { componentName, stateType, averageRenderTime, renderFrequency, information } = props;
44-
const [{ tabs, currentTab }, dispatch] = useStoreContext();
46+
// const [{ tabs, currentTab }, dispatch] = useStoreContext();
47+
// const tabs = useSelector((state:any)=>state.main.tabs)
48+
// const currentTab = useSelector((state:any)=>state.main.currentTab);
4549
const [expand, setExpand] = useState(false);
4650

4751
// render time for each component from each snapshot

src/app/components/StateRoute/Tree.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React, { useEffect } from 'react';
22
import JSONTree from 'react-json-tree'; // React JSON Viewer Component
3-
import { setCurrentTabInApp } from '../../actions/actions';
4-
import { useStoreContext } from '../../store';
3+
import { setCurrentTabInApp } from '../../RTKslices';
4+
// import { useStoreContext } from '../../store';
5+
import { useDispatch } from 'react-redux';
56
import { TreeProps } from '../../FrontendTypes';
67

78
/*
@@ -43,7 +44,8 @@ const Tree = (props: TreeProps) => {
4344
currLocation // from 'tabs[currentTab]' object in 'MainContainer'
4445
} = props;
4546
// @ts-ignore
46-
const [store, dispatch] = useStoreContext();
47+
// const [store, dispatch] = useStoreContext();
48+
const dispatch = useDispatch();
4749

4850
useEffect(() => {
4951
dispatch(setCurrentTabInApp('tree')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'tree' to facilitate render.

src/app/components/WebMetrics.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import React, { useEffect } from 'react';
22
import Charts from 'react-apexcharts';
33
import ReactHover, { Trigger, Hover } from 'react-hover';
44
import { OptionsCursorTrueWithMargin } from '../FrontendTypes';
5-
import { setCurrentTabInApp } from '../actions/actions';
6-
import { useStoreContext } from '../store';
7-
5+
// import { setCurrentTabInApp } from '../actions/actions';
6+
import { setCurrentTabInApp } from '../RTKslices'
7+
// import { useStoreContext } from '../store';
8+
import { useDispatch } from 'react-redux';
89
/*
910
Used to render a single radial graph on the 'Web Metrics' tab
1011
*/
1112

1213
const radialGraph = (props) => {
14+
const dispatch = useDispatch();
1315
const state = {
1416
series: [props.series], // series appears to be the scale at which data is displayed based on the type of webMetrics measured.
1517
options: {
@@ -92,7 +94,8 @@ const radialGraph = (props) => {
9294
},
9395
};
9496

95-
const [store, dispatch] = useStoreContext(); // used to get the dispatch function from our storeContext
97+
// const [store, dispatch] = useStoreContext(); // used to get the dispatch function from our storeContext
98+
9699
useEffect(() => {
97100
dispatch(setCurrentTabInApp('webmetrics')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'webmetrics' to facilitate render.
98101
}, []);

0 commit comments

Comments
 (0)