@beinformed/ui 1.20.0 → 1.20.3

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 (114) hide show
  1. package/CHANGELOG.md +22 -2
  2. package/esm/constants/Constants.js +0 -15
  3. package/esm/constants/Constants.js.map +1 -1
  4. package/esm/constants/Settings.js +6 -0
  5. package/esm/constants/Settings.js.map +1 -1
  6. package/esm/hooks/useAuthentication.js +40 -5
  7. package/esm/hooks/useAuthentication.js.map +1 -1
  8. package/esm/hooks/useContent.js +2 -6
  9. package/esm/hooks/useContent.js.map +1 -1
  10. package/esm/hooks/useI18n.js +10 -11
  11. package/esm/hooks/useI18n.js.map +1 -1
  12. package/esm/hooks/useModularUI.js +2 -3
  13. package/esm/hooks/useModularUI.js.map +1 -1
  14. package/esm/hooks/useModularUIRequest.js +2 -5
  15. package/esm/hooks/useModularUIRequest.js.map +1 -1
  16. package/esm/i18n/Message.js.map +1 -1
  17. package/esm/i18n/withMessage.js +2 -10
  18. package/esm/i18n/withMessage.js.map +1 -1
  19. package/esm/models/application/ApplicationModel.js +6 -1
  20. package/esm/models/application/ApplicationModel.js.map +1 -1
  21. package/esm/redux/_modularui/connector.js +3 -4
  22. package/esm/redux/_modularui/connector.js.map +1 -1
  23. package/esm/redux/_modularui/selectors.js +22 -5
  24. package/esm/redux/_modularui/selectors.js.map +1 -1
  25. package/esm/redux/_modularui/withModularUI.js +2 -10
  26. package/esm/redux/_modularui/withModularUI.js.map +1 -1
  27. package/esm/redux/actions/Application.js +26 -7
  28. package/esm/redux/actions/Application.js.map +1 -1
  29. package/esm/redux/actions/Authorization.js +2 -1
  30. package/esm/redux/actions/Authorization.js.map +1 -1
  31. package/esm/redux/actions/Error.js +3 -1
  32. package/esm/redux/actions/Error.js.map +1 -1
  33. package/esm/redux/selectors/i18n.js +16 -0
  34. package/esm/redux/selectors/i18n.js.map +1 -0
  35. package/esm/utils/datetime/DateTimeUtil.js +3 -1
  36. package/esm/utils/datetime/DateTimeUtil.js.map +1 -1
  37. package/lib/constants/Constants.js +2 -20
  38. package/lib/constants/Constants.js.flow +0 -15
  39. package/lib/constants/Constants.js.map +1 -1
  40. package/lib/constants/Settings.js +6 -0
  41. package/lib/constants/Settings.js.flow +9 -0
  42. package/lib/constants/Settings.js.map +1 -1
  43. package/lib/hooks/__tests__/useAuthentication.spec.js.flow +0 -8
  44. package/lib/hooks/useAuthentication.js +47 -5
  45. package/lib/hooks/useAuthentication.js.flow +40 -3
  46. package/lib/hooks/useAuthentication.js.map +1 -1
  47. package/lib/hooks/useContent.js +3 -7
  48. package/lib/hooks/useContent.js.flow +2 -2
  49. package/lib/hooks/useContent.js.map +1 -1
  50. package/lib/hooks/useI18n.js +12 -9
  51. package/lib/hooks/useI18n.js.flow +10 -11
  52. package/lib/hooks/useI18n.js.map +1 -1
  53. package/lib/hooks/useModularUI.js +3 -3
  54. package/lib/hooks/useModularUI.js.flow +3 -2
  55. package/lib/hooks/useModularUI.js.map +1 -1
  56. package/lib/hooks/useModularUIRequest.js +2 -4
  57. package/lib/hooks/useModularUIRequest.js.flow +8 -10
  58. package/lib/hooks/useModularUIRequest.js.map +1 -1
  59. package/lib/i18n/Message.js.flow +1 -1
  60. package/lib/i18n/Message.js.map +1 -1
  61. package/lib/i18n/withMessage.js +2 -8
  62. package/lib/i18n/withMessage.js.flow +3 -4
  63. package/lib/i18n/withMessage.js.map +1 -1
  64. package/lib/models/application/ApplicationModel.js +7 -1
  65. package/lib/models/application/ApplicationModel.js.flow +7 -1
  66. package/lib/models/application/ApplicationModel.js.map +1 -1
  67. package/lib/redux/_modularui/connector.js +3 -3
  68. package/lib/redux/_modularui/connector.js.flow +3 -2
  69. package/lib/redux/_modularui/connector.js.map +1 -1
  70. package/lib/redux/_modularui/selectors.js +26 -6
  71. package/lib/redux/_modularui/selectors.js.flow +19 -1
  72. package/lib/redux/_modularui/selectors.js.map +1 -1
  73. package/lib/redux/_modularui/withModularUI.js +3 -9
  74. package/lib/redux/_modularui/withModularUI.js.flow +3 -5
  75. package/lib/redux/_modularui/withModularUI.js.map +1 -1
  76. package/lib/redux/actions/Application.js +31 -8
  77. package/lib/redux/actions/Application.js.flow +6 -8
  78. package/lib/redux/actions/Application.js.map +1 -1
  79. package/lib/redux/actions/Authorization.js +3 -2
  80. package/lib/redux/actions/Authorization.js.flow +2 -1
  81. package/lib/redux/actions/Authorization.js.map +1 -1
  82. package/lib/redux/actions/Error.js +4 -1
  83. package/lib/redux/actions/Error.js.flow +3 -1
  84. package/lib/redux/actions/Error.js.map +1 -1
  85. package/lib/redux/actions/__tests__/Application.spec.js.flow +1 -5
  86. package/lib/redux/actions/__tests__/Authorization.spec.js.flow +1 -1
  87. package/lib/redux/selectors/i18n.js +28 -0
  88. package/lib/redux/selectors/i18n.js.flow +15 -0
  89. package/lib/redux/selectors/i18n.js.map +1 -0
  90. package/lib/utils/datetime/DateTimeUtil.js +3 -1
  91. package/lib/utils/datetime/DateTimeUtil.js.flow +1 -1
  92. package/lib/utils/datetime/DateTimeUtil.js.map +1 -1
  93. package/package.json +5 -5
  94. package/src/constants/Constants.js +0 -15
  95. package/src/constants/Settings.js +9 -0
  96. package/src/hooks/__tests__/useAuthentication.spec.js +0 -8
  97. package/src/hooks/useAuthentication.js +40 -3
  98. package/src/hooks/useContent.js +2 -2
  99. package/src/hooks/useI18n.js +10 -11
  100. package/src/hooks/useModularUI.js +3 -2
  101. package/src/hooks/useModularUIRequest.js +8 -10
  102. package/src/i18n/Message.js +1 -1
  103. package/src/i18n/withMessage.js +3 -4
  104. package/src/models/application/ApplicationModel.js +7 -1
  105. package/src/redux/_modularui/connector.js +3 -2
  106. package/src/redux/_modularui/selectors.js +19 -1
  107. package/src/redux/_modularui/withModularUI.js +3 -5
  108. package/src/redux/actions/Application.js +6 -8
  109. package/src/redux/actions/Authorization.js +2 -1
  110. package/src/redux/actions/Error.js +3 -1
  111. package/src/redux/actions/__tests__/Application.spec.js +1 -5
  112. package/src/redux/actions/__tests__/Authorization.spec.js +1 -1
  113. package/src/redux/selectors/i18n.js +15 -0
  114. package/src/utils/datetime/DateTimeUtil.js +1 -1
