@beinformed/ui 1.65.1 → 1.65.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.
- package/CHANGELOG.md +23 -0
- package/esm/hooks/useList.js +4 -4
- package/esm/hooks/useList.js.flow +5 -5
- package/esm/hooks/useList.js.map +1 -1
- package/esm/hooks/useModularUI.js +3 -10
- package/esm/hooks/useModularUI.js.flow +3 -14
- package/esm/hooks/useModularUI.js.map +1 -1
- package/esm/hooks/useModularUIBasic.js +37 -12
- package/esm/hooks/useModularUIBasic.js.flow +47 -10
- package/esm/hooks/useModularUIBasic.js.map +1 -1
- package/esm/hooks/useModularUIKey.js +11 -0
- package/esm/hooks/useModularUIKey.js.flow +14 -0
- package/esm/hooks/useModularUIKey.js.map +1 -0
- package/esm/hooks/usePanel.js +8 -3
- package/esm/hooks/usePanel.js.flow +4 -3
- package/esm/hooks/usePanel.js.map +1 -1
- package/esm/models/href/Href.js +1 -1
- package/esm/models/href/Href.js.flow +1 -1
- package/esm/models/href/Href.js.map +1 -1
- package/esm/models/list/ListModel.js +5 -1
- package/esm/models/list/ListModel.js.flow +7 -3
- package/esm/models/list/ListModel.js.map +1 -1
- package/esm/models/sorting/SortOptionModel.js +7 -0
- package/esm/models/sorting/SortOptionModel.js.flow +7 -0
- package/esm/models/sorting/SortOptionModel.js.map +1 -1
- package/esm/models/sorting/SortingModel.js +14 -2
- package/esm/models/sorting/SortingModel.js.flow +14 -2
- package/esm/models/sorting/SortingModel.js.map +1 -1
- package/esm/redux/_modularui/ModularUIConnector.js +7 -6
- package/esm/redux/_modularui/ModularUIConnector.js.flow +6 -4
- package/esm/redux/_modularui/ModularUIConnector.js.map +1 -1
- package/esm/redux/actions/SignIn.js +15 -15
- package/esm/redux/actions/SignIn.js.flow +25 -26
- package/esm/redux/actions/SignIn.js.map +1 -1
- package/lib/hooks/useList.js +4 -4
- package/lib/hooks/useList.js.map +1 -1
- package/lib/hooks/useModularUI.js +3 -10
- package/lib/hooks/useModularUI.js.map +1 -1
- package/lib/hooks/useModularUIBasic.js +39 -14
- package/lib/hooks/useModularUIBasic.js.map +1 -1
- package/lib/hooks/useModularUIKey.js +17 -0
- package/lib/hooks/useModularUIKey.js.map +1 -0
- package/lib/hooks/usePanel.js +8 -3
- package/lib/hooks/usePanel.js.map +1 -1
- package/lib/models/href/Href.js +1 -1
- package/lib/models/href/Href.js.map +1 -1
- package/lib/models/list/ListModel.js +5 -1
- package/lib/models/list/ListModel.js.map +1 -1
- package/lib/models/sorting/SortOptionModel.js +7 -0
- package/lib/models/sorting/SortOptionModel.js.map +1 -1
- package/lib/models/sorting/SortingModel.js +14 -2
- package/lib/models/sorting/SortingModel.js.map +1 -1
- package/lib/redux/_modularui/ModularUIConnector.js +7 -6
- package/lib/redux/_modularui/ModularUIConnector.js.map +1 -1
- package/lib/redux/actions/SignIn.js +15 -15
- package/lib/redux/actions/SignIn.js.map +1 -1
- package/package.json +6 -6
- package/src/hooks/useList.js +5 -5
- package/src/hooks/useModularUI.js +3 -14
- package/src/hooks/useModularUIBasic.js +47 -10
- package/src/hooks/useModularUIKey.js +14 -0
- package/src/hooks/usePanel.js +4 -3
- package/src/models/href/Href.js +1 -1
- package/src/models/list/ListModel.js +7 -3
- package/src/models/sorting/SortOptionModel.js +7 -0
- package/src/models/sorting/SortingModel.js +14 -2
- package/src/redux/_modularui/ModularUIConnector.js +6 -4
- package/src/redux/actions/SignIn.js +25 -26
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import type { ModularUIModel, Href } from "../models";
|
|
3
2
|
import { useLocation } from "react-router";
|
|
3
|
+
import { useSelector } from "react-redux";
|
|
4
4
|
import { useMemo } from "react";
|
|
5
5
|
import { useModularUI } from "./useModularUI";
|
|
6
6
|
|
|
7
|
+
import { MODULARUI_STATUS } from "../constants";
|
|
8
|
+
import { useModularUIKey } from "./useModularUIKey";
|
|
9
|
+
|
|
10
|
+
import type { ModularUIModel, Href } from "../models";
|
|
7
11
|
export type HookOptions = {
|
|
12
|
+
key?: string,
|
|
8
13
|
origin?: string,
|
|
9
14
|
contextPath?: string,
|
|
15
|
+
removeOnUnmount?: boolean,
|
|
10
16
|
};
|
|
11
17
|
|
|
12
18
|
export type UseModularUIBasicOptions<T: ModularUIModel> = {
|
|
@@ -16,13 +22,16 @@ export type UseModularUIBasicOptions<T: ModularUIModel> = {
|
|
|
16
22
|
origin?: string,
|
|
17
23
|
contextPath?: string,
|
|
18
24
|
cache?: boolean,
|
|
25
|
+
key?: string,
|
|
26
|
+
isReload?: boolean,
|
|
27
|
+
removeOnUnmount?: boolean,
|
|
19
28
|
};
|
|
20
29
|
|
|
21
30
|
// Helper to create useModularUI options
|
|
22
31
|
const createUseModularUIOptions = <T: ModularUIModel>(
|
|
23
32
|
options: UseModularUIBasicOptions<T>,
|
|
24
33
|
href: string,
|
|
25
|
-
|
|
34
|
+
mustReload: boolean,
|
|
26
35
|
): Object => {
|
|
27
36
|
const baseOptions = {
|
|
28
37
|
targetModel: undefined,
|
|
@@ -31,6 +40,7 @@ const createUseModularUIOptions = <T: ModularUIModel>(
|
|
|
31
40
|
origin: undefined,
|
|
32
41
|
contextPath: undefined,
|
|
33
42
|
cache: false,
|
|
43
|
+
removeOnUnmount: false,
|
|
34
44
|
};
|
|
35
45
|
|
|
36
46
|
// Handle targetModel and forceTargetModel
|
|
@@ -44,11 +54,14 @@ const createUseModularUIOptions = <T: ModularUIModel>(
|
|
|
44
54
|
baseOptions.cache = options.cache;
|
|
45
55
|
}
|
|
46
56
|
|
|
47
|
-
|
|
48
|
-
if (location.state?.reload && location.pathname.startsWith(href)) {
|
|
57
|
+
if (mustReload) {
|
|
49
58
|
baseOptions.isReload = true;
|
|
50
59
|
}
|
|
51
60
|
|
|
61
|
+
if (options.removeOnUnmount) {
|
|
62
|
+
baseOptions.removeOnUnmount = true;
|
|
63
|
+
}
|
|
64
|
+
|
|
52
65
|
// Handle origin and contextPath options
|
|
53
66
|
baseOptions.origin = options.origin ?? baseOptions.origin;
|
|
54
67
|
baseOptions.contextPath = options.contextPath ?? baseOptions.contextPath;
|
|
@@ -72,7 +85,7 @@ const validateModel = (model: any, expectedModels: Array<string>) => {
|
|
|
72
85
|
* useModularUIBasic Hook
|
|
73
86
|
*/
|
|
74
87
|
export const useModularUIBasic = <T: ModularUIModel>(
|
|
75
|
-
|
|
88
|
+
defaultKey: string,
|
|
76
89
|
href: string | Href,
|
|
77
90
|
options: UseModularUIBasicOptions<T> = {
|
|
78
91
|
expectedModels: [],
|
|
@@ -80,16 +93,19 @@ export const useModularUIBasic = <T: ModularUIModel>(
|
|
|
80
93
|
forceTargetModel: false,
|
|
81
94
|
origin: undefined,
|
|
82
95
|
contextPath: undefined,
|
|
96
|
+
key: undefined,
|
|
83
97
|
},
|
|
84
98
|
): T | null => {
|
|
85
|
-
const location = useLocation();
|
|
86
99
|
const memoizedHref = useMemo(() => href.toString(), [href]);
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
const key = options.key ?? defaultKey;
|
|
101
|
+
|
|
102
|
+
const mustReload = useReload(key, memoizedHref);
|
|
103
|
+
const modularUIOptions = useMemo(
|
|
104
|
+
() => createUseModularUIOptions(options, memoizedHref, mustReload),
|
|
105
|
+
[options, memoizedHref, mustReload],
|
|
90
106
|
);
|
|
91
107
|
|
|
92
|
-
const modularUI = useModularUI(key, href,
|
|
108
|
+
const modularUI = useModularUI(key, href, modularUIOptions);
|
|
93
109
|
const expectedModels = useMemo(
|
|
94
110
|
() => options.expectedModels ?? [],
|
|
95
111
|
[options.expectedModels],
|
|
@@ -103,3 +119,24 @@ export const useModularUIBasic = <T: ModularUIModel>(
|
|
|
103
119
|
return null;
|
|
104
120
|
}, [expectedModels, modularUI]);
|
|
105
121
|
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Check if the model corresponding to a modular ui service should be reloaded
|
|
125
|
+
*/
|
|
126
|
+
export const useReload = (modelKey: string, url: string): boolean => {
|
|
127
|
+
const location = useLocation();
|
|
128
|
+
const key = useModularUIKey(modelKey, url);
|
|
129
|
+
const modelEntry = useSelector((state) => state.modularui[key]);
|
|
130
|
+
|
|
131
|
+
if (modelEntry) {
|
|
132
|
+
const reload = location.state?.reload || 0;
|
|
133
|
+
if (reload > 0) {
|
|
134
|
+
const isFullyLoaded = modelEntry?.status === MODULARUI_STATUS.FINISHED;
|
|
135
|
+
const lastModification = modelEntry?.lastModification ?? 0;
|
|
136
|
+
if (isFullyLoaded && lastModification < reload) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import { useLocale } from "./useI18n";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generates the key that is used in the modular ui reducer of redux
|
|
7
|
+
*/
|
|
8
|
+
export const useModularUIKey = (modelKey: string, url: string): string => {
|
|
9
|
+
const locale = useLocale();
|
|
10
|
+
return useMemo(
|
|
11
|
+
() => `${modelKey}(${url.split("?")[0]})(${locale})`,
|
|
12
|
+
[modelKey, url, locale],
|
|
13
|
+
);
|
|
14
|
+
};
|
package/src/hooks/usePanel.js
CHANGED
|
@@ -65,11 +65,12 @@ export const usePanel = (
|
|
|
65
65
|
href?: string | Href,
|
|
66
66
|
options?: HookOptions & { fromRoute?: boolean },
|
|
67
67
|
): ListModel | GroupingPanelModel | DetailModel | null => {
|
|
68
|
-
const
|
|
68
|
+
const { fromRoute, ...hookOptions } = options || { fromRoute: false };
|
|
69
|
+
|
|
70
|
+
const url = useUrl(href, fromRoute || false);
|
|
69
71
|
const basicOptions = {
|
|
70
72
|
expectedModels: ["List", "GroupingPanel", "Detail"],
|
|
71
|
-
|
|
72
|
-
contextPath: options?.contextPath,
|
|
73
|
+
...(hookOptions: HookOptions),
|
|
73
74
|
};
|
|
74
75
|
|
|
75
76
|
return useModularUIBasic("panel", url, basicOptions);
|
package/src/models/href/Href.js
CHANGED
|
@@ -281,7 +281,7 @@ class Href {
|
|
|
281
281
|
* Remove a parameter from the parameter collection
|
|
282
282
|
*/
|
|
283
283
|
removeParameter(name: string, prefix: ?string, value: ?string): Href {
|
|
284
|
-
if (value
|
|
284
|
+
if (value != undefined) {
|
|
285
285
|
const valueToRemove = value;
|
|
286
286
|
|
|
287
287
|
this._parameters = this._parameters.map((param) => {
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
SHOW_ONE_RESULT_AS_DETAIL,
|
|
21
21
|
} from "../../constants/LayoutHints";
|
|
22
22
|
|
|
23
|
-
import type { ModularUIModel } from "../types";
|
|
23
|
+
import type { ModularUIModel, FilterType } from "../types";
|
|
24
24
|
import type LinkModel from "../links/LinkModel";
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -288,8 +288,12 @@ export default class ListModel extends ResourceModel {
|
|
|
288
288
|
/**
|
|
289
289
|
* Set filterCollection
|
|
290
290
|
*/
|
|
291
|
-
set filterCollection(filterCollection: FilterCollection) {
|
|
292
|
-
|
|
291
|
+
set filterCollection(filterCollection: FilterCollection | Array<FilterType>) {
|
|
292
|
+
if (Array.isArray(filterCollection)) {
|
|
293
|
+
this._filterCollection.collection = filterCollection;
|
|
294
|
+
} else {
|
|
295
|
+
this._filterCollection = filterCollection;
|
|
296
|
+
}
|
|
293
297
|
}
|
|
294
298
|
|
|
295
299
|
/**
|
|
@@ -47,6 +47,13 @@ class SortingModel extends BaseCollection<SortOptionModel> {
|
|
|
47
47
|
.join(",");
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
*/
|
|
52
|
+
set value(value: string) {
|
|
53
|
+
this.reset();
|
|
54
|
+
this.setSelected(value);
|
|
55
|
+
}
|
|
56
|
+
|
|
50
57
|
/**
|
|
51
58
|
*/
|
|
52
59
|
get param(): string {
|
|
@@ -61,8 +68,13 @@ class SortingModel extends BaseCollection<SortOptionModel> {
|
|
|
61
68
|
|
|
62
69
|
/**
|
|
63
70
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
71
|
+
reset() {
|
|
72
|
+
this.collection.forEach((option) => option.reset());
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
*/
|
|
76
|
+
setSelected(value: string = "") {
|
|
77
|
+
value.split(",").forEach((sortItem) => {
|
|
66
78
|
const [key, direction] = sortItem.split(" ");
|
|
67
79
|
|
|
68
80
|
this.collection.forEach((option) => {
|
|
@@ -118,13 +118,15 @@ const modularUIConnector = (
|
|
|
118
118
|
}, [dispatch, doReload, url, modelKey]);
|
|
119
119
|
|
|
120
120
|
// Remove model when hoc unloads
|
|
121
|
-
useEffect(
|
|
122
|
-
|
|
121
|
+
useEffect(
|
|
122
|
+
// prettier-ignore
|
|
123
|
+
() => () => { //NOSONAR
|
|
123
124
|
if (finalRemoveOnUnmount) {
|
|
124
125
|
dispatch(removeModelByKey(modelKey));
|
|
125
126
|
}
|
|
126
|
-
}
|
|
127
|
-
|
|
127
|
+
},
|
|
128
|
+
[dispatch, modelKey, finalRemoveOnUnmount],
|
|
129
|
+
);
|
|
128
130
|
|
|
129
131
|
// Create new properties object to inject modularui properties to own props
|
|
130
132
|
const locale = useLocale();
|
|
@@ -3,7 +3,6 @@ import Cache from "../../utils/browser/Cache";
|
|
|
3
3
|
import Authenticate from "../../modularui/Authenticate";
|
|
4
4
|
import { getApplication } from "../_modularui/ModularUISelectors";
|
|
5
5
|
|
|
6
|
-
import { handleError } from "./Error";
|
|
7
6
|
import { reloadApplication } from "./Application";
|
|
8
7
|
import { startProgress, finishProgress } from "./ProgressIndicator";
|
|
9
8
|
|
|
@@ -70,34 +69,34 @@ export const changePassword = (): ThunkAction => (dispatch, getState) => {
|
|
|
70
69
|
*/
|
|
71
70
|
export const login =
|
|
72
71
|
(username: string, password: string): ThunkAction =>
|
|
73
|
-
(dispatch, getState) => {
|
|
72
|
+
async (dispatch, getState) => {
|
|
74
73
|
dispatch(startProgress());
|
|
75
74
|
|
|
76
|
-
|
|
77
|
-
.login(username, password)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
Cache.addItem("auth", true);
|
|
81
|
-
const application = getApplication(getState());
|
|
82
|
-
if (application?.userMustChangePassword) {
|
|
83
|
-
dispatch(changePassword());
|
|
84
|
-
} else {
|
|
85
|
-
dispatch(loginSuccess());
|
|
86
|
-
}
|
|
87
|
-
return dispatch(finishProgress());
|
|
88
|
-
})
|
|
89
|
-
.catch((error) => {
|
|
90
|
-
if (error.id === "Error.ChangePasswordRequired") {
|
|
91
|
-
const dispatchedReloadApplication = dispatch(reloadApplication());
|
|
75
|
+
try {
|
|
76
|
+
const response = await new Authenticate().login(username, password);
|
|
77
|
+
|
|
78
|
+
await dispatch(reloadApplication());
|
|
92
79
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
dispatch(changePassword());
|
|
96
|
-
return dispatch(finishProgress());
|
|
97
|
-
});
|
|
98
|
-
}
|
|
80
|
+
Cache.addItem("auth", true);
|
|
81
|
+
const application = getApplication(getState());
|
|
99
82
|
|
|
83
|
+
if (application?.userMustChangePassword) {
|
|
84
|
+
dispatch(changePassword());
|
|
85
|
+
} else {
|
|
86
|
+
dispatch(loginSuccess());
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
dispatch(finishProgress());
|
|
90
|
+
return response;
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (error.id === "Error.ChangePasswordRequired") {
|
|
93
|
+
await dispatch(reloadApplication());
|
|
94
|
+
Cache.addItem("auth", true);
|
|
95
|
+
dispatch(changePassword());
|
|
96
|
+
} else {
|
|
100
97
|
dispatch(loginFailed(error.id));
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
}
|
|
99
|
+
dispatch(finishProgress());
|
|
100
|
+
return error;
|
|
101
|
+
}
|
|
103
102
|
};
|