@beinformed/ui 1.17.4 → 1.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/esm/constants/Constants.js +4 -0
  3. package/esm/constants/Constants.js.map +1 -1
  4. package/esm/constants/Settings.js +25 -1
  5. package/esm/constants/Settings.js.map +1 -1
  6. package/esm/modularui/Authenticate.js +9 -9
  7. package/esm/modularui/Authenticate.js.map +1 -1
  8. package/esm/react-client/client.js +3 -2
  9. package/esm/react-client/client.js.map +1 -1
  10. package/esm/react-server/serverUtil.js +2 -1
  11. package/esm/react-server/serverUtil.js.map +1 -1
  12. package/esm/redux/actions/Preferences.js +32 -2
  13. package/esm/redux/actions/Preferences.js.map +1 -1
  14. package/esm/redux/reducers/PreferencesReducer.js +5 -1
  15. package/esm/redux/reducers/PreferencesReducer.js.map +1 -1
  16. package/lib/constants/Constants.js +9 -1
  17. package/lib/constants/Constants.js.flow +5 -0
  18. package/lib/constants/Constants.js.map +1 -1
  19. package/lib/constants/Settings.js +37 -1
  20. package/lib/constants/Settings.js.flow +25 -1
  21. package/lib/constants/Settings.js.map +1 -1
  22. package/lib/modularui/Authenticate.js +10 -10
  23. package/lib/modularui/Authenticate.js.flow +11 -7
  24. package/lib/modularui/Authenticate.js.map +1 -1
  25. package/lib/react-client/client.js +2 -1
  26. package/lib/react-client/client.js.flow +5 -1
  27. package/lib/react-client/client.js.map +1 -1
  28. package/lib/react-server/__tests__/serverUtil.spec.js.flow +18 -0
  29. package/lib/react-server/serverUtil.js +1 -0
  30. package/lib/react-server/serverUtil.js.flow +2 -0
  31. package/lib/react-server/serverUtil.js.map +1 -1
  32. package/lib/redux/actions/Preferences.js +41 -1
  33. package/lib/redux/actions/Preferences.js.flow +49 -2
  34. package/lib/redux/actions/Preferences.js.map +1 -1
  35. package/lib/redux/actions/__tests__/Preferences.spec.js.flow +11 -0
  36. package/lib/redux/reducers/PreferencesReducer.js +5 -1
  37. package/lib/redux/reducers/PreferencesReducer.js.flow +8 -1
  38. package/lib/redux/reducers/PreferencesReducer.js.map +1 -1
  39. package/lib/redux/reducers/__tests__/PreferencesReducer.spec.js.flow +12 -0
  40. package/lib/redux/types.js.flow +5 -0
  41. package/package.json +12 -11
  42. package/src/constants/Constants.js +5 -0
  43. package/src/constants/Settings.js +25 -1
  44. package/src/modularui/Authenticate.js +11 -7
  45. package/src/react-client/client.js +5 -1
  46. package/src/react-server/__tests__/serverUtil.spec.js +18 -0
  47. package/src/react-server/serverUtil.js +2 -0
  48. package/src/redux/actions/Preferences.js +49 -2
  49. package/src/redux/actions/__tests__/Preferences.spec.js +11 -0
  50. package/src/redux/reducers/PreferencesReducer.js +8 -1
  51. package/src/redux/reducers/__tests__/PreferencesReducer.spec.js +12 -0
  52. package/src/redux/types.js +5 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/redux/actions/Preferences.js"],"names":["getServerPreferenceValue","preferenceName","defaultValue","type","value","preferencesProvider","getPreferenceByName","split","val","setServerPreference","propertyName","setPreference","propertyValue","payload","setThemePreference","configTheme","themeData","JSON","parse","error","JsonParseException","settings","setAllContentInDataSetting","state","allContentInDataSetting","getModularUIContentInData","preferences","ALL_CONTENT_IN_DATA_SETTING"],"mappings":";;;;;;;;;;;;;;;;;AACA;;AAEA;;AACA;;AAOA;;AAEA;AACA;AACA,IAAMA,wBAAwB,GAAG,SAA3BA,wBAA2B,CAC/BC,cAD+B,EAI5B;AAAA,MAFHC,YAEG,uEAF6B,IAE7B;AAAA,MADHC,IACG;AACH,MAAIC,KAAK,GAAG,IAAZ;;AACA,MAAI,OAAOC,mBAAP,KAA+B,WAAnC,EAAgD;AAC9CD,IAAAA,KAAK,GAAGC,mBAAmB,CAACC,mBAApB,CAAwCL,cAAxC,CAAR;AACD;;AAED,MAAIG,KAAK,IAAI,IAAb,EAAmB;AACjBA,IAAAA,KAAK,GAAGF,YAAR;AACD;;AAED,MAAI,OAA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CAAC,OAAD,EAAUK,SAAV,CAApB;AACD,CAhBM;AAkBP;AACA;AACA;;;;;AACO,IAAMM,0BAA0B,GAAG,SAA7BA,0BAA6B,CACxCC,KADwC,EAEhB;AACxB,MAAIC,uBAAuB,GAAG,KAA9B;;AAEA,MACE,OAAOnB,mBAAP,KAA+B,WAA/B,IACA,OAAOA,mBAAmB,CAACoB,yBAA3B,KAAyD,WAF3D,EAGE;AACAD,IAAAA,uBAAuB,GAAGnB,mBAAmB,CAACoB,yBAApB,EAA1B;AACD,GALD,MAKO,IAAI,OAAOF,KAAP,KAAiB,WAArB,EAAkC;AACvCC,IAAAA,uBAAuB,GAAGD,KAAK,CAACG,WAAN,CAAkBC,sCAAlB,CAA1B;AACD;;AAED,4BAAWA,sCAAX,EAAwC,CAAC,CAACH,uBAA1C;AACA,SAAOb,aAAa,CAACgB,sCAAD,EAA8BH,uBAA9B,CAApB;AACD,CAhBM","sourcesContent":["// @flow\nimport { isPlainObject } from \"../../utils/helpers/objects\";\n\nimport { JsonParseException } from \"../../exceptions\";\nimport { setSettings, setSetting } from \"../../constants/Settings\";\n\nimport type {\n PreferenceValue,\n ReduxState,\n SetPreferenceAction,\n} from \"../types\";\nimport { ALL_CONTENT_IN_DATA_SETTING } from \"../../constants\";\n\n/**\n */\nconst getServerPreferenceValue = (\n preferenceName: string,\n defaultValue: PreferenceValue = null,\n type?: string\n) => {\n let value = null;\n if (typeof preferencesProvider !== \"undefined\") {\n value = preferencesProvider.getPreferenceByName(preferenceName);\n }\n\n if (value == null) {\n value = defaultValue;\n }\n\n if (typeof value === \"string\" && type !== \"string\" && value.includes(\",\")) {\n value = value.split(\",\").map((val) => val.trim());\n }\n\n return value;\n};\n\n/**\n */\nexport const setServerPreference = (\n propertyName: string,\n defaultValue: PreferenceValue = null,\n type?: string\n): SetPreferenceAction => {\n const value = getServerPreferenceValue(propertyName, defaultValue, type);\n return setPreference(propertyName, value);\n};\n\n/**\n */\nexport const setPreference = (\n propertyName: string,\n propertyValue: PreferenceValue = null\n): SetPreferenceAction => ({\n type: \"SET_PREFERENCE\",\n payload: {\n [propertyName]: propertyValue,\n },\n});\n\n/**\n */\nexport const setThemePreference = (\n configTheme: string\n): SetPreferenceAction => {\n let themeData = {};\n\n try {\n themeData = configTheme ? JSON.parse(configTheme) : null;\n } catch (error) {\n throw new JsonParseException(`Theme file contains invalid JSON: ${error}`);\n }\n\n if (themeData && isPlainObject(themeData)) {\n setSettings(themeData.settings);\n }\n\n return setPreference(\"theme\", themeData);\n};\n\n/**\n * Make modular-ui-content-in-data preference available client side\n */\nexport const setAllContentInDataSetting = (\n state?: ReduxState\n): SetPreferenceAction => {\n let allContentInDataSetting = false;\n\n if (\n typeof preferencesProvider !== \"undefined\" &&\n typeof preferencesProvider.getModularUIContentInData !== \"undefined\"\n ) {\n allContentInDataSetting = preferencesProvider.getModularUIContentInData();\n } else if (typeof state !== \"undefined\") {\n allContentInDataSetting = state.preferences[ALL_CONTENT_IN_DATA_SETTING];\n }\n\n setSetting(ALL_CONTENT_IN_DATA_SETTING, !!allContentInDataSetting);\n return setPreference(ALL_CONTENT_IN_DATA_SETTING, allContentInDataSetting);\n};\n"],"file":"Preferences.js"}
