Skip to content

Commit 0064cde

Browse files
authored
Merge pull request #24 from oslabs-beta/ui-fixes
UI fixes
2 parents b803ed1 + bc350bc commit 0064cde

File tree

6 files changed

+68
-55
lines changed

6 files changed

+68
-55
lines changed

__tests__/BottomTabs.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,6 @@ describe('Customization Panel', () => {
199199
const panel = screen.getByTestId('customization');
200200
expect(within(panel).getAllByRole('textbox')).toHaveLength(4);
201201
// check dropdowns
202-
expect(within(panel).getAllByRole('button')).toHaveLength(11);
202+
expect(within(panel).getAllByRole('button')).toHaveLength(12);
203203
});
204204
});

app/src/components/ContextAPIManager/ContextManager.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const ContextManager = (props): JSX.Element => {
4242
<TabContext value={value}>
4343
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
4444
<TabList onChange={handleChange} centered={true} sx={{color:color}}>
45-
<Tab style={ { color: color }}label="Create/Edit" value="1" />
45+
<Tab style={{ color: color }}label="Create/Edit" value="1" />
4646
<Tab style={{ color: color }} label="Assign" value="2" />
4747
<Tab style={{ color: color }} label="Display" value="3" />
4848
</TabList>

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

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Fragment, useState, useEffect, useContext } from 'react';
1+
import React, { Fragment, useState } from 'react';
22
import TextField from '@mui/material/TextField';
33
import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
44
import Button from '@mui/material/Button';
@@ -19,15 +19,17 @@ const AddContextForm = ({
1919
}) => {
2020
const { allContext } = contextStore;
2121
const [btnDisabled, setBtnDisabled] = useState(false);
22-
// const [state, dispatch] = useContext(StateContext);
23-
const { state, isDarkMode } = useSelector((store:RootState) => ({
22+
const { state, isDarkMode } = useSelector((store: RootState) => ({
2423
isDarkMode: store.darkMode.isDarkMode,
2524
state: store.appState
26-
}))
27-
const color = isDarkMode ? 'white' : 'black'
25+
}));
26+
const color = isDarkMode ? 'white' : 'black';
2827

2928
const handleClick = () => {
30-
if (contextInput === '' || contextInput === null) return;
29+
if (contextInput === '' || contextInput === null) {
30+
window.alert('must enter context name');
31+
return;
32+
}
3133
handleClickSelectContext();
3234
};
3335

@@ -54,7 +56,7 @@ const color = isDarkMode ? 'white' : 'black'
5456
const filtered = filter(options, params);
5557
const { inputValue } = params;
5658
// Suggest the creation of a new contextInput
57-
const isExisting = options.some(option => inputValue === option.name);
59+
const isExisting = options.some((option) => inputValue === option.name);
5860
if (inputValue !== '' && !isExisting) {
5961
filtered.push({
6062
inputValue,
@@ -67,7 +69,7 @@ const color = isDarkMode ? 'white' : 'black'
6769
return filtered;
6870
};
6971

70-
const getOptionLabel = option => {
72+
const getOptionLabel = (option) => {
7173
// Value selected with enter, right from the input
7274
if (typeof option === 'string') {
7375
return option;
@@ -80,7 +82,11 @@ const color = isDarkMode ? 'white' : 'black'
8082
return option.name;
8183
};
8284

83-
const renderOption = (props, option) => <li style={{ color: 'black' }} {...props}>{option.name}</li>;
85+
const renderOption = (props, option) => (
86+
<li style={{ color: 'black' }} {...props}>
87+
{option.name}
88+
</li>
89+
);
8490

8591
return (
8692
<Fragment>
@@ -101,13 +107,16 @@ const color = isDarkMode ? 'white' : 'black'
101107
renderOption={renderOption}
102108
sx={{ width: 425, border: '1px solid black' }}
103109
freeSolo
104-
renderInput={params => (
105-
<TextField {...params} InputProps={{
106-
...params.InputProps,
107-
style: { color: color },
108-
}}
109-
variant='filled'
110-
label="Create/Select Context" />
110+
renderInput={(params) => (
111+
<TextField
112+
{...params}
113+
InputProps={{
114+
...params.InputProps,
115+
style: { color: color }
116+
}}
117+
variant="filled"
118+
label="Create/Select Context"
119+
/>
111120
)}
112121
/>
113122
<Button
@@ -124,10 +133,9 @@ const color = isDarkMode ? 'white' : 'black'
124133
>
125134
Delete
126135
</Button>
127-
{/* <Button variant="contained">Delete</Button> */}
128136
</Box>
129137
</Fragment>
130138
);
131139
};
132140

133-
export default AddContextForm;
141+
export default AddContextForm;

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

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@ import TextField from '@mui/material/TextField';
33
import Button from '@mui/material/Button';
44
import Box from '@mui/material/Box';
55
import { Typography } from '@mui/material';
6-
import {useSelector} from 'react-redux'
6+
import { useSelector } from 'react-redux';
77
import { RootState } from '../../../../redux/store';
88

99
const AddDataForm = ({ handleClickInputData, contextInput }) => {
1010
//const [contextInput, setContextInput] = React.useState(null);
11-
const defaultInputData = {inputKey: '', inputValue: ''};
11+
const defaultInputData = { inputKey: '', inputValue: '' };
1212
const [dataContext, setDataContext] = React.useState(defaultInputData);
13-
const { isDarkMode } = useSelector((store:RootState)=> store.darkMode)
13+
const { isDarkMode } = useSelector((store: RootState) => store.darkMode);
1414
const saveData = () => {
1515
setDataContext(defaultInputData);
16-
handleClickInputData(contextInput, dataContext)
17-
}
18-
const color = isDarkMode ? 'white' : 'black';
16+
if (dataContext.inputKey === '' || dataContext.inputValue === '') {
17+
window.alert('empty key or value');
18+
return;
19+
}
20+
handleClickInputData(contextInput, dataContext);
21+
};
22+
const color = isDarkMode ? 'white' : 'black';
1923

20-
const handleChange = e => {
21-
setDataContext(prevDataContext => {
24+
const handleChange = (e) => {
25+
setDataContext((prevDataContext) => {
2226
return {
2327
...prevDataContext,
2428
[e.target.name]: e.target.value
@@ -29,38 +33,35 @@ const color = isDarkMode ? 'white' : 'black';
2933
return (
3034
<Fragment>
3135
<Typography style={{ color: color }} variant="h6" gutterBottom={true}>
32-
Add context data
36+
Add context data
3337
</Typography>
34-
<Box sx={{ display: 'flex', gap: 2, color:'black' }}>
38+
<Box sx={{ display: 'flex', gap: 2, color: 'black' }}>
3539
<TextField
3640
id="outlined-basic"
3741
label="Key"
3842
variant="outlined"
3943
value={dataContext.inputKey}
4044
name="inputKey"
41-
onChange={e => handleChange(e)}
42-
InputProps={{style: { color: color }}}
43-
style={{border:'1px solid black'}}
45+
onChange={(e) => handleChange(e)}
46+
InputProps={{ style: { color: color } }}
47+
style={{ border: '1px solid black' }}
4448
/>
4549
<TextField
4650
id="outlined-basic"
4751
label="Value"
4852
variant="outlined"
4953
value={dataContext.inputValue}
5054
name="inputValue"
51-
onChange={e => handleChange(e)}
52-
style={{border:'1px solid black'}}
53-
InputProps={{ style: { color: color }}}
55+
onChange={(e) => handleChange(e)}
56+
style={{ border: '1px solid black' }}
57+
InputProps={{ style: { color: color } }}
5458
/>
55-
<Button
56-
variant="contained"
57-
onClick={saveData}
58-
>
59+
<Button variant="contained" onClick={saveData}>
5960
Save
6061
</Button>
6162
</Box>
6263
</Fragment>
6364
);
6465
};
6566

66-
export default AddDataForm;
67+
export default AddDataForm;
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
1-
import React, { useEffect, useState} from 'react';
2-
import { useStore, useSelector } from 'react-redux';
1+
import React, { useEffect, useState } from 'react';
2+
import { useSelector } from 'react-redux';
33
import { Chart } from 'react-google-charts';
44
import Grid from '@mui/material/Grid';
55
import { RootState } from '../../../redux/store';
66

77
const DisplayContainer = () => {
8-
const allContext = useSelector((store:RootState) => store.contextSlice);
9-
// const { allContext } = store.getState().contextSlice;
8+
const allContext = useSelector(
9+
(store: RootState) => store.contextSlice.allContext
10+
);
1011
const [contextData, setContextData] = useState([]);
1112

12-
//build data for Google charts, tree rendering
1313
useEffect(() => {
14-
transformData(allContext);
14+
transformData();
1515
}, []);
1616

17-
const transformData = contexts => {
18-
const formattedData = contexts
19-
.map(el => {
20-
return el.components.map(component => {
21-
return [`App - ${el.name} - ${component}`];
17+
//formats context data for use in react google charts
18+
const transformData = () => {
19+
const formattedData = allContext
20+
.map((obj) => {
21+
return obj.components.map((component) => {
22+
return [`App ⎯⎯ ${obj.name} ⎯⎯ ${component}`];
2223
});
2324
})
2425
.flat();
2526
setContextData([['Phrases'], ...formattedData]);
2627
};
2728

29+
//format options for google chart
2830
const options = {
2931
wordtree: {
3032
format: 'implicit',
3133
word: 'App'
3234
}
3335
};
36+
3437
return (
3538
<Grid container display="flex" justifyContent="center">
39+
{contextData.length < 2 && <h2>No Contexts consumed</h2>}
3640
<Grid item>
3741
<Chart
3842
chartType="WordTree"
@@ -45,4 +49,4 @@ const DisplayContainer = () => {
4549
</Grid>
4650
);
4751
};
48-
export default DisplayContainer;
52+
export default DisplayContainer;

app/src/components/bottom/BottomTabs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ const useStyles = makeStyles((theme) => ({
174174
textTransform: 'initial',
175175
minWidth: 40,
176176
// fontWeight: theme.typography.fontWeightRegular,
177-
// marginRight: theme.spacing(2), // JZ: updated syntax as per deprecation warning
178-
// marginLeft: theme.spacing(2),
177+
marginRight: '16px',
178+
marginLeft: '16px',
179179

180180
fontFamily: [
181181
'-apple-system',

0 commit comments

Comments
 (0)