@@ -7,14 +7,15 @@ import { loadModularUI, removeModelByKey } from "../redux/_modularui/actions";
7
7
 
8
8
  import useDeepCompareEffect from "./useDeepCompareEffect";
9
9
 
10
+ import { useLocale } from "./useI18n";
11
+
10
12
  import type Href from "../models/href/Href";
11
13
  import type { RequestBaseOptions } from "../utils";
12
14
 
13
15
  /**
14
16
  */
15
17
  const useKeyForHook = (modelKey: string, url: string) => {
16
- const locale = useSelector((state) => state.i18n.locale);
17
-
18
+ const locale = useLocale();
18
19
  return `${modelKey}(${url.split("?")[0]})(${locale})`;
19
20
  };
20
21
 
@@ -3,20 +3,18 @@ import { createSelector } from "reselect";
3
3
  import { useSelector } from "react-redux";
4
4
 
5
5
  import ModularUIRequest from "../modularui/ModularUIRequest";
6
+ import { getLocale } from "../redux/selectors/i18n";
6
7
 
7
8
  import type { RequestBaseOptions } from "../utils";
8
9
  import type Href from "../models/href/Href";
9
10
 
10
- const getModularUIRequest = createSelector(
11
- [(state) => state.i18n.locale ?? "en"],
12
- (localeCode) => {
13
- return (href: Href, options?: $Shape<RequestBaseOptions>) => {
14
- const request = new ModularUIRequest(href, options);
15
- request.locale = localeCode;
16
- return request;
17
- };
18
- }
19
- );
11
+ const getModularUIRequest = createSelector([getLocale], (localeCode) => {
12
+ return (href: Href, options?: $Shape<RequestBaseOptions>) => {
13
+ const request = new ModularUIRequest(href, options);
14
+ request.locale = localeCode;
15
+ return request;
16
+ };
17
+ });
20
18
 
