diff --git a/package.json b/package.json index 1b002b9..5f5ca30 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sn-redux", - "version": "3.2.1", + "version": "3.2.2", "description": "A set of redux actions, reducers and redux-ovbservable epics for Sense/Net ECM", "main": "dist/src/sn-redux.js", "scripts": { diff --git a/src/Actions.ts b/src/Actions.ts index 83d3014..e6bbca8 100644 --- a/src/Actions.ts +++ b/src/Actions.ts @@ -719,7 +719,13 @@ export module Actions { export const DeSelectContent = (id) => ({ type: 'DESELECT_CONTENT', id - }) + })/** + * Action creator for clearing the array of selected content + * @returns {Object} Returns a redux action. + */ + export const ClearSelection = () => ({ + type: 'CLEAR_SELECTION' + }) /** * Action creator for a request for get actions of a content by a given scenario. * @param content {Content} The name of the scenario diff --git a/src/Reducers.ts b/src/Reducers.ts index daea077..45dca6a 100644 --- a/src/Reducers.ts +++ b/src/Reducers.ts @@ -195,10 +195,11 @@ export module Reducers { */ export const entities = (state = {}, action) => { if (action.response && ( - action.type !== 'USER_LOGIN_SUCCESS' && - action.type !== 'USER_LOGIN_BUFFER' && + action.type !== 'USER_LOGIN_SUCCESS' && + action.type !== 'USER_LOGIN_BUFFER' && action.type !== 'LOAD_CONTENT_SUCCESS' && - action.type !== 'REQUEST_CONTENT_ACTIONS_SUCCESS')) { + action.type !== 'REQUEST_CONTENT_ACTIONS_SUCCESS' && + action.type !== 'UPDATE_CONTENT_SUCCESS')) { return (Object).assign({}, state, action.response.entities.entities); } switch (action.type) { @@ -206,6 +207,9 @@ export module Reducers { let res = Object.assign({}, state); delete res[action.id]; return res; + case 'UPDATE_CONTENT_SUCCESS': + state[action.response.Id] = action.response + return state default: return state; } @@ -581,6 +585,8 @@ export module Reducers { case 'DESELECT_CONTENT': const index = state.indexOf(action.id) return [...state.slice(0, index), ...state.slice(index + 1)] + case 'CLEAR_SELECTION': + return [] default: return state } @@ -646,7 +652,7 @@ export module Reducers { export const getChildrenActions = (state) => { return state.actions } - + export const getCurrentContent = (state) => { return state.currentcontent.content } diff --git a/test/ActionsTests.ts b/test/ActionsTests.ts index 8cdd533..2bbc372 100644 --- a/test/ActionsTests.ts +++ b/test/ActionsTests.ts @@ -572,6 +572,14 @@ describe('Actions', () => { expect(Actions.DeSelectContent(1)).to.deep.equal(expectedAction) }) }) + describe('ClearSelection', () => { + it('should return the clear selection action', () => { + const expectedAction = { + type: 'CLEAR_SELECTION' + } + expect(Actions.ClearSelection()).to.deep.equal(expectedAction) + }) + }) describe('RequestContentActions', () => { const content = Content.Create({ DisplayName: 'My content', Id: 123 }, ContentTypes.Task, repo) diff --git a/test/ReducersTests.ts b/test/ReducersTests.ts index bd8582a..ee4aac3 100644 --- a/test/ReducersTests.ts +++ b/test/ReducersTests.ts @@ -171,6 +171,34 @@ describe('Reducers', () => { expect(Reducers.entities({}, { response: { entities: { entities: { a: 0, b: 2 } } } })) .to.be.deep.eq({ a: 0, b: 2 }); }); + it('should handle UPDATE_CONTENT_SUCCESS', () => { + const entities = { + 5145: { + Id: 5145, + DisplayName: 'Some Article', + Status: ['Active'] + }, + 5146: { + Id: 5146, + Displayname: 'Other Article', + Status: ['Completed'] + } + }; + expect(Reducers.entities(entities, { type: 'UPDATE_CONTENT_SUCCESS', response: { Id: 5145, DisplayName: 'aaa', Status: ['Active'] } })).to.be.deep.equal( + { + 5145: { + Id: 5145, + DisplayName: 'aaa', + Status: ['Active'] + }, + 5146: { + Id: 5146, + Displayname: 'Other Article', + Status: ['Completed'] + } + } + ); + }); }); describe('isFetching reducer', () => { @@ -665,6 +693,12 @@ describe('Reducers', () => { } expect(Reducers.selected([1], action)).to.deep.equal([]); }) + it('should return an empty array', () => { + const action = { + type: 'CLEAR_SELECTION' + } + expect(Reducers.selected([1], action)).to.deep.equal([]); + }) }) describe('getContent', () => { const state = {