Skip to content

Commit

Permalink
feat: enable additional features extending defaults in multi-site (#1191
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dhhyi authored Jul 19, 2022
1 parent 51275d5 commit 8a260b1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/guides/multi-site-configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ All other properties are optional:
- **application**: The ICM application
- **identityProvider**: The active identity provider for this site
- **features**: Comma-separated list of activated features
- **addFeatures**: Comma-separated list of additional features extending defaults
- **lang**: The default language as defined in the Angular CLI environment
- **currency**: The default currency for this channel
- **theme**: The theme used for the channel (see [Guide - Multiple Themes](./multiple-themes.md))
Expand Down
3 changes: 2 additions & 1 deletion nginx/templates/multi-channel.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{{- $lang := "default" }}{{ if (has . "lang") }}{{ $lang = .lang }}{{ end }}
{{- $currency := "" }}{{ if (has . "currency") }}{{ $currency = join ( slice ";currency" .currency ) "=" }}{{ end }}
{{- $features := "" }}{{ if (has . "features") }}{{ $features = join ( slice ";features" .features ) "=" }}{{ end }}
{{- $addFeatures := "" }}{{ if (has . "addFeatures") }}{{ $addFeatures = join ( slice ";addFeatures" .addFeatures ) "=" }}{{ end }}
{{- $theme := "" }}{{ if (has . "theme") }}{{ $theme = join ( slice ";theme" .theme ) "=" }}{{ end }}
{{- $baseHref := "/" }}{{ if (has . "baseHref") }}{{ $baseHref = .baseHref }}{{ end }}
{{- $icmScheme := "" }}{{ if (has . "icmScheme") }}{{ $icmScheme = join ( slice "icmScheme" .icmScheme ) "=" }}{{ end }}
Expand Down Expand Up @@ -50,7 +51,7 @@
rewrite '^(?!.*;identityProvider=.*)(.*)$' '$1;identityProvider={{ $identityProvider }}';
{{ end }}

set $default_rewrite_params ';icmHost={{ $icmHost }}{{ $icmScheme }}{{ $icmPort }};channel={{ $channel }}{{ $application }}{{ $features }}{{ $theme }};baseHref={{ $baseHref | strings.ReplaceAll "/" "%2F" }};device=$ua_device';
set $default_rewrite_params ';icmHost={{ $icmHost }}{{ $icmScheme }}{{ $icmPort }};channel={{ $channel }}{{ $application }}{{ $features }}{{ $addFeatures }}{{ $theme }};baseHref={{ $baseHref | strings.ReplaceAll "/" "%2F" }};device=$ua_device';

rewrite '^(.*)$' '$1$default_rewrite_params' break;

Expand Down
5 changes: 5 additions & 0 deletions src/app/core/configurations/configuration.meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SimpleParamMap {
}
}

// eslint-disable-next-line complexity
function extractConfigurationParameters(state: ConfigurationState, paramMap: SimpleParamMap) {
const keys: (keyof ConfigurationState)[] = ['channel', 'application', 'lang', 'currency', 'identityProvider'];
const properties: Partial<ConfigurationState> = keys
Expand All @@ -39,6 +40,10 @@ function extractConfigurationParameters(state: ConfigurationState, paramMap: Sim
}
}

if (paramMap.has('addFeatures')) {
properties.addFeatures = paramMap.get<string>('addFeatures').split(/,/g);
}

if (paramMap.has('device')) {
properties._deviceType = paramMap.get('device');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ConfigurationState {
identityProvider?: string;
identityProviders?: { [id: string]: { type?: string; [key: string]: unknown } };
features?: string[];
addFeatures?: string[];
defaultLocale?: string;
localeCurrencyOverride?: { [locale: string]: string | string[] };
lang?: string;
Expand All @@ -33,6 +34,7 @@ const initialState: ConfigurationState = {
channel: undefined,
application: undefined,
features: undefined,
addFeatures: [],
defaultLocale: environment.defaultLocale,
localeCurrencyOverride: environment.localeCurrencyOverride,
lang: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ describe('Configuration Selectors', () => {
expect(getFeatures(store$.state)).toIncludeAllMembers(['compare', 'recently']);
});
});

describe('after setting additional features', () => {
beforeEach(() => {
store$.dispatch(
applyConfiguration({
addFeatures: ['quoting'],
})
);
});

it('should have additional features active', () => {
expect(getFeatures(store$.state)).toIncludeAllMembers(['compare', 'recently', 'quoting']);
});
});
});

describe('after setting identity provider', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export const getICMStaticURL = createSelector(getConfigurationState, getICMAppli

export const getICMBaseURL = createSelector(getConfigurationState, state => state.baseURL);

export const getFeatures = createSelector(getConfigurationState, state => state.features);
export const getFeatures = createSelector(getConfigurationState, state =>
state.features ? [...state.features, ...state.addFeatures] : undefined
);

const internalDefaultLocale = createSelector(getConfigurationState, state => state.defaultLocale);

Expand Down

0 comments on commit 8a260b1

Please sign in to comment.