21
19
  /**
22
20
  * Creates a ModularUIRequest with the locale as available in the redux store
@@ -6,7 +6,7 @@ import { useMessage } from "../hooks/useI18n";
6
6
 
7
7
  type MessageProps = {
8
8
  +className?: string,
9
- +id?: string | null,
9
+ +id: string,
10
10
  +defaultMessage?: string | null,
11
11
  +children?: string,
12
12
  +data?: Object | null,
@@ -4,6 +4,8 @@ import { connect } from "react-redux";
4
4
  import { createSelector } from "reselect";
5
5
  import memoize from "lodash/memoize";
6
6
 
7
+ import { getLocales, getLocale } from "../redux/selectors/i18n";
8
+
7
9
  import type { ReduxState } from "../redux/types";
8
10
  import type { ComponentType } from "react";
9
11
 
@@ -20,11 +22,8 @@ type Props = {
20
22
  ...
21
23
  };
22
24
 
23
- const getLocaleCode = (state) => state.i18n.locale || "en";
24
- const getLocales = (state) => state.i18n.locales;
25
-
26
25
  const getMessage = createSelector(
27
- [getLocales, getLocaleCode],
26
+ [getLocales, getLocale],
28
27
  (locales, localeCode) =>
29
28
  memoize(
30
29
  (id: string, defaultMessage?: string, placeholders?: Object) =>
@@ -68,7 +68,13 @@ export default class ApplicationModel extends ResourceModel {
68
68
  * Getting the authentication types of the application
69
69
  */
70
70
  get authenticationTypes(): Array<AuthenticationType> {
71
- return this.getContribution("security", []);
71
+ const authenticationTypes = this.getContribution("security", []);
72
+
73
+ //put primary first
74
+ return authenticationTypes?.sort(
75
+ (a: AuthenticationType, b: AuthenticationType) =>
76
+ a.isPrimary === b.isPrimary ? 0 : a.isPrimary ? -1 : 1
77
+ );
72
78
  }
