Skip to content

Commit 6eeaa01

Browse files
committed
finished mvp
Co-authored-by: Sal Saluga [email protected] Co-authored-by: Ken Bains [email protected] Co-authored-by: Bianca Picasso [email protected]
1 parent 3e059ef commit 6eeaa01

File tree

6 files changed

+34
-27
lines changed

6 files changed

+34
-27
lines changed

app/src/components/ContextAPIManager/AssignTab/AssignContainer.tsx

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import React, { useContext, useState, Fragment, useEffect } from 'react';
22
import DataTable from '../CreateTab/components/DataTable';
3-
import { useStore } from 'react-redux';
3+
import { useStore, useDispatch } from 'react-redux';
44
import ContextDropDown from './components/ContextDropDown';
55
import ComponentDropDown from './components/ComponentDropDrown';
66
import Divider from '@mui/material/Divider';
77
import Grid from '@mui/material/Grid';
88
import ComponentTable from './components/ComponentTable';
99
import { Button } from '@mui/material';
1010
import DoubleArrowIcon from '@mui/icons-material/DoubleArrow';
11+
import * as actions from '../../../redux/actions/actions';
1112

1213
const AssignContainer = () => {
14+
const store = useStore();
15+
const dispatch = useDispatch();
16+
1317
const [state, setState] = useState([]);
1418
const defaultTableData = [{ key: 'Key', value: 'Value' }];
1519
const [tableState, setTableState] = React.useState(defaultTableData);
16-
const store = useStore();
1720
const [contextInput, setContextInput] = React.useState(null);
1821
const [componentInput, setComponentInput] = React.useState(null);
1922
const [componentTable, setComponentTable] = useState([]);
@@ -29,25 +32,33 @@ const AssignContainer = () => {
2932
setTableState(targetContext.values);
3033
}
3134
};
35+
//checks if state is no longer an array, thus an object and will eventually render out the fetched
36+
const renderComponentTable = targetComponent => {
37+
//target Component is main
3238

33-
const renderComponentTable = targetContext => {
34-
console.log('current component is', targetContext);
35-
if (!targetContext.values) {
36-
const listOfContexts = [];
37-
if (!Array.isArray(state)) {
38-
state.allContext.forEach(context => {
39-
console.log('each context is', context);
40-
if (context.components.includes(targetContext))
41-
listOfContexts.push(context.name);
42-
});
43-
}
44-
// setComponentTable(defaultTableData);
39+
const listOfContexts = [];
40+
if (!Array.isArray(state)) {
41+
state.allContext.forEach(context => {
42+
if (context.components.includes(targetComponent.name)) {
43+
listOfContexts.push(context.name);
44+
}
45+
});
4546
setComponentTable(listOfContexts);
46-
} else {
47-
setComponentTable(targetContext.values);
4847
}
4948
};
5049

50+
const handleAssignment = () => {
51+
dispatch(
52+
actions.addComponentToContext({
53+
context: contextInput,
54+
component: componentInput
55+
})
56+
);
57+
58+
setState(store.getState().contextSlice);
59+
renderComponentTable(componentInput);
60+
};
61+
5162
return (
5263
<Fragment>
5364
<Grid container display="flex" justifyContent="space-evenly">
@@ -75,7 +86,7 @@ const AssignContainer = () => {
7586
</Grid>
7687
</Grid>
7788
<Divider orientation="vertical" variant="middle" flexItem>
78-
<Button>
89+
<Button onClick={handleAssignment}>
7990
<DoubleArrowIcon fontSize="large" color="primary" />
8091
</Button>
8192
</Divider>

app/src/components/ContextAPIManager/AssignTab/components/ComponentDropDrown.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ const ComponentDropDown = ({
1313
setComponentInput
1414
}) => {
1515
const { allContext } = contextStore;
16-
const [componentList, dispatch] = useContext(StateContext);
16+
const [componentList] = useContext(StateContext);
1717

18-
console.log('list of components', componentList);
1918
const onChange = (event, newValue) => {
2019
if (typeof newValue === 'string') {
2120
setComponentInput({

app/src/components/ContextAPIManager/AssignTab/components/ComponentTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function DataTable({ target }) {
3434
<Table sx={{ width: '510px' }} aria-label="customized table">
3535
<TableHead>
3636
<TableRow>
37-
<StyledTableCell>Key</StyledTableCell>
37+
<StyledTableCell>Contexts Consumed</StyledTableCell>
3838
</TableRow>
3939
</TableHead>
4040
<TableBody>

app/src/components/ContextAPIManager/CreateTab/CreateContainer.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const CreateContainer = () => {
3434
};
3535

3636
const renderTable = targetContext => {
37-
console.log(targetContext);
3837
if (!targetContext.values) {
3938
setTableState(defaultTableData);
4039
} else {

app/src/components/ContextAPIManager/CreateTab/components/AddDataForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const AddDataForm = ({ handleClickInputData, contextInput }) => {
1919
};
2020
});
2121
};
22-
console.log(contextInput)
22+
2323
return (
2424
<Fragment>
2525
<Typography style={{ color: 'black' }} variant="h6" gutterBottom={true}>

app/src/redux/reducers/slice/contextReducer.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ const contextReducer = (state = initialState, action) => {
3636
};
3737

3838
case types.ADD_CONTEXT_VALUES:
39-
// console.log('payload is', action.payload);
40-
4139
const newAllContext = [...state.allContext];
4240

4341
for (let i = 0; i < newAllContext.length; i += 1) {
@@ -53,12 +51,12 @@ const contextReducer = (state = initialState, action) => {
5351
...state,
5452
allContext: newAllContext
5553
};
56-
case types.ADD_COMPONENT_TO_CONTEXT:
54+
case types.ADD_COMPONENT_TO_CONTEXT:
5755
const newTempState = [...state.allContext];
5856

5957
for (let i = 0; i < newTempState.length; i += 1) {
60-
if (newTempState[i].name === action.payload.context) {
61-
newTempState[i].components.push(action.payload.component);
58+
if (newTempState[i].name === action.payload.context.name) {
59+
newTempState[i].components.push(action.payload.component.name);
6260
}
6361
}
6462

0 commit comments

Comments
 (0)