Skip to content

Commit ccf3ca4

Browse files
Bianca PicassoBianca Picasso
authored andcommitted
delete context
Co-authored-by: Sal Saluga [email protected] Co-authored-by: Ken Bains [email protected] Co-authored-by: Huy Pham [email protected]
1 parent c8a1241 commit ccf3ca4

File tree

7 files changed

+40
-6
lines changed

7 files changed

+40
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const ComponentDropDown = ({
8484
sx={{ width: 425 }}
8585
freeSolo
8686
renderInput={params => (
87-
<TextField {...params} label="Select Component" />
87+
<TextField {...params} label="Select Component" helperText='Select a component for your selected context to consume' />
8888
)}
8989
/>
9090
</Box>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const ContextDropDown = ({
8484
sx={{ width: 425 }}
8585
freeSolo
8686
renderInput={params => (
87-
<TextField {...params} label="Select Context" />
87+
<TextField {...params} label="Select Context" helperText='Select a context you would like to assign'/>
8888
)}
8989
/>
9090
</Box>

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ const CreateContainer = () => {
2222

2323
const dispatch = useDispatch();
2424

25-
const handleClickSelectContext = contextInput => {
25+
const handleClickSelectContext = () => {
26+
//prevent user from adding duplicate context
27+
for (let i = 0; i < state.allContext.length; i += 1) {
28+
if (state.allContext[i].name === contextInput.name) {
29+
return;
30+
}
31+
}
2632
dispatch(actions.addContextActionCreator(contextInput));
2733
setState(store.getState().contextSlice);
34+
2835
};
2936

3037
const handleClickInputData = ({ name }, { inputKey, inputValue }) => {
@@ -34,6 +41,12 @@ const CreateContainer = () => {
3441
setState(store.getState().contextSlice);
3542
};
3643

44+
const handleDeleteContextClick = () => {
45+
dispatch(actions.deleteContext(contextInput));
46+
setContextInput('');
47+
setState(store.getState().contextSlice);
48+
};
49+
3750
const renderTable = targetContext => {
3851
if (!targetContext.values) {
3952
setTableState(defaultTableData);
@@ -57,6 +70,7 @@ const CreateContainer = () => {
5770
<AddContextForm
5871
contextStore={state}
5972
handleClickSelectContext={handleClickSelectContext}
73+
handleDeleteContextClick={handleDeleteContextClick}
6074
renderTable={renderTable}
6175
contextInput={contextInput}
6276
setContextInput={setContextInput}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ const filter = createFilterOptions();
1010
const AddContextForm = ({
1111
contextStore,
1212
handleClickSelectContext,
13+
handleDeleteContextClick,
1314
renderTable,
1415
contextInput,
1516
setContextInput
1617
}) => {
1718
const { allContext } = contextStore;
1819
const [btnDisabled, setBtnDisabled] = useState(false);
20+
1921
const handleClick = () => {
2022
if (contextInput === '' || contextInput === null) return;
21-
const temp = contextInput;
22-
setContextInput('');
23-
handleClickSelectContext(temp);
23+
handleClickSelectContext();
2424
};
2525

2626
const onChange = (event, newValue) => {
@@ -108,6 +108,13 @@ const AddContextForm = ({
108108
>
109109
Create
110110
</Button>
111+
<Button
112+
color="error"
113+
variant="contained"
114+
onClick={handleDeleteContextClick}
115+
>
116+
Delete
117+
</Button>
111118
{/* <Button variant="contained">Delete</Button> */}
112119
</Box>
113120
</Fragment>

app/src/redux/actions/actions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ export const addComponentToContext = newEntry => ({
1818
type: types.ADD_COMPONENT_TO_CONTEXT,
1919
payload: newEntry
2020
});
21+
22+
export const deleteContext = (contextInput) => ({
23+
type: types.DELETE_CONTEXT,
24+
payload: contextInput
25+
})

app/src/redux/constants/actionTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export const CODE_PREVIEW_INPUT = 'CODE_PREVIEW_INPUT';
55
export const ADD_CONTEXT = 'ADD_CONTEXT';
66
export const ADD_CONTEXT_VALUES = 'ADD_CONTEXT_VALUES';
77
export const ADD_COMPONENT_TO_CONTEXT = 'ADD_COMPONENT_TO_CONTEXT';
8+
export const DELETE_CONTEXT = 'DELETE_CONTEXT;'

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ const contextReducer = (state = initialState, action) => {
5151
...state,
5252
allContext: newAllContext
5353
};
54+
case types.DELETE_CONTEXT:
55+
const remains = state.allContext.filter((el) => el.name !== action.payload.name)
56+
return {
57+
...state,
58+
allContext : remains
59+
}
60+
5461
case types.ADD_COMPONENT_TO_CONTEXT:
5562
const newTempState = [...state.allContext];
5663

0 commit comments

Comments
 (0)