@beinformed/ui 1.65.0 → 1.65.2
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 +17 -0
- 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/filters/FilterCollection.js +8 -10
- package/esm/models/filters/FilterCollection.js.flow +12 -12
- package/esm/models/filters/FilterCollection.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/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/filters/FilterCollection.js +8 -10
- package/lib/models/filters/FilterCollection.js.map +1 -1
- package/lib/redux/actions/SignIn.js +15 -15
- package/lib/redux/actions/SignIn.js.map +1 -1
- package/package.json +1 -1
- 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/filters/FilterCollection.js +12 -12
- package/src/redux/actions/SignIn.js +25 -26
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
|
2
1
|
import Cache from "../../utils/browser/Cache";
|
|
3
2
|
import Authenticate from "../../modularui/Authenticate";
|
|
4
3
|
import { getApplication } from "../_modularui/ModularUISelectors";
|
|
5
|
-
import { handleError } from "./Error";
|
|
6
4
|
import { reloadApplication } from "./Application";
|
|
7
5
|
import { startProgress, finishProgress } from "./ProgressIndicator";
|
|
8
6
|
import { push } from "../_router/RouterActions";
|
|
@@ -51,9 +49,11 @@ export const changePassword = () => (dispatch, getState) => {
|
|
|
51
49
|
|
|
52
50
|
/**
|
|
53
51
|
*/
|
|
54
|
-
export const login = (username, password) => (dispatch, getState) => {
|
|
52
|
+
export const login = (username, password) => async (dispatch, getState) => {
|
|
55
53
|
dispatch(startProgress());
|
|
56
|
-
|
|
54
|
+
try {
|
|
55
|
+
const response = await new Authenticate().login(username, password);
|
|
56
|
+
await dispatch(reloadApplication());
|
|
57
57
|
Cache.addItem("auth", true);
|
|
58
58
|
const application = getApplication(getState());
|
|
59
59
|
if (application?.userMustChangePassword) {
|
|
@@ -61,18 +61,18 @@ export const login = (username, password) => (dispatch, getState) => {
|
|
|
61
61
|
} else {
|
|
62
62
|
dispatch(loginSuccess());
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
dispatch(finishProgress());
|
|
65
|
+
return response;
|
|
66
|
+
} catch (error) {
|
|
66
67
|
if (error.id === "Error.ChangePasswordRequired") {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
68
|
+
await dispatch(reloadApplication());
|
|
69
|
+
Cache.addItem("auth", true);
|
|
70
|
+
dispatch(changePassword());
|
|
71
|
+
} else {
|
|
72
|
+
dispatch(loginFailed(error.id));
|
|
73
73
|
}
|
|
74
|
-
dispatch(
|
|
75
|
-
return
|
|
76
|
-
}
|
|
74
|
+
dispatch(finishProgress());
|
|
75
|
+
return error;
|
|
76
|
+
}
|
|
77
77
|
};
|
|
78
78
|
//# sourceMappingURL=SignIn.js.map
|
|
@@ -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
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignIn.js","names":["Cache","Authenticate","getApplication","
|
|
1
|
+
{"version":3,"file":"SignIn.js","names":["Cache","Authenticate","getApplication","reloadApplication","startProgress","finishProgress","push","CHANGEPASSWORD_PATH","loginFailed","errorMessage","sendAuthenticationError","type","payload","resetAuthErrors","loginSuccess","changePassword","dispatch","getState","isModal","router","location","state","modal","locationFrom","from","login","username","password","response","addItem","application","userMustChangePassword","error","id"],"sources":["../../../src/redux/actions/SignIn.js"],"sourcesContent":["// @flow\nimport Cache from \"../../utils/browser/Cache\";\nimport Authenticate from \"../../modularui/Authenticate\";\nimport { getApplication } from \"../_modularui/ModularUISelectors\";\n\nimport { reloadApplication } from \"./Application\";\nimport { startProgress, finishProgress } from \"./ProgressIndicator\";\n\nimport { push } from \"../_router/RouterActions\";\nimport { CHANGEPASSWORD_PATH } from \"../../constants/Constants\";\n\nimport type {\n SendAuthenticationErrorAction,\n ResetAuthErrorsAction,\n LoginSuccessAction,\n ThunkAction,\n} from \"../types\";\n\n/**\n * Send login failed action\n */\nexport const loginFailed = (\n errorMessage: string,\n): SendAuthenticationErrorAction => sendAuthenticationError(errorMessage);\n\n/**\n * Send authentication error action\n */\nexport const sendAuthenticationError = (\n errorMessage: string,\n): SendAuthenticationErrorAction => ({\n type: \"AUTHENTICATION_ERROR\",\n payload: errorMessage,\n});\n\n/**\n * Resets any authentication errors\n */\nexport const resetAuthErrors = (): ResetAuthErrorsAction => ({\n type: \"AUTHENTICATION_RESET_ERRORS\",\n});\n\n/**\n * Send login success action\n */\nexport const loginSuccess = (): LoginSuccessAction => ({\n type: \"AUTHENTICATION_SUCCESS\",\n});\n\n/**\n * Send change password action\n */\nexport const changePassword = (): ThunkAction => (dispatch, getState) => {\n dispatch({\n type: \"CHANGE_PASSWORD\",\n });\n\n const isModal = getState().router.location?.state?.modal;\n const locationFrom = getState().router.location?.state?.from;\n return dispatch(\n push(CHANGEPASSWORD_PATH, {\n from: locationFrom ? locationFrom : getState().router.location,\n modal: isModal,\n }),\n );\n};\n\n/**\n */\nexport const login =\n (username: string, password: string): ThunkAction =>\n async (dispatch, getState) => {\n dispatch(startProgress());\n\n try {\n const response = await new Authenticate().login(username, password);\n\n await dispatch(reloadApplication());\n\n Cache.addItem(\"auth\", true);\n const application = getApplication(getState());\n\n if (application?.userMustChangePassword) {\n dispatch(changePassword());\n } else {\n dispatch(loginSuccess());\n }\n\n dispatch(finishProgress());\n return response;\n } catch (error) {\n if (error.id === \"Error.ChangePasswordRequired\") {\n await dispatch(reloadApplication());\n Cache.addItem(\"auth\", true);\n dispatch(changePassword());\n } else {\n dispatch(loginFailed(error.id));\n }\n dispatch(finishProgress());\n return error;\n }\n };\n"],"mappings":"AACA,OAAOA,KAAK,MAAM,2BAA2B;AAC7C,OAAOC,YAAY,MAAM,8BAA8B;AACvD,SAASC,cAAc,QAAQ,kCAAkC;AAEjE,SAASC,iBAAiB,QAAQ,eAAe;AACjD,SAASC,aAAa,EAAEC,cAAc,QAAQ,qBAAqB;AAEnE,SAASC,IAAI,QAAQ,0BAA0B;AAC/C,SAASC,mBAAmB,QAAQ,2BAA2B;AAS/D;AACA;AACA;AACA,OAAO,MAAMC,WAAW,GACtBC,YAAoB,I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;IAEnCH,KAAK,CAAC6B,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC;IAC3B,MAAMC,WAAW,GAAG5B,cAAc,CAACe,QAAQ,CAAC,CAAC,CAAC;IAE9C,IAAIa,WAAW,EAAEC,sBAAsB,EAAE;MACvCf,QAAQ,CAACD,cAAc,CAAC,CAAC,CAAC;IAC5B,CAAC,MAAM;MACLC,QAAQ,CAACF,YAAY,CAAC,CAAC,CAAC;IAC1B;IAEAE,QAAQ,CAACX,cAAc,CAAC,CAAC,CAAC;IAC1B,OAAOuB,QAAQ;EACjB,CAAC,CAAC,OAAOI,KAAK,EAAE;IACd,IAAIA,KAAK,CAACC,EAAE,KAAK,8BAA8B,EAAE;MAC/C,MAAMjB,QAAQ,CAACb,iBAAiB,CAAC,CAAC,CAAC;MACnCH,KAAK,CAAC6B,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC;MAC3Bb,QAAQ,CAACD,cAAc,CAAC,CAAC,CAAC;IAC5B,CAAC,MAAM;MACLC,QAAQ,CAACR,WAAW,CAACwB,KAAK,CAACC,EAAE,CAAC,CAAC;IACjC;IACAjB,QAAQ,CAACX,cAAc,CAAC,CAAC,CAAC;IAC1B,OAAO2B,KAAK;EACd;AACF,CAAC","ignoreList":[]}
|
|
@@ -11,17 +11,10 @@ var _reactRouter = require("react-router");
|
|
|
11
11
|
var _constants = require("../constants");
|
|
12
12
|
var _ModularUIActions = require("../redux/_modularui/ModularUIActions");
|
|
13
13
|
var _useDeepCompareEffect = _interopRequireDefault(require("./useDeepCompareEffect"));
|
|
14
|
-
var
|
|
14
|
+
var _useModularUIKey = require("./useModularUIKey");
|
|
15
15
|
var _Href = _interopRequireDefault(require("../models/href/Href"));
|
|
16
16
|
/**
|
|
17
|
-
|
|
18
|
-
const useKeyForHook = (modelKey, url) => {
|
|
19
|
-
const locale = (0, _useI18n.useLocale)();
|
|
20
|
-
return (0, _react.useMemo)(() => `${modelKey}(${url.split("?")[0]})(${locale})`, [modelKey, url, locale]);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Use redux action and selector to retrieve the correct modular ui service model
|
|
17
|
+
* Core hook to retrieve information for a Be Informed modular ui resource
|
|
25
18
|
*/
|
|
26
19
|
const useModularUI = (modelKey, url, options = {
|
|
27
20
|
method: _constants.HTTP_METHODS.GET,
|
|
@@ -29,7 +22,7 @@ const useModularUI = (modelKey, url, options = {
|
|
|
29
22
|
}) => {
|
|
30
23
|
const dispatch = (0, _reactRedux.useDispatch)();
|
|
31
24
|
const href = (0, _react.useMemo)(() => url?.toString() || "", [url]);
|
|
32
|
-
const key =
|
|
25
|
+
const key = (0, _useModularUIKey.useModularUIKey)(modelKey, href);
|
|
33
26
|
const modelSelector = (0, _react.useMemo)(() => state => state.modularui[key], [key]);
|
|
34
27
|
const model = (0, _reactRedux.useSelector)(modelSelector);
|
|
35
28
|
if (url instanceof _Href.default) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModularUI.js","names":["_react","require","_reactRedux","_reactRouter","_constants","_ModularUIActions","_useDeepCompareEffect","_interopRequireDefault","
|
|
1
|
+
{"version":3,"file":"useModularUI.js","names":["_react","require","_reactRedux","_reactRouter","_constants","_ModularUIActions","_useDeepCompareEffect","_interopRequireDefault","_useModularUIKey","_Href","useModularUI","modelKey","url","options","method","HTTP_METHODS","GET","removeOnUnmount","dispatch","useDispatch","href","useMemo","toString","key","useModularUIKey","modelSelector","state","modularui","model","useSelector","Href","origin","contextPath","location","useLocation","redirectLocation","forceLoad","equals","prevOptions","useRef","prevHref","prevForceLoad","useDeepCompareEffect","isOldReload","current","isReload","doForceLoad","loadModularUI","useEffect","removeModelByKey","exports"],"sources":["../../src/hooks/useModularUI.js"],"sourcesContent":["// @flow\nimport { useEffect, useRef, useMemo } from \"react\";\nimport { useDispatch, useSelector } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport { HTTP_METHODS } from \"../constants\";\nimport {\n loadModularUI,\n removeModelByKey,\n} from \"../redux/_modularui/ModularUIActions\";\n\nimport useDeepCompareEffect from \"./useDeepCompareEffect\";\nimport { useModularUIKey } from \"./useModularUIKey\";\n\nimport Href from \"../models/href/Href\";\nimport type { RequestModularUIOptions } from \"../utils\";\n\n/**\n * Core hook to retrieve information for a Be Informed modular ui resource\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: false,\n },\n): any => {\n const dispatch = useDispatch();\n const href = useMemo(() => url?.toString() || \"\", [url]);\n const key = useModularUIKey(modelKey, href);\n\n const modelSelector = useMemo(() => (state) => state.modularui[key], [key]);\n const model = useSelector(modelSelector);\n\n if (url instanceof Href) {\n options.origin = options.origin ?? url.origin;\n options.contextPath = options.contextPath ?? url.contextPath;\n }\n\n const location = useLocation();\n const redirectLocation = location.state?.redirectLocation;\n const forceLoad =\n model == null ||\n (redirectLocation instanceof Href ? redirectLocation?.equals(href) : false);\n\n const prevOptions = useRef(options);\n const prevHref = useRef(href);\n const prevForceLoad = useRef(forceLoad);\n\n // dispatch loadModularUI\n useDeepCompareEffect(() => {\n // prevent reloads when previous option had the isReload, but the new options not\n const isOldReload =\n prevHref.current === href &&\n prevOptions.current.isReload &&\n !options.isReload;\n\n const doForceLoad = forceLoad && !prevForceLoad.current;\n\n if (href !== \"\" && (doForceLoad || !isOldReload)) {\n dispatch(loadModularUI(key, href, options));\n }\n\n prevOptions.current = options;\n prevHref.current = href;\n prevForceLoad.current = forceLoad;\n }, [key, href, options, forceLoad]);\n\n useEffect(() => {\n if (options.removeOnUnmount) {\n return () => {\n dispatch(removeModelByKey(key));\n };\n }\n }, [dispatch, key, options.removeOnUnmount]);\n\n return model;\n};\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,iBA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/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
|
-
exports.useModularUIBasic = void 0;
|
|
8
|
-
var _startsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/starts-with"));
|
|
6
|
+
exports.useReload = exports.useModularUIBasic = void 0;
|
|
9
7
|
var _reactRouter = require("react-router");
|
|
8
|
+
var _reactRedux = require("react-redux");
|
|
10
9
|
var _react = require("react");
|
|
11
10
|
var _useModularUI = require("./useModularUI");
|
|
11
|
+
var _constants = require("../constants");
|
|
12
|
+
var _useModularUIKey = require("./useModularUIKey");
|
|
12
13
|
// Helper to create useModularUI options
|
|
13
|
-
const createUseModularUIOptions = (options, href,
|
|
14
|
-
var _context;
|
|
14
|
+
const createUseModularUIOptions = (options, href, mustReload) => {
|
|
15
15
|
const baseOptions = {
|
|
16
16
|
targetModel: undefined,
|
|
17
17
|
forceTargetModel: undefined,
|
|
18
18
|
isReload: false,
|
|
19
19
|
origin: undefined,
|
|
20
20
|
contextPath: undefined,
|
|
21
|
-
cache: false
|
|
21
|
+
cache: false,
|
|
22
|
+
removeOnUnmount: false
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
// Handle targetModel and forceTargetModel
|
|
@@ -31,11 +32,12 @@ const createUseModularUIOptions = (options, href, location) => {
|
|
|
31
32
|
if (options.cache) {
|
|
32
33
|
baseOptions.cache = options.cache;
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
-
// Check for reload if location matches href
|
|
36
|
-
if (location.state?.reload && (0, _startsWith.default)(_context = location.pathname).call(_context, href)) {
|
|
35
|
+
if (mustReload) {
|
|
37
36
|
baseOptions.isReload = true;
|
|
38
37
|
}
|
|
38
|
+
if (options.removeOnUnmount) {
|
|
39
|
+
baseOptions.removeOnUnmount = true;
|
|
40
|
+
}
|
|
39
41
|
|
|
40
42
|
// Handle origin and contextPath options
|
|
41
43
|
baseOptions.origin = options.origin ?? baseOptions.origin;
|
|
@@ -56,17 +58,19 @@ const validateModel = (model, expectedModels) => {
|
|
|
56
58
|
/**
|
|
57
59
|
* useModularUIBasic Hook
|
|
58
60
|
*/
|
|
59
|
-
const useModularUIBasic = (
|
|
61
|
+
const useModularUIBasic = (defaultKey, href, options = {
|
|
60
62
|
expectedModels: [],
|
|
61
63
|
targetModel: undefined,
|
|
62
64
|
forceTargetModel: false,
|
|
63
65
|
origin: undefined,
|
|
64
|
-
contextPath: undefined
|
|
66
|
+
contextPath: undefined,
|
|
67
|
+
key: undefined
|
|
65
68
|
}) => {
|
|
66
|
-
const location = (0, _reactRouter.useLocation)();
|
|
67
69
|
const memoizedHref = (0, _react.useMemo)(() => href.toString(), [href]);
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
+
const key = options.key ?? defaultKey;
|
|
71
|
+
const mustReload = useReload(key, memoizedHref);
|
|
72
|
+
const modularUIOptions = (0, _react.useMemo)(() => createUseModularUIOptions(options, memoizedHref, mustReload), [options, memoizedHref, mustReload]);
|
|
73
|
+
const modularUI = (0, _useModularUI.useModularUI)(key, href, modularUIOptions);
|
|
70
74
|
const expectedModels = (0, _react.useMemo)(() => options.expectedModels ?? [], [options.expectedModels]);
|
|
71
75
|
return (0, _react.useMemo)(() => {
|
|
72
76
|
if (modularUI?.model) {
|
|
@@ -76,5 +80,26 @@ const useModularUIBasic = (key, href, options = {
|
|
|
76
80
|
return null;
|
|
77
81
|
}, [expectedModels, modularUI]);
|
|
78
82
|
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Check if the model corresponding to a modular ui service should be reloaded
|
|
86
|
+
*/
|
|
79
87
|
exports.useModularUIBasic = useModularUIBasic;
|
|
88
|
+
const useReload = (modelKey, url) => {
|
|
89
|
+
const location = (0, _reactRouter.useLocation)();
|
|
90
|
+
const key = (0, _useModularUIKey.useModularUIKey)(modelKey, url);
|
|
91
|
+
const modelEntry = (0, _reactRedux.useSelector)(state => state.modularui[key]);
|
|
92
|
+
if (modelEntry) {
|
|
93
|
+
const reload = location.state?.reload || 0;
|
|
94
|
+
if (reload > 0) {
|
|
95
|
+
const isFullyLoaded = modelEntry?.status === _constants.MODULARUI_STATUS.FINISHED;
|
|
96
|
+
const lastModification = modelEntry?.lastModification ?? 0;
|
|
97
|
+
if (isFullyLoaded && lastModification < reload) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
};
|
|
104
|
+
exports.useReload = useReload;
|
|
80
105
|
//# sourceMappingURL=useModularUIBasic.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModularUIBasic.js","names":["_reactRouter","require","_react","_useModularUI","createUseModularUIOptions","options","href","
|
|
1
|
+
{"version":3,"file":"useModularUIBasic.js","names":["_reactRouter","require","_reactRedux","_react","_useModularUI","_constants","_useModularUIKey","createUseModularUIOptions","options","href","mustReload","baseOptions","targetModel","undefined","forceTargetModel","isReload","origin","contextPath","cache","removeOnUnmount","validateModel","model","expectedModels","length","isCorrectModel","some","expectedModel","type","console","warn","useModularUIBasic","defaultKey","key","memoizedHref","useMemo","toString","useReload","modularUIOptions","modularUI","useModularUI","exports","modelKey","url","location","useLocation","useModularUIKey","modelEntry","useSelector","state","modularui","reload","isFullyLoaded","status","MODULARUI_STATUS","FINISHED","lastModification"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useLocation } from \"react-router\";\nimport { useSelector } from \"react-redux\";\nimport { useMemo } from \"react\";\nimport { useModularUI } from \"./useModularUI\";\n\nimport { MODULARUI_STATUS } from \"../constants\";\nimport { useModularUIKey } from \"./useModularUIKey\";\n\nimport type { ModularUIModel, Href } from \"../models\";\nexport type HookOptions = {\n key?: string,\n origin?: string,\n contextPath?: string,\n removeOnUnmount?: boolean,\n};\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels?: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n origin?: string,\n contextPath?: string,\n cache?: boolean,\n key?: string,\n isReload?: boolean,\n removeOnUnmount?: boolean,\n};\n\n// Helper to create useModularUI options\nconst createUseModularUIOptions = <T: ModularUIModel>(\n options: UseModularUIBasicOptions<T>,\n href: string,\n mustReload: boolean,\n): Object => {\n const baseOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n origin: undefined,\n contextPath: undefined,\n cache: false,\n removeOnUnmount: false,\n };\n\n // Handle targetModel and forceTargetModel\n if (options.targetModel) {\n baseOptions.targetModel = options.targetModel;\n baseOptions.forceTargetModel = options.forceTargetModel;\n }\n\n // Handle cache option\n if (options.cache) {\n baseOptions.cache = options.cache;\n }\n\n if (mustReload) {\n baseOptions.isReload = true;\n }\n\n if (options.removeOnUnmount) {\n baseOptions.removeOnUnmount = true;\n }\n\n // Handle origin and contextPath options\n baseOptions.origin = options.origin ?? baseOptions.origin;\n baseOptions.contextPath = options.contextPath ?? baseOptions.contextPath;\n\n return baseOptions;\n};\n\n// Helper to validate the model against expectedModels\nconst validateModel = (model: any, expectedModels: Array<string>) => {\n if (expectedModels.length > 0) {\n const isCorrectModel = expectedModels.some(\n (expectedModel) => model.type === expectedModel,\n );\n if (!isCorrectModel) {\n console.warn(model, \"is not of instance\", expectedModels);\n }\n }\n};\n\n/**\n * useModularUIBasic Hook\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n defaultKey: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {\n expectedModels: [],\n targetModel: undefined,\n forceTargetModel: false,\n origin: undefined,\n contextPath: undefined,\n key: undefined,\n },\n): T | null => {\n const memoizedHref = useMemo(() => href.toString(), [href]);\n const key = options.key ?? defaultKey;\n\n const mustReload = useReload(key, memoizedHref);\n const modularUIOptions = useMemo(\n () => createUseModularUIOptions(options, memoizedHref, mustReload),\n [options, memoizedHref, mustReload],\n );\n\n const modularUI = useModularUI(key, href, modularUIOptions);\n const expectedModels = useMemo(\n () => options.expectedModels ?? [],\n [options.expectedModels],\n );\n\n return useMemo((): T | null => {\n if (modularUI?.model) {\n validateModel(modularUI.model, expectedModels);\n return modularUI.model;\n }\n return null;\n }, [expectedModels, modularUI]);\n};\n\n/**\n * Check if the model corresponding to a modular ui service should be reloaded\n */\nexport const useReload = (modelKey: string, url: string): boolean => {\n const location = useLocation();\n const key = useModularUIKey(modelKey, url);\n const modelEntry = useSelector((state) => state.modularui[key]);\n\n if (modelEntry) {\n const reload = location.state?.reload || 0;\n if (reload > 0) {\n const isFullyLoaded = modelEntry?.status === MODULARUI_STATUS.FINISHED;\n const lastModification = modelEntry?.lastModification ?? 0;\n if (isFullyLoaded && lastModification < reload) {\n return true;\n }\n }\n }\n return false;\n};\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AAEA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AAsBA;AACA,MAAMM,yBAAyB,GAAGA,CAChCC,OAAoC,EACpCC,IAAY,EACZC,UAAmB,KACR;EACX,MAAMC,WAAW,GAAG;IAClBC,WAAW,EAAEC,SAAS;IACtBC,gBAAgB,EAAED,SAAS;IAC3BE,QAAQ,EAAE,KAAK;IACfC,MAAM,EAAEH,SAAS;IACjBI,WAAW,EAAEJ,SAAS;IACtBK,KAAK,EAAE,KAAK;IACZC,eAAe,EAAE;EACnB,CAAC;;EAED;EACA,IAAIX,OAAO,CAACI,WAAW,EAAE;IACvBD,WAAW,CAACC,WAAW,GAAGJ,OAAO,CAACI,WAAW;IAC7CD,WAAW,CAACG,gBAAgB,GAAGN,OAAO,CAACM,gBAAgB;EACzD;;EAEA;EACA,IAAIN,OAAO,CAACU,KAAK,EAAE;IACjBP,WAAW,CAACO,KAAK,GAAGV,OAAO,CAACU,KAAK;EACnC;EAEA,IAAIR,U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J,aAAa,IAAII,gBAAgB,GAAGL,MAAM,EAAE;QAC9C,OAAO,IAAI;MACb;IACF;EACF;EACA,OAAO,KAAK;AACd,CAAC;AAACV,OAAA,CAAAJ,SAAA,GAAAA,SAAA","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useModularUIKey = void 0;
|
|
7
|
+
var _useI18n = require("./useI18n");
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
/**
|
|
10
|
+
* Generates the key that is used in the modular ui reducer of redux
|
|
11
|
+
*/
|
|
12
|
+
const useModularUIKey = (modelKey, url) => {
|
|
13
|
+
const locale = (0, _useI18n.useLocale)();
|
|
14
|
+
return (0, _react.useMemo)(() => `${modelKey}(${url.split("?")[0]})(${locale})`, [modelKey, url, locale]);
|
|
15
|
+
};
|
|
16
|
+
exports.useModularUIKey = useModularUIKey;
|
|
17
|
+
//# sourceMappingURL=useModularUIKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useModularUIKey.js","names":["_useI18n","require","_react","useModularUIKey","modelKey","url","locale","useLocale","useMemo","split","exports"],"sources":["../../src/hooks/useModularUIKey.js"],"sourcesContent":["// @flow\nimport { useLocale } from \"./useI18n\";\nimport { useMemo } from \"react\";\n\n/**\n * Generates the key that is used in the modular ui reducer of redux\n */\nexport const useModularUIKey = (modelKey: string, url: string): string => {\n const locale = useLocale();\n return useMemo(\n () => `${modelKey}(${url.split(\"?\")[0]})(${locale})`,\n [modelKey, url, locale],\n );\n};\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACO,MAAME,eAAe,GAAGA,CAACC,QAAgB,EAAEC,GAAW,KAAa;EACxE,MAAMC,MAAM,GAAG,IAAAC,kBAAS,EAAC,CAAC;EAC1B,OAAO,IAAAC,cAAO,EACZ,MAAM,GAAGJ,QAAQ,IAAIC,GAAG,CAACI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAKH,MAAM,GAAG,EACpD,CAACF,QAAQ,EAAEC,GAAG,EAAEC,MAAM,CACxB,CAAC;AACH,CAAC;AAACI,OAAA,CAAAP,eAAA,GAAAA,eAAA","ignoreList":[]}
|
package/lib/hooks/usePanel.js
CHANGED
|
@@ -45,11 +45,16 @@ const useUrl = (href, fromRoute = false) => {
|
|
|
45
45
|
/**
|
|
46
46
|
*/
|
|
47
47
|
const usePanel = (href, options) => {
|
|
48
|
-
const
|
|
48
|
+
const {
|
|
49
|
+
fromRoute,
|
|
50
|
+
...hookOptions
|
|
51
|
+
} = options || {
|
|
52
|
+
fromRoute: false
|
|
53
|
+
};
|
|
54
|
+
const url = useUrl(href, fromRoute || false);
|
|
49
55
|
const basicOptions = {
|
|
50
56
|
expectedModels: ["List", "GroupingPanel", "Detail"],
|
|
51
|
-
|
|
52
|
-
contextPath: options?.contextPath
|
|
57
|
+
...hookOptions
|
|
53
58
|
};
|
|
54
59
|
return (0, _useModularUIBasic.useModularUIBasic)("panel", url, basicOptions);
|
|
55
60
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePanel.js","names":["_react","require","_reactRouter","_Href","_interopRequireDefault","_useModularUIBasic","useUrl","href","fromRoute","previousUrl","setPreviousUrl","useState","previousExact","setPreviousExact","match","useRouteMatch","location","useLocation","useMemo","_context","Href","url","isExact","addParametersFromString","search","equalsWithParameters","shouldUpdate","Function","call","bind","_startsWith","default","usePanel","options","
|
|
1
|
+
{"version":3,"file":"usePanel.js","names":["_react","require","_reactRouter","_Href","_interopRequireDefault","_useModularUIBasic","useUrl","href","fromRoute","previousUrl","setPreviousUrl","useState","previousExact","setPreviousExact","match","useRouteMatch","location","useLocation","useMemo","_context","Href","url","isExact","addParametersFromString","search","equalsWithParameters","shouldUpdate","Function","call","bind","_startsWith","default","usePanel","options","hookOptions","basicOptions","expectedModels","useModularUIBasic","exports"],"sources":["../../src/hooks/usePanel.js"],"sourcesContent":["// @flow\nimport { useState, useMemo } from \"react\";\nimport { useLocation, useRouteMatch } from \"react-router\";\nimport Href from \"../models/href/Href\";\nimport { useModularUIBasic } from \"./useModularUIBasic\";\n\nimport type { HookOptions } from \"./useModularUIBasic\";\nimport type GroupingPanelModel from \"../models/panels/GroupingPanelModel\";\nimport type ListModel from \"../models/list/ListModel\";\nimport type DetailModel from \"../models/detail/DetailModel\";\n\nconst useUrl = (href?: string | Href, fromRoute: boolean = false) => {\n const [previousUrl, setPreviousUrl] = useState(null);\n const [previousExact, setPreviousExact] = useState(false);\n\n const match = useRouteMatch();\n const location = useLocation();\n\n return useMemo(() => {\n if (href == null && previousUrl == null) {\n return new Href(\"\");\n }\n\n const url = href instanceof Href ? href : new Href(href);\n\n if (!fromRoute) {\n return url;\n }\n\n if (match.isExact) {\n url.addParametersFromString(location.search);\n }\n\n // Check equality to prevent unnecessary state updates\n if (url.equalsWithParameters(previousUrl)) {\n return previousUrl || url;\n }\n\n const shouldUpdate =\n match.isExact === true ||\n previousExact === match.isExact ||\n !previousUrl?.startsWith(match.url);\n\n if (shouldUpdate) {\n setPreviousUrl(url);\n setPreviousExact(match.isExact);\n return url;\n }\n\n return previousUrl || new Href(\"\");\n }, [\n href,\n previousUrl,\n fromRoute,\n match.isExact,\n match.url,\n previousExact,\n location.search,\n ]);\n};\n\n/**\n */\nexport const usePanel = (\n href?: string | Href,\n options?: HookOptions & { fromRoute?: boolean },\n): ListModel | GroupingPanelModel | DetailModel | null => {\n const { fromRoute, ...hookOptions } = options || { fromRoute: false };\n\n const url = useUrl(href, fromRoute || false);\n const basicOptions = {\n expectedModels: [\"List\", \"GroupingPanel\", \"Detail\"],\n ...(hookOptions: HookOptions),\n };\n\n return useModularUIBasic(\"panel\", url, basicOptions);\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,MA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,QAAA,KAAaL,KAAK,CAACO,GAAG,CAAC;IAErC,IAAIK,YAAY,EAAE;MAChBhB,cAAc,CAACW,GAAG,CAAC;MACnBR,gBAAgB,CAACC,KAAK,CAACQ,OAAO,CAAC;MAC/B,OAAOD,GAAG;IACZ;IAEA,OAAOZ,WAAW,IAAI,IAAIW,aAAI,CAAC,EAAE,CAAC;EACpC,CAAC,EAAE,CACDb,IAAI,EACJE,WAAW,EACXD,SAAS,EACTM,KAAK,CAACQ,OAAO,EACbR,KAAK,CAACO,GAAG,EACTT,aAAa,EACbI,QAAQ,CAACQ,MAAM,CAChB,CAAC;AACJ,CAAC;;AAED;AACA;AACO,MAAMQ,QAAQ,GAAGA,CACtBzB,IAAoB,EACpB0B,OAA+C,KACS;EACxD,MAAM;IAAEzB,SAAS;IAAE,GAAG0B;EAAY,CAAC,GAAGD,OAAO,IAAI;IAAEzB,SAAS,EAAE;EAAM,CAAC;EAErE,MAAMa,GAAG,GAAGf,MAAM,CAACC,IAAI,EAAEC,SAAS,IAAI,KAAK,CAAC;EAC5C,MAAM2B,YAAY,GAAG;IACnBC,cAAc,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,QAAQ,CAAC;IACnD,GAAIF;EACN,CAAC;EAED,OAAO,IAAAG,oCAAiB,EAAC,OAAO,EAAEhB,GAAG,EAAEc,YAAY,CAAC;AACtD,CAAC;AAACG,OAAA,CAAAN,QAAA,GAAAA,QAAA","ignoreList":[]}
|
|
@@ -10,6 +10,7 @@ var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable
|
|
|
10
10
|
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
|
|
11
11
|
var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));
|
|
12
12
|
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
|
13
|
+
var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
|
|
13
14
|
var _BaseCollection = _interopRequireDefault(require("../base/BaseCollection"));
|
|
14
15
|
var _StringFilterModel = _interopRequireDefault(require("../filters/StringFilterModel"));
|
|
15
16
|
var _RangeFilterModel = _interopRequireDefault(require("../filters/RangeFilterModel"));
|
|
@@ -153,16 +154,13 @@ class FilterCollection extends _BaseCollection.default {
|
|
|
153
154
|
*/
|
|
154
155
|
get formdata() {
|
|
155
156
|
var _context7;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
};
|
|
164
|
-
});
|
|
165
|
-
return data;
|
|
157
|
+
const bodyFields = (0, _filter.default)(_context7 = this).call(_context7, f => f.parameterType === _constants.PARAMETER_TYPES.BODY && f.hasValue() && f.formdata);
|
|
158
|
+
if (bodyFields.length === 0) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
return bodyFields.reduce((data, f) => {
|
|
162
|
+
return (0, _assign.default)(data, f.formdata);
|
|
163
|
+
}, {});
|
|
166
164
|
}
|
|
167
165
|
}
|
|
168
166
|
exports.default = FilterCollection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilterCollection.js","names":["_BaseCollection","_interopRequireDefault","require","_StringFilterModel","_RangeFilterModel","_AssignmentFilterModel","_ConceptIndexFilterModel","_CompositeAttributeModel","_FilterModel","_constants","FilterCollection","BaseCollection","constructor","data","contributions","modelOptions","Array","isArray","_filter","default","_context","_context2","collection","_map","call","filterContribution","_keys","filterKey","filterData","filterContributionByKey","filter","createFilter","dynamicschema","listkey","contexts","contextid","_context3","filterContext","_find","context","id","type","ConceptIndexFilterModel","_includes","RangeFilterModel","AssignmentFilterModel","StringFilterModel","FilterModel","reset","_context4","checkRangeFilterByAttributeKey","key","rangeAttribute","attribute","CompositeAttributeModel","start","end","checkAssignmentFilterByAttributeKey","user","assignmenttype","getFilterByAttributeKey","_context5","update","value","_context6","filterToUpdate","parentKey","Error","newFilter","clone","name","isValid","every","hasActiveFilters","some","isActive","formdata","_context7","f","parameterType","PARAMETER_TYPES","BODY","hasValue","forEach","exports"],"sources":["../../../src/models/filters/FilterCollection.js"],"sourcesContent":["// @flow\nimport BaseCollection from \"../base/BaseCollection\";\n\nimport StringFilterModel from \"../filters/StringFilterModel\";\nimport RangeFilterModel from \"../filters/RangeFilterModel\";\nimport AssignmentFilterModel from \"../filters/AssignmentFilterModel\";\nimport ConceptIndexFilterModel from \"../filters/ConceptIndexFilterModel\";\nimport CompositeAttributeModel from \"../attributes/CompositeAttributeModel\";\nimport FilterModel from \"../filters/FilterModel\";\n\nimport type { AttributeType, FilterType, ModelOptions } from \"../types\";\nimport { PARAMETER_TYPES } from \"../../constants\";\n\n/**\n * Contains a collection of filters\n */\nexport default class FilterCollection extends BaseCollection<FilterType> {\n /**\n * Construct a collection of filters\n */\n constructor(\n data: Object = {},\n contributions: Object = {},\n modelOptions?: ModelOptions,\n ) {\n super();\n\n if (data && contributions && Array.isArray(contributions.filter)) {\n this.collection = contributions.filter\n .filter((filterContribution) => Object.keys(filterContribution)[0])\n .map((filterContribution) => {\n const [filterKey] = Object.keys(filterContribution);\n const filterData = data[filterKey];\n const filterContributionByKey = filterContribution[filterKey];\n\n const filter = this.createFilter(\n filterKey,\n {\n ...filterData,\n dynamicschema: contributions.dynamicschema,\n },\n filterContributionByKey,\n modelOptions,\n );\n\n if (contributions.listkey) {\n filter.listkey = contributions.listkey;\n }\n\n if (contributions.contexts && filterContributionByKey.contextid) {\n const filterContext = contributions.contexts.find(\n (context) => context.id === filterContributionByKey.contextid,\n );\n if (filterContext) {\n filter.context = filterContext;\n }\n }\n\n return filter;\n });\n }\n }\n\n /**\n */\n createFilter(\n filterKey: string,\n data: Object,\n contributions: Object,\n modelOptions?: ModelOptions,\n ): FilterType {\n const type = contributions.type || \"stringfilter\";\n if (type === \"choicefilter\" && filterKey === \"index\") {\n return new ConceptIndexFilterModel(data, contributions, modelOptions);\n }\n\n if (type.includes(\"rangefilter\")) {\n return new RangeFilterModel(data, contributions, modelOptions);\n }\n\n if (type === \"assignmentfilter\") {\n return new AssignmentFilterModel(data, contributions, modelOptions);\n }\n\n if (type === \"stringfilter\") {\n return new StringFilterModel(data, contributions, modelOptions);\n }\n\n return new FilterModel(data, contributions, modelOptions);\n }\n\n /**\n * Call the reset function on all filters\n *\n * @see {FilterType#reset()}\n */\n reset(): FilterCollection {\n this.collection = this.collection.map((filter) => filter.reset());\n\n return this;\n }\n\n /**\n * Checks if range attribute key equals key\n */\n checkRangeFilterByAttributeKey(\n filter: RangeFilterModel,\n key: string,\n ): boolean {\n const rangeAttribute = filter.attribute;\n\n if (rangeAttribute instanceof CompositeAttributeModel) {\n return (\n rangeAttribute.key === key ||\n (rangeAttribute.start && rangeAttribute.start.key === key) ||\n (rangeAttribute.end && rangeAttribute.end.key === key)\n );\n }\n\n return false;\n }\n\n /**\n * Check if assignment filter attribute matches key\n */\n checkAssignmentFilterByAttributeKey(\n filter: AssignmentFilterModel,\n key: string,\n ): boolean {\n return (\n filter.key === key ||\n filter.user?.key === key ||\n filter.assignmenttype?.key === key\n );\n }\n\n /**\n * Getting the filter by name\n */\n getFilterByAttributeKey(key: string): FilterType | null {\n return (\n this.find((filter) => {\n if (filter instanceof RangeFilterModel) {\n return this.checkRangeFilterByAttributeKey(filter, key);\n }\n\n if (filter instanceof AssignmentFilterModel) {\n return this.checkAssignmentFilterByAttributeKey(filter, key);\n }\n\n return filter.attribute?.key === key;\n }) || null\n );\n }\n\n /**\n * Update Filter by input name and value\n */\n update(attribute: AttributeType, value: string): void {\n const filterToUpdate = attribute.parentKey\n ? this.getFilterByAttributeKey(attribute.parentKey)\n : this.getFilterByAttributeKey(attribute.key);\n\n if (!filterToUpdate) {\n throw new Error(`Can not find filter by attribute key: ${attribute.key}`);\n }\n\n const newFilter = filterToUpdate.clone();\n newFilter.update(attribute, value);\n\n this.collection = this.collection.map((filter) => {\n if (filter.name === newFilter.name) {\n return newFilter;\n }\n\n return filter;\n });\n }\n\n /**\n * Retrieve if all filters are valid\n */\n get isValid(): boolean {\n return this.collection.every((filter) => filter.isValid);\n }\n\n /**\n * Indicates if an active filter is present in the collection\n */\n hasActiveFilters(): boolean {\n return this.collection.some((filter) => filter.isActive());\n }\n\n /**\n */\n get formdata(): { [string]: any } | null {\n let data = {};\n this.filter(\n (f) => f.parameterType === PARAMETER_TYPES.BODY && f.hasValue(),\n ).forEach((f) => {\n // $FlowIgnore[cannot-spread-indexer]\n // $FlowIgnore[exponential-spread]\n data = {\n ...data,\n ...f.formdata,\n };\n });\n return data;\n }\n}\n"],"mappings":";;;;;;;;;;;;AACA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,kBAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,iBAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,sBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,wBAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,wBAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,YAAA,GAAAP,sBAAA,CAAAC,OAAA;AAGA,IAAAO,UAAA,GAAAP,OAAA;AAEA;AACA;AACA;AACe,MAAMQ,gBAAgB,SAASC,uBAAc,CAAa;EACvE;AACF;AACA;EACEC,WAAWA,CACTC,IAAY,GAAG,CAAC,CAAC,EACjBC,aAAqB,GAAG,CAAC,CAAC,EAC1BC,YAA2B,EAC3B;IACA,KAAK,CAAC,CAAC;IAEP,IAAIF,IAAI,IAAIC,aAAa,IAAIE,KAAK,CAACC,OAAO,KAAAC,OAAA,CAAAC,OAAA,EAACL,aAAa,CAAO,CAAC,EAAE;MAAA,IAAAM,QAAA,EAAAC,SAAA;MAChE,IAAI,CAACC,UAAU,GAAG,IAAAC,IAAA,CAAAJ,OAAA,EAAAC,QAAA,OAAAF,OAAA,CAAAC,OAAA,EAAAE,SAAA,OAAAH,OAAA,CAAAC,OAA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AElC,IAAI,CAACzC,UAAU,GAAG,IAAAC,IAAA,CAAAJ,OAAA,EAAA6C,SAAA,OAAI,CAAC1C,UAAU,EAAAE,IAAA,CAAAwC,SAAA,EAAMlC,MAAM,IAAK;MAChD,IAAIA,MAAM,CAACwC,IAAI,KAAKF,SAAS,CAACE,IAAI,EAAE;QAClC,OAAOF,SAAS;MAClB;MAEA,OAAOtC,MAAM;IACf,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;EACE,IAAIyC,OAAOA,CAAA,EAAY;IACrB,OAAO,IAAI,CAACjD,UAAU,CAACkD,KAAK,CAAE1C,MAAM,IAAKA,MAAM,CAACyC,OAAO,CAAC;EAC1D;;EAEA;AACF;AACA;EACEE,gBAAgBA,CAAA,EAAY;IAC1B,OAAO,IAAI,CAACnD,UAAU,CAACoD,IAAI,CAAE5C,MAAM,IAAKA,MAAM,CAAC6C,QAAQ,CAAC,CAAC,CAAC;EAC5D;;EAEA;AACF;EACE,IAAIC,QAAQA,CAAA,EAA6B;IAAA,IAAAC,SAAA;IACvC,IAAIhE,IAAI,GAAG,CAAC,CAAC;IACb,IAAAK,OAAA,CAAAC,OAAA,EAAA0D,SAAA,OAAI,EAAArD,IAAA,CAAAqD,SAAA,EACDC,CAAC,IAAKA,CAAC,CAACC,aAAa,KAAKC,0BAAe,CAACC,IAAI,IAAIH,CAAC,CAACI,QAAQ,CAAC,CAChE,CAAC,CAACC,OAAO,CAAEL,CAAC,IAAK;MACf;MACA;MACAjE,IAAI,GAAG;QACL,GAAGA,IAAI;QACP,GAAGiE,CAAC,CAACF;MACP,CAAC;IACH,CAAC,CAAC;IACF,OAAO/D,IAAI;EACb;AACF;AAACuE,OAAA,CAAAjE,OAAA,GAAAT,gBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"FilterCollection.js","names":["_BaseCollection","_interopRequireDefault","require","_StringFilterModel","_RangeFilterModel","_AssignmentFilterModel","_ConceptIndexFilterModel","_CompositeAttributeModel","_FilterModel","_constants","FilterCollection","BaseCollection","constructor","data","contributions","modelOptions","Array","isArray","_filter","default","_context","_context2","collection","_map","call","filterContribution","_keys","filterKey","filterData","filterContributionByKey","filter","createFilter","dynamicschema","listkey","contexts","contextid","_context3","filterContext","_find","context","id","type","ConceptIndexFilterModel","_includes","RangeFilterModel","AssignmentFilterModel","StringFilterModel","FilterModel","reset","_context4","checkRangeFilterByAttributeKey","key","rangeAttribute","attribute","CompositeAttributeModel","start","end","checkAssignmentFilterByAttributeKey","user","assignmenttype","getFilterByAttributeKey","_context5","update","value","_context6","filterToUpdate","parentKey","Error","newFilter","clone","name","isValid","every","hasActiveFilters","some","isActive","formdata","_context7","bodyFields","f","parameterType","PARAMETER_TYPES","BODY","hasValue","length","reduce","_assign","exports"],"sources":["../../../src/models/filters/FilterCollection.js"],"sourcesContent":["// @flow\nimport BaseCollection from \"../base/BaseCollection\";\n\nimport StringFilterModel from \"../filters/StringFilterModel\";\nimport RangeFilterModel from \"../filters/RangeFilterModel\";\nimport AssignmentFilterModel from \"../filters/AssignmentFilterModel\";\nimport ConceptIndexFilterModel from \"../filters/ConceptIndexFilterModel\";\nimport CompositeAttributeModel from \"../attributes/CompositeAttributeModel\";\nimport FilterModel from \"../filters/FilterModel\";\n\nimport type { AttributeType, FilterType, ModelOptions } from \"../types\";\nimport { PARAMETER_TYPES } from \"../../constants\";\n\n/**\n * Contains a collection of filters\n */\nexport default class FilterCollection extends BaseCollection<FilterType> {\n /**\n * Construct a collection of filters\n */\n constructor(\n data: Object = {},\n contributions: Object = {},\n modelOptions?: ModelOptions,\n ) {\n super();\n\n if (data && contributions && Array.isArray(contributions.filter)) {\n this.collection = contributions.filter\n .filter((filterContribution) => Object.keys(filterContribution)[0])\n .map((filterContribution) => {\n const [filterKey] = Object.keys(filterContribution);\n const filterData = data[filterKey];\n const filterContributionByKey = filterContribution[filterKey];\n\n const filter = this.createFilter(\n filterKey,\n {\n ...filterData,\n dynamicschema: contributions.dynamicschema,\n },\n filterContributionByKey,\n modelOptions,\n );\n\n if (contributions.listkey) {\n filter.listkey = contributions.listkey;\n }\n\n if (contributions.contexts && filterContributionByKey.contextid) {\n const filterContext = contributions.contexts.find(\n (context) => context.id === filterContributionByKey.contextid,\n );\n if (filterContext) {\n filter.context = filterContext;\n }\n }\n\n return filter;\n });\n }\n }\n\n /**\n */\n createFilter(\n filterKey: string,\n data: Object,\n contributions: Object,\n modelOptions?: ModelOptions,\n ): FilterType {\n const type = contributions.type || \"stringfilter\";\n if (type === \"choicefilter\" && filterKey === \"index\") {\n return new ConceptIndexFilterModel(data, contributions, modelOptions);\n }\n\n if (type.includes(\"rangefilter\")) {\n return new RangeFilterModel(data, contributions, modelOptions);\n }\n\n if (type === \"assignmentfilter\") {\n return new AssignmentFilterModel(data, contributions, modelOptions);\n }\n\n if (type === \"stringfilter\") {\n return new StringFilterModel(data, contributions, modelOptions);\n }\n\n return new FilterModel(data, contributions, modelOptions);\n }\n\n /**\n * Call the reset function on all filters\n *\n * @see {FilterType#reset()}\n */\n reset(): FilterCollection {\n this.collection = this.collection.map((filter) => filter.reset());\n\n return this;\n }\n\n /**\n * Checks if range attribute key equals key\n */\n checkRangeFilterByAttributeKey(\n filter: RangeFilterModel,\n key: string,\n ): boolean {\n const rangeAttribute = filter.attribute;\n\n if (rangeAttribute instanceof CompositeAttributeModel) {\n return (\n rangeAttribute.key === key ||\n (rangeAttribute.start && rangeAttribute.start.key === key) ||\n (rangeAttribute.end && rangeAttribute.end.key === key)\n );\n }\n\n return false;\n }\n\n /**\n * Check if assignment filter attribute matches key\n */\n checkAssignmentFilterByAttributeKey(\n filter: AssignmentFilterModel,\n key: string,\n ): boolean {\n return (\n filter.key === key ||\n filter.user?.key === key ||\n filter.assignmenttype?.key === key\n );\n }\n\n /**\n * Getting the filter by name\n */\n getFilterByAttributeKey(key: string): FilterType | null {\n return (\n this.find((filter) => {\n if (filter instanceof RangeFilterModel) {\n return this.checkRangeFilterByAttributeKey(filter, key);\n }\n\n if (filter instanceof AssignmentFilterModel) {\n return this.checkAssignmentFilterByAttributeKey(filter, key);\n }\n\n return filter.attribute?.key === key;\n }) || null\n );\n }\n\n /**\n * Update Filter by input name and value\n */\n update(attribute: AttributeType, value: string): void {\n const filterToUpdate = attribute.parentKey\n ? this.getFilterByAttributeKey(attribute.parentKey)\n : this.getFilterByAttributeKey(attribute.key);\n\n if (!filterToUpdate) {\n throw new Error(`Can not find filter by attribute key: ${attribute.key}`);\n }\n\n const newFilter = filterToUpdate.clone();\n newFilter.update(attribute, value);\n\n this.collection = this.collection.map((filter) => {\n if (filter.name === newFilter.name) {\n return newFilter;\n }\n\n return filter;\n });\n }\n\n /**\n * Retrieve if all filters are valid\n */\n get isValid(): boolean {\n return this.collection.every((filter) => filter.isValid);\n }\n\n /**\n * Indicates if an active filter is present in the collection\n */\n hasActiveFilters(): boolean {\n return this.collection.some((filter) => filter.isActive());\n }\n\n /**\n */\n get formdata(): { [string]: any } | null {\n const bodyFields = this.filter(\n (f) =>\n f.parameterType === PARAMETER_TYPES.BODY && f.hasValue() && f.formdata,\n );\n\n if (bodyFields.length === 0) {\n return null;\n }\n\n return bodyFields.reduce((data, f) => {\n return Object.assign(data, f.formdata);\n }, {});\n }\n}\n"],"mappings":";;;;;;;;;;;;;AACA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,kBAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,iBAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,sBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,wBAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,wBAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,YAAA,GAAAP,sBAAA,CAAAC,OAAA;AAGA,IAAAO,UAAA,GAAAP,OAAA;AAEA;AACA;AACA;AACe,MAAMQ,gBAAgB,SAASC,uBAAc,CAAa;EACvE;AACF;AACA;EACEC,WAAWA,CACTC,IAAY,GAAG,C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CAACH,QAClE,CAAC;IAED,IAAIE,UAAU,CAACM,MAAM,KAAK,CAAC,EAAE;MAC3B,OAAO,IAAI;IACb;IAEA,OAAON,UAAU,CAACO,MAAM,CAAC,CAACxE,IAAI,EAAEkE,CAAC,KAAK;MACpC,OAAO,IAAAO,OAAA,CAAAnE,OAAA,EAAcN,IAAI,EAAEkE,CAAC,CAACH,QAAQ,CAAC;IACxC,CAAC,EAAE,CAAC,CAAC,CAAC;EACR;AACF;AAACW,OAAA,CAAApE,OAAA,GAAAT,gBAAA","ignoreList":[]}
|
|
@@ -5,11 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.sendAuthenticationError = exports.resetAuthErrors = exports.loginSuccess = exports.loginFailed = exports.login = exports.changePassword = void 0;
|
|
8
|
-
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
9
8
|
var _Cache = _interopRequireDefault(require("../../utils/browser/Cache"));
|
|
10
9
|
var _Authenticate = _interopRequireDefault(require("../../modularui/Authenticate"));
|
|
11
10
|
var _ModularUISelectors = require("../_modularui/ModularUISelectors");
|
|
12
|
-
var _Error = require("./Error");
|
|
13
11
|
var _Application = require("./Application");
|
|
14
12
|
var _ProgressIndicator = require("./ProgressIndicator");
|
|
15
13
|
var _RouterActions = require("../_router/RouterActions");
|
|
@@ -63,9 +61,11 @@ const changePassword = () => (dispatch, getState) => {
|
|
|
63
61
|
/**
|
|
64
62
|
*/
|
|
65
63
|
exports.changePassword = changePassword;
|
|
66
|
-
const login = (username, password) => (dispatch, getState) => {
|
|
64
|
+
const login = (username, password) => async (dispatch, getState) => {
|
|
67
65
|
dispatch((0, _ProgressIndicator.startProgress)());
|
|
68
|
-
|
|
66
|
+
try {
|
|
67
|
+
const response = await new _Authenticate.default().login(username, password);
|
|
68
|
+
await dispatch((0, _Application.reloadApplication)());
|
|
69
69
|
_Cache.default.addItem("auth", true);
|
|
70
70
|
const application = (0, _ModularUISelectors.getApplication)(getState());
|
|
71
71
|
if (application?.userMustChangePassword) {
|
|
@@ -73,19 +73,19 @@ const login = (username, password) => (dispatch, getState) => {
|
|
|
73
73
|
} else {
|
|
74
74
|
dispatch(loginSuccess());
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
dispatch((0, _ProgressIndicator.finishProgress)());
|
|
77
|
+
return response;
|
|
78
|
+
} catch (error) {
|
|
78
79
|
if (error.id === "Error.ChangePasswordRequired") {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
});
|
|
80
|
+
await dispatch((0, _Application.reloadApplication)());
|
|
81
|
+
_Cache.default.addItem("auth", true);
|
|
82
|
+
dispatch(changePassword());
|
|
83
|
+
} else {
|
|
84
|
+
dispatch(loginFailed(error.id));
|
|
85
85
|
}
|
|
86
|
-
dispatch(
|
|
87
|
-
return
|
|
88
|
-
}
|
|
86
|
+
dispatch((0, _ProgressIndicator.finishProgress)());
|
|
87
|
+
return error;
|
|
88
|
+
}
|
|
89
89
|
};
|
|
90
90
|
exports.login = login;
|
|
91
91
|
//# sourceMappingURL=SignIn.js.map
|