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 = {
clientKey: 'changeme',
apiUrl: 'http://localhost:8080',
filter: { institute: { code: [ 'COL003', 'BEL084', 'ETH013' ] } },
accession: { enabled: true },
language: { locale: queryLang, enableSwitch: true },
request: { enabled: true },
};
showGenesysUI(document.getElementById('genesys'), config);
......
export class Config {
public apiUrl: string;
public apiUrl?: string;
public clientId: string;
public clientKey: string;
public filter: Record<string, any>;
public filter?: Record<string, any>;
// module config
public language: Partial<LanguageConfig>;
public language?: Partial<LanguageConfig>;
public accession?: BaseFeatureConfig;
public request?: BaseFeatureConfig;
public constructor(config: Config) {
this.apiUrl = config.apiUrl;
this.apiUrl = config.apiUrl || defaultConfig.apiUrl;
this.clientId = config.clientId;
this.clientKey = config.clientKey;
this.filter = config.filter;
this.filter = config.filter || defaultConfig.filter;
// features
this.accession = config.accession || {} as BaseFeatureConfig;
this.request = config.request || {} as BaseFeatureConfig;
this.language = config.language || { locale: 'en' };
this.accession = config.accession || defaultConfig.accession;
this.request = config.request || defaultConfig.request;
this.language = config.language || defaultConfig.language;
}
}
......@@ -31,7 +31,7 @@ class LanguageConfig {
public enableSwitch: boolean;
}
export const DefaultConfig = new Config( {
export const defaultConfig = {
apiUrl: 'https://api.sandbox.genesys-pgr.org',
clientId: 'clientid@genesys',
clientKey: 'changeme',
......@@ -39,4 +39,4 @@ export const DefaultConfig = new Config( {
language: { locale: 'en', enableSwitch: true },
accession: { enabled: true },
request: { enabled: true },
});
};
......@@ -13,8 +13,10 @@ export default (state = INITIAL_STATE, action: { type?: string, payload?: any }
switch (action.type) {
case RECEIVE_APP_CONFIG: {
const config = new Config(action.payload);
return update(state, {
config: { $set: action.payload },
config: { $set: config },
});
}
......
......@@ -10,7 +10,7 @@ import { Provider } from 'react-redux';
import { reconfigureServiceAxios, LoginService } from '@genesys/client/service';
import App from 'ui/core/App';
import ApiAccessError from 'ui/core/ApiAccessError';
import { Config, DefaultConfig } from 'config/config';
import { Config } from 'config/config';
import rootReducer from 'core/reducer';
import { setConfig } from 'core/actions/appConfig';
import OverviewPage from 'accession/OverviewPage';
......@@ -51,7 +51,7 @@ function checkAccessTokens(apiUrl: string, clientId: string, clientSecret: strin
return appLogin;
};
export function showGenesysUI(holdingNode: HTMLElement, config: Config = DefaultConfig) {
export function showGenesysUI(holdingNode: HTMLElement, config: Config) {
const { apiUrl, clientId, clientKey, language } = config;
reconfigureServiceAxios({ apiUrl });
......@@ -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;
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