Skip to content

Commit aba81bc

Browse files
committed
css refractoring on create context form. Also clearing existing errors.
1 parent 380fdc8 commit aba81bc

File tree

3 files changed

+60
-40
lines changed

3 files changed

+60
-40
lines changed

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

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import AddContextForm from './components/AddContextForm';
99
import * as actions from '../../../redux/actions/actions';
1010

1111
const CreateContainer = () => {
12-
const defaultTableData = [{key: 'Enter Key', value: 'Enter value'}]
12+
const defaultTableData = [{ key: 'Enter Key', value: 'Enter value' }];
1313
const store = useStore();
1414
const [state, setState] = useState([]);
1515
const [tableState, setTableState] = React.useState(defaultTableData);
@@ -27,40 +27,53 @@ const CreateContainer = () => {
2727
};
2828

2929
const handleClickInputData = ({ name }, { inputKey, inputValue }) => {
30-
dispatch(actions.addContextValuesActionCreator({ name, inputKey, inputValue }));
30+
dispatch(
31+
actions.addContextValuesActionCreator({ name, inputKey, inputValue })
32+
);
3133
setState(store.getState().contextSlice);
3234
};
3335

3436
const renderTable = targetContext => {
35-
if (!targetContext.values[0]) {
37+
console.log(targetContext)
38+
if (!targetContext.values) {
3639
setTableState(defaultTableData);
3740
} else {
3841
setTableState(targetContext.values);
3942
}
4043
};
4144
return (
4245
<>
43-
<Grid container spacing={2}>
44-
<Grid
45-
item
46-
xs={6}
47-
display="flex"
48-
direction="column"
49-
justifyContent="center"
50-
alignItems="center"
51-
>
52-
<AddContextForm
53-
contextStore={state}
54-
handleClickSelectContext={handleClickSelectContext}
55-
renderTable={renderTable}
56-
contextInput={contextInput}
57-
setContextInput={setContextInput}
58-
/>
59-
<Divider variant="middle" sx={{ mb: 3 }} />
60-
<AddDataForm handleClickInputData={handleClickInputData} contextInput={contextInput}/>
61-
</Grid>
46+
<Grid container display="flex" justifyContent="space-evenly" >
47+
<Grid item >
48+
<Grid
49+
container
50+
spacing={2}
51+
display="flex"
52+
direction="column"
53+
justifyContent="center"
54+
alignItems="center"
55+
>
56+
<Grid item >
57+
<AddContextForm
58+
contextStore={state}
59+
handleClickSelectContext={handleClickSelectContext}
60+
renderTable={renderTable}
61+
contextInput={contextInput}
62+
setContextInput={setContextInput}
63+
/>
64+
</Grid>
6265

63-
<Grid item xs={6}>
66+
<Divider variant="middle" />
67+
<Grid item >
68+
<AddDataForm
69+
handleClickInputData={handleClickInputData}
70+
contextInput={contextInput}
71+
/>
72+
</Grid>
73+
</Grid>
74+
</Grid>
75+
<Divider orientation="vertical" variant="middle" flexItem />
76+
<Grid item>
6477
<DataTable target={tableState} />
6578
</Grid>
6679
</Grid>

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

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,53 @@ const AddContextForm = ({
1515
setContextInput
1616
}) => {
1717
const { allContext } = contextStore;
18-
18+
const [btnDisabled, setBtnDisabled] = useState(false);
1919
const handleClick = () => {
2020
if (contextInput === '' || contextInput === null) return;
2121
const temp = contextInput;
2222
setContextInput('');
2323
handleClickSelectContext(temp);
2424
};
2525

26-
const autoOnChange = (event, newValue) => {
26+
const onChange = (event, newValue) => {
2727
if (typeof newValue === 'string') {
2828
setContextInput({
2929
name: newValue
3030
});
3131
} else if (newValue && newValue.inputValue) {
3232
// Create a new contextInput from the user input
33+
//console.log(newValue,newValue.inputValue)
3334
setContextInput({
34-
name: newValue.inputValue
35+
name: newValue.inputValue,
36+
values: []
3537
});
38+
renderTable(newValue);
39+
3640
} else {
3741
setContextInput(newValue);
3842
renderTable(newValue);
3943
}
4044
};
4145

42-
const autoFitler = (options, params) => {
46+
const filterOptions = (options, params) => {
47+
// setBtnDisabled(true);
4348
const filtered = filter(options, params);
44-
4549
const { inputValue } = params;
4650
// Suggest the creation of a new contextInput
47-
const isExisting = options.some(
48-
option => inputValue === option.name
49-
// console.log(inputValue)
50-
);
51+
const isExisting = options.some(option => inputValue === option.name);
5152
if (inputValue !== '' && !isExisting) {
5253
filtered.push({
5354
inputValue,
5455
name: `Add "${inputValue}"`
5556
});
57+
58+
// setBtnDisabled(false);
5659
}
5760

5861
return filtered;
5962
};
6063

61-
const autoGetOptions = option => {
64+
const getOptionLabel = option => {
6265
// Value selected with enter, right from the input
6366
if (typeof option === 'string') {
6467
return option;
@@ -71,7 +74,7 @@ const AddContextForm = ({
7174
return option.name;
7275
};
7376

74-
const autoRenderOptions = (props, option) => (
77+
const renderOption = (props, option) => (
7578
<li {...props}>{option.name}</li>
7679
);
7780

@@ -84,21 +87,25 @@ const AddContextForm = ({
8487
<Autocomplete
8588
id="autoCompleteContextField"
8689
value={contextInput}
87-
onChange={autoOnChange}
88-
filterOptions={autoFitler}
90+
onChange={onChange}
91+
filterOptions={filterOptions}
8992
selectOnFocus
9093
clearOnBlur
9194
handleHomeEndKeys
9295
options={allContext || []}
93-
getOptionLabel={autoGetOptions}
94-
renderOption={autoRenderOptions}
96+
getOptionLabel={getOptionLabel}
97+
renderOption={renderOption}
9598
sx={{ width: 425 }}
9699
freeSolo
97100
renderInput={params => (
98101
<TextField {...params} label="Create/Select Context" />
99102
)}
100103
/>
101-
<Button variant="contained" onClick={handleClick}>
104+
<Button
105+
variant="contained"
106+
onClick={handleClick}
107+
disabled={btnDisabled ? true : false}
108+
>
102109
Create
103110
</Button>
104111
{/* <Button variant="contained">Delete</Button> */}

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-
22+
console.log(contextInput)
2323
return (
2424
<Fragment>
2525
<Typography style={{ color: 'black' }} variant="h6" gutterBottom={true}>

0 commit comments

Comments
 (0)