@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.
- package/CHANGELOG.md +8 -2
- package/esm/hooks/useContent.js +2 -6
- package/esm/hooks/useContent.js.map +1 -1
- package/esm/hooks/useI18n.js +10 -11
- package/esm/hooks/useI18n.js.map +1 -1
- package/esm/hooks/useModularUI.js +2 -3
- package/esm/hooks/useModularUI.js.map +1 -1
- package/esm/hooks/useModularUIRequest.js +2 -5
- package/esm/hooks/useModularUIRequest.js.map +1 -1
- package/esm/i18n/Message.js.map +1 -1
- package/esm/i18n/withMessage.js +2 -10
- package/esm/i18n/withMessage.js.map +1 -1
- package/esm/redux/_modularui/connector.js +3 -4
- package/esm/redux/_modularui/connector.js.map +1 -1
- package/esm/redux/_modularui/selectors.js +22 -5
- package/esm/redux/_modularui/selectors.js.map +1 -1
- package/esm/redux/_modularui/withModularUI.js +2 -10
- package/esm/redux/_modularui/withModularUI.js.map +1 -1
- package/esm/redux/actions/Application.js +26 -7
- package/esm/redux/actions/Application.js.map +1 -1
- package/esm/redux/selectors/i18n.js +16 -0
- package/esm/redux/selectors/i18n.js.map +1 -0
- package/esm/utils/datetime/DateTimeUtil.js +3 -1
- package/esm/utils/datetime/DateTimeUtil.js.map +1 -1
- package/lib/hooks/__tests__/useAuthentication.spec.js.flow +0 -8
- package/lib/hooks/useContent.js +3 -7
- package/lib/hooks/useContent.js.flow +2 -2
- package/lib/hooks/useContent.js.map +1 -1
- package/lib/hooks/useI18n.js +12 -9
- package/lib/hooks/useI18n.js.flow +10 -11
- package/lib/hooks/useI18n.js.map +1 -1
- package/lib/hooks/useModularUI.js +3 -3
- package/lib/hooks/useModularUI.js.flow +3 -2
- package/lib/hooks/useModularUI.js.map +1 -1
- package/lib/hooks/useModularUIRequest.js +2 -4
- package/lib/hooks/useModularUIRequest.js.flow +8 -10
- package/lib/hooks/useModularUIRequest.js.map +1 -1
- package/lib/i18n/Message.js.flow +1 -1
- package/lib/i18n/Message.js.map +1 -1
- package/lib/i18n/withMessage.js +2 -8
- package/lib/i18n/withMessage.js.flow +3 -4
- package/lib/i18n/withMessage.js.map +1 -1
- package/lib/redux/_modularui/connector.js +3 -3
- package/lib/redux/_modularui/connector.js.flow +3 -2
- package/lib/redux/_modularui/connector.js.map +1 -1
- package/lib/redux/_modularui/selectors.js +26 -6
- package/lib/redux/_modularui/selectors.js.flow +19 -1
- package/lib/redux/_modularui/selectors.js.map +1 -1
- package/lib/redux/_modularui/withModularUI.js +3 -9
- package/lib/redux/_modularui/withModularUI.js.flow +3 -5
- package/lib/redux/_modularui/withModularUI.js.map +1 -1
- package/lib/redux/actions/Application.js +31 -8
- package/lib/redux/actions/Application.js.flow +6 -8
- package/lib/redux/actions/Application.js.map +1 -1
- package/lib/redux/actions/__tests__/Application.spec.js.flow +1 -5
- package/lib/redux/actions/__tests__/Authorization.spec.js.flow +1 -1
- package/lib/redux/selectors/i18n.js +28 -0
- package/lib/redux/selectors/i18n.js.flow +15 -0
- package/lib/redux/selectors/i18n.js.map +1 -0
- package/lib/utils/datetime/DateTimeUtil.js +3 -1
- package/lib/utils/datetime/DateTimeUtil.js.flow +1 -1
- package/lib/utils/datetime/DateTimeUtil.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/__tests__/useAuthentication.spec.js +0 -8
- package/src/hooks/useContent.js +2 -2
- package/src/hooks/useI18n.js +10 -11
- package/src/hooks/useModularUI.js +3 -2
- package/src/hooks/useModularUIRequest.js +8 -10
- package/src/i18n/Message.js +1 -1
- package/src/i18n/withMessage.js +3 -4
- package/src/redux/_modularui/connector.js +3 -2
- package/src/redux/_modularui/selectors.js +19 -1
- package/src/redux/_modularui/withModularUI.js +3 -5
- package/src/redux/actions/Application.js +6 -8
- package/src/redux/actions/__tests__/Application.spec.js +1 -5
- package/src/redux/actions/__tests__/Authorization.spec.js +1 -1
- package/src/redux/selectors/i18n.js +15 -0
- package/src/utils/datetime/DateTimeUtil.js +1 -1
package/src/hooks/useI18n.js
CHANGED
|
@@ -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
|
-
|
|
7
|
-
const getLocales = (state) => state.i18n.locales;
|
|
6
|
+
import { getLocales, getLocale } from "../redux/selectors/i18n";
|
|
8
7
|
|
|
9
8
|
const getMessage = createSelector(
|
|
10
|
-
[getLocales,
|
|
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
|
|
29
|
-
defaultMessage?: string
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
package/src/i18n/Message.js
CHANGED
package/src/i18n/withMessage.js
CHANGED
|
@@ -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,
|
|
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
|
|
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 =
|
|
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
|
-
[
|
|
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 {
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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({
|
|
@@ -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;
|