@beinformed/ui 1.20.0 → 1.20.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 (78) hide show
  1. package/CHANGELOG.md +8 -2
  2. package/esm/hooks/useContent.js +2 -6
  3. package/esm/hooks/useContent.js.map +1 -1
  4. package/esm/hooks/useI18n.js +10 -11
  5. package/esm/hooks/useI18n.js.map +1 -1
  6. package/esm/hooks/useModularUI.js +2 -3
  7. package/esm/hooks/useModularUI.js.map +1 -1
  8. package/esm/hooks/useModularUIRequest.js +2 -5
  9. package/esm/hooks/useModularUIRequest.js.map +1 -1
  10. package/esm/i18n/Message.js.map +1 -1
  11. package/esm/i18n/withMessage.js +2 -10
  12. package/esm/i18n/withMessage.js.map +1 -1
  13. package/esm/redux/_modularui/connector.js +3 -4
  14. package/esm/redux/_modularui/connector.js.map +1 -1
  15. package/esm/redux/_modularui/selectors.js +22 -5
  16. package/esm/redux/_modularui/selectors.js.map +1 -1
  17. package/esm/redux/_modularui/withModularUI.js +2 -10
  18. package/esm/redux/_modularui/withModularUI.js.map +1 -1
  19. package/esm/redux/actions/Application.js +26 -7
  20. package/esm/redux/actions/Application.js.map +1 -1
  21. package/esm/redux/selectors/i18n.js +16 -0
  22. package/esm/redux/selectors/i18n.js.map +1 -0
  23. package/esm/utils/datetime/DateTimeUtil.js +3 -1
  24. package/esm/utils/datetime/DateTimeUtil.js.map +1 -1
  25. package/lib/hooks/__tests__/useAuthentication.spec.js.flow +0 -8
  26. package/lib/hooks/useContent.js +3 -7
  27. package/lib/hooks/useContent.js.flow +2 -2
  28. package/lib/hooks/useContent.js.map +1 -1
  29. package/lib/hooks/useI18n.js +12 -9
  30. package/lib/hooks/useI18n.js.flow +10 -11
  31. package/lib/hooks/useI18n.js.map +1 -1
  32. package/lib/hooks/useModularUI.js +3 -3
  33. package/lib/hooks/useModularUI.js.flow +3 -2
  34. package/lib/hooks/useModularUI.js.map +1 -1
  35. package/lib/hooks/useModularUIRequest.js +2 -4
  36. package/lib/hooks/useModularUIRequest.js.flow +8 -10
  37. package/lib/hooks/useModularUIRequest.js.map +1 -1
  38. package/lib/i18n/Message.js.flow +1 -1
  39. package/lib/i18n/Message.js.map +1 -1
  40. package/lib/i18n/withMessage.js +2 -8
  41. package/lib/i18n/withMessage.js.flow +3 -4
  42. package/lib/i18n/withMessage.js.map +1 -1
  43. package/lib/redux/_modularui/connector.js +3 -3
  44. package/lib/redux/_modularui/connector.js.flow +3 -2
  45. package/lib/redux/_modularui/connector.js.map +1 -1
  46. package/lib/redux/_modularui/selectors.js +26 -6
  47. package/lib/redux/_modularui/selectors.js.flow +19 -1
  48. package/lib/redux/_modularui/selectors.js.map +1 -1
  49. package/lib/redux/_modularui/withModularUI.js +3 -9
  50. package/lib/redux/_modularui/withModularUI.js.flow +3 -5
  51. package/lib/redux/_modularui/withModularUI.js.map +1 -1
  52. package/lib/redux/actions/Application.js +31 -8
  53. package/lib/redux/actions/Application.js.flow +6 -8
  54. package/lib/redux/actions/Application.js.map +1 -1
  55. package/lib/redux/actions/__tests__/Application.spec.js.flow +1 -5
  56. package/lib/redux/actions/__tests__/Authorization.spec.js.flow +1 -1
  57. package/lib/redux/selectors/i18n.js +28 -0
  58. package/lib/redux/selectors/i18n.js.flow +15 -0
  59. package/lib/redux/selectors/i18n.js.map +1 -0
  60. package/lib/utils/datetime/DateTimeUtil.js +3 -1
  61. package/lib/utils/datetime/DateTimeUtil.js.flow +1 -1
  62. package/lib/utils/datetime/DateTimeUtil.js.map +1 -1
  63. package/package.json +1 -1
  64. package/src/hooks/__tests__/useAuthentication.spec.js +0 -8
  65. package/src/hooks/useContent.js +2 -2
  66. package/src/hooks/useI18n.js +10 -11
  67. package/src/hooks/useModularUI.js +3 -2
  68. package/src/hooks/useModularUIRequest.js +8 -10
  69. package/src/i18n/Message.js +1 -1
  70. package/src/i18n/withMessage.js +3 -4
  71. package/src/redux/_modularui/connector.js +3 -2
  72. package/src/redux/_modularui/selectors.js +19 -1
  73. package/src/redux/_modularui/withModularUI.js +3 -5
  74. package/src/redux/actions/Application.js +6 -8
  75. package/src/redux/actions/__tests__/Application.spec.js +1 -5
  76. package/src/redux/actions/__tests__/Authorization.spec.js +1 -1
  77. package/src/redux/selectors/i18n.js +15 -0
  78. package/src/utils/datetime/DateTimeUtil.js +1 -1
@@ -3,18 +3,13 @@ import { useSelector } from "react-redux";
3
3
  import { createSelector } from "reselect";
4
4
  import memoize from "lodash/memoize";
5
5
 
6
- const getLocaleCode = (state) => state.i18n.locale || "en";
7
- const getLocales = (state) => state.i18n.locales;
6
+ import { getLocales, getLocale } from "../redux/selectors/i18n";
8
7
 
9
8
  const getMessage = createSelector(
10
- [getLocales, getLocaleCode],
9
+ [getLocales, getLocale],
11
10
  (locales, localeCode) =>
12
11
  memoize(
13
- (
14
- id?: string | null,
15
- defaultMessage?: string | null,
16
- placeholders?: Object
17
- ) =>
12
+ (id: string, defaultMessage?: string, placeholders?: Object) =>
18
13
  locales
19
14
  .getLocale(localeCode)
20
15
  .getMessage(id, defaultMessage, placeholders),
@@ -25,8 +20,8 @@ const getMessage = createSelector(
25
20
  /**
26
21
  */
27
22
  const useMessage = (
28
- id?: string | null,
29
- defaultMessage?: string | null,
23
+ id: string,
24
+ defaultMessage?: string,
30
25
  placeholders?: Object | null
31
26
  ): any => useSelector(getMessage)(id, defaultMessage, placeholders);
32
27
 
@@ -34,4 +29,8 @@ const useMessage = (
34
29
  */
35
30
  const useTranslate = (): ((...any) => any) => useSelector(getMessage);
36
31
 
37
- export { useTranslate, useMessage };
32
+ /**
33
+ */
34
+ const useLocale = (): string => useSelector(getLocale);
35
+
36
+ export { useTranslate, useMessage, useLocale };
@@ -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) =>
@@ -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,
@@ -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;