Skip to content

Commit 66ac1fa

Browse files
authored
Merge pull request #4 from oslabs-beta/walkthrough
Created new component for tutorial walkthrough
2 parents 37f7106 + b4f3410 commit 66ac1fa

22 files changed

+1028
-266
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"@types/jest": "^26.0.4",
9292
"@types/lodash.isequal": "^4.5.5",
9393
"@types/node": "^12.19.6",
94+
"@types/react": "^17.0.43",
9495
"@typescript-eslint/eslint-plugin": "^3.6.1",
9596
"@typescript-eslint/parser": "^3.6.1",
9697
"babel-loader": "^8.1.0",
@@ -135,6 +136,8 @@
135136
"@fortawesome/free-solid-svg-icons": "^5.15.1",
136137
"@fortawesome/react-fontawesome": "^0.1.12",
137138
"@material-ui/core": "^4.11.2",
139+
"@types/react-dom": "^17.0.14",
140+
"@types/react-router-dom": "^5.3.3",
138141
"@visx/axis": "^1.0.0",
139142
"@visx/brush": "^1.2.0",
140143
"@visx/clip-path": "^1.0.0",
@@ -160,6 +163,8 @@
160163
"d3-shape": "^2.0.0",
161164
"d3-zoom": "^1.8.3",
162165
"immer": "^9.0.12",
166+
"intro.js": "^5.0.0",
167+
"intro.js-react": "^0.6.0",
163168
"jest-runner": "^26.1.0",
164169
"jscharting": "^3.0.2",
165170
"jsondiffpatch": "^0.3.11",

src/app/__tests__/action.test.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ describe('unit testing for Action.tsx', () => {
4545
wrapper.setProps({ selected: false });
4646
expect(wrapper.hasClass('action-component selected')).toEqual(false);
4747
});
48-
test('should have a text that is equal to props.index', () => {
49-
expect(wrapper.find('.action-component-text').text()).toEqual(`${props.displayName}: ${props.componentName} `);
50-
});
5148

