Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/components/2-molecules/AttachDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,25 @@ import {
Divider,
Grid,
Typography,
ListItemText,
List,
IconButton,
ListItem,
} from '@mui/material';
import PropTypes from 'prop-types';
import { useStyles } from './AttachDialogStyles';
import Autocomplete from '../1-atoms/Autocomplete';
import DeleteForeverIcon from '@mui/icons-material/DeleteForever';

const AttachDialog = (props) => {
const { open, handleClose, attachWithFile, networks, attachWithId } = props;
const {
open,
handleClose,
attachWithFile,
networks,
attachWithId,
onDeleteNetwork,
} = props;
const [file, setFile] = useState(null);
const [networkId, setNetworkId] = useState('');
const classes = useStyles();
Expand Down Expand Up @@ -107,6 +119,31 @@ const AttachDialog = (props) => {
)}
</DialogContent>
<Divider />
<DialogContent>
<Typography>Delete a known network :</Typography>
<List>
{networks.map((network) => (
<ListItem
key={network.networkName}
divider
secondaryAction={
<IconButton
onClick={() =>
onDeleteNetwork(network.networkId)
}
edge="end"
aria-label="delete"
>
<DeleteForeverIcon />
</IconButton>
}
>
<ListItemText primary={`${network.networkName}`} />
</ListItem>
))}
</List>
</DialogContent>
<Divider />
<DialogActions>
<Button onClick={closeDialog} color="primary">
Cancel
Expand Down
6 changes: 6 additions & 0 deletions src/containers/MappingContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from '../redux/slices/Mapping';
import { convertScript } from '../redux/slices/Script';
import {
deleteNetwork,
getCurrentNetworkObj,
getNetworkNames,
getPropertyValuesFromFile,
Expand Down Expand Up @@ -128,6 +129,10 @@ const MappingContainer = () => {
dispatch(getPropertyValuesFromFile(file));
}

const handleDeleteNetwork = (networkId) => {
dispatch(deleteNetwork(networkId));
};

function setFilteredType(type) {
dispatch(MappingSlice.actions.changeFilteredType(type));
}
Expand Down Expand Up @@ -256,6 +261,7 @@ const MappingContainer = () => {
handleClose={() => setIsAttachedModalOpen(false)}
attachWithId={attachWithId}
attachWithFile={attachWithFile}
onDeleteNetwork={handleDeleteNetwork}
/>
{editParameters && (
<ParametersContainer
Expand Down
21 changes: 21 additions & 0 deletions src/redux/slices/Network.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ export const getNetworkNames = createAsyncThunk(
}
);

export const deleteNetwork = createAsyncThunk(
'network/delete',
async (networkId, { getState }) => {
const token = getState()?.user.user?.id_token;
return await networkAPI.deleteNetwork(networkId, token);
}
);

const reducers = {
cleanNetwork: (state) => {
state.propertyValues = [];
Expand Down Expand Up @@ -156,6 +164,19 @@ const extraReducers = {
[getNetworkNames.pending]: (state, _action) => {
state.status = RequestStatus.PENDING;
},
[deleteNetwork.fulfilled]: (state, action) => {
state.status = RequestStatus.SUCCESS;
const networkId = action.payload;
state.knownNetworks = state.knownNetworks.filter(
(network) => network.networkId !== networkId
);
},
[deleteNetwork.rejected]: (state, _action) => {
state.status = RequestStatus.ERROR;
},
[deleteNetwork.pending]: (state, _action) => {
state.status = RequestStatus.PENDING;
},
};

export const NetworkSlice = createSlice({
Expand Down
1 change: 1 addition & 0 deletions src/redux/slices/Script.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const deleteScript = createAsyncThunk(
return await scriptsAPI.deleteScript(scriptName, token);
}
);

export const copyScript = createAsyncThunk(
'scripts/copy',
async ({ originalName, copyName }, { getState }) => {
Expand Down
12 changes: 12 additions & 0 deletions src/rest/networkAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,15 @@ export function getNetworkMatchesFromRule(networkId, ruleToMatch, token) {
token
);
}

export function deleteNetwork(networkId, token) {
return backendFetchJson(`${API_URL}/${networkId}`, {
method: 'DELETE',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
},
cache: 'default',
});
}