INNER CODE UNIT · JavaScript
handleUpdate
infrahq/infra · ui/pages/destinations/[id]/index.js:195
function handleUpdate(newPrivilege, selectedPrivilege, resource) {
// update to add roles
if (newPrivilege.length > selectedPrivilege.length) {
const newRole = newPrivilege.filter(x => !selectedPrivilege.includes(x))
onUpdate(newRole, resource)
} else {
// update to delete roles
const removeRoles = selectedPrivilege.filter(
x => !newPrivilege.includes(x)
)
const deleteGrantIdList = grantsList
.filter(g => g.resource === resource)
.filter(g => g.user === grant.user)
.filter(g => g.group === grant.group)
.filter(g => removeRoles.includes(g.privilege))
.map(g => g.id)
onRemove(deleteGrantIdList)