Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1579. Group cache clean on creation/delete #1594

Merged
merged 1 commit into from
Mar 16, 2017
Merged
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
1 change: 1 addition & 0 deletions web/client/actions/usergroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ module.exports = {
deleteGroup, DELETEGROUP,
STATUS_SUCCESS,
STATUS_LOADING,
STATUS_CREATED,
STATUS_ERROR,
STATUS_DELETED
};
30 changes: 30 additions & 0 deletions web/client/reducers/__tests__/users-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const {
USERMANAGER_UPDATE_USER, USERMANAGER_DELETE_USER, USERMANAGER_GETGROUPS
} = require('../../actions/users');

const {UPDATEGROUP, STATUS_CREATED, DELETEGROUP, STATUS_DELETED} = require('../../actions/usergroups');

describe('Test the users reducer', () => {
it('default loading', () => {
let oldState = {test: "test"};
Expand Down Expand Up @@ -166,5 +168,33 @@ describe('Test the users reducer', () => {
expect(state.groups).toExist();
expect(state.groupsStatus).toBe("success");
});
it('test group cache clean after group creation', () => {
const state = users({}, {
type: USERMANAGER_GETGROUPS,
groups: [{groupName: "group1", id: 10, description: "test"}],
status: "success"
});
expect(state.groups).toExist();
expect(state.groupsStatus).toBe("success");
let stateWOutgroups = users(state, {
type: UPDATEGROUP,
status: STATUS_CREATED
});
expect(stateWOutgroups.group).toBe(undefined);
});
it('test group cache clean after group delete', () => {
const state = users({}, {
type: USERMANAGER_GETGROUPS,
groups: [{groupName: "group1", id: 10, description: "test"}],
status: "success"
});
expect(state.groups).toExist();
expect(state.groupsStatus).toBe("success");
let stateWOutgroups = users(state, {
type: DELETEGROUP,
status: STATUS_DELETED
});
expect(stateWOutgroups.group).toBe(undefined);
});

});
22 changes: 22 additions & 0 deletions web/client/reducers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const {
USERMANAGER_GETUSERS, USERMANAGER_EDIT_USER, USERMANAGER_EDIT_USER_DATA, USERMANAGER_UPDATE_USER, USERMANAGER_DELETE_USER,
USERMANAGER_GETGROUPS, USERS_SEARCH_TEXT_CHANGED
} = require('../actions/users');

const {UPDATEGROUP, STATUS_CREATED, DELETEGROUP, STATUS_DELETED} = require('../actions/usergroups');
const assign = require('object-assign');

const {findIndex} = require('lodash');
Expand Down Expand Up @@ -124,6 +126,26 @@ function users(state = {
groupsError: action.error
});
}
case UPDATEGROUP: {
if (action.status === STATUS_CREATED) {
return assign({}, state, {
groups: null,
groupsStatus: null,
groupsError: null
});
}
return state;
}
case DELETEGROUP: {
if (action.status === STATUS_DELETED) {
return assign({}, state, {
groups: null,
groupsStatus: null,
groupsError: null
});
}
return state;
}
default:
return state;
}
Expand Down