5249
test('should invoke dispatch method when clicked', () => {
5350
wrapper.find('.action-component').simulate('click');

src/app/components/Action.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ const Action = (props: ActionProps): JSX.Element => {
9696
};
9797

9898
return (
99-
<div
99+
<div className="individual-action">
100+
<div
100101
// Invoking keyboard functionality; functionality is in ActionContainer;
101-
onKeyDown={e => handleOnkeyDown(e, viewIndex)}
102-
className={
102+
onKeyDown={e => handleOnkeyDown(e, viewIndex)}
103+
className={
103104
selected || last ? 'action-component selected' : 'action-component'
104105
}
105106
onClick={() => {
@@ -113,7 +114,7 @@ const Action = (props: ActionProps): JSX.Element => {
113114
<Trigger type="trigger">
114115
<div className="action-component-trigger" style={index > sliderIndex ? { color: '#5f6369' } : {}}>
115116
<div className="action-component-text">
116-
{`${displayName}: ${componentName !== 'nameless' ? componentName : ''} `}
117+
<input key={`ActionInput${displayName}`} type="text" className="actionname" placeholder={`${displayName}: ${componentName !== 'nameless' ? componentName : ''} `} />
117118
</div>
118119
<button className="time-button" type="button">
119120
{displayTime}
@@ -142,10 +143,11 @@ const Action = (props: ActionProps): JSX.Element => {
142143
</button>
143144
)
144145
}
145-
</div>
146-
</Trigger>
147-
<Hover type="hover" />
148-
</ReactHover>
146+
</div>
147+
</Trigger>
148+
<Hover type="hover" />
149+
</ReactHover>
150+
</div>
149151
</div>
150152
);
151153
};

src/app/components/App.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import React, { useReducer } from 'react';
1+
import React, { useReducer, useState } from 'react';
2+
// import { Steps, Hints } from 'intro.js-react';
23
import MainContainer from '../containers/MainContainer';
34
import { StoreContext } from '../store';
45
import mainReducer from '../reducers/mainReducer.js';
56

7+
// import 'intro.js/introjs.css';
8+
69
const initialState: {
710
port: null | number,
811
currentTab: null | number,

src/app/components/BarGraph.tsx

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-nocheck
2-
import React, { useEffect, useRef } from 'react';
2+
import React, { useEffect, useState } from 'react';
33
import { BarStack } from '@visx/shape';
44
import { SeriesPoint } from '@visx/shape/lib/types';
55
import { Group } from '@visx/group';
@@ -61,7 +61,8 @@ const tooltipStyles = {
6161

6262
const BarGraph = props => {
6363
const [{ tabs, currentTab }, dispatch] = useStoreContext();
64-
const { width, height, data } = props;
64+
const { width, height, data, comparison } = props;
65+
const [ seriesNameInput, setSeriesNameInput ] = useState(`Series ${comparison.length}`);
6566
const {
6667
tooltipOpen,
6768
tooltipLeft,
@@ -123,39 +124,32 @@ const BarGraph = props => {
123124
}
124125
});
125126

126-
// const test = 0;
127-
128-
// let textbox;
129-
// function textboxCreator() {
130-
// if (test === 0) {
131-
// textbox = <input type="text" className="seriesname" placeholder="Series Name" />
132-
// }
133-
// test++;
134-
// }
135-
136-
// const textbox = tabs[currentTab].seriesSavedStatus === 'inputBoxOpen' ? <input type="text" className="seriesname" placeholder="Series Name" /> : null
127+
const saveSeriesClickHandler = () => {
128+
if (tabs[currentTab].seriesSavedStatus === 'inputBoxOpen') {
129+
const actionNames = document.getElementsByClassName('actionname');
130+
for (let i = 0; i < actionNames.length; i++ ) {
131+
toStorage.data.barStack[i].name = actionNames[i].value;
132+
}
133+
dispatch(save(toStorage, seriesNameInput));
134+
setSeriesNameInput(`Series ${comparison.length}`)
135+
return
136+
}
137+
dispatch(save(toStorage))
138+
}
137139

140+
const textbox = tabs[currentTab].seriesSavedStatus === 'inputBoxOpen' ? <input type="text" id="seriesname" value={seriesNameInput} onChange={e => setSeriesNameInput(e.target.value)} /> : null;
138141
return (
139142
<div className="bargraph-position">
140-
<input type="text" id ="seriesname" placeholder="Series Name" />
143+
{/* <input type="text" id ="seriesname" placeholder="Series Name" /> */}
144+
{textbox}
141145
<button
142146
type="button"
143147
className="save-series-button"
144-
onClick={e => {
145-
// textboxCreator();
146-
const seriesName = document.getElementById('seriesname').value;
147-
console.log("seriesName", seriesName)
148-
// render text box if not already rendered
149-
// grab text from textbox
150-
// dispatch save tostorage if text is being passed in
151-
// if not do nothing
152-
dispatch(save(toStorage, seriesName));
153-
}}
148+
onClick={saveSeriesClickHandler}
154149
>
155150
Save Series
156151
</button>
157152
<svg ref={containerRef} width={width} height={height}>
158-
{}
159153
<rect
160154
x={0}
161155
y={0}
@@ -191,7 +185,7 @@ const BarGraph = props => {
191185
}
192186
return (
193187
<rect
194-
key={`bar-stack-${barStack.id}-${bar.id}`}
188+
key={`bar-stack-${bar.bar.data.snapshotId}-${bar.key}`}
195189
x={bar.x}
196190
y={bar.y}
197191
height={bar.height === 0 ? null : bar.height}

src/app/components/BarGraphComparison.tsx

Lines changed: 31 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,11 @@ const tooltipStyles = {
7070
const BarGraphComparison = props => {
7171
const [{ tabs, currentTab }, dispatch] = useStoreContext();
7272
const {
73-
width, height, data, comparison,
73+
width, height, data, comparison, setSeries, series, setAction
7474
} = props;
75-
const [series, setSeries] = React.useState(0);
7675
const [snapshots, setSnapshots] = React.useState(0);
7776
const [open, setOpen] = React.useState(false);
7877
const [picOpen, setPicOpen] = React.useState(false);
79-
const [maxRender, setMaxRender] = React.useState(data.maxTotalRender);
80-
81-
function titleFilter(comparisonArray) {
82-
// const comparisonArrayModded = comparisonArray[0];
83-
console.log('titleFilter', comparisonArray);
84-
return comparisonArray.filter(
85-
elem => elem.title.split('-')[1] === tabs[currentTab].title.split('-')[1],
86-
);
87-
}
8878

8979
const currentIndex = tabs[currentTab].sliderIndex;
9080

@@ -121,9 +111,6 @@ const BarGraphComparison = props => {
121111
// with the render time of the current tab.
122112
// The max render time will determine the Y-axis's highest number.
123113
const calculateMaxTotalRender = series => {
124-
console.log(comparison)
125-
console.log(series)
126-
// let currentMax = 5
127114
const currentSeriesBarStacks = !comparison[series]
128115
? []
129116
: comparison[series].data.barStack;
@@ -175,45 +162,37 @@ const BarGraphComparison = props => {
175162

176163
const classes = useStyles();
177164

178-
const handleChange = event => {
165+
const handleSeriesChange = event => {
179166
setSeries(event.target.value);
180-
// setXpoints();
167+
setAction(false);
181168
};
182169

183170
const handleClose = () => {
184171
setOpen(false);
185-
// setXpoints();
186172
};
187173

188174
const handleOpen = () => {
189175
setOpen(true);
190-
// setXpoints();
191176
};
192177

193-
const picHandleChange = event => {
194-
setSnapshots(`${(event.target.value + 1).toString()}.0`);
195-
// setXpoints();
178+
const handleActionChange = event => {
179+
setAction(event.target.value);
180+
setSeries(false);
196181
};
197182

198183
const picHandleClose = () => {
199184
setPicOpen(false);
200-
// setXpoints();
201185
};
202186

203187
const picHandleOpen = () => {
204188
setPicOpen(true);
205-
// setXpoints();
206189
};
207190

208191
// manually assignin X -axis points with tab ID.
209192
function setXpointsComparison() {
210193
comparison[series].data.barStack.forEach(elem => {
211194
elem.currentTab = 'comparison';
212195
});
213-
// comparison[series].data.barStack.currentTab = currentTab;
214-
console.log(comparison)
215-
console.log(series)
216-
console.log(comparison[series].data.barStack)
217196
return comparison[series].data.barStack;
218197
}
219198
function setXpointsCurrentTab() {
@@ -235,6 +214,15 @@ const BarGraphComparison = props => {
235214
for (let i = 0; i < classname.length; i++) {
236215
classname[i].addEventListener('click', animateButton, false);
237216
}
217+
const seriesList = comparison.map(elem => elem.data.barStack);
218+
const actionsList = seriesList.flat();
219+
const testList = actionsList.map(elem => elem.name);
220+
221+
const finalList = [];
222+
for (let i = 0; i < testList.length; i++) {
223+
if (testList[i] !== "" && !finalList.includes(testList[i])) finalList.push(testList[i]);
224+
}
225+
238226
return (
239227
<div>
240228
<div className="series-options-container">
@@ -248,7 +236,7 @@ const BarGraphComparison = props => {
248236
>
249237
Clear All Series
250238
</button>
251-
<h4 style={{ padding: '0 1rem' }}>Comparison Series: </h4>
239+
<h4 style={{ padding: '0 1rem' }}>Compare Series: </h4>
252240
<FormControl variant="outlined" className={classes.formControl}>
253241
<Select
254242
style={{ color: 'white' }}
@@ -259,21 +247,18 @@ const BarGraphComparison = props => {
259247
onClose={handleClose}
260248
onOpen={handleOpen}
261249
value={series}
262-
onChange={handleChange}
250+
onChange={handleSeriesChange}
263251
>
264-
{!comparison[series] ? (
252+
{!comparison.length ? (
265253
<MenuItem>No series available</MenuItem>
266254
) : (
267-
// titleFilter(comparison).map((tabElem, index) => (
268-
// <MenuItem value={index}>{`Series ${index + 1}`}</MenuItem>
269-
// ))
270255
comparison.map((tabElem, index) => (
271-
<MenuItem value={index}>{tabElem.name}</MenuItem>
256+
<MenuItem key={`MenuItem${tabElem.name}`} value={index}>{tabElem.name}</MenuItem>
272257
))
273258
)}
274259
</Select>
275260
</FormControl>
276-
{/* <h4 style={{ padding: '0 1rem' }}>Comparator Snapshot? </h4>
261+
<h4 style={{ padding: '0 1rem' }}>Compare Actions </h4>
277262
<FormControl variant="outlined" className={classes.formControl}>
278263
<Select
279264
style={{ color: 'white' }}
@@ -283,20 +268,19 @@ const BarGraphComparison = props => {
283268
open={picOpen}
284269
onClose={picHandleClose}
285270
onOpen={picHandleOpen}
286-
value={snapshots} //snapshots
287-
onChange={picHandleChange}
271+
value={''} //snapshots
272+
onChange={handleActionChange}
288273
>
289274
{!comparison[snapshots] ? (
290275
<MenuItem>No snapshots available</MenuItem>
291276
) : (
292-
titleFilter(comparison).map((tabElem, index) => {
293-
return (
294-
<MenuItem value={index}>{`${index + 1}`}</MenuItem>
295-
);
296-
})
297-
)}
277+
finalList.map((elem, index) => (
278+
<MenuItem value={elem}>{elem}</MenuItem>
279+
// <MenuItem value="test">{}</MenuItem>
280+
)))
281+
}
298282
</Select>
299-
</FormControl> */}
283+
</FormControl>
300284
</div>
301285
</div>
302286

@@ -335,7 +319,7 @@ const BarGraphComparison = props => {
335319
// Uses map method to iterate through all components,
336320
// creating a rect component (from visx) for each iteration.
337321
// height/width/etc. are calculated by visx.
338-
// to set X and Y scale, it will used the passed in function and
322+
// to set X and Y scale, it will used the p`assed in function and
339323
// will run it on the array thats outputted by data
340324
const bar = barStack.bars[currentIndex];
341325
if (Number.isNaN(bar.bar[1]) || bar.height < 0) {
@@ -379,6 +363,8 @@ const BarGraphComparison = props => {
379363
// Comparison Barstack (populates based on series selected)
380364
// to set X and Y scale, it will used the passed in function and
381365
// will run it on the array thats outputted by data
366+
// setXpointsComparison()}
367+
// comparison[series].data.barStack
382368
data={!comparison[series] ? [] : setXpointsComparison()}
383369
keys={keys}
384370
x={getCurrentTab}

0 commit comments

Comments
 (0)