73
79
  /**
74
80
  * Getting the tab links
@@ -1,6 +1,6 @@
1
1
  // @flow
2
2
  import { useEffect } from "react";
3
- import { useDispatch, useSelector } from "react-redux";
3
+ import { useDispatch } from "react-redux";
4
4
  import { useLocation } from "react-router";
5
5
 
6
6
  import { loadModularUI, reloadModel, removeModelByKey } from "./actions";
@@ -10,6 +10,7 @@ import { getDisplayName } from "../../react/utils";
10
10
 
11
11
  import { useUrl, useReload } from "./modularuiUtils";
12
12
  import { useModularUI } from "../../hooks/useModularUI";
13
+ import { useLocale } from "../../hooks/useI18n";
13
14
 
14
15
  import type { ComponentType, Node } from "react";
15
16
  import type { Location } from "react-router";
@@ -88,7 +89,7 @@ const connector = (
88
89
  }, [dispatch, modelKey]);
89
90
 
90
91
  // Create new properties object to inject modularui properties to own props
91
- const locale = useSelector((state) => state.i18n.locale);
92
+ const locale = useLocale();
92
93
  const newProps: InjectedProps = {
93
94
  modelKey,
94
95
  [propName]: modelEntry ? modelEntry.model : null,
@@ -150,7 +150,6 @@ export const keyByHref = (state: ReduxState, href: Href | string): ?string => {
150
150
 
151
151
  return Object.keys(state.modularui).find((key) => {
152
152
  const { model } = state.modularui[key];
153
-
154
153
  return model && model.selfhref && model.selfhref.equals(findHref);
155
154
  });
156
155
  }
@@ -158,6 +157,25 @@ export const keyByHref = (state: ReduxState, href: Href | string): ?string => {
158
157
  return null;
159
158
  };
160
159
 
160
+ /**
161
+ * Returns all model keys found in the store, restrict on href
162
+ */
163
+ export const allKeysByHref = (
164
+ state: ReduxState,
165
+ href: Href | string
166
+ ): Array<string> => {
167
+ if (state && state.modularui) {
168
+ const findHref = href instanceof Href ? href : new Href(href);
169
+
170
+ return Object.keys(state.modularui).filter((key) => {
171
+ const { model } = state.modularui[key];
172
+ return model && model.selfhref && model.selfhref.equals(findHref);
173
+ });
174
+ }
175
+
176
+ return [];
177
+ };
178
+
161
179
  /**
162
180
  */
163
181
  const getLocation = (state): string => state?.router?.location.pathname;
@@ -9,6 +9,8 @@ import { startProgress, finishProgress } from "../actions/ProgressIndicator";
9
9
 
10
10
  import { handleError } from "../actions/Error";
11
11
 
12
+ import { getLocale } from "../selectors/i18n";
13
+
12
14
  import { reloadModel } from "./actions";
13
15
 