1
+ {"version":3,"sources":["../../../src/redux/actions/Preferences.js"],"names":["getServerPreferenceValue","preferenceName","defaultValue","type","value","preferencesProvider","getPreferenceByName","split","val","setServerPreference","propertyName","setPreference","propertyValue","payload","setPreferences","preferences","setThemePreference","configTheme","themeData","JSON","parse","error","JsonParseException","settings","setAllContentInDataSetting","state","allContentInDataSetting","getModularUIContentInData","ALL_CONTENT_IN_DATA_SETTING","setLoginPreferences","loginSettings","LOGIN_PATH_SETTING","BASE","LOGIN_USERNAME_SETTING","LOGIN_PASSWORD_SETTING","LOGOUT_PATH_SETTING"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AAEA;;AACA;;AASA;;;;;;AASA;AACA;AACA,IAAMA,wBAAwB,GAAG,SAA3BA,wBAA2B,CAC/BC,cAD+B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F4C,aAE5CA,KAF4C,uBAE5CA,KAAK,CAAEV,WAAP,CAAmBgB,6BAAnB,CAF4C,mFAECC,eAFD,uBAD7B,iDAKhBC,iCALgB,EAKSjC,wBAAwB,CAChDiC,iCADgD,4BAEhDR,KAFgD,aAEhDA,KAFgD,uBAEhDA,KAAK,CAAEV,WAAP,CAAmBkB,iCAAnB,CAFgD,2EAEF,YAFE,CALjC,iDAShBC,iCATgB,EASSlC,wBAAwB,CAChDkC,iCADgD,4BAEhDT,KAFgD,aAEhDA,KAFgD,uBAEhDA,KAAK,CAAEV,WAAP,CAAmBmB,iCAAnB,CAFgD,2EAEF,YAFE,CATjC,iDAahBC,8BAbgB,EAaMnC,wBAAwB,CAC7CmC,8BAD6C,4BAE7CV,KAF6C,aAE7CA,KAF6C,uBAE7CA,KAAK,CAAEV,WAAP,CAAmBoB,8BAAnB,CAF6C,qFAECH,eAFD,aAb9B,kBAAnB;AAmBA,6BAAYF,aAAZ;AACA,SAAOhB,cAAc,CAACgB,aAAD,CAArB;AACD,CAxBM","sourcesContent":["// @flow\nimport { isPlainObject } from \"../../utils/helpers/objects\";\n\nimport { JsonParseException } from \"../../exceptions\";\nimport { setSetting, setSettings } from \"../../constants/Settings\";\n\nimport type {\n PreferenceValue,\n ReduxState,\n SetPreferenceAction,\n SetPreferencesAction,\n} from \"../types\";\n\nimport {\n BASE,\n ALL_CONTENT_IN_DATA_SETTING,\n LOGIN_PASSWORD_SETTING,\n LOGIN_PATH_SETTING,\n LOGIN_USERNAME_SETTING,\n LOGOUT_PATH_SETTING,\n} from \"../../constants\";\n\n/**\n */\nconst getServerPreferenceValue = (\n preferenceName: string,\n defaultValue: PreferenceValue = null,\n type?: string\n) => {\n let value = null;\n if (typeof preferencesProvider !== \"undefined\") {\n value = preferencesProvider.getPreferenceByName(preferenceName);\n }\n\n if (value == null) {\n value = defaultValue;\n }\n\n if (typeof value === \"string\" && type !== \"string\" && value.includes(\",\")) {\n value = value.split(\",\").map((val) => val.trim());\n }\n\n return value;\n};\n\n/**\n */\nexport const setServerPreference = (\n propertyName: string,\n defaultValue: PreferenceValue = null,\n type?: string\n): SetPreferenceAction => {\n const value = getServerPreferenceValue(propertyName, defaultValue, type);\n return setPreference(propertyName, value);\n};\n\n/**\n */\nexport const setPreference = (\n propertyName: string,\n propertyValue: PreferenceValue = null\n): SetPreferenceAction => ({\n type: \"SET_PREFERENCE\",\n payload: {\n [propertyName]: propertyValue,\n },\n});\n\n/**\n */\nexport const setPreferences = (preferences: Object): SetPreferencesAction => ({\n type: \"SET_PREFERENCES\",\n payload: {\n ...preferences,\n },\n});\n\n/**\n */\nexport const setThemePreference = (\n configTheme: string\n): SetPreferenceAction => {\n let themeData = {};\n\n try {\n themeData = configTheme ? JSON.parse(configTheme) : null;\n } catch (error) {\n throw new JsonParseException(`Theme file contains invalid JSON: ${error}`);\n }\n\n if (themeData && isPlainObject(themeData)) {\n setSettings(themeData.settings);\n }\n\n return setPreference(\"theme\", themeData);\n};\n\n/**\n * Make modular-ui-content-in-data preference available client side\n */\nexport const setAllContentInDataSetting = (\n state?: ReduxState\n): SetPreferenceAction => {\n let allContentInDataSetting = false;\n\n if (\n typeof preferencesProvider !== \"undefined\" &&\n typeof preferencesProvider.getModularUIContentInData !== \"undefined\"\n ) {\n allContentInDataSetting = preferencesProvider.getModularUIContentInData();\n } else if (typeof state !== \"undefined\") {\n allContentInDataSetting = state.preferences[ALL_CONTENT_IN_DATA_SETTING];\n }\n\n setSetting(ALL_CONTENT_IN_DATA_SETTING, !!allContentInDataSetting);\n return setPreference(ALL_CONTENT_IN_DATA_SETTING, allContentInDataSetting);\n};\n\n/**\n * Retrieves login settings from runtime preferences and sets them as setting in the preference reducer\n */\nexport const setLoginPreferences = (\n state?: ReduxState\n): SetPreferencesAction => {\n const loginSettings = {\n [LOGIN_PATH_SETTING]: getServerPreferenceValue(\n LOGIN_PATH_SETTING,\n state?.preferences[LOGIN_PATH_SETTING] ?? `${BASE}/j_security_check`\n ),\n [LOGIN_USERNAME_SETTING]: getServerPreferenceValue(\n LOGIN_USERNAME_SETTING,\n state?.preferences[LOGIN_USERNAME_SETTING] ?? \"j_username\"\n ),\n [LOGIN_PASSWORD_SETTING]: getServerPreferenceValue(\n LOGIN_PASSWORD_SETTING,\n state?.preferences[LOGIN_PASSWORD_SETTING] ?? \"j_password\"\n ),\n [LOGOUT_PATH_SETTING]: getServerPreferenceValue(\n LOGOUT_PATH_SETTING,\n state?.preferences[LOGOUT_PATH_SETTING] ?? `${BASE}/Logoff`\n ),\n };\n\n setSettings(loginSettings);\n return setPreferences(loginSettings);\n};\n"],"file":"Preferences.js"}
@@ -4,6 +4,7 @@ import thunk from "redux-thunk";
4
4
  import {
5
5
  setServerPreference,
6
6
  setPreference,
7
+ setPreferences,
7
8
  setThemePreference,
8
9
  } from "../Preferences";
9
10
 
@@ -31,6 +32,16 @@ describe("preference actions", () => {
31
32
  ]);
32
33
  });
