@beinformed/ui 1.14.5 → 1.16.0
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 +19 -0
- package/esm/hooks/index.js +1 -0
- package/esm/hooks/index.js.map +1 -1
- package/esm/hooks/useAllFormsOnModel.js +110 -0
- package/esm/hooks/useAllFormsOnModel.js.map +1 -0
- package/esm/hooks/useAuthentication.js +4 -1
- package/esm/hooks/useAuthentication.js.map +1 -1
- package/esm/models/attributes/AttributeContent.js +4 -4
- package/esm/models/attributes/AttributeContent.js.map +1 -1
- package/esm/redux/actions/FormAttributeSet.js +4 -0
- package/esm/redux/actions/FormAttributeSet.js.map +1 -1
- package/esm/redux/actions/SignIn.js +9 -0
- package/esm/redux/actions/SignIn.js.map +1 -1
- package/esm/redux/reducers/AuthReducer.js +5 -0
- package/esm/redux/reducers/AuthReducer.js.map +1 -1
- package/esm/utils/helpers/checkResource.js +43 -0
- package/esm/utils/helpers/checkResource.js.map +1 -0
- package/esm/utils/index.js +1 -1
- package/esm/utils/index.js.map +1 -1
- package/lib/hooks/index.js +13 -0
- package/lib/hooks/index.js.flow +1 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useAllFormsOnModel.js +131 -0
- package/lib/hooks/useAllFormsOnModel.js.flow +92 -0
- package/lib/hooks/useAllFormsOnModel.js.map +1 -0
- package/lib/hooks/useAuthentication.js +3 -0
- package/lib/hooks/useAuthentication.js.flow +7 -5
- package/lib/hooks/useAuthentication.js.map +1 -1
- package/lib/models/attributes/AttributeContent.js +4 -4
- package/lib/models/attributes/AttributeContent.js.flow +3 -3
- package/lib/models/attributes/AttributeContent.js.map +1 -1
- package/lib/redux/actions/FormAttributeSet.js +4 -0
- package/lib/redux/actions/FormAttributeSet.js.flow +7 -2
- package/lib/redux/actions/FormAttributeSet.js.map +1 -1
- package/lib/redux/actions/SignIn.js +14 -2
- package/lib/redux/actions/SignIn.js.flow +8 -0
- package/lib/redux/actions/SignIn.js.map +1 -1
- package/lib/redux/reducers/AuthReducer.js +5 -0
- package/lib/redux/reducers/AuthReducer.js.flow +3 -0
- package/lib/redux/reducers/AuthReducer.js.map +1 -1
- package/lib/redux/reducers/__tests__/AuthReducer.spec.js.flow +52 -13
- package/lib/redux/types.js.flow +6 -1
- package/lib/utils/helpers/__tests__/checkResource.spec.js.flow +56 -0
- package/lib/utils/helpers/checkResource.js +57 -0
- package/{src/utils/helpers/checkResourceExists.js → lib/utils/helpers/checkResource.js.flow} +19 -0
- package/lib/utils/helpers/checkResource.js.map +1 -0
- package/lib/utils/index.js +4 -4
- package/lib/utils/index.js.flow +1 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +9 -9
- package/src/hooks/index.js +1 -0
- package/src/hooks/useAllFormsOnModel.js +92 -0
- package/src/hooks/useAuthentication.js +7 -5
- package/src/models/attributes/AttributeContent.js +3 -3
- package/src/redux/actions/FormAttributeSet.js +7 -2
- package/src/redux/actions/SignIn.js +8 -0
- package/src/redux/reducers/AuthReducer.js +3 -0
- package/src/redux/reducers/__tests__/AuthReducer.spec.js +52 -13
- package/src/redux/types.js +6 -1
- package/src/utils/helpers/__tests__/checkResource.spec.js +56 -0
- package/{lib/utils/helpers/checkResourceExists.js.flow → src/utils/helpers/checkResource.js} +19 -0
- package/src/utils/index.js +1 -1
- package/esm/utils/helpers/checkResourceExists.js +0 -23
- package/esm/utils/helpers/checkResourceExists.js.map +0 -1
- package/lib/utils/helpers/checkResourceExists.js +0 -34
- package/lib/utils/helpers/checkResourceExists.js.map +0 -1
|
@@ -17,9 +17,12 @@ describe("authentication reducer", () => {
|
|
|
17
17
|
|
|
18
18
|
it("should handle AUTHENTICATION_SUCCESS", () => {
|
|
19
19
|
expect(
|
|
20
|
-
AuthReducer(
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
AuthReducer(
|
|
21
|
+
{},
|
|
22
|
+
{
|
|
23
|
+
type: "AUTHENTICATION_SUCCESS",
|
|
24
|
+
}
|
|
25
|
+
)
|
|
23
26
|
).toStrictEqual({
|
|
24
27
|
isAuthenticated: true,
|
|
25
28
|
mustChangePassword: false,
|
|
@@ -29,10 +32,13 @@ describe("authentication reducer", () => {
|
|
|
29
32
|
|
|
30
33
|
it("should handle AUTHENTICATION_ERROR", () => {
|
|
31
34
|
expect(
|
|
32
|
-
AuthReducer(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
AuthReducer(
|
|
36
|
+
{},
|
|
37
|
+
{
|
|
38
|
+
type: "AUTHENTICATION_ERROR",
|
|
39
|
+
payload: "error",
|
|
40
|
+
}
|
|
41
|
+
)
|
|
36
42
|
).toStrictEqual({
|
|
37
43
|
mustChangePassword: false,
|
|
38
44
|
error: "error",
|
|
@@ -41,9 +47,35 @@ describe("authentication reducer", () => {
|
|
|
41
47
|
|
|
42
48
|
it("should handle AUTHENTICATION_LOGOUT", () => {
|
|
43
49
|
expect(
|
|
44
|
-
AuthReducer(
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
AuthReducer(
|
|
51
|
+
{
|
|
52
|
+
isAuthenticated: true,
|
|
53
|
+
mustChangePassword: false,
|
|
54
|
+
error: null,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: "AUTHENTICATION_LOGOUT",
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
).toStrictEqual({
|
|
61
|
+
isAuthenticated: false,
|
|
62
|
+
mustChangePassword: false,
|
|
63
|
+
error: null,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should handle AUTHENTICATION_RESET_ERRORS", () => {
|
|
68
|
+
expect(
|
|
69
|
+
AuthReducer(
|
|
70
|
+
{
|
|
71
|
+
isAuthenticated: false,
|
|
72
|
+
mustChangePassword: false,
|
|
73
|
+
error: "In error",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
type: "AUTHENTICATION_RESET_ERRORS",
|
|
77
|
+
}
|
|
78
|
+
)
|
|
47
79
|
).toStrictEqual({
|
|
48
80
|
isAuthenticated: false,
|
|
49
81
|
mustChangePassword: false,
|
|
@@ -53,9 +85,16 @@ describe("authentication reducer", () => {
|
|
|
53
85
|
|
|
54
86
|
it("should handle CHANGE_PASSWORD", () => {
|
|
55
87
|
expect(
|
|
56
|
-
AuthReducer(
|
|
57
|
-
|
|
58
|
-
|
|
88
|
+
AuthReducer(
|
|
89
|
+
{
|
|
90
|
+
isAuthenticated: true,
|
|
91
|
+
mustChangePassword: false,
|
|
92
|
+
error: null,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
type: "CHANGE_PASSWORD",
|
|
96
|
+
}
|
|
97
|
+
)
|
|
59
98
|
).toStrictEqual({
|
|
60
99
|
isAuthenticated: true,
|
|
61
100
|
mustChangePassword: true,
|
package/lib/redux/types.js.flow
CHANGED
|
@@ -46,7 +46,7 @@ export type UpdateFormOptions = {
|
|
|
46
46
|
autosave: boolean,
|
|
47
47
|
forceUpdate?: boolean,
|
|
48
48
|
/** Default true: Activate/deactivate the form object validate by an update */
|
|
49
|
-
validate?:boolean
|
|
49
|
+
validate?: boolean,
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
export type NoAction = {
|
|
@@ -104,6 +104,10 @@ export type LoginFailedAction = {
|
|
|
104
104
|
payload: string,
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
+
export type ResetAuthErrorsAction = {
|
|
108
|
+
type: "AUTHENTICATION_RESET_ERRORS",
|
|
109
|
+
};
|
|
110
|
+
|
|
107
111
|
export type LoginSuccessAction = {
|
|
108
112
|
type: "AUTHENTICATION_SUCCESS",
|
|
109
113
|
};
|
|
@@ -143,6 +147,7 @@ export type ReduxAction =
|
|
|
143
147
|
| ResetProgressAction
|
|
144
148
|
| UpdateProgressAction
|
|
145
149
|
| LoginFailedAction
|
|
150
|
+
| ResetAuthErrorsAction
|
|
146
151
|
| LoginSuccessAction
|
|
147
152
|
| ChangePasswordAction
|
|
148
153
|
| LogoutSuccessAction
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resourceExists,
|
|
3
|
+
resourceRedirectsToSecureLogin,
|
|
4
|
+
} from "../checkResource";
|
|
5
|
+
|
|
6
|
+
const mockXMLHttpRequest = () => {
|
|
7
|
+
const mock = {
|
|
8
|
+
open: jest.fn(),
|
|
9
|
+
addEventListener: jest.fn(),
|
|
10
|
+
setRequestHeader: jest.fn(),
|
|
11
|
+
send: jest.fn(),
|
|
12
|
+
getResponseHeader: jest.fn(),
|
|
13
|
+
|
|
14
|
+
upload: {
|
|
15
|
+
addEventListener: jest.fn(),
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
jest.spyOn(global, "XMLHttpRequest").mockImplementation(() => mock);
|
|
20
|
+
|
|
21
|
+
return mock;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe("checkResource", () => {
|
|
25
|
+
it("indicates a resource exists if it has a status code other then 404", () => {
|
|
26
|
+
const mock = mockXMLHttpRequest();
|
|
27
|
+
mock.status = 200;
|
|
28
|
+
|
|
29
|
+
expect.assertions(1);
|
|
30
|
+
|
|
31
|
+
const exists = resourceExists("/");
|
|
32
|
+
|
|
33
|
+
expect(exists).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("indicates a resource does not exists if it has a status code of 404", () => {
|
|
37
|
+
const mock = mockXMLHttpRequest();
|
|
38
|
+
mock.status = 404;
|
|
39
|
+
|
|
40
|
+
expect.assertions(1);
|
|
41
|
+
|
|
42
|
+
const exists = resourceExists("/");
|
|
43
|
+
|
|
44
|
+
expect(exists).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("indicates resource request redirects to secureLogin", () => {
|
|
48
|
+
const mock = mockXMLHttpRequest();
|
|
49
|
+
mock.responseURL = "/BeInformed/secureLogin";
|
|
50
|
+
mock.status = 400;
|
|
51
|
+
|
|
52
|
+
const toLogin = resourceRedirectsToSecureLogin("/");
|
|
53
|
+
|
|
54
|
+
expect(toLogin).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.resourceRedirectsToSecureLogin = exports.resourceExists = void 0;
|
|
9
|
+
|
|
10
|
+
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
11
|
+
|
|
12
|
+
var _endsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/ends-with"));
|
|
13
|
+
|
|
14
|
+
var _Constants = require("../../constants/Constants");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Checks if a given url to a modular ui resource exists using a HEAD request to the resource (synchronous)
|
|
18
|
+
* When the resource returns a 404, the resource does not exists and the method returns false
|
|
19
|
+
*
|
|
20
|
+
* @param url
|
|
21
|
+
* @returns {boolean}
|
|
22
|
+
*/
|
|
23
|
+
var resourceExists = function resourceExists(url) {
|
|
24
|
+
var _context;
|
|
25
|
+
|
|
26
|
+
var fullUrl = (0, _concat.default)(_context = "".concat(_Constants.BASE, "/")).call(_context, url).replace(/\/\//g, "/");
|
|
27
|
+
var xhr = new XMLHttpRequest();
|
|
28
|
+
xhr.open("HEAD", fullUrl, false);
|
|
29
|
+
xhr.setRequestHeader("Accept", "application/json");
|
|
30
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
31
|
+
xhr.send();
|
|
32
|
+
return xhr.status !== 404;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Indicates if a request to the given url resuls in a redirect to /secureRedirect
|
|
36
|
+
* @param url
|
|
37
|
+
* @returns {boolean}
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
exports.resourceExists = resourceExists;
|
|
42
|
+
|
|
43
|
+
var resourceRedirectsToSecureLogin = function resourceRedirectsToSecureLogin(url) {
|
|
44
|
+
var _context2, _xhr$responseURL;
|
|
45
|
+
|
|
46
|
+
var fullUrl = (0, _concat.default)(_context2 = "".concat(_Constants.BASE, "/")).call(_context2, url).replace(/\/\//g, "/");
|
|
47
|
+
var xhr = new XMLHttpRequest();
|
|
48
|
+
xhr.open("HEAD", fullUrl, false);
|
|
49
|
+
xhr.setRequestHeader("Accept", "application/json");
|
|
50
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
51
|
+
xhr.send();
|
|
52
|
+
var responseURL = (_xhr$responseURL = xhr.responseURL) !== null && _xhr$responseURL !== void 0 ? _xhr$responseURL : "";
|
|
53
|
+
return xhr.status === 400 && (0, _endsWith.default)(responseURL).call(responseURL, "/secureLogin");
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
exports.resourceRedirectsToSecureLogin = resourceRedirectsToSecureLogin;
|
|
57
|
+
//# sourceMappingURL=checkResource.js.map
|
package/{src/utils/helpers/checkResourceExists.js → lib/utils/helpers/checkResource.js.flow}
RENAMED
|
@@ -19,3 +19,22 @@ export const resourceExists = (url: string): boolean => {
|
|
|
19
19
|
|
|
20
20
|
return xhr.status !== 404;
|
|
21
21
|
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Indicates if a request to the given url resuls in a redirect to /secureRedirect
|
|
25
|
+
* @param url
|
|
26
|
+
* @returns {boolean}
|
|
27
|
+
*/
|
|
28
|
+
export const resourceRedirectsToSecureLogin = (url: string): boolean => {
|
|
29
|
+
const fullUrl = `${BASE}/${url}`.replace(/\/\//g, "/");
|
|
30
|
+
|
|
31
|
+
const xhr = new XMLHttpRequest();
|
|
32
|
+
xhr.open("HEAD", fullUrl, false);
|
|
33
|
+
xhr.setRequestHeader("Accept", "application/json");
|
|
34
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
35
|
+
xhr.send();
|
|
36
|
+
|
|
37
|
+
const responseURL = xhr.responseURL ?? "";
|
|
38
|
+
|
|
39
|
+
return xhr.status === 400 && responseURL.endsWith("/secureLogin");
|
|
40
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/helpers/checkResource.js"],"names":["resourceExists","url","fullUrl","BASE","replace","xhr","XMLHttpRequest","open","setRequestHeader","send","status","resourceRedirectsToSecureLogin","responseURL"],"mappings":";;;;;;;;;;;;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAACC,GAAD,EAA0B;AAAA;;AACtD,MAAMC,OAAO,GAAG,0CAAGC,eAAH,uBAAWF,GAAX,EAAiBG,OAAjB,CAAyB,OAAzB,EAAkC,GAAlC,CAAhB;AAEA,MAAMC,GAAG,GAAG,IAAIC,cAAJ,EAAZ;AACAD,EAAAA,GAAG,CAACE,IAAJ,CAAS,MAAT,EAAiBL,OAAjB,EAA0B,KAA1B;AACAG,EAAAA,GAAG,CAACG,gBAAJ,CAAqB,QAArB,EAA+B,kBAA/B;AACAH,EAAAA,GAAG,CAACG,gBAAJ,CAAqB,cAArB,EAAqC,kBAArC;AACAH,EAAAA,GAAG,CAACI,IAAJ;AAEA,SAAOJ,GAAG,CAACK,MAAJ,KAAe,GAAtB;AACD,CAVM;AAYP;AACA;AACA;AACA;AACA;;;;;AACO,IAAMC,8BAA8B,GAAG,SAAjCA,8BAAiC,CAACV,GAAD,EAA0B;AAAA;;AACtE,MAAMC,OAAO,GAAG,2CAAGC,eAAH,wBAAWF,GAAX,EAAiBG,OAAjB,CAAyB,OAAzB,EAAkC,GAAlC,CAAhB;AAEA,MAAMC,GAAG,GAAG,IAAIC,cAAJ,EAAZ;AACAD,EAAAA,GAAG,CAACE,IAAJ,CAAS,MAAT,EAAiBL,OAAjB,EAA0B,KAA1B;AACAG,EAAAA,GAAG,CAACG,gBAAJ,CAAqB,QAArB,EAA+B,kBAA/B;AACAH,EAAAA,GAAG,CAACG,gBAAJ,CAAqB,cAArB,EAAqC,kBAArC;AACAH,EAAAA,GAAG,CAACI,IAAJ;AAEA,MAAMG,WAAW,uBAAGP,GAAG,CAACO,WAAP,+DAAsB,EAAvC;AAEA,SAAOP,GAAG,CAACK,MAAJ,KAAe,GAAf,IAAsB,uBAAAE,WAAW,MAAX,CAAAA,WAAW,EAAU,cAAV,CAAxC;AACD,CAZM","sourcesContent":["// @flow\nimport { BASE } from \"../../constants/Constants\";\n\n/**\n * Checks if a given url to a modular ui resource exists using a HEAD request to the resource (synchronous)\n * When the resource returns a 404, the resource does not exists and the method returns false\n *\n * @param url\n * @returns {boolean}\n */\nexport const resourceExists = (url: string): boolean => {\n const fullUrl = `${BASE}/${url}`.replace(/\\/\\//g, \"/\");\n\n const xhr = new XMLHttpRequest();\n xhr.open(\"HEAD\", fullUrl, false);\n xhr.setRequestHeader(\"Accept\", \"application/json\");\n xhr.setRequestHeader(\"Content-Type\", \"application/json\");\n xhr.send();\n\n return xhr.status !== 404;\n};\n\n/**\n * Indicates if a request to the given url resuls in a redirect to /secureRedirect\n * @param url\n * @returns {boolean}\n */\nexport const resourceRedirectsToSecureLogin = (url: string): boolean => {\n const fullUrl = `${BASE}/${url}`.replace(/\\/\\//g, \"/\");\n\n const xhr = new XMLHttpRequest();\n xhr.open(\"HEAD\", fullUrl, false);\n xhr.setRequestHeader(\"Accept\", \"application/json\");\n xhr.setRequestHeader(\"Content-Type\", \"application/json\");\n xhr.send();\n\n const responseURL = xhr.responseURL ?? \"\";\n\n return xhr.status === 400 && responseURL.endsWith(\"/secureLogin\");\n};\n"],"file":"checkResource.js"}
|
package/lib/utils/index.js
CHANGED
|
@@ -153,16 +153,16 @@ _Object$keys(_text).forEach(function (key) {
|
|
|
153
153
|
});
|
|
154
154
|
});
|
|
155
155
|
|
|
156
|
-
var
|
|
156
|
+
var _checkResource = require("./helpers/checkResource");
|
|
157
157
|
|
|
158
|
-
_Object$keys(
|
|
158
|
+
_Object$keys(_checkResource).forEach(function (key) {
|
|
159
159
|
if (key === "default" || key === "__esModule") return;
|
|
160
160
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
161
|
-
if (key in exports && exports[key] ===
|
|
161
|
+
if (key in exports && exports[key] === _checkResource[key]) return;
|
|
162
162
|
Object.defineProperty(exports, key, {
|
|
163
163
|
enumerable: true,
|
|
164
164
|
get: function get() {
|
|
165
|
-
return
|
|
165
|
+
return _checkResource[key];
|
|
166
166
|
}
|
|
167
167
|
});
|
|
168
168
|
});
|
package/lib/utils/index.js.flow
CHANGED
|
@@ -19,7 +19,7 @@ export { default as createUUID } from "./helpers/createUUID";
|
|
|
19
19
|
export * from "./helpers/sanitizeHtml";
|
|
20
20
|
export * from "./helpers/objects";
|
|
21
21
|
export * from "./helpers/text";
|
|
22
|
-
export * from "./helpers/
|
|
22
|
+
export * from "./helpers/checkResource";
|
|
23
23
|
|
|
24
24
|
// number
|
|
25
25
|
export { default as DecimalFormat } from "./number/DecimalFormat";
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AACA;;AACA;;AAIA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AACA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["// @flow\n\n// browser\nexport { default as Cache } from \"./browser/Cache\";\nexport * from \"./browser/Cookies\";\n\n// datetime\nexport * from \"./datetime/DateTimeUtil\";\n\n// fetch\nexport { default as serverFetch } from \"./fetch/serverFetch\";\nexport { default as universalFetch } from \"./fetch/universalFetch\";\nexport { default as xhr } from \"./fetch/xhr\";\nexport type * from \"./fetch/types\";\n\n// helpers\nexport * from \"./helpers/createHash\";\nexport { default as createUUID } from \"./helpers/createUUID\";\nexport * from \"./helpers/sanitizeHtml\";\nexport * from \"./helpers/objects\";\nexport * from \"./helpers/text\";\nexport * from \"./helpers/
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AACA;;AACA;;AAIA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AACA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["// @flow\n\n// browser\nexport { default as Cache } from \"./browser/Cache\";\nexport * from \"./browser/Cookies\";\n\n// datetime\nexport * from \"./datetime/DateTimeUtil\";\n\n// fetch\nexport { default as serverFetch } from \"./fetch/serverFetch\";\nexport { default as universalFetch } from \"./fetch/universalFetch\";\nexport { default as xhr } from \"./fetch/xhr\";\nexport type * from \"./fetch/types\";\n\n// helpers\nexport * from \"./helpers/createHash\";\nexport { default as createUUID } from \"./helpers/createUUID\";\nexport * from \"./helpers/sanitizeHtml\";\nexport * from \"./helpers/objects\";\nexport * from \"./helpers/text\";\nexport * from \"./helpers/checkResource\";\n\n// number\nexport { default as DecimalFormat } from \"./number/DecimalFormat\";\nexport { default as formatValue } from \"./number/formatValue\";\nexport * from \"./number/parseNumbers\";\n"],"file":"index.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beinformed/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"description": "Toolbox for be informed javascript layouts",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"bugs": "http://support.beinformed.com",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"styled-components": "^5.2.0"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@babel/runtime-corejs3": "^7.17.
|
|
81
|
+
"@babel/runtime-corejs3": "^7.17.8",
|
|
82
82
|
"big.js": "^6.1.1",
|
|
83
83
|
"date-fns": "^2.28.0",
|
|
84
84
|
"deepmerge": "^4.2.2",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
98
|
"@babel/cli": "^7.17.3",
|
|
99
|
-
"@babel/core": "^7.17.
|
|
99
|
+
"@babel/core": "^7.17.8",
|
|
100
100
|
"@babel/eslint-parser": "^7.17.0",
|
|
101
101
|
"@babel/eslint-plugin": "^7.16.5",
|
|
102
102
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
"@babel/preset-env": "^7.16.11",
|
|
105
105
|
"@babel/preset-flow": "^7.16.7",
|
|
106
106
|
"@babel/preset-react": "^7.16.7",
|
|
107
|
-
"@commitlint/cli": "^16.2.
|
|
107
|
+
"@commitlint/cli": "^16.2.3",
|
|
108
108
|
"@commitlint/config-conventional": "^16.2.1",
|
|
109
109
|
"@testing-library/react-hooks": "^7.0.2",
|
|
110
110
|
"auditjs": "^4.0.36",
|
|
@@ -118,11 +118,11 @@
|
|
|
118
118
|
"eslint-plugin-babel": "^5.3.1",
|
|
119
119
|
"eslint-plugin-ft-flow": "^2.0.1",
|
|
120
120
|
"eslint-plugin-import": "^2.25.4",
|
|
121
|
-
"eslint-plugin-jest": "^26.1.
|
|
122
|
-
"eslint-plugin-jsdoc": "^38.0.
|
|
121
|
+
"eslint-plugin-jest": "^26.1.2",
|
|
122
|
+
"eslint-plugin-jsdoc": "^38.0.6",
|
|
123
123
|
"eslint-plugin-react": "^7.28.0",
|
|
124
124
|
"eslint-plugin-react-hooks": "^4.3.0",
|
|
125
|
-
"flow-bin": "^0.
|
|
125
|
+
"flow-bin": "^0.174.1",
|
|
126
126
|
"flow-copy-source": "^2.0.9",
|
|
127
127
|
"flow-typed": "^3.6.1",
|
|
128
128
|
"glob": "^7.2.0",
|
|
@@ -132,9 +132,9 @@
|
|
|
132
132
|
"jest-junit": "^13.0.0",
|
|
133
133
|
"jest-sonar-reporter": "^2.0.0",
|
|
134
134
|
"jscodeshift": "^0.13.1",
|
|
135
|
-
"lint-staged": "^12.3.
|
|
135
|
+
"lint-staged": "^12.3.7",
|
|
136
136
|
"polished": "^4.1.4",
|
|
137
|
-
"prettier": "^2.
|
|
137
|
+
"prettier": "^2.6.0",
|
|
138
138
|
"react": "^17.0.2",
|
|
139
139
|
"react-dom": "^17.0.2",
|
|
140
140
|
"react-helmet-async": "^1.2.3",
|
package/src/hooks/index.js
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
|
+
|
|
4
|
+
import { useModularUIRequest } from "./useModularUIRequest";
|
|
5
|
+
|
|
6
|
+
import { HTTP_METHODS } from "../constants";
|
|
7
|
+
|
|
8
|
+
import ListModel from "../models/list/ListModel";
|
|
9
|
+
import FormModel from "../models/form/FormModel";
|
|
10
|
+
|
|
11
|
+
import type DetailModel from "../models/detail/DetailModel";
|
|
12
|
+
import type TabModel from "../models/tab/TabModel";
|
|
13
|
+
import type ActionModel from "../models/actions/ActionModel";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Retrieve all forms configured on a model with actions
|
|
17
|
+
* @param model
|
|
18
|
+
* @returns Object - { actionName: FormModel }
|
|
19
|
+
*/
|
|
20
|
+
export const useRetrieveFormsOnModel = (
|
|
21
|
+
model: ListModel | DetailModel | TabModel
|
|
22
|
+
): null | { [actionName: string]: FormModel } => {
|
|
23
|
+
const modularui = useModularUIRequest();
|
|
24
|
+
const [forms, setForms] = useState(null);
|
|
25
|
+
const [requestCount, setRequestCount] = useState(0);
|
|
26
|
+
const [responseCount, setResponseCount] = useState(0);
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const requests = getActions(model).map((action) => {
|
|
30
|
+
const href = action.selfhref.addParameter("commit", "false");
|
|
31
|
+
|
|
32
|
+
return modularui(href, { method: HTTP_METHODS.POST })
|
|
33
|
+
.fetch()
|
|
34
|
+
.then((form) => {
|
|
35
|
+
if (form instanceof FormModel) {
|
|
36
|
+
form.tokens = [];
|
|
37
|
+
}
|
|
38
|
+
return { [action.name]: form };
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
setRequestCount(requests.length);
|
|
43
|
+
|
|
44
|
+
Promise.all(requests).then((responses) => {
|
|
45
|
+
// put response array in object
|
|
46
|
+
const actionForms = Object.assign({}, ...responses);
|
|
47
|
+
setForms(actionForms);
|
|
48
|
+
setResponseCount(responses.length);
|
|
49
|
+
});
|
|
50
|
+
}, [model, modularui]);
|
|
51
|
+
|
|
52
|
+
if (responseCount === requestCount) {
|
|
53
|
+
return forms;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return null;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const getActions = (
|
|
60
|
+
model: ListModel | DetailModel | TabModel
|
|
61
|
+
): Array<ActionModel> => {
|
|
62
|
+
if (!model.actionCollection) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const createActions = model.actionCollection
|
|
67
|
+
.getActionsByType("create")
|
|
68
|
+
.filter((action) => !action.isDisabled);
|
|
69
|
+
|
|
70
|
+
const allActions = [...createActions];
|
|
71
|
+
|
|
72
|
+
if (model instanceof ListModel) {
|
|
73
|
+
model.listItemCollection.forEach((listItem) => {
|
|
74
|
+
const updateActions = listItem.actionCollection
|
|
75
|
+
.getActionsByType("update")
|
|
76
|
+
.filter((action) => !action.isDisabled);
|
|
77
|
+
|
|
78
|
+
allActions.push(...updateActions);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const actions = [];
|
|
83
|
+
const unique = [];
|
|
84
|
+
allActions.forEach((action) => {
|
|
85
|
+
if (!unique.includes(action.name)) {
|
|
86
|
+
unique.push(action.name);
|
|
87
|
+
actions.push(action);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return actions;
|
|
92
|
+
};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import { useSelector, useDispatch } from "react-redux";
|
|
3
3
|
import { getApplication } from "../redux/_modularui/selectors";
|
|
4
|
-
import { login, logout } from "../redux/actions";
|
|
4
|
+
import { login, logout, resetAuthErrors } from "../redux/actions";
|
|
5
5
|
import UserServicesModel from "../models/user/UserServicesModel";
|
|
6
6
|
import { useState, useEffect } from "react";
|
|
7
7
|
|
|
8
|
+
import type { ResetAuthErrorsAction } from "../redux/types";
|
|
8
9
|
type LoginHook = {
|
|
9
10
|
isAuthenticated: boolean,
|
|
10
11
|
errorMessage: ?string,
|
|
12
|
+
resetErrors: () => ResetAuthErrorsAction,
|
|
11
13
|
login: (username: string, password: string) => void,
|
|
12
14
|
};
|
|
13
15
|
type LogoutHook = {
|
|
@@ -39,6 +41,7 @@ export const useLogin = (): LoginHook => {
|
|
|
39
41
|
return {
|
|
40
42
|
isAuthenticated: getIsAuthenticated(auth.isAuthenticated, application),
|
|
41
43
|
errorMessage: auth.error,
|
|
44
|
+
resetErrors: () => dispatch(resetAuthErrors()),
|
|
42
45
|
login: (username: string, password: string) =>
|
|
43
46
|
dispatch(login(username, password)),
|
|
44
47
|
};
|
|
@@ -66,12 +69,11 @@ export const useLogout = (): LogoutHook => {
|
|
|
66
69
|
|
|
67
70
|
return {
|
|
68
71
|
isAuthenticated,
|
|
69
|
-
logout: () =>
|
|
70
|
-
|
|
72
|
+
logout: () =>
|
|
73
|
+
dispatch(logout()).then(() => {
|
|
71
74
|
if (!cancel) {
|
|
72
75
|
setIsAuthenticated(false);
|
|
73
76
|
}
|
|
74
|
-
})
|
|
75
|
-
},
|
|
77
|
+
}),
|
|
76
78
|
};
|
|
77
79
|
};
|
|
@@ -62,7 +62,7 @@ class AttributeContent {
|
|
|
62
62
|
if (this._content?.elements) {
|
|
63
63
|
return this._content.elements?.map((element) => {
|
|
64
64
|
if ("propertyElement" in element) {
|
|
65
|
-
// $FlowIssue[
|
|
65
|
+
// $FlowIssue[incompatible-use]
|
|
66
66
|
const { label, layouthint, properties } = element.propertyElement;
|
|
67
67
|
|
|
68
68
|
return {
|
|
@@ -75,8 +75,8 @@ class AttributeContent {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
if ("textFragmentElement" in element) {
|
|
78
|
+
// $FlowIssue[incompatible-use]
|
|
78
79
|
const { label, layouthint, textfragments } =
|
|
79
|
-
// $FlowIssue[prop-missing]
|
|
80
80
|
element.textFragmentElement;
|
|
81
81
|
return {
|
|
82
82
|
textFragmentElement: {
|
|
@@ -91,7 +91,7 @@ class AttributeContent {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
if ("contentElement" in element) {
|
|
94
|
-
// $FlowIssue[
|
|
94
|
+
// $FlowIssue[incompatible-use]
|
|
95
95
|
const { label, layouthint, sections } = element.contentElement;
|
|
96
96
|
return {
|
|
97
97
|
contentElement: {
|
|
@@ -25,12 +25,16 @@ export const updateFormAttribute =
|
|
|
25
25
|
autosubmit: false,
|
|
26
26
|
autosave: false,
|
|
27
27
|
forceUpdate: false,
|
|
28
|
-
validate: true
|
|
28
|
+
validate: true,
|
|
29
29
|
}
|
|
30
30
|
): ThunkAction =>
|
|
31
31
|
(dispatch: Dispatch) => {
|
|
32
32
|
const newForm = form.clone();
|
|
33
33
|
|
|
34
|
+
if (!options.validate) {
|
|
35
|
+
options.validate = true;
|
|
36
|
+
}
|
|
37
|
+
|
|
34
38
|
if (
|
|
35
39
|
newForm.currentFormObject &&
|
|
36
40
|
newForm.currentFormObject.equals(formObject)
|
|
@@ -60,7 +64,8 @@ export const updateFormAttribute =
|
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
if (
|
|
63
|
-
newForm.currentFormObject &&
|
|
67
|
+
newForm.currentFormObject &&
|
|
68
|
+
options.validate &&
|
|
64
69
|
newForm.currentFormObject.hasDynamicValidations &&
|
|
65
70
|
getSetting("USE_INSTANT_SERVER_VALIDATION")
|
|
66
71
|
) {
|
|
@@ -10,6 +10,7 @@ import { CHANGEPASSWORD_PATH } from "../../constants/Constants";
|
|
|
10
10
|
|
|
11
11
|
import type {
|
|
12
12
|
LoginFailedAction,
|
|
13
|
+
ResetAuthErrorsAction,
|
|
13
14
|
LoginSuccessAction,
|
|
14
15
|
ThunkAction,
|
|
15
16
|
} from "../types";
|
|
@@ -22,6 +23,13 @@ export const loginFailed = (errorMessage: string): LoginFailedAction => ({
|
|
|
22
23
|
payload: errorMessage,
|
|
23
24
|
});
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Resets any authentication errors
|
|
28
|
+
*/
|
|
29
|
+
export const resetAuthErrors = (): ResetAuthErrorsAction => ({
|
|
30
|
+
type: "AUTHENTICATION_RESET_ERRORS",
|
|
31
|
+
});
|
|
32
|
+
|
|
25
33
|
/**
|
|
26
34
|
* Send login success action
|
|
27
35
|
*/
|
|
@@ -34,6 +34,9 @@ const AuthReducer: Reducer<AuthState, ReduxAction> = (
|
|
|
34
34
|
case "AUTHENTICATION_ERROR":
|
|
35
35
|
return { ...state, mustChangePassword: false, error: action.payload };
|
|
36
36
|
|
|
37
|
+
case "AUTHENTICATION_RESET_ERRORS":
|
|
38
|
+
return { ...state, error: null };
|
|
39
|
+
|
|
37
40
|
case "AUTHENTICATION_LOGOUT": {
|
|
38
41
|
// clear cache because of cached contributions
|
|
39
42
|
if (state.isAuthenticated) {
|