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, limitEnabled: true,
bulkSelect: [], bulkSelect: [],
applySamePermissions: [], applySamePermissions: [],
isEditing: false,
}; };
const defaultPresetsState = { const defaultPresetsState = {

View File

@ -250,15 +250,18 @@ const modifyReducer = (tableName, schemas, modifyStateOrig, action) => {
}, },
}; };
case PERM_OPEN_EDIT: case PERM_OPEN_EDIT:
const isNewRole = modifyState.permissionsState.newRole === action.role;
const permState = getBasePermissionsState( const permState = getBasePermissionsState(
action.tableSchema, action.tableSchema,
action.role, action.role,
action.query action.query,
isNewRole
); );
return { return {
...modifyState, ...modifyState,
permissionsState: { permissionsState: {
...permState, ...permState,
isEditing: true,
}, },
prevPermissionState: { prevPermissionState: {
...permState, ...permState,
@ -396,11 +399,17 @@ const modifyReducer = (tableName, schemas, modifyStateOrig, action) => {
}; };
case PERM_SET_ROLE_NAME: case PERM_SET_ROLE_NAME:
const newRole = action.data;
const role = modifyState.permissionsState.isEditing
? newRole
: modifyState.permissionsState.role;
return { return {
...modifyState, ...modifyState,
permissionsState: { permissionsState: {
...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'; return query === 'insert' ? 'check' : 'filter';
}; };
const getBasePermissionsState = (tableSchema, role, query) => { const getBasePermissionsState = (tableSchema, role, query, isNewRole) => {
const _permissions = JSON.parse(JSON.stringify(defaultPermissionsState)); const _permissions = JSON.parse(JSON.stringify(defaultPermissionsState));
_permissions.table = tableSchema.table_name; _permissions.table = tableSchema.table_name;
@ -165,7 +165,9 @@ const getBasePermissionsState = (tableSchema, role, query) => {
} }
} }
}); });
} else { }
if (isNewRole) {
_permissions.newRole = role; _permissions.newRole = role;
} }

View File

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