Skip to content

Commit 759e5e0

Browse files
authored
Merge pull request #4 from oslabs-beta/daniel
DropDown & Conditional Rendering
2 parents 8f70979 + 80d9880 commit 759e5e0

File tree

3 files changed

+45
-25
lines changed

3 files changed

+45
-25
lines changed
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
import Select from 'react-select';
2-
import React, { useEffect, useState } from 'react';
2+
import React from 'react';
33

4-
const DropDown = (): JSX.Element => {
5-
const [hook, setHook] = useState('useState');
4+
const DropDown = ({ dropdownSelection, setDropdownSelection }: { dropdownSelection: string; setDropdownSelection: (value: string) => void }): JSX.Element => {
5+
const handleChange = (selected: { value: string; label: string }) => {
6+
setDropdownSelection(selected.value);
7+
};
68

7-
const handleChange = (selectedHook: {hooks:string}) => {
8-
setHook(selectedHook);
9-
}
9+
const options = [
10+
{ value: 'TimeJump', label: 'TimeJump' },
11+
{ value: 'Provider/Consumer', label: 'Provider/Consumer' },
12+
];
1013

11-
const options = [
12-
{value: 'useState', label: 'useState'},
13-
{value: 'useReducer', label: 'useReducer'},
14-
{value: 'useContext', label: 'useContext'}
15-
];
14+
return (
15+
<Select
16+
placeholder="Select Hook"
17+
onChange={handleChange}
18+
options={options}
19+
value={options.find((option) => option.value === dropdownSelection)}
20+
/>
21+
);
22+
};
1623

17-
return (
18-
<Select
19-
placeholder = 'Select Hook'
20-
onChange={handleChange}
21-
options = {options}
22-
/>
23-
)
24-
}
25-
export default DropDown;
24+
export default DropDown;

src/app/containers/ActionContainer.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import { emptySnapshots, changeView, changeSlider } from '../slices/mainSlice';
77
import { useDispatch, useSelector } from 'react-redux';
88
import RouteDescription from '../components/Actions/RouteDescription';
99
import DropDown from '../components/Actions/DropDown';
10+
import ProvConContainer from './ProvConContainer';
1011
import { ActionContainerProps, CurrentTab, MainState, Obj, RootState } from '../FrontendTypes';
1112
import { Button, Switch } from '@mui/material';
1213

14+
1315
/*
1416
This file renders the 'ActionContainer'. The action container is the leftmost column in the application. It includes the button that shrinks and expands the action container, a dropdown to select the active site, a clear button, the current selected Route, and a list of selectable snapshots with timestamps.
1517
*/
@@ -25,6 +27,9 @@ const resetSlider = () => {
2527
};
2628

2729
function ActionContainer(props: ActionContainerProps): JSX.Element {
30+
31+
const [dropdownSelection, setDropdownSelection] = useState('TimeJump');
32+
2833
const dispatch = useDispatch();
2934
const { currentTab, tabs, port }: MainState = useSelector((state: RootState) => state.main);
3035

@@ -224,7 +229,10 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
224229
</a>
225230
<SwitchAppDropdown />
226231
{/* add new component here for dropdown menu for useStae/ useReducer- ragad */}
227-
<DropDown />
232+
<DropDown
233+
dropdownSelection = {dropdownSelection}
234+
setDropdownSelection={setDropdownSelection}
235+
/>
228236
<div className='action-component exclude'>
229237
<Button
230238
className='clear-button'
@@ -239,10 +247,12 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
239247
Clear
240248
</Button>
241249
</div>
242-
{/* Rendering of route description components */}
243-
{Object.keys(routes).map((route, i) => (
244-
<RouteDescription key={`route${i}`} actions={routes[route]} />
245-
))}
250+
{dropdownSelection === 'Provider/Consumer' && <ProvConContainer/>}
251+
{dropdownSelection === 'TimeJump' &&
252+
Object.keys(routes).map((route, i) => (
253+
<RouteDescription key={`route${i}`} actions={routes[route]} />
254+
))
255+
}
246256
</div>
247257
) : null}
248258
</div>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from "react";
2+
3+
const ProvConContainer = (): JSX.Element => {
4+
return (
5+
<div>
6+
hello
7+
</div>
8+
)
9+
}
10+
11+
export default ProvConContainer;

0 commit comments

Comments
 (0)