Skip to content

Commit 44526ef

Browse files
authored
Merge pull request #13 from oslabs-beta/ctstamper/migrate-SRComponents
migrated ComponentMap, PerformancesVisx, and Tree to RTK
2 parents 3b67c24 + 63136eb commit 44526ef

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

src/app/RTKslices.tsx

Lines changed: 17 additions & 0 deletions
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,
@@ -432,6 +433,21 @@ export const mainSlice = createSlice({
432433
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: action.payload }
433434

434435
},
436+
toggleExpanded: (state, action) => {
437+
const { tabs, currentTab } = state;
438+
// find correct node from currLocation and toggle isExpanded
439+
const checkChildren = (node) => {
440+
if (_.isEqual(node, action.payload))
441+
node.isExpanded = !node.isExpanded;
442+
else if (node.children) {
443+
node.children.forEach(child => {
444+
checkChildren(child);
445+
});
446+
}
447+
};
448+
checkChildren(tabs[currentTab].currLocation.stateSnapshot);
449+
},
450+
435451
deleteSeries: (state) => {
436452
const { tabs, currentTab } = state;
437453
const allStorage = () => {
@@ -474,6 +490,7 @@ export const {
474490
toggleMode,
475491
importSnapshots,
476492
tutorialSaveSeriesToggle,
493+
toggleExpanded,
477494
deleteSeries
478495
} = mainSlice.actions
479496

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/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/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.

0 commit comments

Comments
 (0)