From 1c5c0dcbd11a0104c3ea3694e44679e1d0a9b8bb Mon Sep 17 00:00:00 2001 From: gallayl Date: Fri, 3 Aug 2018 10:58:12 +0200 Subject: [PATCH 1/6] [KFI]refactor(Reducers): added explicit types to generics to avoid nested type loss --- src/reducers/batchresponses.ts | 5 ++++- src/reducers/contentstate.ts | 7 ++++++- src/reducers/currentcontent.ts | 9 ++++++++- src/reducers/currentitems.ts | 10 +++++++++- src/reducers/selected.ts | 5 ++++- src/reducers/sensenet.ts | 10 +++++++++- src/reducers/session.ts | 31 ++++++++++++++++++++++--------- 7 files changed, 62 insertions(+), 15 deletions(-) diff --git a/src/reducers/batchresponses.ts b/src/reducers/batchresponses.ts index 69e629f..e8d87fa 100644 --- a/src/reducers/batchresponses.ts +++ b/src/reducers/batchresponses.ts @@ -38,7 +38,10 @@ export const batchResponseError: Reducer = (state = '', action) => { /** * Reducer combining response and error into a single object, ```batchResponses```. */ -export const batchResponses = combineReducers({ +export const batchResponses = combineReducers<{ + response: ReturnType, + error: ReturnType, +}>({ response: odataBatchResponse, error: batchResponseError, }) diff --git a/src/reducers/contentstate.ts b/src/reducers/contentstate.ts index 61bbf74..7a32e20 100644 --- a/src/reducers/contentstate.ts +++ b/src/reducers/contentstate.ts @@ -56,7 +56,12 @@ export const isOperationInProgress: Reducer = (state = false, action) = /** * Reducer combining isSaved, isValid, isDirty and isOperationInProgress into a single object, ```contentState```. */ -export const contentState = combineReducers({ +export const contentState = combineReducers<{ + isSaved: ReturnType, + isValid: ReturnType, + isDirty: ReturnType, + isOperationInProgress: ReturnType, +}>({ isSaved, isValid, isDirty, diff --git a/src/reducers/currentcontent.ts b/src/reducers/currentcontent.ts index 2e8a11e..a25387b 100644 --- a/src/reducers/currentcontent.ts +++ b/src/reducers/currentcontent.ts @@ -115,7 +115,14 @@ export const schema: Reducer = (stat /** * Reducer combining contentState, error, actions, fields and content into a single object, ```currentcontent```. */ -export const currentcontent = combineReducers({ +export const currentcontent = combineReducers<{ + contentState: ReturnType, + error: ReturnType, + actions: ReturnType, + fields: ReturnType, + content: ReturnType, + schema: ReturnType, +}>({ contentState, error: contenterror, actions: contentactions, diff --git a/src/reducers/currentitems.ts b/src/reducers/currentitems.ts index c3b27ce..86c77dd 100644 --- a/src/reducers/currentitems.ts +++ b/src/reducers/currentitems.ts @@ -168,7 +168,15 @@ export const options: Reducer | null> = (state = nu /** * Reducer combining ids, entities, isFetching, actions, error, top, skip, query, order, filter, select and isOpened into a single object, ```currentitems```. */ -export const currentitems = combineReducers({ +export const currentitems = combineReducers<{ + ids: ReturnType, + entities: ReturnType, + isFetching: ReturnType, + actions: ReturnType, + error: ReturnType, + isOpened: ReturnType, + options: ReturnType, +}>({ ids, entities, isFetching, diff --git a/src/reducers/selected.ts b/src/reducers/selected.ts index b51072b..ba40722 100644 --- a/src/reducers/selected.ts +++ b/src/reducers/selected.ts @@ -46,7 +46,10 @@ export const selectedContentItems: Reducer + entities: ReturnType, +}>({ ids: selectedIds, entities: selectedContentItems, }) diff --git a/src/reducers/sensenet.ts b/src/reducers/sensenet.ts index 3b2e0c9..9ad8804 100644 --- a/src/reducers/sensenet.ts +++ b/src/reducers/sensenet.ts @@ -1,3 +1,4 @@ +import { LoginState } from '@sensenet/client-core' import { Workspace } from '@sensenet/default-content-types' import { combineReducers, Reducer } from 'redux' import { loadContent, PromiseReturns } from '../Actions' @@ -28,7 +29,14 @@ export const currentworkspace: Reducer = (state = null, action /** * Reducer combining session, currentitems, currentcontent and selected into a single object, ```sensenet``` which will be the top-level one. */ -export const sensenet = combineReducers({ +export const sensenet = combineReducers<{ + session: ReturnType & { loginState: LoginState }, + currentworkspace: ReturnType, + currentcontent: ReturnType, + currentitems: ReturnType, + selected: ReturnType, + batchResponses: ReturnType, +}>({ session, currentworkspace, currentcontent, diff --git a/src/reducers/session.ts b/src/reducers/session.ts index 67bdc24..5b1cb28 100644 --- a/src/reducers/session.ts +++ b/src/reducers/session.ts @@ -129,7 +129,12 @@ export const userAvatarPath: Reducer> = ( /** * Reducer combining userName, fullName, userLanguage, userAvatarPath into a single object, ```user```. */ -const user = combineReducers({ +const user = combineReducers<{ + userName: ReturnType, + fullName: ReturnType, + userLanguage: ReturnType, + userAvatarPath: ReturnType, +}>({ userName, fullName, userLanguage, @@ -152,11 +157,19 @@ export const repository: Reducer, + language: ReturnType, + loginState: ReturnType, + error: ReturnType, + user: ReturnType, + repository: ReturnType, +}> + ({ + country, + language, + loginState, + error: loginError, + user, + repository, + }) From c42a6cabba377d6cf37bb1f71dfde9a9be9b511e Mon Sep 17 00:00:00 2001 From: Aniko Litvanyi Date: Fri, 3 Aug 2018 11:32:05 +0200 Subject: [PATCH 2/6] Add 'version' prop to restoreVersion action --- src/Actions.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Actions.ts b/src/Actions.ts index aff7f7c..9214961 100644 --- a/src/Actions.ts +++ b/src/Actions.ts @@ -336,6 +336,7 @@ export const forceUndoCheckout = (idOrPath: numbe */ export const restoreVersion = (idOrPath: number | string, version: string, options?: IODataParams) => ({ type: 'RESTOREVERSION_CONTENT', + version, payload: (repository: Repository) => repository.versioning.restoreVersion(idOrPath, version, options), }) /** From 74757ec2b8f4368b8491381496a0b118560d1308 Mon Sep 17 00:00:00 2001 From: Aniko Litvanyi Date: Fri, 3 Aug 2018 11:32:47 +0200 Subject: [PATCH 3/6] Update versionnumber of the promise middleware --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3bb76a2..1bbcf9e 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "@sensenet/authentication-jwt": "^1.0.4", "@sensenet/client-core": "^1.2.4", "@sensenet/default-content-types": "^1.1.0", - "@sensenet/redux-promise-middleware": "^2.0.0", + "@sensenet/redux-promise-middleware": "^2.1.0", "redux": "^4.0.0", "redux-logger": "^3.0.6" }, From 95ad2cad82dca6acd471355041fb62b73feacb97 Mon Sep 17 00:00:00 2001 From: gallayl Date: Fri, 3 Aug 2018 13:00:16 +0200 Subject: [PATCH 4/6] [KFI]refactor(Store): Changed persistedState type to DeepPartial --- src/Store.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Store.ts b/src/Store.ts index 2c768c8..b7761b3 100644 --- a/src/Store.ts +++ b/src/Store.ts @@ -30,7 +30,7 @@ */ import { Repository } from '@sensenet/client-core' import { promiseMiddleware } from '@sensenet/redux-promise-middleware' -import { applyMiddleware, compose, createStore, Middleware, Reducer, Store, StoreEnhancer } from 'redux' +import { applyMiddleware, compose, createStore, DeepPartial, Middleware, Reducer, Store, StoreEnhancer } from 'redux' import { createLogger } from 'redux-logger' import * as Actions from './Actions' @@ -86,7 +86,7 @@ export interface CreateStoreOptions { /** * Initial state of the store */ - persistedState?: T, + persistedState?: DeepPartial, /** * Array of additional enhancers */ From 10d3a3cb9512ed61203f5cf0804c45fc459a525c Mon Sep 17 00:00:00 2001 From: gallayl Date: Fri, 3 Aug 2018 13:01:06 +0200 Subject: [PATCH 5/6] [KFI]feat(Session): added the original current user content to the state tree --- src/reducers/session.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/reducers/session.ts b/src/reducers/session.ts index 5b1cb28..b4435e8 100644 --- a/src/reducers/session.ts +++ b/src/reducers/session.ts @@ -1,5 +1,6 @@ import { ConstantContent, LoginState } from '@sensenet/client-core' import { RepositoryConfiguration } from '@sensenet/client-core/dist/Repository/RepositoryConfiguration' +import { User } from '@sensenet/default-content-types' import { combineReducers, Reducer } from 'redux' import { loadRepository, userChanged } from '../Actions' @@ -126,6 +127,21 @@ export const userAvatarPath: Reducer> = ( return state } } + +/** + * Reducer to handle Actions on the id property in the user object. + * @param state Represents the current state. + * @param action Represents an action that is called. + * @returns state. Returns the next state based on the action. + */ +export const userContent: Reducer> = (state = ConstantContent.VISITOR_USER, action) => { + switch (action.type) { + case 'USER_CHANGED': + return action.user + default: + return state + } +} /** * Reducer combining userName, fullName, userLanguage, userAvatarPath into a single object, ```user```. */ @@ -134,11 +150,13 @@ const user = combineReducers<{ fullName: ReturnType, userLanguage: ReturnType, userAvatarPath: ReturnType, + content: ReturnType, }>({ userName, fullName, userLanguage, userAvatarPath, + content: userContent, }) /** * Reducer to handle Actions on the repostory property in the user object. From 995d232143eeea7c972511155e567d3c62481be2 Mon Sep 17 00:00:00 2001 From: gallayl Date: Fri, 3 Aug 2018 13:01:43 +0200 Subject: [PATCH 6/6] [KFI]chore(package): updated dependencies, bumped version --- package-lock.json | 20 ++++++++++---------- package.json | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 72cd6d6..dd5bb9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@sensenet/redux", - "version": "5.0.1", + "version": "5.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -130,9 +130,9 @@ } }, "@sensenet/client-core": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/@sensenet/client-core/-/client-core-1.2.4.tgz", - "integrity": "sha512-bAByBiniuIm6YqPC5qsk+azk9Wku8rqcWJ+7hcG3J7jyK15P5cbhtMshJac4Jsn7+GNHGo1kja51avIWZf5dsA==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@sensenet/client-core/-/client-core-1.2.5.tgz", + "integrity": "sha512-UQw4znWpplb5h8tTTGCvq/fsEzCl3g+JeGJ0G5KGipm7L55d7qLgmr5/HBbvnASSjO3FttKUbqrL2s/6yI0vhw==", "requires": { "@sensenet/client-utils": "^1.0.1", "@sensenet/default-content-types": "^1.1.0", @@ -157,9 +157,9 @@ "integrity": "sha512-3v7zJcoN+IjGIJp5SLopJMb9woiHF8YhIT/D2cX2f08cvkt/nFFk7zRnPTiBJNLtD5/F8m98esAjTKhMOgU+4A==" }, "@sensenet/redux-promise-middleware": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@sensenet/redux-promise-middleware/-/redux-promise-middleware-2.0.0.tgz", - "integrity": "sha512-mZthNMekRfxSz5GuVnwq/gr5+Ms/N6eSWrKcLOdTWtRdSIK5fgvaDQPATqbIhzQsOsIPjZ/mIiir8o/zxfplLg==" + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@sensenet/redux-promise-middleware/-/redux-promise-middleware-2.1.0.tgz", + "integrity": "sha512-4AjnDWGLCUmIkbRTwd8d2HA9hMhBROnOmJFWLCERktZaEiklqdUV7rFOxipVjj4Q4yujrSZHocy5Voy9OpBrnQ==" }, "@types/chai": { "version": "4.1.4", @@ -174,9 +174,9 @@ "dev": true }, "@types/node": { - "version": "10.5.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.5.4.tgz", - "integrity": "sha512-8TqvB0ReZWwtcd3LXq3YSrBoLyXFgBX/sBZfGye9+YS8zH7/g+i6QRIuiDmwBoTzcQ/pk89nZYTYU4c5akKkzw==" + "version": "10.5.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.5.5.tgz", + "integrity": "sha512-6Qnb1gXbp3g1JX9QVJj3A6ORzc9XCyhokxUKaoonHgNXcQhmk8adhotxfkeK8El9TnFeUuH72yI6jQ5nDJKS6w==" }, "@types/redux-logger": { "version": "3.0.6", diff --git a/package.json b/package.json index 1bbcf9e..f2acd15 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sensenet/redux", - "version": "5.0.1", + "version": "5.1.0", "description": "A set of redux actions, reducers and redux-ovbservable epics for sensenet", "main": "dist/index.js", "scripts": { @@ -61,7 +61,7 @@ "dependencies": { "@sensenet/authentication-google": "^2.0.0", "@sensenet/authentication-jwt": "^1.0.4", - "@sensenet/client-core": "^1.2.4", + "@sensenet/client-core": "^1.2.5", "@sensenet/default-content-types": "^1.1.0", "@sensenet/redux-promise-middleware": "^2.1.0", "redux": "^4.0.0", @@ -70,7 +70,7 @@ "devDependencies": { "@types/chai": "^4.1.4", "@types/mocha": "^5.2.5", - "@types/node": "^10.5.4", + "@types/node": "^10.5.5", "@types/redux-logger": "^3.0.5", "chai": "^4.1.1", "codecov": "^3.0.4",