14
16
  import type {
@@ -43,12 +45,8 @@ type Props = {
43
45
  ...DispatchProps,
44
46
  };
45
47
 
46
- /**
47
- */
48
- const getLocaleCode = (state) => state.i18n.locale ?? "en";
49
-
50
48
  const modularui = createSelector(
51
- [getLocaleCode],
49
+ [getLocale],
52
50
  (localeCode) =>
53
51
  (href, options = {}) => {
54
52
  const modularuiRequest = new ModularUIRequest(href, options);
@@ -1,7 +1,8 @@
1
1
  // @flow
2
2
  import { loadModularUI, removeModelByKey } from "../_modularui/actions";
3
- import { keyByHref } from "../_modularui/selectors";
3
+ import { allKeysByHref } from "../_modularui/selectors";
4
4
  import { ApplicationModel, Href } from "../../models";
5
+ import { getLocale } from "../selectors/i18n";
5
6
 
6
7
  import type { Dispatch, GetState, ThunkAction } from "../types";
7
8
 
@@ -9,15 +10,12 @@ import type { Dispatch, GetState, ThunkAction } from "../types";
9
10
  */
10
11
  export const reloadApplication =
11
12
  (): ThunkAction => (dispatch: Dispatch, getState: GetState) => {
12
- let modelKey = keyByHref(getState(), "/");
13
-
14
- if (!modelKey) {
15
- const locale = getState().i18n?.locale;
16
- modelKey = `application(/)(${locale})`;
13
+ const allKeys = allKeysByHref(getState(), "/");
14
+ for (const key of allKeys) {
15
+ dispatch(removeModelByKey(key));
17
16
  }
18
17
 
19
- dispatch(removeModelByKey(modelKey));
20
-
18
+ const modelKey = `application(/)(${getLocale(getState())})`;
21
19
  return dispatch(
22
20
  loadModularUI(modelKey, new Href("/", "Application"), {
23
21
  targetModel: ApplicationModel,
@@ -1,5 +1,5 @@
1
1
  // @flow
2
- import { LOGIN_PATH, NOTIFICATION_TYPES } from "../../constants/Constants";
2
+ import { NOTIFICATION_TYPES } from "../../constants/Constants";
3
3
 
4
4
  import ErrorResponse from "../../models/error/ErrorResponse";
5
5
 
@@ -62,6 +62,7 @@ export const handleUnauthorized =
62
62
 
63
63
  // add current location as from location before redirect
64
64
  const location = getState().router.location;
65
+ const LOGIN_PATH = getSetting("LOGIN_PATH", "/signin");
65
66
  if (location?.pathname !== LOGIN_PATH) {
66
67
  const locationFrom = location?.state?.from;
67
68
  return dispatch(
@@ -1,5 +1,6 @@
1
1
  // @flow
2
- import { LOGOUT_PATH, IS_SERVER } from "../../constants/Constants";
2
+ import { IS_SERVER } from "../../constants/Constants";
3
+ import { getSetting } from "../../constants/Settings";
3
4
 
4
5
  import ErrorResponse from "../../models/error/ErrorResponse";
5
6
 
@@ -39,6 +40,7 @@ const defaultErrorResponseHandler: DefaultErrorResponseHandler =
39
40
  }
40
41
 
41
42
  if (error.isBlocked || error.isConcurrentUser) {
43
+ const LOGOUT_PATH = getSetting("LOGOUT_PATH", "/signout");
42
44
  dispatch(push(LOGOUT_PATH));
43
45
  }
44
46
 
@@ -16,10 +16,6 @@ describe("application actions", () => {
16
16
  await store.dispatch(reloadApplication());
17
17
 
18
18
  expect(store.getActions()).toStrictEqual([
19
- {
20
- type: "MODULARUI/REMOVE_KEY",
21
- payload: "application(/)(en)",
22
- },
23
19
  {
24
20
  type: "MODULARUI/STATUS",
25
21
  payload: { key: "application(/)(en)", status: "LOADING" },
@@ -49,7 +45,7 @@ describe("application actions", () => {
49
45
  },
50
46
  {
51
47
  type: "MODULARUI/STATUS",
52
- payload: { key: "/", status: "LOADING" },
48
+ payload: { key: "application(/)(en)", status: "LOADING" },
53
49
  },
54
50
  { type: "START_PROGRESS" },
55
51
  expect.objectContaining({
@@ -45,7 +45,7 @@ describe("authorization actions", () => {
45
45
  },
46
46
  {
47
47
  type: "MODULARUI/STATUS",
48
- payload: { key: "/", status: "LOADING" },
48
+ payload: { key: "application(/)(en)", status: "LOADING" },
49
49
  },
50
50
  {
51
51
  type: "START_PROGRESS",
@@ -0,0 +1,15 @@
1
+ // @flow
2
+ import type Locales from "../../i18n/Locales";
3
+ import type { ReduxState } from "../types";
4
+
5
+ /**
6
+ * Retrieve the locale from state
7
+ */
8
+ export const getLocale = (state: ReduxState): string => {
9
+ return state.i18n?.locale ?? "en";
10
+ };
11
+
12
+ /**
13
+ * Retrieve all available locales in the store
14
+ */
15
+ export const getLocales = (state: ReduxState): Locales => state.i18n.locales;
@@ -63,7 +63,7 @@ class BaseDateTimeUtil {
63
63
  /**
64
64
  */
65
65
  getLocale(): typeof nl | typeof enGB {
66
- const locale = getCookie("locale") || "en";
66
+ const locale = getCookie("locale") ?? "en";
67
67
 
68
68
  if (locale === "nl") {
69
69
  return nl;