Skip to content

Commit

Permalink
fix: added delete functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mjatin-dev committed Feb 23, 2022
1 parent 4b85cb8 commit 5cd1a66
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
23 changes: 23 additions & 0 deletions admin-ui/plugins/admin/components/Mapping/MappingItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
addPermissionsToRole,
updatePermissionsToServer,
updatePermissionsServerResponse,
deleteMapping,
} from '../../redux/actions/MappingActions'
import GluuTypeAhead from '../../../../app/routes/Apps/Gluu/GluuTypeAhead'
import applicationStyle from '../../../../app/routes/Apps/Gluu/styles/applicationstyle'
Expand Down Expand Up @@ -76,6 +77,14 @@ function MappingItem({ candidate }) {
resetForm()
autocompleteRef.current.clear()
}
const handleDeleteRole = () => {
dispatch(
deleteMapping({
role: candidate.role,
permissions: candidate.permissions,
}),
)
}

return (
<div>
Expand All @@ -86,6 +95,20 @@ function MappingItem({ candidate }) {
<Accordion.Header className="text-info">
<Accordion.Indicator className="mr-2" />
{candidate.role}

<Button
type="button"
color="danger"
onClick={() => handleDeleteRole()}
style={{
margin: '1px',
float: 'right',
padding: '0px',
}}
>
<i className="fa fa-trash mr-2"></i>
Delete
</Button>
<Badge
color="info"
style={{
Expand Down
6 changes: 6 additions & 0 deletions admin-ui/plugins/admin/redux/actions/MappingActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
UPDATE_PERMISSIONS_LOADING,
UPDATE_PERMISSIONS_SERVER_RESPONSE,
ADD_MAPPING_ROLE_PERMISSIONS,
DELETE_MAPPING,
} from './types'

export const getMapping = (action) => ({
Expand Down Expand Up @@ -47,3 +48,8 @@ export const addNewRolePermissions = (data) => ({
type: ADD_MAPPING_ROLE_PERMISSIONS,
payload: { data },
})

export const deleteMapping = (data) => ({
type: DELETE_MAPPING,
payload: { data },
})
1 change: 1 addition & 0 deletions admin-ui/plugins/admin/redux/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const UPDATE_PERMISSIONS_SERVER_RESPONSE =
'UPDATE_PERMISSIONS_SERVER_RESPONSE'
export const UPDATE_PERMISSIONS_LOADING = 'UPDATE_PERMISSIONS_LOADING'
export const ADD_MAPPING_ROLE_PERMISSIONS = 'ADD_MAPPING_ROLE_PERMISSIONS'
export const DELETE_MAPPING = 'DELETE_MAPPING'
//License Details

export const GET_LICENSE_DETAILS = 'GET_LICENSE_DETAILS'
Expand Down
9 changes: 9 additions & 0 deletions admin-ui/plugins/admin/redux/api/MappingApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export default class MappingApi {
})
})
}
deleteMapping = (data) => {
const options = {}
options['rolePermissionMapping'] = data
return new Promise((resolve, reject) => {
this.api.removeRolePermissionsPermission(options, (error, options) => {
this.handleResponse(error, reject, resolve, data)
})
})
}

handleResponse(error, reject, resolve, data) {
if (error) {
Expand Down
18 changes: 18 additions & 0 deletions admin-ui/plugins/admin/redux/sagas/MappingSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
GET_MAPPING,
UPDATE_PERMISSIONS_TO_SERVER,
ADD_MAPPING_ROLE_PERMISSIONS,
DELETE_MAPPING,
} from '../actions/types'
import MappingApi from '../api/MappingApi'
import { getClient } from '../../../../app/redux/api/base'
Expand Down Expand Up @@ -88,10 +89,27 @@ export function* addMapping({ payload }) {
}
}

export function* deleteMapping({ payload }) {
yield put(updatePermissionsLoading(true))
try {
const mappingApi = yield* newFunction()
const data = yield call(mappingApi.deleteMapping, payload.data)
yield put(getMapping({}))
} catch (e) {
yield put(updatePermissionsLoading(false))
// yield put(getMappingResponse(null))
if (isFourZeroOneError(e)) {
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
yield put(getAPIAccessToken(jwt))
}
}
}

export function* watchGetMapping() {
yield takeLatest(GET_MAPPING, fetchMapping)
yield takeEvery(UPDATE_PERMISSIONS_TO_SERVER, updateMapping)
yield takeEvery(ADD_MAPPING_ROLE_PERMISSIONS, addMapping)
yield takeEvery(DELETE_MAPPING, deleteMapping)
}

export default function* rootSaga() {
Expand Down

0 comments on commit 5cd1a66

Please sign in to comment.