@beinformed/ui 1.57.0-contextpath.1 → 1.57.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 +53 -0
- package/esm/constants/Settings.js +10 -2
- package/esm/constants/Settings.js.map +1 -1
- package/esm/hooks/useModularUI.js +19 -18
- package/esm/hooks/useModularUI.js.map +1 -1
- package/esm/hooks/useModularUIBasic.js +52 -41
- package/esm/hooks/useModularUIBasic.js.map +1 -1
- package/esm/models/concepts/ConceptDetailModel.js +1 -8
- package/esm/models/concepts/ConceptDetailModel.js.map +1 -1
- package/esm/models/concepts/ConceptIndexModel.js +1 -1
- package/esm/models/concepts/ConceptIndexModel.js.map +1 -1
- package/esm/models/concepts/ConceptLinkModel.js +8 -9
- package/esm/models/concepts/ConceptLinkModel.js.map +1 -1
- package/esm/models/concepts/ConceptTypeDetailModel.js +3 -20
- package/esm/models/concepts/ConceptTypeDetailModel.js.map +1 -1
- package/esm/models/concepts/SourceReferenceCollection.js +3 -1
- package/esm/models/concepts/SourceReferenceCollection.js.map +1 -1
- package/esm/models/concepts/SourceReferenceModel.js +9 -3
- package/esm/models/concepts/SourceReferenceModel.js.map +1 -1
- package/esm/models/content/ContentLinkModel.js +10 -4
- package/esm/models/content/ContentLinkModel.js.map +1 -1
- package/esm/models/content/SectionModel.js +10 -6
- package/esm/models/content/SectionModel.js.map +1 -1
- package/esm/models/error/ErrorResponse.js +20 -5
- package/esm/models/error/ErrorResponse.js.map +1 -1
- package/esm/modularui/CaptchaRequest.js +12 -3
- package/esm/modularui/CaptchaRequest.js.map +1 -1
- package/esm/modularui/ModularUIRequest.js +1 -1
- package/esm/modularui/ModularUIRequest.js.map +1 -1
- package/esm/modularui/UploadRequest.js +7 -3
- package/esm/modularui/UploadRequest.js.map +1 -1
- package/esm/redux/_modularui/ModularUIActions.js +11 -9
- package/esm/redux/_modularui/ModularUIActions.js.map +1 -1
- package/esm/redux/_modularui/ModularUIMiddleware.js +4 -1
- package/esm/redux/_modularui/ModularUIMiddleware.js.map +1 -1
- package/esm/redux/_modularui/ModularUIReducer.js +2 -1
- package/esm/redux/_modularui/ModularUIReducer.js.map +1 -1
- package/esm/redux/_modularui/ModularUISelectors.js +7 -6
- package/esm/redux/_modularui/ModularUISelectors.js.map +1 -1
- package/esm/redux/_modularui/types.js.map +1 -1
- package/esm/redux/connectors/PanelRenderer.js +0 -2
- package/esm/redux/connectors/PanelRenderer.js.map +1 -1
- package/esm/utils/helpers/repositoryResource.js +6 -5
- package/esm/utils/helpers/repositoryResource.js.map +1 -1
- package/lib/constants/Settings.js +10 -2
- package/lib/constants/Settings.js.flow +8 -2
- package/lib/constants/Settings.js.map +1 -1
- package/lib/hooks/__tests__/UseModularUIModel.spec.js.flow +11 -4
- package/lib/hooks/__tests__/useAuthentication.spec.js.flow +2 -8
- package/lib/hooks/__tests__/useForm.spec.js.flow +14 -12
- package/lib/hooks/__tests__/useModelCatalog.spec.js.flow +10 -4
- package/lib/hooks/__tests__/useModels.spec.js.flow +3 -12
- package/lib/hooks/__tests__/useModularUIBasic.spec.js.flow +9 -8
- package/lib/hooks/useModularUI.js +18 -17
- package/lib/hooks/useModularUI.js.flow +25 -15
- package/lib/hooks/useModularUI.js.map +1 -1
- package/lib/hooks/useModularUIBasic.js +52 -41
- package/lib/hooks/useModularUIBasic.js.flow +66 -50
- package/lib/hooks/useModularUIBasic.js.map +1 -1
- package/lib/models/concepts/ConceptDetailModel.js +1 -8
- package/lib/models/concepts/ConceptDetailModel.js.flow +2 -7
- package/lib/models/concepts/ConceptDetailModel.js.map +1 -1
- package/lib/models/concepts/ConceptIndexModel.js +1 -1
- package/lib/models/concepts/ConceptIndexModel.js.flow +7 -1
- package/lib/models/concepts/ConceptIndexModel.js.map +1 -1
- package/lib/models/concepts/ConceptLinkModel.js +8 -9
- package/lib/models/concepts/ConceptLinkModel.js.flow +14 -9
- package/lib/models/concepts/ConceptLinkModel.js.map +1 -1
- package/lib/models/concepts/ConceptTypeDetailModel.js +3 -20
- package/lib/models/concepts/ConceptTypeDetailModel.js.flow +3 -25
- package/lib/models/concepts/ConceptTypeDetailModel.js.map +1 -1
- package/lib/models/concepts/SourceReferenceCollection.js +3 -1
- package/lib/models/concepts/SourceReferenceCollection.js.flow +8 -1
- package/lib/models/concepts/SourceReferenceCollection.js.map +1 -1
- package/lib/models/concepts/SourceReferenceModel.js +9 -3
- package/lib/models/concepts/SourceReferenceModel.js.flow +19 -3
- package/lib/models/concepts/SourceReferenceModel.js.map +1 -1
- package/lib/models/concepts/__mock__/conceptindex.js.flow +15 -0
- package/lib/models/concepts/__tests__/ConceptIndexModel.spec.js.flow +30 -2
- package/lib/models/concepts/__tests__/ConceptTypeDetailModel.spec.js.flow +1 -18
- package/lib/models/content/ContentLinkModel.js +9 -4
- package/lib/models/content/ContentLinkModel.js.flow +19 -4
- package/lib/models/content/ContentLinkModel.js.map +1 -1
- package/lib/models/content/SectionModel.js +10 -6
- package/lib/models/content/SectionModel.js.flow +31 -5
- package/lib/models/content/SectionModel.js.map +1 -1
- package/lib/models/error/ErrorResponse.js +20 -5
- package/lib/models/error/ErrorResponse.js.flow +34 -5
- package/lib/models/error/ErrorResponse.js.map +1 -1
- package/lib/modularui/CaptchaRequest.js +11 -2
- package/lib/modularui/CaptchaRequest.js.flow +17 -3
- package/lib/modularui/CaptchaRequest.js.map +1 -1
- package/lib/modularui/ModularUIRequest.js +1 -1
- package/lib/modularui/ModularUIRequest.js.flow +3 -1
- package/lib/modularui/ModularUIRequest.js.map +1 -1
- package/lib/modularui/UploadRequest.js +6 -2
- package/lib/modularui/UploadRequest.js.flow +12 -2
- package/lib/modularui/UploadRequest.js.map +1 -1
- package/lib/redux/_modularui/ModularUIActions.js +11 -9
- package/lib/redux/_modularui/ModularUIActions.js.flow +20 -10
- package/lib/redux/_modularui/ModularUIActions.js.map +1 -1
- package/lib/redux/_modularui/ModularUIMiddleware.js +3 -0
- package/lib/redux/_modularui/ModularUIMiddleware.js.flow +6 -3
- package/lib/redux/_modularui/ModularUIMiddleware.js.map +1 -1
- package/lib/redux/_modularui/ModularUIReducer.js +2 -1
- package/lib/redux/_modularui/ModularUIReducer.js.flow +1 -0
- package/lib/redux/_modularui/ModularUIReducer.js.map +1 -1
- package/lib/redux/_modularui/ModularUISelectors.js +5 -6
- package/lib/redux/_modularui/ModularUISelectors.js.flow +22 -10
- package/lib/redux/_modularui/ModularUISelectors.js.map +1 -1
- package/lib/redux/_modularui/__tests__/actions.spec.js.flow +1 -4
- package/lib/redux/_modularui/types.js.flow +1 -0
- package/lib/redux/_modularui/types.js.map +1 -1
- package/lib/redux/actions/__tests__/Application.spec.js.flow +1 -8
- package/lib/redux/actions/__tests__/Authorization.spec.js.flow +0 -4
- package/lib/redux/connectors/PanelRenderer.js +0 -2
- package/lib/redux/connectors/PanelRenderer.js.flow +0 -1
- package/lib/redux/connectors/PanelRenderer.js.map +1 -1
- package/lib/utils/helpers/repositoryResource.js +6 -5
- package/lib/utils/helpers/repositoryResource.js.flow +8 -6
- package/lib/utils/helpers/repositoryResource.js.map +1 -1
- package/package.json +18 -18
- package/src/constants/Settings.js +8 -2
- package/src/hooks/__tests__/UseModularUIModel.spec.js +11 -4
- package/src/hooks/__tests__/useAuthentication.spec.js +2 -8
- package/src/hooks/__tests__/useForm.spec.js +14 -12
- package/src/hooks/__tests__/useModelCatalog.spec.js +10 -4
- package/src/hooks/__tests__/useModels.spec.js +3 -12
- package/src/hooks/__tests__/useModularUIBasic.spec.js +9 -8
- package/src/hooks/useModularUI.js +25 -15
- package/src/hooks/useModularUIBasic.js +66 -50
- package/src/models/concepts/ConceptDetailModel.js +2 -7
- package/src/models/concepts/ConceptIndexModel.js +7 -1
- package/src/models/concepts/ConceptLinkModel.js +14 -9
- package/src/models/concepts/ConceptTypeDetailModel.js +3 -25
- package/src/models/concepts/SourceReferenceCollection.js +8 -1
- package/src/models/concepts/SourceReferenceModel.js +19 -3
- package/src/models/concepts/__mock__/conceptindex.js +15 -0
- package/src/models/concepts/__mock__/conceptindex_contributions.json +86 -0
- package/src/models/concepts/__mock__/conceptindex_data.json +323 -0
- package/src/models/concepts/__mock__/concepttype_hierarchy.json +1 -11
- package/src/models/concepts/__tests__/ConceptIndexModel.spec.js +30 -2
- package/src/models/concepts/__tests__/ConceptTypeDetailModel.spec.js +1 -18
- package/src/models/content/ContentLinkModel.js +19 -4
- package/src/models/content/SectionModel.js +31 -5
- package/src/models/error/ErrorResponse.js +34 -5
- package/src/modularui/CaptchaRequest.js +17 -3
- package/src/modularui/ModularUIRequest.js +3 -1
- package/src/modularui/UploadRequest.js +12 -2
- package/src/redux/_modularui/ModularUIActions.js +20 -10
- package/src/redux/_modularui/ModularUIMiddleware.js +6 -3
- package/src/redux/_modularui/ModularUIReducer.js +1 -0
- package/src/redux/_modularui/ModularUISelectors.js +22 -10
- package/src/redux/_modularui/__tests__/actions.spec.js +1 -4
- package/src/redux/_modularui/types.js +1 -0
- package/src/redux/actions/__tests__/Application.spec.js +1 -8
- package/src/redux/actions/__tests__/Authorization.spec.js +0 -4
- package/src/redux/connectors/PanelRenderer.js +0 -1
- package/src/utils/helpers/repositoryResource.js +8 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repositoryResource.js","names":["_constants","require","getRepositoryResourceUrl","resourceUrl","
|
|
1
|
+
{"version":3,"file":"repositoryResource.js","names":["_constants","require","getRepositoryResourceUrl","resourceUrl","contextPath","arguments","length","undefined","getBasePath","origin","_startsWith","default","call","RESOURCE_PATH","exports"],"sources":["../../../src/utils/helpers/repositoryResource.js"],"sourcesContent":["// @flow\nimport { getBasePath, RESOURCE_PATH } from \"../../constants\";\n\n/**\n * Creates an url to a resource in the Be Informed repository\n * Only possible when serving using the UI Servlet of Be Informed\n */\nexport const getRepositoryResourceUrl = (\n resourceUrl: string,\n contextPath: string = getBasePath(),\n origin: string = \"\",\n): string => {\n if (resourceUrl.startsWith(origin + contextPath)) {\n return resourceUrl;\n }\n\n if (resourceUrl.startsWith(RESOURCE_PATH)) {\n return `${origin}${contextPath}${resourceUrl}`;\n }\n\n return `${origin}${contextPath}${RESOURCE_PATH}${resourceUrl}`;\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACO,MAAMC,wBAAwB,GAAG,SAAAA,CACtCC,WAAmB,EAGR;EAAA,IAFXC,WAAmB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAAG,sBAAW,EAAC,CAAC;EAAA,IACnCC,MAAc,GAAAJ,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EAEnB,IAAI,IAAAK,WAAA,CAAAC,OAAA,EAAAR,WAAW,EAAAS,IAAA,CAAXT,WAAW,EAAYM,MAAM,GAAGL,WAAW,CAAC,EAAE;IAChD,OAAOD,WAAW;EACpB;EAEA,IAAI,IAAAO,WAAA,CAAAC,OAAA,EAAAR,WAAW,EAAAS,IAAA,CAAXT,WAAW,EAAYU,wBAAa,CAAC,EAAE;IACzC,OAAO,GAAGJ,MAAM,GAAGL,WAAW,GAAGD,WAAW,EAAE;EAChD;EAEA,OAAO,GAAGM,MAAM,GAAGL,WAAW,GAAGS,wBAAa,GAAGV,WAAW,EAAE;AAChE,CAAC;AAACW,OAAA,CAAAZ,wBAAA,GAAAA,wBAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beinformed/ui",
|
|
3
|
-
"version": "1.57.0
|
|
3
|
+
"version": "1.57.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",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"flow": "flow",
|
|
30
30
|
"flow:ci": "flow check",
|
|
31
31
|
"flow-typed-install": "flow-typed install -l .flow/flow-typed/ --ignoreDeps peer --overwrite",
|
|
32
|
-
"test": "jest",
|
|
32
|
+
"test": "jest --bail",
|
|
33
33
|
"test:ci": "jest --ci",
|
|
34
34
|
"test:changed": "jest --onlyChanged",
|
|
35
35
|
"upgrade-interactive": "npm-check -u",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"styled-components": "^5.0.0"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@babel/runtime-corejs3": "^7.25.
|
|
85
|
+
"@babel/runtime-corejs3": "^7.25.9",
|
|
86
86
|
"big.js": "^6.2.2",
|
|
87
87
|
"date-fns": "^4.1.0",
|
|
88
88
|
"deepmerge": "^4.3.1",
|
|
@@ -98,16 +98,16 @@
|
|
|
98
98
|
"setimmediate": "^1.0.5"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
|
-
"@babel/cli": "^7.25.
|
|
102
|
-
"@babel/core": "^7.25.
|
|
103
|
-
"@babel/eslint-parser": "^7.25.
|
|
104
|
-
"@babel/eslint-plugin": "^7.25.
|
|
101
|
+
"@babel/cli": "^7.25.9",
|
|
102
|
+
"@babel/core": "^7.25.9",
|
|
103
|
+
"@babel/eslint-parser": "^7.25.9",
|
|
104
|
+
"@babel/eslint-plugin": "^7.25.9",
|
|
105
105
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
106
106
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
107
|
-
"@babel/plugin-transform-runtime": "^7.25.
|
|
108
|
-
"@babel/preset-env": "^7.25.
|
|
109
|
-
"@babel/preset-flow": "^7.25.
|
|
110
|
-
"@babel/preset-react": "^7.25.
|
|
107
|
+
"@babel/plugin-transform-runtime": "^7.25.9",
|
|
108
|
+
"@babel/preset-env": "^7.25.9",
|
|
109
|
+
"@babel/preset-flow": "^7.25.9",
|
|
110
|
+
"@babel/preset-react": "^7.25.9",
|
|
111
111
|
"@commitlint/cli": "^19.5.0",
|
|
112
112
|
"@commitlint/config-conventional": "^19.5.0",
|
|
113
113
|
"@testing-library/react": "^16.0.1",
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"babel-jest": "^29.7.0",
|
|
116
116
|
"babel-plugin-styled-components": "^2.1.4",
|
|
117
117
|
"cherry-pick": "^0.5.0",
|
|
118
|
-
"commit-and-tag-version": "^12.
|
|
118
|
+
"commit-and-tag-version": "^12.5.0",
|
|
119
119
|
"cross-env": "^7.0.3",
|
|
120
120
|
"documentation": "^14.0.2",
|
|
121
121
|
"eslint": "^8.57.0",
|
|
@@ -124,21 +124,21 @@
|
|
|
124
124
|
"eslint-plugin-ft-flow": "^3.0.11",
|
|
125
125
|
"eslint-plugin-import": "^2.31.0",
|
|
126
126
|
"eslint-plugin-jest": "^28.8.3",
|
|
127
|
-
"eslint-plugin-jsdoc": "^50.3
|
|
128
|
-
"eslint-plugin-react": "^7.37.
|
|
129
|
-
"eslint-plugin-react-hooks": "^
|
|
127
|
+
"eslint-plugin-jsdoc": "^50.4.3",
|
|
128
|
+
"eslint-plugin-react": "^7.37.2",
|
|
129
|
+
"eslint-plugin-react-hooks": "^5.0.0",
|
|
130
130
|
"eslint-plugin-you-dont-need-lodash-underscore": "^6.14.0",
|
|
131
131
|
"flow-bin": "^0.200.1",
|
|
132
132
|
"flow-copy-source": "^2.0.9",
|
|
133
133
|
"flow-typed": "^3.9.0",
|
|
134
|
-
"hermes-eslint": "^0.
|
|
134
|
+
"hermes-eslint": "^0.25.0",
|
|
135
135
|
"history": "^4.0.0",
|
|
136
136
|
"husky": "^9.1.6",
|
|
137
137
|
"jest": "^29.7.0",
|
|
138
138
|
"jest-environment-jsdom": "^29.7.0",
|
|
139
139
|
"jest-junit": "^16.0.0",
|
|
140
140
|
"jest-sonar-reporter": "^2.0.0",
|
|
141
|
-
"jscodeshift": "^0.
|
|
141
|
+
"jscodeshift": "^17.0.0",
|
|
142
142
|
"lint-staged": "^15.2.10",
|
|
143
143
|
"polished": "^4.0.0",
|
|
144
144
|
"prettier": "^3.3.3",
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
"react-router": "^5.0.0",
|
|
150
150
|
"react-test-renderer": "^18.3.1",
|
|
151
151
|
"redux": "^4.2.1",
|
|
152
|
-
"redux-mock-store": "^1.5.
|
|
152
|
+
"redux-mock-store": "^1.5.5",
|
|
153
153
|
"redux-thunk": "^2.4.2",
|
|
154
154
|
"rimraf": "^6.0.1",
|
|
155
155
|
"styled-components": "^5.3.11",
|
|
@@ -172,12 +172,18 @@ export const getBasePath = (): string =>
|
|
|
172
172
|
/**
|
|
173
173
|
* Path to upload service
|
|
174
174
|
*/
|
|
175
|
-
export const getUploadPath = (
|
|
175
|
+
export const getUploadPath = (
|
|
176
|
+
contextPath: string = getBasePath(),
|
|
177
|
+
origin: string = "",
|
|
178
|
+
): string => `${origin}${contextPath}${UPLOAD_PATH}`;
|
|
176
179
|
|
|
177
180
|
/**
|
|
178
181
|
* Path to captcha service
|
|
179
182
|
*/
|
|
180
|
-
export const getCaptchaPath = (
|
|
183
|
+
export const getCaptchaPath = (
|
|
184
|
+
contextPath: string = getBasePath(),
|
|
185
|
+
origin: string = "",
|
|
186
|
+
): string => `${origin}${contextPath}${CAPTCHA_PATH}`;
|
|
181
187
|
|
|
182
188
|
/**
|
|
183
189
|
*/
|
|
@@ -4,6 +4,8 @@ import { Provider } from "react-redux";
|
|
|
4
4
|
import { renderHook } from "@testing-library/react";
|
|
5
5
|
import xhrMock from "xhr-mock";
|
|
6
6
|
|
|
7
|
+
import { useLocation } from "react-router";
|
|
8
|
+
|
|
7
9
|
import {
|
|
8
10
|
useApplication,
|
|
9
11
|
useTab,
|
|
@@ -32,6 +34,11 @@ import {
|
|
|
32
34
|
const middlewares = [thunk];
|
|
33
35
|
const mockStore = configureMockStore(middlewares);
|
|
34
36
|
|
|
37
|
+
jest.mock("react-router", () => ({
|
|
38
|
+
...jest.requireActual("react-router"), // Keep other methods from react-router as is
|
|
39
|
+
useLocation: jest.fn(), // Mock useLocation
|
|
40
|
+
}));
|
|
41
|
+
|
|
35
42
|
const JSON_TYPE = "application/json";
|
|
36
43
|
|
|
37
44
|
describe("modularui hooks", () => {
|
|
@@ -64,14 +71,11 @@ describe("modularui hooks", () => {
|
|
|
64
71
|
expect(result.current).toBeNull();
|
|
65
72
|
|
|
66
73
|
expect(store.getActions()).toStrictEqual([
|
|
67
|
-
{
|
|
68
|
-
type: "MODULARUI/STATUS",
|
|
69
|
-
payload: { key: `${key}(${url})(en)`, status: "LOADING" },
|
|
70
|
-
},
|
|
71
74
|
{ type: "START_PROGRESS" },
|
|
72
75
|
{
|
|
73
76
|
type: "MODULARUI/FETCH",
|
|
74
77
|
payload: expect.objectContaining({
|
|
78
|
+
key: `${key}(${url})(en)`,
|
|
75
79
|
href: new Href(url),
|
|
76
80
|
locale: "en",
|
|
77
81
|
targetModel: targetModel,
|
|
@@ -83,6 +87,9 @@ describe("modularui hooks", () => {
|
|
|
83
87
|
// replace the real XHR object with the mock XHR object before each test
|
|
84
88
|
// eslint-disable-next-line jest/no-hooks
|
|
85
89
|
beforeEach(() => {
|
|
90
|
+
useLocation.mockReturnValue({
|
|
91
|
+
state: null,
|
|
92
|
+
});
|
|
86
93
|
xhrMock.setup();
|
|
87
94
|
});
|
|
88
95
|
|
|
@@ -61,14 +61,11 @@ describe("authentication hooks", () => {
|
|
|
61
61
|
|
|
62
62
|
expect(store.getActions()).toStrictEqual([
|
|
63
63
|
{ type: "START_PROGRESS" },
|
|
64
|
-
{
|
|
65
|
-
type: "MODULARUI/STATUS",
|
|
66
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
67
|
-
},
|
|
68
64
|
{ type: "START_PROGRESS" },
|
|
69
65
|
expect.objectContaining({
|
|
70
66
|
type: "MODULARUI/FETCH",
|
|
71
67
|
payload: expect.objectContaining({
|
|
68
|
+
key: "application(/)(en)",
|
|
72
69
|
href: new Href("/", "Application"),
|
|
73
70
|
}),
|
|
74
71
|
}),
|
|
@@ -108,14 +105,11 @@ describe("authentication hooks", () => {
|
|
|
108
105
|
expect(store.getActions()).toStrictEqual([
|
|
109
106
|
{ type: "START_PROGRESS" },
|
|
110
107
|
{ type: "MODULARUI/RESET" },
|
|
111
|
-
{
|
|
112
|
-
type: "MODULARUI/STATUS",
|
|
113
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
114
|
-
},
|
|
115
108
|
{ type: "START_PROGRESS" },
|
|
116
109
|
expect.objectContaining({
|
|
117
110
|
type: "MODULARUI/FETCH",
|
|
118
111
|
payload: expect.objectContaining({
|
|
112
|
+
key: "application(/)(en)",
|
|
119
113
|
href: new Href("/", "Application"),
|
|
120
114
|
}),
|
|
121
115
|
}),
|
|
@@ -3,6 +3,7 @@ import thunk from "redux-thunk";
|
|
|
3
3
|
import { Provider } from "react-redux";
|
|
4
4
|
import { renderHook } from "@testing-library/react";
|
|
5
5
|
import xhrMock from "xhr-mock";
|
|
6
|
+
import { useLocation } from "react-router";
|
|
6
7
|
|
|
7
8
|
import {
|
|
8
9
|
useAttributeSet,
|
|
@@ -19,12 +20,22 @@ import { IllegalArgumentException } from "../../exceptions";
|
|
|
19
20
|
const middlewares = [thunk];
|
|
20
21
|
const mockStore = configureMockStore(middlewares);
|
|
21
22
|
|
|
23
|
+
jest.mock("react-router", () => ({
|
|
24
|
+
...jest.requireActual("react-router"), // Keep other methods from react-router as is
|
|
25
|
+
useLocation: jest.fn(), // Mock useLocation
|
|
26
|
+
}));
|
|
27
|
+
|
|
22
28
|
const JSON_TYPE = "application/json";
|
|
23
29
|
|
|
24
30
|
describe("form hooks", () => {
|
|
25
31
|
// replace the real XHR object with the mock XHR object before each test
|
|
26
32
|
// eslint-disable-next-line jest/no-hooks
|
|
27
|
-
beforeEach(() =>
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
useLocation.mockReturnValue({
|
|
35
|
+
state: null,
|
|
36
|
+
});
|
|
37
|
+
xhrMock.setup();
|
|
38
|
+
});
|
|
28
39
|
|
|
29
40
|
// put the real XHR object back and clear the mocks after each test
|
|
30
41
|
// eslint-disable-next-line jest/no-hooks
|
|
@@ -58,14 +69,11 @@ describe("form hooks", () => {
|
|
|
58
69
|
expect(result.current).toBeUndefined();
|
|
59
70
|
|
|
60
71
|
expect(store.getActions()).toStrictEqual([
|
|
61
|
-
{
|
|
62
|
-
type: "MODULARUI/STATUS",
|
|
63
|
-
payload: { key: "form(/form)(en)", status: "LOADING" },
|
|
64
|
-
},
|
|
65
72
|
{ type: "START_PROGRESS" },
|
|
66
73
|
{
|
|
67
74
|
type: "MODULARUI/FETCH",
|
|
68
75
|
payload: expect.objectContaining({
|
|
76
|
+
key: "form(/form)(en)",
|
|
69
77
|
href: new Href("/form?commit=false"),
|
|
70
78
|
locale: "en",
|
|
71
79
|
targetModel: FormModel,
|
|
@@ -102,17 +110,11 @@ describe("form hooks", () => {
|
|
|
102
110
|
href.resourcetype = "Form";
|
|
103
111
|
|
|
104
112
|
expect(store.getActions()).toStrictEqual([
|
|
105
|
-
{
|
|
106
|
-
type: "MODULARUI/STATUS",
|
|
107
|
-
payload: {
|
|
108
|
-
key: "form(/persons/persons/createperson)(en)",
|
|
109
|
-
status: "LOADING",
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
113
|
{ type: "START_PROGRESS" },
|
|
113
114
|
{
|
|
114
115
|
type: "MODULARUI/FETCH",
|
|
115
116
|
payload: expect.objectContaining({
|
|
117
|
+
key: "form(/persons/persons/createperson)(en)",
|
|
116
118
|
href: href,
|
|
117
119
|
locale: "en",
|
|
118
120
|
targetModel: FormModel,
|
|
@@ -3,6 +3,7 @@ import thunk from "redux-thunk";
|
|
|
3
3
|
import { Provider } from "react-redux";
|
|
4
4
|
import { renderHook } from "@testing-library/react";
|
|
5
5
|
import xhrMock from "xhr-mock";
|
|
6
|
+
import { useLocation } from "react-router";
|
|
6
7
|
|
|
7
8
|
import {
|
|
8
9
|
ConceptIndexModel,
|
|
@@ -26,6 +27,11 @@ import {
|
|
|
26
27
|
const middlewares = [thunk];
|
|
27
28
|
const mockStore = configureMockStore(middlewares);
|
|
28
29
|
|
|
30
|
+
jest.mock("react-router", () => ({
|
|
31
|
+
...jest.requireActual("react-router"), // Keep other methods from react-router as is
|
|
32
|
+
useLocation: jest.fn(), // Mock useLocation
|
|
33
|
+
}));
|
|
34
|
+
|
|
29
35
|
const JSON_TYPE = "application/json";
|
|
30
36
|
|
|
31
37
|
describe("modelcatalog hooks", () => {
|
|
@@ -58,14 +64,11 @@ describe("modelcatalog hooks", () => {
|
|
|
58
64
|
expect(result.current).toBeNull();
|
|
59
65
|
|
|
60
66
|
expect(store.getActions()).toStrictEqual([
|
|
61
|
-
{
|
|
62
|
-
type: "MODULARUI/STATUS",
|
|
63
|
-
payload: { key: `${key}(${url})(en)`, status: "LOADING" },
|
|
64
|
-
},
|
|
65
67
|
{ type: "START_PROGRESS" },
|
|
66
68
|
{
|
|
67
69
|
type: "MODULARUI/FETCH",
|
|
68
70
|
payload: expect.objectContaining({
|
|
71
|
+
key: `${key}(${url})(en)`,
|
|
69
72
|
href: new Href(url),
|
|
70
73
|
locale: "en",
|
|
71
74
|
targetModel: targetModel,
|
|
@@ -77,6 +80,9 @@ describe("modelcatalog hooks", () => {
|
|
|
77
80
|
// replace the real XHR object with the mock XHR object before each test
|
|
78
81
|
// eslint-disable-next-line jest/no-hooks
|
|
79
82
|
beforeEach(() => {
|
|
83
|
+
useLocation.mockReturnValue({
|
|
84
|
+
state: null,
|
|
85
|
+
});
|
|
80
86
|
xhrMock.setup();
|
|
81
87
|
});
|
|
82
88
|
|
|
@@ -37,14 +37,11 @@ describe("model hooks", () => {
|
|
|
37
37
|
|
|
38
38
|
result.current.reload(application);
|
|
39
39
|
expect(store.getActions()).toStrictEqual([
|
|
40
|
-
{
|
|
41
|
-
type: "MODULARUI/STATUS",
|
|
42
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
43
|
-
},
|
|
44
40
|
{ type: "START_PROGRESS" },
|
|
45
41
|
{
|
|
46
42
|
type: "MODULARUI/FETCH",
|
|
47
43
|
payload: expect.objectContaining({
|
|
44
|
+
key: "application(/)(en)",
|
|
48
45
|
href: new Href("/", "Application"),
|
|
49
46
|
locale: "en",
|
|
50
47
|
}),
|
|
@@ -83,14 +80,11 @@ describe("model hooks", () => {
|
|
|
83
80
|
model.selfhref.equals(new Href("/")),
|
|
84
81
|
);
|
|
85
82
|
expect(store.getActions()).toStrictEqual([
|
|
86
|
-
{
|
|
87
|
-
type: "MODULARUI/STATUS",
|
|
88
|
-
payload: { key: "application(/)(en)", status: "LOADING" },
|
|
89
|
-
},
|
|
90
83
|
{ type: "START_PROGRESS" },
|
|
91
84
|
{
|
|
92
85
|
type: "MODULARUI/FETCH",
|
|
93
86
|
payload: expect.objectContaining({
|
|
87
|
+
key: "application(/)(en)",
|
|
94
88
|
href: new Href("/", "Application"),
|
|
95
89
|
locale: "en",
|
|
96
90
|
}),
|
|
@@ -130,14 +124,11 @@ describe("model hooks", () => {
|
|
|
130
124
|
model.selfhref.equals(new Href("/books/books")),
|
|
131
125
|
);
|
|
132
126
|
expect(store.getActions()).toStrictEqual([
|
|
133
|
-
{
|
|
134
|
-
type: "MODULARUI/STATUS",
|
|
135
|
-
payload: { key: "list(/books/books)(en)", status: "LOADING" },
|
|
136
|
-
},
|
|
137
127
|
{ type: "START_PROGRESS" },
|
|
138
128
|
{
|
|
139
129
|
type: "MODULARUI/FETCH",
|
|
140
130
|
payload: expect.objectContaining({
|
|
131
|
+
key: "list(/books/books)(en)",
|
|
141
132
|
href: caselist.selfhref,
|
|
142
133
|
locale: "en",
|
|
143
134
|
}),
|
|
@@ -6,16 +6,25 @@ import xhrMock from "xhr-mock";
|
|
|
6
6
|
|
|
7
7
|
import { useModularUIBasic } from "../useModularUIBasic";
|
|
8
8
|
import { ApplicationModel, Href } from "../../models";
|
|
9
|
+
import { useLocation } from "react-router";
|
|
9
10
|
|
|
10
11
|
const middlewares = [thunk];
|
|
11
12
|
const mockStore = configureMockStore(middlewares);
|
|
12
13
|
|
|
14
|
+
jest.mock("react-router", () => ({
|
|
15
|
+
...jest.requireActual("react-router"), // Keep other methods from react-router as is
|
|
16
|
+
useLocation: jest.fn(), // Mock useLocation
|
|
17
|
+
}));
|
|
18
|
+
|
|
13
19
|
const JSON_TYPE = "application/json";
|
|
14
20
|
|
|
15
21
|
describe("modularui hooks", () => {
|
|
16
22
|
// replace the real XHR object with the mock XHR object before each test
|
|
17
23
|
// eslint-disable-next-line jest/no-hooks
|
|
18
24
|
beforeEach(() => {
|
|
25
|
+
useLocation.mockReturnValue({
|
|
26
|
+
state: null,
|
|
27
|
+
});
|
|
19
28
|
xhrMock.setup();
|
|
20
29
|
});
|
|
21
30
|
|
|
@@ -57,10 +66,6 @@ describe("modularui hooks", () => {
|
|
|
57
66
|
expect(result.current).toBeNull();
|
|
58
67
|
|
|
59
68
|
expect(store.getActions()).toStrictEqual([
|
|
60
|
-
{
|
|
61
|
-
type: "MODULARUI/STATUS",
|
|
62
|
-
payload: { key: `app(/)(en)`, status: "LOADING" },
|
|
63
|
-
},
|
|
64
69
|
{ type: "START_PROGRESS" },
|
|
65
70
|
{
|
|
66
71
|
type: "MODULARUI/FETCH",
|
|
@@ -107,10 +112,6 @@ describe("modularui hooks", () => {
|
|
|
107
112
|
expect(result.current).toBeNull();
|
|
108
113
|
|
|
109
114
|
expect(store.getActions()).toStrictEqual([
|
|
110
|
-
{
|
|
111
|
-
type: "MODULARUI/STATUS",
|
|
112
|
-
payload: { key: `app(/)(en)`, status: "LOADING" },
|
|
113
|
-
},
|
|
114
115
|
{ type: "START_PROGRESS" },
|
|
115
116
|
{
|
|
116
117
|
type: "MODULARUI/FETCH",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import { useEffect, useRef } from "react";
|
|
2
|
+
import { useEffect, useRef, useMemo } from "react";
|
|
3
3
|
import { useDispatch, useSelector } from "react-redux";
|
|
4
|
+
import { useLocation } from "react-router";
|
|
4
5
|
|
|
5
6
|
import { HTTP_METHODS } from "../constants";
|
|
6
7
|
import {
|
|
@@ -19,7 +20,10 @@ import type { RequestModularUIOptions } from "../utils";
|
|
|
19
20
|
*/
|
|
20
21
|
const useKeyForHook = (modelKey: string, url: string) => {
|
|
21
22
|
const locale = useLocale();
|
|
22
|
-
return
|
|
23
|
+
return useMemo(
|
|
24
|
+
() => `${modelKey}(${url.split("?")[0]})(${locale})`,
|
|
25
|
+
[modelKey, url, locale],
|
|
26
|
+
);
|
|
23
27
|
};
|
|
24
28
|
|
|
25
29
|
/**
|
|
@@ -34,7 +38,7 @@ export const useModularUI = (
|
|
|
34
38
|
},
|
|
35
39
|
): any => {
|
|
36
40
|
const dispatch = useDispatch();
|
|
37
|
-
const href = url?.toString() || "";
|
|
41
|
+
const href = useMemo(() => url?.toString() || "", [url]);
|
|
38
42
|
const key = useKeyForHook(modelKey, href);
|
|
39
43
|
|
|
40
44
|
if (url instanceof Href) {
|
|
@@ -42,8 +46,14 @@ export const useModularUI = (
|
|
|
42
46
|
options.contextPath = options.contextPath ?? url.contextPath;
|
|
43
47
|
}
|
|
44
48
|
|
|
49
|
+
const location = useLocation();
|
|
50
|
+
const redirectLocation = location.state?.redirectLocation;
|
|
51
|
+
const forceReload =
|
|
52
|
+
redirectLocation instanceof Href ? redirectLocation?.equals(href) : false;
|
|
53
|
+
|
|
45
54
|
const prevOptions = useRef(options);
|
|
46
55
|
const prevHref = useRef(href);
|
|
56
|
+
const prevForceReload = useRef(forceReload);
|
|
47
57
|
|
|
48
58
|
// dispatch loadModularUI
|
|
49
59
|
useDeepCompareEffect(() => {
|
|
@@ -53,25 +63,25 @@ export const useModularUI = (
|
|
|
53
63
|
prevOptions.current.isReload &&
|
|
54
64
|
!options.isReload;
|
|
55
65
|
|
|
56
|
-
|
|
66
|
+
const doForceReload = forceReload && !prevForceReload.current;
|
|
67
|
+
|
|
68
|
+
if (href !== "" && (doForceReload || !isOldReload)) {
|
|
57
69
|
dispatch(loadModularUI(key, href, options));
|
|
58
70
|
}
|
|
59
71
|
|
|
60
72
|
prevOptions.current = options;
|
|
61
73
|
prevHref.current = href;
|
|
62
|
-
|
|
74
|
+
prevForceReload.current = forceReload;
|
|
75
|
+
}, [key, href, options, forceReload]);
|
|
63
76
|
|
|
64
|
-
const { removeOnUnmount = false } = options;
|
|
65
77
|
useEffect(() => {
|
|
66
|
-
|
|
67
|
-
|
|
78
|
+
if (options.removeOnUnmount) {
|
|
79
|
+
return () => {
|
|
68
80
|
dispatch(removeModelByKey(key));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}, [dispatch, key, removeOnUnmount]);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}, [dispatch, key, options.removeOnUnmount]);
|
|
72
84
|
|
|
73
|
-
|
|
74
|
-
return useSelector(
|
|
75
|
-
return state.modularui[key];
|
|
76
|
-
});
|
|
85
|
+
const selector = useMemo(() => (state) => state.modularui[key], [key]);
|
|
86
|
+
return useSelector(selector);
|
|
77
87
|
};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
// @flow
|
|
2
|
+
import { useMemo } from "react";
|
|
2
3
|
import { useModularUI } from "./useModularUI";
|
|
3
|
-
|
|
4
4
|
import { useLocation } from "./useRouter";
|
|
5
|
-
|
|
6
5
|
import { IllegalStateException } from "../exceptions";
|
|
7
|
-
|
|
8
6
|
import type { ModularUIModel, Href } from "../models";
|
|
9
7
|
|
|
10
8
|
export type UseModularUIBasicOptions<T: ModularUIModel> = {
|
|
@@ -16,22 +14,13 @@ export type UseModularUIBasicOptions<T: ModularUIModel> = {
|
|
|
16
14
|
cache?: boolean,
|
|
17
15
|
};
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
targetModel: undefined,
|
|
27
|
-
forceTargetModel: false,
|
|
28
|
-
origin: undefined,
|
|
29
|
-
contextPath: undefined,
|
|
30
|
-
},
|
|
31
|
-
): T | null => {
|
|
32
|
-
const location = useLocation();
|
|
33
|
-
|
|
34
|
-
const useModularUIOptions = {
|
|
17
|
+
// Helper to create useModularUI options
|
|
18
|
+
const createUseModularUIOptions = <T: ModularUIModel>(
|
|
19
|
+
options: UseModularUIBasicOptions<T>,
|
|
20
|
+
href: string,
|
|
21
|
+
location: any,
|
|
22
|
+
): Object => {
|
|
23
|
+
const baseOptions = {
|
|
35
24
|
targetModel: undefined,
|
|
36
25
|
forceTargetModel: undefined,
|
|
37
26
|
isReload: false,
|
|
@@ -39,48 +28,75 @@ export const useModularUIBasic = <T: ModularUIModel>(
|
|
|
39
28
|
contextPath: undefined,
|
|
40
29
|
cache: false,
|
|
41
30
|
};
|
|
31
|
+
|
|
32
|
+
// Handle targetModel and forceTargetModel
|
|
42
33
|
if (options.targetModel) {
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
baseOptions.targetModel = options.targetModel;
|
|
35
|
+
baseOptions.forceTargetModel = options.forceTargetModel;
|
|
45
36
|
}
|
|
46
37
|
|
|
38
|
+
// Handle cache option
|
|
47
39
|
if (options.cache) {
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// reload when the modular service starts with the current location
|
|
52
|
-
if (location.state?.reload && location.pathname.startsWith(href.toString())) {
|
|
53
|
-
useModularUIOptions.isReload = true;
|
|
40
|
+
baseOptions.cache = options.cache;
|
|
54
41
|
}
|
|
55
42
|
|
|
56
|
-
if
|
|
57
|
-
|
|
43
|
+
// Check for reload if location matches href
|
|
44
|
+
if (location.state?.reload && location.pathname.startsWith(href)) {
|
|
45
|
+
baseOptions.isReload = true;
|
|
58
46
|
}
|
|
59
47
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// $FlowFixMe[incompatible-call]
|
|
65
|
-
const modularUI = useModularUI(key, href, useModularUIOptions);
|
|
66
|
-
|
|
67
|
-
if (modularUI?.model) {
|
|
68
|
-
const { model } = modularUI;
|
|
48
|
+
// Handle origin and contextPath options
|
|
49
|
+
baseOptions.origin = options.origin ?? baseOptions.origin;
|
|
50
|
+
baseOptions.contextPath = options.contextPath ?? baseOptions.contextPath;
|
|
69
51
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const isCorrectModel = expectedModels.some((expectedModel) => {
|
|
73
|
-
return model.type === expectedModel;
|
|
74
|
-
});
|
|
52
|
+
return baseOptions;
|
|
53
|
+
};
|
|
75
54
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
55
|
+
// Helper to validate the model against expectedModels
|
|
56
|
+
const validateModel = (model: any, expectedModels: Array<string>) => {
|
|
57
|
+
if (expectedModels.length > 0) {
|
|
58
|
+
const isCorrectModel = expectedModels.some(
|
|
59
|
+
(expectedModel) => model.type === expectedModel,
|
|
60
|
+
);
|
|
61
|
+
if (!isCorrectModel) {
|
|
62
|
+
console.error(model, "is not of instance", expectedModels);
|
|
63
|
+
throw new IllegalStateException("Resolved model has incorrect type");
|
|
80
64
|
}
|
|
81
|
-
|
|
82
|
-
return model;
|
|
83
65
|
}
|
|
66
|
+
};
|
|
84
67
|
|
|
85
|
-
|
|
68
|
+
/**
|
|
69
|
+
* useModularUIBasic Hook
|
|
70
|
+
*/
|
|
71
|
+
export const useModularUIBasic = <T: ModularUIModel>(
|
|
72
|
+
key: string,
|
|
73
|
+
href: string | Href,
|
|
74
|
+
options: UseModularUIBasicOptions<T> = {
|
|
75
|
+
expectedModels: [],
|
|
76
|
+
targetModel: undefined,
|
|
77
|
+
forceTargetModel: false,
|
|
78
|
+
origin: undefined,
|
|
79
|
+
contextPath: undefined,
|
|
80
|
+
},
|
|
81
|
+
): T | null => {
|
|
82
|
+
const location = useLocation();
|
|
83
|
+
const memoizedHref = useMemo(() => href.toString(), [href]);
|
|
84
|
+
const useModularUIOptions = useMemo(
|
|
85
|
+
() => createUseModularUIOptions(options, memoizedHref, location),
|
|
86
|
+
[options, memoizedHref, location],
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const modularUI = useModularUI(key, memoizedHref, useModularUIOptions);
|
|
90
|
+
const expectedModels = useMemo(
|
|
91
|
+
() => options.expectedModels ?? [],
|
|
92
|
+
[options.expectedModels],
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
return useMemo((): T | null => {
|
|
96
|
+
if (modularUI?.model) {
|
|
97
|
+
validateModel(modularUI.model, expectedModels);
|
|
98
|
+
return modularUI.model;
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}, [expectedModels, modularUI]);
|
|
86
102
|
};
|
|
@@ -273,6 +273,8 @@ export default class ConceptDetailModel extends ResourceModel {
|
|
|
273
273
|
this._sourceReferences = new SourceReferenceCollection(
|
|
274
274
|
this.getSourceReferencesForCurrentLanguage(availableLocales),
|
|
275
275
|
this.entryDate,
|
|
276
|
+
this.origin,
|
|
277
|
+
this.contextPath,
|
|
276
278
|
);
|
|
277
279
|
}
|
|
278
280
|
|
|
@@ -338,11 +340,4 @@ export default class ConceptDetailModel extends ResourceModel {
|
|
|
338
340
|
isOfConceptType(conceptTypeId: string): boolean {
|
|
339
341
|
return this.conceptType?.isOfConceptType(conceptTypeId) ?? false;
|
|
340
342
|
}
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Indicates if the given metamodel functional identifier exists in the hierarchy of concept types for this concept
|
|
344
|
-
*/
|
|
345
|
-
hasMetamodelIdInConceptTypeHierarchy(metamodelId: string): boolean {
|
|
346
|
-
return this.conceptType?.hasMetamodelIdInHierarchy(metamodelId) ?? false;
|
|
347
|
-
}
|
|
348
343
|
}
|