@beinformed/ui 1.17.2 → 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 (84) hide show
  1. package/CHANGELOG.md +22 -2
  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/hooks/useForm.js +1 -11
  7. package/esm/hooks/useForm.js.map +1 -1
  8. package/esm/i18n/Locale.js +2 -1
  9. package/esm/i18n/Locale.js.map +1 -1
  10. package/esm/models/attributes/AttributeContent.js +2 -0
  11. package/esm/models/attributes/AttributeContent.js.map +1 -1
  12. package/esm/models/content/SectionModel.js +2 -0
  13. package/esm/models/content/SectionModel.js.map +1 -1
  14. package/esm/modularui/Authenticate.js +9 -9
  15. package/esm/modularui/Authenticate.js.map +1 -1
  16. package/esm/react-client/client.js +3 -2
  17. package/esm/react-client/client.js.map +1 -1
  18. package/esm/react-server/serverUtil.js +2 -1
  19. package/esm/react-server/serverUtil.js.map +1 -1
  20. package/esm/redux/actions/FormAttributeSet.js +5 -11
  21. package/esm/redux/actions/FormAttributeSet.js.map +1 -1
  22. package/esm/redux/actions/Preferences.js +32 -2
  23. package/esm/redux/actions/Preferences.js.map +1 -1
  24. package/esm/redux/reducers/PreferencesReducer.js +5 -1
  25. package/esm/redux/reducers/PreferencesReducer.js.map +1 -1
  26. package/lib/constants/Constants.js +9 -1
  27. package/lib/constants/Constants.js.flow +5 -0
  28. package/lib/constants/Constants.js.map +1 -1
  29. package/lib/constants/Settings.js +37 -1
  30. package/lib/constants/Settings.js.flow +25 -1
  31. package/lib/constants/Settings.js.map +1 -1
  32. package/lib/hooks/useForm.js +2 -15
  33. package/lib/hooks/useForm.js.flow +0 -10
  34. package/lib/hooks/useForm.js.map +1 -1
  35. package/lib/i18n/Locale.js +2 -1
  36. package/lib/i18n/Locale.js.flow +4 -2
  37. package/lib/i18n/Locale.js.map +1 -1
  38. package/lib/i18n/__tests__/Locale.spec.js.flow +3 -2
  39. package/lib/models/attributes/AttributeContent.js +2 -0
  40. package/lib/models/attributes/AttributeContent.js.flow +2 -0
  41. package/lib/models/attributes/AttributeContent.js.map +1 -1
  42. package/lib/models/content/SectionModel.js +2 -0
  43. package/lib/models/content/SectionModel.js.flow +2 -0
  44. package/lib/models/content/SectionModel.js.map +1 -1
  45. package/lib/modularui/Authenticate.js +10 -10
  46. package/lib/modularui/Authenticate.js.flow +11 -7
  47. package/lib/modularui/Authenticate.js.map +1 -1
  48. package/lib/react-client/client.js +2 -1
  49. package/lib/react-client/client.js.flow +5 -1
  50. package/lib/react-client/client.js.map +1 -1
  51. package/lib/react-server/__tests__/serverUtil.spec.js.flow +18 -0
  52. package/lib/react-server/serverUtil.js +1 -0
  53. package/lib/react-server/serverUtil.js.flow +2 -0
  54. package/lib/react-server/serverUtil.js.map +1 -1
  55. package/lib/redux/actions/FormAttributeSet.js +6 -15
  56. package/lib/redux/actions/FormAttributeSet.js.flow +3 -16
  57. package/lib/redux/actions/FormAttributeSet.js.map +1 -1
  58. package/lib/redux/actions/Preferences.js +41 -1
  59. package/lib/redux/actions/Preferences.js.flow +49 -2
  60. package/lib/redux/actions/Preferences.js.map +1 -1
  61. package/lib/redux/actions/__tests__/Preferences.spec.js.flow +11 -0
  62. package/lib/redux/reducers/PreferencesReducer.js +5 -1
  63. package/lib/redux/reducers/PreferencesReducer.js.flow +8 -1
  64. package/lib/redux/reducers/PreferencesReducer.js.map +1 -1
  65. package/lib/redux/reducers/__tests__/PreferencesReducer.spec.js.flow +12 -0
  66. package/lib/redux/types.js.flow +5 -0
  67. package/package.json +26 -24
  68. package/src/constants/Constants.js +5 -0
  69. package/src/constants/Settings.js +25 -1
  70. package/src/hooks/useForm.js +0 -10
  71. package/src/i18n/Locale.js +4 -2
  72. package/src/i18n/__tests__/Locale.spec.js +3 -2
  73. package/src/models/attributes/AttributeContent.js +2 -0
  74. package/src/models/content/SectionModel.js +2 -0
  75. package/src/modularui/Authenticate.js +11 -7
  76. package/src/react-client/client.js +5 -1
  77. package/src/react-server/__tests__/serverUtil.spec.js +18 -0
  78. package/src/react-server/serverUtil.js +2 -0
  79. package/src/redux/actions/FormAttributeSet.js +3 -16
  80. package/src/redux/actions/Preferences.js +49 -2
  81. package/src/redux/actions/__tests__/Preferences.spec.js +11 -0
  82. package/src/redux/reducers/PreferencesReducer.js +8 -1
  83. package/src/redux/reducers/__tests__/PreferencesReducer.spec.js +12 -0
  84. package/src/redux/types.js +5 -0
@@ -35,10 +35,7 @@ export const updateFormAttribute =
35
35
  options.validate = true;
36
36
  }
37
37
 
38
- if (
39
- newForm.currentFormObject &&
40
- newForm.currentFormObject.equals(formObject)
41
- ) {
38
+ if (newForm.currentFormObject?.equals(formObject)) {
42
39
  newForm.currentFormObject.updateAttribute(attribute, inputvalue);
43
40
  } else {
44
41
  newForm.completedFormObjects.forEach((completeObject) => {
@@ -64,22 +61,12 @@ export const updateFormAttribute =
64
61
  }
65
62
 
66
63
  if (
67
- newForm.currentFormObject &&
68
64
  options.validate &&
69
- newForm.currentFormObject.hasDynamicValidations &&
65
+ newForm.currentFormObject?.hasDynamicValidations &&
70
66
  getSetting("USE_INSTANT_SERVER_VALIDATION")
71
67
  ) {
68
+ // server form validations happens async, don't wait for the form to return
72
69
  dispatch(validateFormObject(newForm));
73
70
  }
74
-
75
71
  return dispatch(updateModel(newForm));
76
72
  };
77
-
78
- /**
79
- * Validate an attribute on a form
80
- */
81
- export const validateFormAttribute =
82
- (form: FormModel): ThunkAction =>
83
- (dispatch: Dispatch) => {
84
- return dispatch(validateFormObject(form));
85
- };
@@ -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