Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3915 from cloudfoundry-incubator/fix-store-init-s…
Browse files Browse the repository at this point in the history
…tate

catalogue: fixed initial state that was overwritten
  • Loading branch information
KlapTrap committed Sep 24, 2019
2 parents 97257b0 + 7fe6a02 commit 2399903
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IRequestTypeState } from '../../../../store/src/app-state';
import { entityCatalogue } from './entity-catalogue.service';

// FIXME: These should be removed/come from the entity catalogue - STRAT-151
Expand All @@ -14,7 +15,7 @@ export function getAllEntityStoreKeys() {
];
}

export function getDefaultStateFromEntityCatalogue<T = any>(entityKeys: string[], defaultState: T) {
export function getDefaultStateFromEntityCatalogue<T = any>(entityKeys: string[], defaultState: T, initialState: IRequestTypeState) {
return entityKeys.reduce((currentState, entityKey) => {
if (currentState[entityKey]) {
return currentState;
Expand All @@ -23,5 +24,5 @@ export function getDefaultStateFromEntityCatalogue<T = any>(entityKeys: string[]
...currentState,
[entityKey]: defaultState
};
}, {}) as T;
}, initialState) as T;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function requestDataReducerFactory(actions: IRequestArray): ActionReducer
return function entitiesReducer(state = {}, action: Action): Record<string, any> {
switch (action.type) {
case InitCatalogueEntitiesAction.ACTION_TYPE:
return getDefaultStateFromEntityCatalogue((action as InitCatalogueEntitiesAction).entityKeys, {});
return getDefaultStateFromEntityCatalogue((action as InitCatalogueEntitiesAction).entityKeys, {}, state);
case successAction:
const success = action as ISuccessRequestAction;
if (!success.apiAction.updatingKey && success.requestType === 'delete') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function requestReducerFactory(actions: IRequestArray) {
return function apiRequestReducer(state = {}, action: Action) {
switch (action.type) {
case InitCatalogueEntitiesAction.ACTION_TYPE:
return getDefaultStateFromEntityCatalogue((action as InitCatalogueEntitiesAction).entityKeys, {});
return getDefaultStateFromEntityCatalogue((action as InitCatalogueEntitiesAction).entityKeys, {}, state);
case startAction:
return startRequest(state, action as StartRequestAction);
case successAction:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function paginate(action, state = {}, updatePagination) {
}

if (action.type === InitCatalogueEntitiesAction.ACTION_TYPE) {
return getDefaultStateFromEntityCatalogue((action as InitCatalogueEntitiesAction).entityKeys, {});
return getDefaultStateFromEntityCatalogue((action as InitCatalogueEntitiesAction).entityKeys, {}, state);
}

if (action.type === CREATE_PAGINATION) {
Expand Down

0 comments on commit 2399903

Please sign in to comment.