Skip to content

Commit

Permalink
refactor: move server-config state back to core state
Browse files Browse the repository at this point in the history
- needed for access to locale setting of ICM in core configuration state
- relates to #227
  • Loading branch information
dhhyi committed Feb 26, 2021
1 parent 76b3864 commit f330f82
Show file tree
Hide file tree
Showing 20 changed files with 22 additions and 33 deletions.
2 changes: 1 addition & 1 deletion docs/concepts/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ To access these properties we provide the [`StatePropertiesService`](../../src/a
ICM provides a Configurations REST resource - `/configurations` - that is supposed to provide all relevant runtime configurations that can be defined in the ICM back office and are required to configure a REST client as well.
This includes service configurations, locales, basket preferences, etc.

The ICM configurations information can be accessed through the [`getServerConfigParameter`](../../src/app/core/store/general/server-config/server-config.selectors.ts) selector.
The ICM configurations information can be accessed through the [`getServerConfigParameter`](../../src/app/core/store/core/server-config/server-config.selectors.ts) selector.

## ICM Endpoint Configuration

Expand Down
2 changes: 1 addition & 1 deletion src/app/core/facades/app.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { filter, map, mapTo, shareReplay, startWith, withLatestFrom } from 'rxjs
import { getAvailableLocales, getCurrentLocale, getDeviceType, getICMBaseURL } from 'ish-core/store/core/configuration';
import { businessError, getGeneralError, getGeneralErrorType } from 'ish-core/store/core/error';
import { selectPath } from 'ish-core/store/core/router';
import { getServerConfigParameter } from 'ish-core/store/core/server-config';
import { getBreadcrumbData, getHeaderType, getWrapperClass, isStickyHeader } from 'ish-core/store/core/viewconf';
import { getLoggedInCustomer } from 'ish-core/store/customer/user';
import { getAllCountries, loadCountries } from 'ish-core/store/general/countries';
import { getRegionsByCountryCode, loadRegions } from 'ish-core/store/general/regions';
import { getServerConfigParameter } from 'ish-core/store/general/server-config';

@Injectable({ providedIn: 'root' })
export class AppFacade {
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/facades/checkout.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Attribute } from 'ish-core/models/attribute/attribute.model';
import { LineItemUpdate } from 'ish-core/models/line-item-update/line-item-update.model';
import { PaymentInstrument } from 'ish-core/models/payment-instrument/payment-instrument.model';
import { selectRouteData } from 'ish-core/store/core/router';
import { getServerConfigParameter } from 'ish-core/store/core/server-config';
import { getAllAddresses } from 'ish-core/store/customer/addresses';
import {
addPromotionCodeToBasket,
Expand Down Expand Up @@ -45,7 +46,6 @@ import {
} from 'ish-core/store/customer/basket';
import { getOrdersError, getSelectedOrder } from 'ish-core/store/customer/orders';
import { getLoggedInUser } from 'ish-core/store/customer/user';
import { getServerConfigParameter } from 'ish-core/store/general/server-config';
import { whenFalsy, whenTruthy } from 'ish-core/utils/operators';

// tslint:disable:member-ordering
Expand Down
5 changes: 4 additions & 1 deletion src/app/core/store/core/core-store.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { ErrorEffects } from './error/error.effects';
import { errorReducer } from './error/error.reducer';
import { MessagesEffects } from './messages/messages.effects';
import { CustomRouterSerializer } from './router/router.serializer';
import { ServerConfigEffects } from './server-config/server-config.effects';
import { serverConfigReducer } from './server-config/server-config.reducer';
import { ViewconfEffects } from './viewconf/viewconf.effects';
import { viewconfReducer } from './viewconf/viewconf.reducer';

Expand All @@ -25,9 +27,10 @@ const coreReducers: ActionReducerMap<CoreState> = {
error: errorReducer,
viewconf: viewconfReducer,
configuration: configurationReducer,
serverConfig: serverConfigReducer,
};

const coreEffects = [ErrorEffects, ViewconfEffects, ConfigurationEffects, MessagesEffects];
const coreEffects = [ErrorEffects, ViewconfEffects, ConfigurationEffects, MessagesEffects, ServerConfigEffects];

const coreMetaReducers: MetaReducer<CoreState>[] = [
ngrxStateTransferMeta,
Expand Down
2 changes: 2 additions & 0 deletions src/app/core/store/core/core-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { ErrorState } from 'ish-core/store/core/error/error.reducer';
import { ViewconfState } from 'ish-core/store/core/viewconf/viewconf.reducer';

import { RouterState } from './router/router.reducer';
import { ServerConfigState } from './server-config/server-config.reducer';

export interface CoreState {
router: RouterReducerState<RouterState>;
error: ErrorState;
viewconf: ViewconfState;
configuration: ConfigurationState;
serverConfig: ServerConfigState;
}

export const getCoreState: Selector<CoreState, CoreState> = state => state;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { instance, mock, when } from 'ts-mockito';

import { ConfigurationService } from 'ish-core/services/configuration/configuration.service';
import { CoreStoreModule } from 'ish-core/store/core/core-store.module';
import { GeneralStoreModule } from 'ish-core/store/general/general-store.module';
import { makeHttpError } from 'ish-core/utils/dev/api-service-utils';
import { routerTestNavigationAction } from 'ish-core/utils/dev/routing';

Expand All @@ -24,7 +23,7 @@ describe('Server Config Effects', () => {
configurationServiceMock = mock(ConfigurationService);

TestBed.configureTestingModule({
imports: [CoreStoreModule.forTesting(), GeneralStoreModule.forTesting('serverConfig')],
imports: [CoreStoreModule.forTesting(['serverConfig'])],
providers: [
ServerConfigEffects,
provideMockActions(() => actions$),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { TestBed } from '@angular/core/testing';

import { CoreStoreModule } from 'ish-core/store/core/core-store.module';
import { GeneralStoreModule } from 'ish-core/store/general/general-store.module';
import { StoreWithSnapshots, provideStoreSnapshots } from 'ish-core/utils/dev/ngrx-testing';

import { loadServerConfigSuccess } from './server-config.actions';
Expand All @@ -12,7 +11,7 @@ describe('Server Config Selectors', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [CoreStoreModule.forTesting(), GeneralStoreModule.forTesting('serverConfig')],
imports: [CoreStoreModule.forTesting(['serverConfig'])],
providers: [provideStoreSnapshots()],
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createSelector } from '@ngrx/store';

import { getGeneralState } from 'ish-core/store/general/general-store';
import { getCoreState } from 'ish-core/store/core/core-store';

const getServerConfigState = createSelector(getGeneralState, state => state.serverConfig);
const getServerConfigState = createSelector(getCoreState, state => state.serverConfig);

const getServerConfig = createSelector(getServerConfigState, state => state._config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import { BasketValidation } from 'ish-core/models/basket-validation/basket-valid
import { Product } from 'ish-core/models/product/product.model';
import { BasketService } from 'ish-core/services/basket/basket.service';
import { CoreStoreModule } from 'ish-core/store/core/core-store.module';
import { loadServerConfigSuccess } from 'ish-core/store/core/server-config';
import { CustomerStoreModule } from 'ish-core/store/customer/customer-store.module';
import { createOrder } from 'ish-core/store/customer/orders';
import { GeneralStoreModule } from 'ish-core/store/general/general-store.module';
import { loadServerConfigSuccess } from 'ish-core/store/general/server-config';
import { loadProductSuccess } from 'ish-core/store/shopping/products';
import { makeHttpError } from 'ish-core/utils/dev/api-service-utils';
import { BasketMockData } from 'ish-core/utils/dev/basket-mock-data';
Expand Down Expand Up @@ -50,9 +49,8 @@ describe('Basket Validation Effects', () => {
TestBed.configureTestingModule({
declarations: [DummyComponent],
imports: [
CoreStoreModule.forTesting(),
CoreStoreModule.forTesting(['serverConfig']),
CustomerStoreModule.forTesting('user', 'basket'),
GeneralStoreModule.forTesting('serverConfig'),
RouterTestingModule.withRoutes([
{ path: 'checkout', children: [{ path: 'address', component: DummyComponent }] },
{ path: 'checkout', children: [{ path: 'review', component: DummyComponent }] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
BasketValidationScopeType,
} from 'ish-core/models/basket-validation/basket-validation.model';
import { BasketService } from 'ish-core/services/basket/basket.service';
import { getServerConfigParameter } from 'ish-core/store/core/server-config';
import { createOrder } from 'ish-core/store/customer/orders';
import { getServerConfigParameter } from 'ish-core/store/general/server-config';
import { loadProduct } from 'ish-core/store/shopping/products';
import { mapErrorToAction, mapToPayload, mapToPayloadProperty, whenTruthy } from 'ish-core/utils/operators';

Expand Down
4 changes: 1 addition & 3 deletions src/app/core/store/customer/customer-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { CoreStoreModule } from 'ish-core/store/core/core-store.module';
import { CustomerStoreModule } from 'ish-core/store/customer/customer-store.module';
import { loginUser } from 'ish-core/store/customer/user';
import { UserEffects } from 'ish-core/store/customer/user/user.effects';
import { GeneralStoreModule } from 'ish-core/store/general/general-store.module';
import { loadProductSuccess } from 'ish-core/store/shopping/products';
import { ShoppingStoreModule } from 'ish-core/store/shopping/shopping-store.module';
import { CookiesService } from 'ish-core/utils/cookies/cookies.service';
Expand Down Expand Up @@ -157,9 +156,8 @@ describe('Customer Store', () => {
TestBed.configureTestingModule({
declarations: [DummyComponent],
imports: [
CoreStoreModule.forTesting(['configuration'], [UserEffects]),
CoreStoreModule.forTesting(['configuration', 'serverConfig'], [UserEffects]),
CustomerStoreModule,
GeneralStoreModule.forTesting('serverConfig'),
RouterTestingModule.withRoutes([
{
path: 'account',
Expand Down
9 changes: 2 additions & 7 deletions src/app/core/store/customer/user/user.selectors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { PaymentMethod } from 'ish-core/models/payment-method/payment-method.mod
import { Product } from 'ish-core/models/product/product.model';
import { User } from 'ish-core/models/user/user.model';
import { CoreStoreModule } from 'ish-core/store/core/core-store.module';
import { loadServerConfigSuccess } from 'ish-core/store/core/server-config';
import { CustomerStoreModule } from 'ish-core/store/customer/customer-store.module';
import { GeneralStoreModule } from 'ish-core/store/general/general-store.module';
import { loadServerConfigSuccess } from 'ish-core/store/general/server-config';
import { loadProductSuccess } from 'ish-core/store/shopping/products';
import { makeHttpError } from 'ish-core/utils/dev/api-service-utils';
import { StoreWithSnapshots, provideStoreSnapshots } from 'ish-core/utils/dev/ngrx-testing';
Expand Down Expand Up @@ -42,11 +41,7 @@ describe('User Selectors', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
CoreStoreModule.forTesting(['configuration']),
CustomerStoreModule.forTesting('user'),
GeneralStoreModule.forTesting('serverConfig'),
],
imports: [CoreStoreModule.forTesting(['configuration', 'serverConfig']), CustomerStoreModule.forTesting('user')],
providers: [provideStoreSnapshots()],
});

Expand Down
2 changes: 1 addition & 1 deletion src/app/core/store/customer/user/user.selectors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createSelector } from '@ngrx/store';

import { getServerConfigParameter } from 'ish-core/store/core/server-config';
import { getCustomerState } from 'ish-core/store/customer/customer-store';
import { getServerConfigParameter } from 'ish-core/store/general/server-config';

const getUserState = createSelector(getCustomerState, state => state.user);

Expand Down
5 changes: 1 addition & 4 deletions src/app/core/store/general/general-store.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ import { countriesReducer } from './countries/countries.reducer';
import { GeneralState } from './general-store';
import { RegionsEffects } from './regions/regions.effects';
import { regionsReducer } from './regions/regions.reducer';
import { ServerConfigEffects } from './server-config/server-config.effects';
import { serverConfigReducer } from './server-config/server-config.reducer';

const generalReducers: ActionReducerMap<GeneralState> = {
countries: countriesReducer,
regions: regionsReducer,
contact: contactReducer,
serverConfig: serverConfigReducer,
};

const generalEffects = [ContactEffects, CountriesEffects, RegionsEffects, ServerConfigEffects];
const generalEffects = [ContactEffects, CountriesEffects, RegionsEffects];

@NgModule({
imports: [EffectsModule.forFeature(generalEffects), StoreModule.forFeature('general', generalReducers)],
Expand Down
2 changes: 0 additions & 2 deletions src/app/core/store/general/general-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import { createFeatureSelector } from '@ngrx/store';
import { ContactState } from './contact/contact.reducer';
import { CountriesState } from './countries/countries.reducer';
import { RegionsState } from './regions/regions.reducer';
import { ServerConfigState } from './server-config/server-config.reducer';

export interface GeneralState {
countries: CountriesState;
regions: RegionsState;
contact: ContactState;
serverConfig: ServerConfigState;
}

export const getGeneralState = createFeatureSelector<GeneralState>('general');
2 changes: 1 addition & 1 deletion src/app/extensions/captcha/facades/captcha.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Store, select } from '@ngrx/store';
import { Observable } from 'rxjs';
import { filter, map, switchMap, switchMapTo } from 'rxjs/operators';

import { getServerConfigParameter } from 'ish-core/store/general/server-config';
import { getServerConfigParameter } from 'ish-core/store/core/server-config';
import { whenTruthy } from 'ish-core/utils/operators';

export type CaptchaTopic =
Expand Down

0 comments on commit f330f82

Please sign in to comment.