33
34
 
35
+ it("set preferences", () => {
36
+ const store = mockStore({ preferences: {} });
37
+
38
+ store.dispatch(setPreferences({ name: "value" }));
39
+
40
+ expect(store.getActions()).toStrictEqual([
41
+ { type: "SET_PREFERENCES", payload: { name: "value" } },
42
+ ]);
43
+ });
44
+
34
45
  it("theme settings", () => {
35
46
  const store = mockStore({ preferences: {} });
36
47
 
@@ -32,7 +32,11 @@ var PreferencesReducer = function PreferencesReducer() {
32
32
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
33
33
  var action = arguments.length > 1 ? arguments[1] : undefined;
34
34
 
35
- if (action && action.type === "SET_PREFERENCE") {
35
+ if ((action === null || action === void 0 ? void 0 : action.type) === "SET_PREFERENCE") {
36
+ return _objectSpread(_objectSpread({}, state), action.payload);
37
+ }
38
+
39
+ if ((action === null || action === void 0 ? void 0 : action.type) === "SET_PREFERENCES") {
36
40
  return _objectSpread(_objectSpread({}, state), action.payload);
37
41
  }
38
42
 
@@ -11,7 +11,14 @@ const PreferencesReducer: Reducer<PreferencesState, ReduxAction> = (
11
11
  state = initialState,
12
12
  action
13
13
  ) => {
14
- if (action && action.type === "SET_PREFERENCE") {
14
+ if (action?.type === "SET_PREFERENCE") {
15
+ return {
16
+ ...state,
17
+ ...action.payload,
18
+ };
19
+ }
20
+
21
+ if (action?.type === "SET_PREFERENCES") {
15
22
  return {
16
23
  ...state,
17
24
  ...action.payload,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/redux/reducers/PreferencesReducer.js"],"names":["initialState","PreferencesReducer","state","action","type","payload"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAMA,YAAsC,GAAG,EAA/C;AAEA;AACA;AACA;;AACA,IAAMC,kBAA0D,GAAG,SAA7DA,kBAA6D,GAG9D;AAAA,MAFHC,KAEG,uEAFKF,YAEL;AAAA,MADHG,MACG;;AACH,MAAIA,MAAM,IAAIA,MAAM,CAACC,IAAP,KAAgB,gBAA9B,EAAgD;AAC9C,2CACKF,KADL,GAEKC,MAAM,CAACE,OAFZ;AAID;;AAED,SAAOH,KAAP;AACD,CAZD;;eAceD,kB","sourcesContent":["// @flow\nimport type { Reducer } from \"redux\";\nimport type { ReduxAction, PreferencesState } from \"../types\";\n\nconst initialState: $Shape<PreferencesState> = {};\n\n/**\n * Pref reducer\n */\nconst PreferencesReducer: Reducer<PreferencesState, ReduxAction> = (\n state = initialState,\n action\n) => {\n if (action && action.type === \"SET_PREFERENCE\") {\n return {\n ...state,\n ...action.payload,\n };\n }\n\n return state;\n};\n\nexport default PreferencesReducer;\n"],"file":"PreferencesReducer.js"}
1
+ {"version":3,"sources":["../../../src/redux/reducers/PreferencesReducer.js"],"names":["initialState","PreferencesReducer","state","action","type","payload"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAMA,YAAsC,GAAG,EAA/C;AAEA;AACA;AACA;;AACA,IAAMC,kBAA0D,GAAG,SAA7DA,kBAA6D,GAG9D;AAAA,MAFHC,KAEG,uEAFKF,YAEL;AAAA,MADHG,MACG;;AACH,MAAI,CAAAA,MAAM,SAAN,IAAAA,MAAM,WAAN,YAAAA,MAAM,CAAEC,IAAR,MAAiB,gBAArB,EAAuC;AACrC,2CACKF,KADL,GAEKC,MAAM,CAACE,OAFZ;AAID;;AAED,MAAI,CAAAF,MAAM,SAAN,IAAAA,MAAM,WAAN,YAAAA,MAAM,CAAEC,IAAR,MAAiB,iBAArB,EAAwC;AACtC,2CACKF,KADL,GAEKC,MAAM,CAACE,OAFZ;AAID;;AAED,SAAOH,KAAP;AACD,CAnBD;;eAqBeD,kB","sourcesContent":["// @flow\nimport type { Reducer } from \"redux\";\nimport type { ReduxAction, PreferencesState } from \"../types\";\n\nconst initialState: $Shape<PreferencesState> = {};\n\n/**\n * Pref reducer\n */\nconst PreferencesReducer: Reducer<PreferencesState, ReduxAction> = (\n state = initialState,\n action\n) => {\n if (action?.type === \"SET_PREFERENCE\") {\n return {\n ...state,\n ...action.payload,\n };\n }\n\n if (action?.type === \"SET_PREFERENCES\") {\n return {\n ...state,\n ...action.payload,\n };\n }\n\n return state;\n};\n\nexport default PreferencesReducer;\n"],"file":"PreferencesReducer.js"}
@@ -16,4 +16,16 @@ describe("preferences reducer", () => {
16
16
  name: "value",
17
17
  });
18
18
  });
19
+
20
+ it("should handle SET_PREFERENCES", () => {
21
+ expect(
22
+ PreferencesReducer([], {
23
+ type: "SET_PREFERENCES",
24
+ payload: { name: "value", name2: "value2" },
25
+ })
26
+ ).toStrictEqual({
27
+ name: "value",
28
+ name2: "value2",
29
+ });
30
+ });
19
31
  });
@@ -84,6 +84,10 @@ export type SetPreferenceAction = {
84
84
  type: "SET_PREFERENCE",
85
85
  payload: { [name: string]: PreferenceValue },
86
86
  };
87
+ export type SetPreferencesAction = {
88
+ type: "SET_PREFERENCES",
89
+ payload: { [name: string]: PreferenceValue },
90
+ };
87
91
 
88
92
  export type StartProgressAction = {
89
93
  type: "START_PROGRESS",
@@ -142,6 +146,7 @@ export type ReduxAction =
142
146
  | DismissNotificationAction
143
147
  | ShowNotificationAction
144
148
  | SetPreferenceAction
149
+ | SetPreferencesAction
145
150
  | StartProgressAction
146
151
  | FinishProgressAction
147
152
  | ResetProgressAction
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beinformed/ui",
3
- "version": "1.17.4",
3
+ "version": "1.18.1",
4
4
  "description": "Toolbox for be informed javascript layouts",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "bugs": "http://support.beinformed.com",
@@ -105,35 +105,36 @@
105
105
  "@babel/preset-env": "^7.16.11",
106
106
  "@babel/preset-flow": "^7.16.7",
107
107
  "@babel/preset-react": "^7.16.7",
108
- "@commitlint/cli": "^16.2.3",
109
- "@commitlint/config-conventional": "^16.2.1",
108
+ "@commitlint/cli": "^16.2.4",
109
+ "@commitlint/config-conventional": "^16.2.4",
110
110
  "@testing-library/react-hooks": "^8.0.0",
111
111
  "auditjs": "^4.0.37",
112
- "babel-jest": "^27.5.1",
112
+ "babel-jest": "^28.0.2",
113
113
  "babel-plugin-styled-components": "^2.0.7",
114
114
  "cherry-pick": "^0.5.0",
115
115
  "cross-env": "^7.0.3",
116
116
  "documentation": "^13.2.5",
117
- "eslint": "^8.13.0",
117
+ "eslint": "^8.14.0",
118
118
  "eslint-config-prettier": "^8.3.0",
119
119
  "eslint-plugin-babel": "^5.3.1",
120
120
  "eslint-plugin-ft-flow": "^2.0.1",
121
121
  "eslint-plugin-import": "^2.26.0",
122
- "eslint-plugin-jest": "^26.1.4",
123
- "eslint-plugin-jsdoc": "^39.2.7",
122
+ "eslint-plugin-jest": "^26.1.5",
123
+ "eslint-plugin-jsdoc": "^39.2.9",
124
124
  "eslint-plugin-react": "^7.28.0",
125
- "eslint-plugin-react-hooks": "^4.4.0",
126
- "flow-bin": "^0.176.2",
125
+ "eslint-plugin-react-hooks": "^4.5.0",
126
+ "flow-bin": "^0.176.3",
127
127
  "flow-copy-source": "^2.0.9",
128
128
  "flow-typed": "^3.6.1",
129
129
  "glob": "^8.0.1",
130
130
  "history": "^4.0.0",
131
131
  "husky": "^7.0.4",
132
- "jest": "^27.5.1",
132
+ "jest": "^28.0.2",
133
+ "jest-environment-jsdom": "^28.0.2",
133
134
  "jest-junit": "^13.2.0",
134
135
  "jest-sonar-reporter": "^2.0.0",
135
136
  "jscodeshift": "^0.13.1",
136
- "lint-staged": "^12.4.0",
137
+ "lint-staged": "^12.4.1",
137
138
  "polished": "^4.2.2",
138
139
  "prettier": "^2.6.2",
139
140
  "react": "^17.0.2",
@@ -197,3 +197,8 @@ export const ATTRIBUTE_WIDTH = {
197
197
  };
198
198
 
199
199
  export const ALL_CONTENT_IN_DATA_SETTING = "hasAllContentInData";
200
+
201
+ export const LOGIN_PATH_SETTING = "FormClient.login_url";
202
+ export const LOGIN_USERNAME_SETTING = "FormClient.username_field_name";
203
+ export const LOGIN_PASSWORD_SETTING = "FormClient.password_field_name";
204
+ export const LOGOUT_PATH_SETTING = "FormClient.logout_url";
@@ -1,6 +1,13 @@
1
1
  // @flow
2
2
  import { isPlainObject, has } from "../utils/helpers/objects";
3
- import { ALL_CONTENT_IN_DATA_SETTING } from "./Constants";
3
+ import {
4
+ BASE,
5
+ ALL_CONTENT_IN_DATA_SETTING,
6
+ LOGIN_PATH_SETTING,
7
+ LOGIN_USERNAME_SETTING,
8
+ LOGIN_PASSWORD_SETTING,
9
+ LOGOUT_PATH_SETTING,
10
+ } from "./Constants";
4
11
 
5
12
  type Setting = boolean | string | number | Array<string>;
6
13
 
@@ -115,3 +122,20 @@ export const allSettings = (): { [name: string]: Setting } => settings;
115
122
  */
116
123
  export const hasAllContentInData = (): boolean =>
117
124
  getSetting(ALL_CONTENT_IN_DATA_SETTING, true);
125
+
126
+ /**
127
+ */
128
+ export const loginPath = (): string =>
129
+ getSetting(LOGIN_PATH_SETTING, `${BASE}/j_security_check`);
130
+ /**
131
+ */
132
+ export const loginUsernameField = (): string =>
133
+ getSetting(LOGIN_USERNAME_SETTING, "j_username");
134
+ /**
135
+ */
136
+ export const loginPasswordField = (): string =>
137
+ getSetting(LOGIN_PASSWORD_SETTING, "j_password");
138
+ /**
139
+ */
140
+ export const logoutPath = (): string =>
141
+ getSetting(LOGOUT_PATH_SETTING, `${BASE}/Logoff`);
@@ -6,12 +6,12 @@ import Cache from "../utils/browser/Cache";
6
6
 
7
7
  import { UnauthorizedException } from "../exceptions";
8
8
  import type { RequestOptions } from "../utils/fetch/types";
9
-
10
- const LOGIN_PATH = `${BASE}/j_security_check`;
11
- const LOGOUT_PATH = `${BASE}/Logoff`;
12
-
13
- const usernameField = "j_username";
14
- const passwordField = "j_password";
9
+ import {
10
+ loginPasswordField,
11
+ loginPath,
12
+ loginUsernameField,
13
+ logoutPath,
14
+ } from "../constants";
15
15
 
16
16
  /**
17
17
  */
@@ -65,6 +65,10 @@ class Authenticate {
65
65
  /**
66
66
  */
67
67
  createLogin(username: string, password: string): $Shape<RequestOptions> {
68
+ const LOGIN_PATH = loginPath();
69
+ const usernameField = loginUsernameField();
70
+ const passwordField = loginPasswordField();
71
+
68
72
  const encodedUsername = encodeURIComponent(username);
69
73
  const encodedPassword = encodeURIComponent(password);
70
74
 
@@ -97,7 +101,7 @@ class Authenticate {
97
101
  */
98
102
  logout(): Promise<void> {
99
103
  return universalFetch({
100
- url: LOGOUT_PATH,
104
+ url: logoutPath(),
101
105
  }).then(() => {
102
106
  // clear cache because of cached contributions
103
107
  Cache.clear();
@@ -19,7 +19,10 @@ import configureStore from "../redux/store/configureStore";
19
19
  import rehydrate from "./rehydrate";
20
20
  import { BASE } from "../constants/Constants";
21
21
 
22
- import { setAllContentInDataSetting } from "../redux/actions/Preferences";
22
+ import {
23
+ setAllContentInDataSetting,
24
+ setLoginPreferences,
25
+ } from "../redux/actions/Preferences";
23
26
  import { showXHRErrorNotification } from "../redux/actions/Notification";
24
27
 
25
28
  import { handleError } from "../redux/actions/Error";
@@ -99,6 +102,7 @@ const client = ({
99
102
  );
100
103
 
101
104
  setAllContentInDataSetting(store.getState());
105
+ setLoginPreferences(store.getState());
102
106
 
103
107
  // load existing cache from other browser tabs
104
108
  Cache.loadOtherBrowserTabs(() => {
@@ -109,6 +109,15 @@ describe("serverUtil", () => {
109
109
  hasAllContentInData: false,
110
110
  },
111
111
  },
112
+ {
113
+ type: "SET_PREFERENCES",
114
+ payload: {
115
+ "FormClient.login_url": "/BeInformed/j_security_check",
116
+ "FormClient.logout_url": "/BeInformed/Logoff",
117
+ "FormClient.password_field_name": "j_password",
118
+ "FormClient.username_field_name": "j_username",
119
+ },
120
+ },
112
121
  ]);
113
122
  });
114
123
 
@@ -146,6 +155,15 @@ describe("serverUtil", () => {
146
155
  hasAllContentInData: false,
147
156
  },
148
157
  },
158
+ {
159
+ type: "SET_PREFERENCES",
160
+ payload: {
161
+ "FormClient.login_url": "/BeInformed/j_security_check",
162
+ "FormClient.logout_url": "/BeInformed/Logoff",
163
+ "FormClient.password_field_name": "j_password",
164
+ "FormClient.username_field_name": "j_username",
165
+ },
166
+ },
149
167
  ]);
150
168
  });
151
169
  });
@@ -16,6 +16,7 @@ import {
16
16
  setThemePreference,
17
17
  setPreference,
18
18
  setAllContentInDataSetting,
19
+ setLoginPreferences,
19
20
  } from "../redux/actions/Preferences";
20
21
 
21
22
  import { getSetting } from "../constants/Settings";
@@ -126,6 +127,7 @@ const setServerPreferences = (
126
127
  }
127
128
 
128
129
  store.dispatch(setAllContentInDataSetting());
130
+ store.dispatch(setLoginPreferences());
129
131
 
130
132
  if (
131
133
  preferencesProvider &&
@@ -2,14 +2,23 @@
2
2
  import { isPlainObject } from "../../utils/helpers/objects";
3
3
 
4
4
  import { JsonParseException } from "../../exceptions";
5
- import { setSettings, setSetting } from "../../constants/Settings";
5
+ import { setSetting, setSettings } from "../../constants/Settings";
6
6
 
7
7
  import type {
8
8
  PreferenceValue,
9
9
  ReduxState,
10
10
  SetPreferenceAction,
11
+ SetPreferencesAction,
11
12
  } from "../types";
12
- import { ALL_CONTENT_IN_DATA_SETTING } from "../../constants";
13
+
14
+ import {
15
+ BASE,
16
+ ALL_CONTENT_IN_DATA_SETTING,
17
+ LOGIN_PASSWORD_SETTING,
18
+ LOGIN_PATH_SETTING,
19
+ LOGIN_USERNAME_SETTING,
20
+ LOGOUT_PATH_SETTING,
21
+ } from "../../constants";
13
22
 
14
23
  /**
15
24
  */
@@ -57,6 +66,15 @@ export const setPreference = (
57
66
  },
58
67
  });
59
68
 
69
+ /**
70
+ */
71
+ export const setPreferences = (preferences: Object): SetPreferencesAction => ({
72
+ type: "SET_PREFERENCES",
73
+ payload: {
74
+ ...preferences,
75
+ },
76
+ });
77
+
60
78
  /**
61
79
  */
62
80
  export const setThemePreference = (
@@ -97,3 +115,32 @@ export const setAllContentInDataSetting = (
97
115
  setSetting(ALL_CONTENT_IN_DATA_SETTING, !!allContentInDataSetting);
98
116
  return setPreference(ALL_CONTENT_IN_DATA_SETTING, allContentInDataSetting);
99
117
  };
118
+
119
+ /**
120
+ * Retrieves login settings from runtime preferences and sets them as setting in the preference reducer
121
+ */
122
+ export const setLoginPreferences = (
123
+ state?: ReduxState
124
+ ): SetPreferencesAction => {
125
+ const loginSettings = {
126
+ [LOGIN_PATH_SETTING]: getServerPreferenceValue(
127
+ LOGIN_PATH_SETTING,
128
+ state?.preferences[LOGIN_PATH_SETTING] ?? `${BASE}/j_security_check`
129
+ ),
130
+ [LOGIN_USERNAME_SETTING]: getServerPreferenceValue(
131
+ LOGIN_USERNAME_SETTING,
132
+ state?.preferences[LOGIN_USERNAME_SETTING] ?? "j_username"
133
+ ),
134
+ [LOGIN_PASSWORD_SETTING]: getServerPreferenceValue(
135
+ LOGIN_PASSWORD_SETTING,
136
+ state?.preferences[LOGIN_PASSWORD_SETTING] ?? "j_password"
137
+ ),
138
+ [LOGOUT_PATH_SETTING]: getServerPreferenceValue(
139
+ LOGOUT_PATH_SETTING,
140
+ state?.preferences[LOGOUT_PATH_SETTING] ?? `${BASE}/Logoff`
141
+ ),
142
+ };
143
+
144
+ setSettings(loginSettings);
145
+ return setPreferences(loginSettings);
146
+ };
@@ -4,6 +4,7 @@ import thunk from "redux-thunk";
4
4
  import {
5
5
  setServerPreference,
6
6
  setPreference,
7
+ setPreferences,
7
8
  setThemePreference,
8
9
  } from "../Preferences";
9
10
 
@@ -31,6 +32,16 @@ describe("preference actions", () => {
31
32
  ]);
32
33
  });
33
34
 
35
+ it("set preferences", () => {
36
+ const store = mockStore({ preferences: {} });
37
+
38
+ store.dispatch(setPreferences({ name: "value" }));
39
+
40
+ expect(store.getActions()).toStrictEqual([
41
+ { type: "SET_PREFERENCES", payload: { name: "value" } },
42
+ ]);
43
+ });
44
+
34
45
  it("theme settings", () => {
35
46
  const store = mockStore({ preferences: {} });
36
47
 
@@ -11,7 +11,14 @@ const PreferencesReducer: Reducer<PreferencesState, ReduxAction> = (
11
11
  state = initialState,
12
12
  action
13
13
  ) => {
14
- if (action && action.type === "SET_PREFERENCE") {
14
+ if (action?.type === "SET_PREFERENCE") {
15
+ return {
16
+ ...state,
17
+ ...action.payload,
18
+ };
19
+ }
20
+
21
+ if (action?.type === "SET_PREFERENCES") {
15
22
  return {
16
23
  ...state,
17
24
  ...action.payload,
@@ -16,4 +16,16 @@ describe("preferences reducer", () => {
16
16
  name: "value",
17
17
  });
18
18
  });
19
+
20
+ it("should handle SET_PREFERENCES", () => {
21
+ expect(
22
+ PreferencesReducer([], {
23
+ type: "SET_PREFERENCES",
24
+ payload: { name: "value", name2: "value2" },
25
+ })
26
+ ).toStrictEqual({
27
+ name: "value",
28
+ name2: "value2",
29
+ });
30
+ });
19
31
  });
@@ -84,6 +84,10 @@ export type SetPreferenceAction = {
84
84
  type: "SET_PREFERENCE",
85
85
  payload: { [name: string]: PreferenceValue },
86
86
  };
87
+ export type SetPreferencesAction = {
88
+ type: "SET_PREFERENCES",
89
+ payload: { [name: string]: PreferenceValue },
90
+ };
87
91
 
88
92
  export type StartProgressAction = {
89
93
  type: "START_PROGRESS",
@@ -142,6 +146,7 @@ export type ReduxAction =
142
146
  | DismissNotificationAction
143
147
  | ShowNotificationAction
144
148
  | SetPreferenceAction
149
+ | SetPreferencesAction
145
150
  | StartProgressAction
146
151
  | FinishProgressAction
147
152
  | ResetProgressAction