fix setting new role name when perm edit is open (closes #2682) (#2997)

This commit is contained in:
Rishichandra Wawhal 2019-10-15 18:49:23 +05:30 committed by Rikin Kachhia
parent 61d6610ed6
commit 86ab64232d
4 changed files with 17 additions and 5 deletions

View File

@ -33,6 +33,7 @@ const defaultPermissionsState = {
limitEnabled: true,
bulkSelect: [],
applySamePermissions: [],
isEditing: false,
};
const defaultPresetsState = {

View File

@ -250,15 +250,18 @@ const modifyReducer = (tableName, schemas, modifyStateOrig, action) => {
},
};
case PERM_OPEN_EDIT:
const isNewRole = modifyState.permissionsState.newRole === action.role;
const permState = getBasePermissionsState(
action.tableSchema,
action.role,
action.query
action.query,
isNewRole
);
return {
...modifyState,
permissionsState: {
...permState,
isEditing: true,
},
prevPermissionState: {
...permState,
@ -396,11 +399,17 @@ const modifyReducer = (tableName, schemas, modifyStateOrig, action) => {
};
case PERM_SET_ROLE_NAME:
const newRole = action.data;
const role = modifyState.permissionsState.isEditing
? newRole
: modifyState.permissionsState.role;
return {
...modifyState,
permissionsState: {
...modifyState.permissionsState,
newRole: action.data,
newRole: newRole,
role: role,
},
};

View File

@ -120,7 +120,7 @@ const getFilterKey = query => {
return query === 'insert' ? 'check' : 'filter';
};
const getBasePermissionsState = (tableSchema, role, query) => {
const getBasePermissionsState = (tableSchema, role, query, isNewRole) => {
const _permissions = JSON.parse(JSON.stringify(defaultPermissionsState));
_permissions.table = tableSchema.table_name;
@ -165,7 +165,9 @@ const getBasePermissionsState = (tableSchema, role, query) => {
}
}
});
} else {
}
if (isNewRole) {
_permissions.newRole = role;
}

View File

@ -512,7 +512,7 @@ class Permissions extends Component {
};
const getEditSection = (tableSchema, queryTypes, roleList) => {
if (!permissionsState.role || !permissionsState.query) {
if (!permissionsState.isEditing) {
return;
}