Commit 87406384 authored by Oleksii Savran's avatar Oleksii Savran Committed by Matija Obreza
Browse files

Config: Added default configuration options

parent b08f2c8c
...@@ -10,9 +10,7 @@ const config = { ...@@ -10,9 +10,7 @@ const config = {
clientKey: 'changeme', clientKey: 'changeme',
apiUrl: 'http://localhost:8080', apiUrl: 'http://localhost:8080',
filter: { institute: { code: [ 'COL003', 'BEL084', 'ETH013' ] } }, filter: { institute: { code: [ 'COL003', 'BEL084', 'ETH013' ] } },
accession: { enabled: true },
language: { locale: queryLang, enableSwitch: true }, language: { locale: queryLang, enableSwitch: true },
request: { enabled: true },
}; };
showGenesysUI(document.getElementById('genesys'), config); showGenesysUI(document.getElementById('genesys'), config);
......
export class Config { export class Config {
public apiUrl: string; public apiUrl?: string;
public clientId: string; public clientId: string;
public clientKey: string; public clientKey: string;
public filter: Record<string, any>; public filter?: Record<string, any>;
// module config // module config
public language: Partial<LanguageConfig>; public language?: Partial<LanguageConfig>;
public accession?: BaseFeatureConfig; public accession?: BaseFeatureConfig;
public request?: BaseFeatureConfig; public request?: BaseFeatureConfig;
public constructor(config: Config) { public constructor(config: Config) {
this.apiUrl = config.apiUrl; this.apiUrl = config.apiUrl || defaultConfig.apiUrl;
this.clientId = config.clientId; this.clientId = config.clientId;
this.clientKey = config.clientKey; this.clientKey = config.clientKey;
this.filter = config.filter; this.filter = config.filter || defaultConfig.filter;
// features // features
this.accession = config.accession || {} as BaseFeatureConfig; this.accession = config.accession || defaultConfig.accession;
this.request = config.request || {} as BaseFeatureConfig; this.request = config.request || defaultConfig.request;
this.language = config.language || { locale: 'en' }; this.language = config.language || defaultConfig.language;
} }
} }
...@@ -31,7 +31,7 @@ class LanguageConfig { ...@@ -31,7 +31,7 @@ class LanguageConfig {
public enableSwitch: boolean; public enableSwitch: boolean;
} }
export const DefaultConfig = new Config( { export const defaultConfig = {
apiUrl: 'https://api.sandbox.genesys-pgr.org', apiUrl: 'https://api.sandbox.genesys-pgr.org',
clientId: 'clientid@genesys', clientId: 'clientid@genesys',
clientKey: 'changeme', clientKey: 'changeme',
...@@ -39,4 +39,4 @@ export const DefaultConfig = new Config( { ...@@ -39,4 +39,4 @@ export const DefaultConfig = new Config( {
language: { locale: 'en', enableSwitch: true }, language: { locale: 'en', enableSwitch: true },
accession: { enabled: true }, accession: { enabled: true },
request: { enabled: true }, request: { enabled: true },
}); };
...@@ -13,8 +13,10 @@ export default (state = INITIAL_STATE, action: { type?: string, payload?: any } ...@@ -13,8 +13,10 @@ export default (state = INITIAL_STATE, action: { type?: string, payload?: any }
switch (action.type) { switch (action.type) {
case RECEIVE_APP_CONFIG: { case RECEIVE_APP_CONFIG: {
const config = new Config(action.payload);
return update(state, { return update(state, {
config: { $set: action.payload }, config: { $set: config },
}); });
} }
......
...@@ -10,7 +10,7 @@ import { Provider } from 'react-redux'; ...@@ -10,7 +10,7 @@ import { Provider } from 'react-redux';
import { reconfigureServiceAxios, LoginService } from '@genesys/client/service'; import { reconfigureServiceAxios, LoginService } from '@genesys/client/service';
import App from 'ui/core/App'; import App from 'ui/core/App';
import ApiAccessError from 'ui/core/ApiAccessError'; import ApiAccessError from 'ui/core/ApiAccessError';
import { Config, DefaultConfig } from 'config/config'; import { Config } from 'config/config';
import rootReducer from 'core/reducer'; import rootReducer from 'core/reducer';
import { setConfig } from 'core/actions/appConfig'; import { setConfig } from 'core/actions/appConfig';
import OverviewPage from 'accession/OverviewPage'; import OverviewPage from 'accession/OverviewPage';
...@@ -51,7 +51,7 @@ function checkAccessTokens(apiUrl: string, clientId: string, clientSecret: strin ...@@ -51,7 +51,7 @@ function checkAccessTokens(apiUrl: string, clientId: string, clientSecret: strin
return appLogin; return appLogin;
}; };
export function showGenesysUI(holdingNode: HTMLElement, config: Config = DefaultConfig) { export function showGenesysUI(holdingNode: HTMLElement, config: Config) {
const { apiUrl, clientId, clientKey, language } = config; const { apiUrl, clientId, clientKey, language } = config;
reconfigureServiceAxios({ apiUrl }); reconfigureServiceAxios({ apiUrl });
...@@ -76,7 +76,7 @@ export function showGenesysUI(holdingNode: HTMLElement, config: Config = Default ...@@ -76,7 +76,7 @@ export function showGenesysUI(holdingNode: HTMLElement, config: Config = Default
} }
export function showOverview(holdingNode: HTMLElement, config: Config = DefaultConfig) { export function showOverview(holdingNode: HTMLElement, config: Config) {
const { apiUrl, clientId, clientKey, language } = config; const { apiUrl, clientId, clientKey, language } = config;
reconfigureServiceAxios({ apiUrl }); reconfigureServiceAxios({ apiUrl });
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment