@beinformed/ui 1.27.5 → 1.28.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.
Files changed (134) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/esm/constants/LayoutHintConfig.js +0 -9
  3. package/esm/constants/LayoutHintConfig.js.map +1 -1
  4. package/esm/constants/LayoutHints.js +0 -4
  5. package/esm/constants/LayoutHints.js.map +1 -1
  6. package/esm/constants/Settings.js +0 -4
  7. package/esm/constants/Settings.js.map +1 -1
  8. package/esm/hooks/useForm.js.map +1 -1
  9. package/esm/models/attributes/ChoiceAttributeModel.js +1 -0
  10. package/esm/models/attributes/ChoiceAttributeModel.js.map +1 -1
  11. package/esm/models/attributes/ChoiceAttributeOptionModel.js +2 -2
  12. package/esm/models/attributes/ChoiceAttributeOptionModel.js.map +1 -1
  13. package/esm/models/attributes/DatetimeAttributeModel.js +3 -29
  14. package/esm/models/attributes/DatetimeAttributeModel.js.map +1 -1
  15. package/esm/react-client/Init.js +2 -2
  16. package/esm/react-client/Init.js.map +1 -1
  17. package/esm/react-client/client.js +80 -52
  18. package/esm/react-client/client.js.map +1 -1
  19. package/esm/redux/_modularui/ModularUIActions.js +7 -0
  20. package/esm/redux/_modularui/ModularUIActions.js.map +1 -1
  21. package/esm/redux/_modularui/ModularUIReducer.js +1 -0
  22. package/esm/redux/_modularui/ModularUIReducer.js.map +1 -1
  23. package/esm/redux/_modularui/types.js.map +1 -1
  24. package/esm/redux/actions/Form.js +2 -2
  25. package/esm/redux/actions/Form.js.map +1 -1
  26. package/esm/redux/actions/FormAttributeSet.js +2 -2
  27. package/esm/redux/actions/FormAttributeSet.js.map +1 -1
  28. package/esm/redux/actions/FormAttributeSetRepeatable.js +4 -4
  29. package/esm/redux/actions/FormAttributeSetRepeatable.js.map +1 -1
  30. package/esm/redux/actions/FormAutosave.js +2 -2
  31. package/esm/redux/actions/FormAutosave.js.map +1 -1
  32. package/esm/redux/actions/FormValidations.js +2 -2
  33. package/esm/redux/actions/FormValidations.js.map +1 -1
  34. package/esm/redux/connectors/Form.js.map +1 -1
  35. package/esm/redux/connectors/FormAttributeSet.js.map +1 -1
  36. package/esm/redux/store/configureStore.js +4 -4
  37. package/esm/redux/store/configureStore.js.map +1 -1
  38. package/esm/redux/types.js.map +1 -1
  39. package/lib/constants/LayoutHintConfig.js +0 -9
  40. package/lib/constants/LayoutHintConfig.js.flow +0 -9
  41. package/lib/constants/LayoutHintConfig.js.map +1 -1
  42. package/lib/constants/LayoutHints.js +2 -7
  43. package/lib/constants/LayoutHints.js.flow +0 -4
  44. package/lib/constants/LayoutHints.js.map +1 -1
  45. package/lib/constants/Settings.js +0 -4
  46. package/lib/constants/Settings.js.flow +0 -6
  47. package/lib/constants/Settings.js.map +1 -1
  48. package/lib/hooks/__tests__/useForm.spec.js.flow +4 -4
  49. package/lib/hooks/useForm.js.flow +5 -5
  50. package/lib/hooks/useForm.js.map +1 -1
  51. package/lib/models/attributes/ChoiceAttributeModel.js +1 -0
  52. package/lib/models/attributes/ChoiceAttributeModel.js.flow +1 -0
  53. package/lib/models/attributes/ChoiceAttributeModel.js.map +1 -1
  54. package/lib/models/attributes/ChoiceAttributeOptionModel.js +2 -2
  55. package/lib/models/attributes/ChoiceAttributeOptionModel.js.flow +2 -2
  56. package/lib/models/attributes/ChoiceAttributeOptionModel.js.map +1 -1
  57. package/lib/models/attributes/DatetimeAttributeModel.js +3 -29
  58. package/lib/models/attributes/DatetimeAttributeModel.js.flow +7 -41
  59. package/lib/models/attributes/DatetimeAttributeModel.js.map +1 -1
  60. package/lib/models/attributes/__tests__/DateAttributeModel.spec.js.flow +1 -35
  61. package/lib/models/attributes/__tests__/DatetimeAttributeModel.spec.js.flow +158 -216
  62. package/lib/models/attributes/__tests__/TimestampModel.spec.js.flow +0 -5
  63. package/lib/react-client/Init.js +2 -2
  64. package/lib/react-client/Init.js.flow +3 -3
  65. package/lib/react-client/Init.js.map +1 -1
  66. package/lib/react-client/client.js +83 -53
  67. package/lib/react-client/client.js.flow +106 -67
  68. package/lib/react-client/client.js.map +1 -1
  69. package/lib/redux/_modularui/ModularUIActions.js +9 -1
  70. package/lib/redux/_modularui/ModularUIActions.js.flow +8 -0
  71. package/lib/redux/_modularui/ModularUIActions.js.map +1 -1
  72. package/lib/redux/_modularui/ModularUIReducer.js +1 -0
  73. package/lib/redux/_modularui/ModularUIReducer.js.flow +1 -0
  74. package/lib/redux/_modularui/ModularUIReducer.js.map +1 -1
  75. package/lib/redux/_modularui/types.js.flow +5 -0
  76. package/lib/redux/_modularui/types.js.map +1 -1
  77. package/lib/redux/actions/Form.js +1 -1
  78. package/lib/redux/actions/Form.js.flow +4 -4
  79. package/lib/redux/actions/Form.js.map +1 -1
  80. package/lib/redux/actions/FormAttributeSet.js +1 -1
  81. package/lib/redux/actions/FormAttributeSet.js.flow +3 -2
  82. package/lib/redux/actions/FormAttributeSet.js.map +1 -1
  83. package/lib/redux/actions/FormAttributeSetRepeatable.js +3 -3
  84. package/lib/redux/actions/FormAttributeSetRepeatable.js.flow +8 -8
  85. package/lib/redux/actions/FormAttributeSetRepeatable.js.map +1 -1
  86. package/lib/redux/actions/FormAutosave.js +1 -1
  87. package/lib/redux/actions/FormAutosave.js.flow +2 -2
  88. package/lib/redux/actions/FormAutosave.js.map +1 -1
  89. package/lib/redux/actions/FormValidations.js +1 -1
  90. package/lib/redux/actions/FormValidations.js.flow +2 -2
  91. package/lib/redux/actions/FormValidations.js.map +1 -1
  92. package/lib/redux/actions/__tests__/Form.spec.js.flow +1 -1
  93. package/lib/redux/connectors/Form.js.flow +2 -5
  94. package/lib/redux/connectors/Form.js.map +1 -1
  95. package/lib/redux/connectors/FormAttributeSet.js.flow +5 -5
  96. package/lib/redux/connectors/FormAttributeSet.js.map +1 -1
  97. package/lib/redux/store/configureStore.js +4 -4
  98. package/lib/redux/store/configureStore.js.flow +5 -5
  99. package/lib/redux/store/configureStore.js.map +1 -1
  100. package/lib/redux/types.js.flow +2 -0
  101. package/lib/redux/types.js.map +1 -1
  102. package/package.json +17 -19
  103. package/src/constants/LayoutHintConfig.js +0 -9
  104. package/src/constants/LayoutHints.js +0 -4
  105. package/src/constants/Settings.js +0 -6
  106. package/src/hooks/__tests__/useForm.spec.js +4 -4
  107. package/src/hooks/useForm.js +5 -5
  108. package/src/models/attributes/ChoiceAttributeModel.js +1 -0
  109. package/src/models/attributes/ChoiceAttributeOptionModel.js +2 -2
  110. package/src/models/attributes/DatetimeAttributeModel.js +7 -41
  111. package/src/models/attributes/__tests__/DateAttributeModel.spec.js +1 -35
  112. package/src/models/attributes/__tests__/DatetimeAttributeModel.spec.js +158 -216
  113. package/src/models/attributes/__tests__/TimestampModel.spec.js +0 -5
  114. package/src/react-client/Init.js +3 -3
  115. package/src/react-client/client.js +106 -67
  116. package/src/redux/_modularui/ModularUIActions.js +8 -0
  117. package/src/redux/_modularui/ModularUIReducer.js +1 -0
  118. package/src/redux/_modularui/types.js +5 -0
  119. package/src/redux/actions/Form.js +4 -4
  120. package/src/redux/actions/FormAttributeSet.js +3 -2
  121. package/src/redux/actions/FormAttributeSetRepeatable.js +8 -8
  122. package/src/redux/actions/FormAutosave.js +2 -2
  123. package/src/redux/actions/FormValidations.js +2 -2
  124. package/src/redux/actions/__tests__/Form.spec.js +1 -1
  125. package/src/redux/connectors/Form.js +2 -5
  126. package/src/redux/connectors/FormAttributeSet.js +5 -5
  127. package/src/redux/store/configureStore.js +5 -5
  128. package/src/redux/types.js +2 -0
  129. package/types/constants/LayoutHintConfig.d.ts +8 -23
  130. package/types/constants/LayoutHints.d.ts +0 -4
  131. package/types/models/actions/ActionCollection.d.ts +1 -1
  132. package/types/models/attributes/DatetimeAttributeModel.d.ts +8 -2
  133. package/types/redux/_modularui/types.d.ts +4 -0
  134. package/types/redux/types.d.ts +1 -1
@@ -1,226 +1,168 @@
1
1
  import DatetimeAttributeModel from "../DatetimeAttributeModel";
2
- import { setSettings } from "../../../constants/Settings";
3
2
  import { ATTRIBUTE_WIDTH } from "../../../constants";
4
3
 
5
4
  describe("datetimeAttributeModel", () => {
6
- describe("with date readonly format in product default format", () => {
7
- beforeAll(() => {
8
- // using product default format
9
- setSettings({ DATE_READONLY_FORMAT: "dd-MM-yyyy" });
10
- setSettings({ DATE_INPUT_FORMAT: "dd-MM-yyyy" });
11
- });
12
-
13
- it("should be able to create an empty DatetimeAttribute object", () => {
14
- const attribute = new DatetimeAttributeModel({}, { type: "datetime" });
15
-
16
- expect(attribute).toBeInstanceOf(DatetimeAttributeModel);
17
-
18
- expect(attribute.type).toBe("datetime");
19
- expect(attribute.format).toBe("yyyy-MM-dd'T'HH:mm:ss");
20
- expect(attribute.getInputValue()).toBe("");
21
- expect(attribute.inputvalue).toBe("");
22
- expect(attribute.readonlyvalue).toBe("");
23
-
24
- attribute.addConstraints();
25
- expect(attribute.constraintCollection).toHaveLength(1);
26
- });
27
-
28
- it("should be able to update", () => {
29
- const attribute = new DatetimeAttributeModel(
30
- {},
31
- {
32
- type: "datetime",
33
- format: "dd-MM-yyyy HH:mm",
34
- }
35
- );
36
-
37
- attribute.update("18-08-2016 13:45");
38
- expect(attribute.getInputValue()).toBe("18-08-2016 13:45");
39
- expect(attribute.getInitialInputValue("2016-08-18T13:45:23")).toBe(
40
- "18-08-2016 13:45"
41
- );
42
-
43
- expect(attribute.readonlyvalue).toBe("18-08-2016 13:45");
44
-
45
- attribute.update(null);
46
- expect(attribute.getInputValue()).toBe("");
47
-
48
- attribute.update("");
49
- expect(attribute.value).toBeNull();
50
-
51
- attribute.update("aaaa");
52
- expect(attribute.value).toBe("Invalid Date");
53
- });
54
-
55
- it("should be able to handle min and max date in only date format and renders in format", () => {
56
- const attribute = new DatetimeAttributeModel(
57
- {},
58
- {
59
- type: "datetime",
60
- format: "dd-MM-yyyy HH:mm",
61
- mindate: "2010-10-01T00:00:00",
62
- maxdate: "2010-10-31T23:59:59",
63
- }
64
- );
65
-
66
- attribute.update("18-08-2016 13:45");
67
-
68
- expect(attribute.isValid).toBe(false);
69
- expect(attribute.formatValue(attribute.mindate)).toBe("01-10-2010 00:00");
70
- expect(attribute.formatValue(attribute.maxdate)).toBe("31-10-2010 23:59");
71
- });
5
+ it("should be able to create an empty DatetimeAttribute object", () => {
6
+ const attribute = new DatetimeAttributeModel({}, { type: "datetime" });
7
+
8
+ expect(attribute).toBeInstanceOf(DatetimeAttributeModel);
9
+
10
+ expect(attribute.type).toBe("datetime");
11
+ expect(attribute.format).toBe("yyyy-MM-dd'T'HH:mm:ss");
12
+ expect(attribute.getInputValue()).toBe("");
13
+ expect(attribute.inputvalue).toBe("");
14
+ expect(attribute.readonlyvalue).toBe("");
15
+
16
+ attribute.addConstraints();
17
+ expect(attribute.constraintCollection).toHaveLength(1);
72
18
  });
73
19
 
74
- describe("with customized readonly format for dates", () => {
75
- beforeAll(() => {
76
- // readonly format in non product default format
77
- setSettings({ DATE_READONLY_FORMAT: "MM-dd-yyyy" });
78
- });
79
-
80
- it("should show datetime readonly value in custom date format", () => {
81
- const attribute = new DatetimeAttributeModel(
82
- {},
83
- {
84
- type: "datetime",
85
- format: "dd-MM-yyyy HH:mm",
86
- }
87
- );
88
-
89
- attribute.update("18-08-2016 13:45");
90
- expect(attribute.readonlyvalue).toBe("08-18-2016 13:45");
91
- });
92
-
93
- it("should show date only value according in custom date format", () => {
94
- const attribute = new DatetimeAttributeModel(
95
- { value: "2017-07-29" },
96
- {
97
- type: "date",
98
- format: "dd-MM-yyyy",
99
- }
100
- );
101
-
102
- expect(attribute.readonlyvalue).toBe("07-29-2017");
103
- });
104
-
105
- it("should show custom format with am/pm in custom date format", () => {
106
- const attribute = new DatetimeAttributeModel(
107
- { value: "2031-12-21T17:41:21" },
108
- { type: "datetime", format: "dd-MM-yyyy hh:mm:ss a" }
109
- );
110
-
111
- expect(attribute.readonlyvalue).toBe("12-21-2031 05:41:21 PM");
112
- });
113
-
114
- it("should return AttributeWidth for dates", () => {
115
- const attribute = new DatetimeAttributeModel(
116
- {},
117
- {
118
- type: "date",
119
- }
120
- );
121
- expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.SMALL);
122
- });
123
-
124
- it("should return AttributeWidth for times", () => {
125
- const attribute = new DatetimeAttributeModel(
126
- {},
127
- {
128
- type: "time",
129
- }
130
- );
131
- expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.SMALL);
132
- });
133
-
134
- it("should return AttributeWidth for datetime", () => {
135
- const attribute = new DatetimeAttributeModel(
136
- {},
137
- {
138
- type: "datetime",
139
- }
140
- );
141
- expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.MEDIUM);
142
- });
143
-
144
- it("can validate datetime with datetime format", () => {
145
- const datetimeFormat = new DatetimeAttributeModel(
146
- {},
147
- {
148
- type: "datetime",
149
- format: "dd-MM-yyyy HH:mm",
150
- }
151
- );
152
-
153
- expect(datetimeFormat.validate("19-10-2010 1:45")).toBe(true);
154
- expect(datetimeFormat.validate("19-10-2010 13:45")).toBe(true);
155
-
156
- expect(datetimeFormat.validate("19-10-2010")).toBe(false);
157
- expect(datetimeFormat.validate("13:45")).toBe(false);
158
- expect(datetimeFormat.validate("19-10-2010 1:45 am")).toBe(false);
159
- });
160
-
161
- it("can validate datetime with only date format", () => {
162
- const dateFormat = new DatetimeAttributeModel(
163
- {},
164
- {
165
- type: "datetime",
166
- format: "dd-MM-yyyy",
167
- }
168
- );
169
-
170
- expect(dateFormat.validate("19-10-2010")).toBe(true);
171
-
172
- expect(dateFormat.validate("19-10-2010 1:45")).toBe(false);
173
- expect(dateFormat.validate("13:45")).toBe(false);
174
- expect(dateFormat.validate("19-10-2010 1:45 am")).toBe(false);
175
- });
176
-
177
- it("can validate datetime with datetime am/pm format", () => {
178
- const datetimeAmPmFormat = new DatetimeAttributeModel(
179
- {},
180
- {
181
- type: "datetime",
182
- format: "dd-MM-yyyy hh:mm a",
183
- }
184
- );
185
-
186
- expect(datetimeAmPmFormat.validate("19-10-2010 1:45 am")).toBe(true);
187
- expect(datetimeAmPmFormat.validate("19-10-2010 1:45 pm")).toBe(true);
188
-
189
- expect(datetimeAmPmFormat.validate("19-10-2010 1:45")).toBe(false);
190
- expect(datetimeAmPmFormat.validate("19-10-2010 13:45")).toBe(false);
191
- });
192
-
193
- it("can handle old datetime format with ms", () => {
194
- const attribute = new DatetimeAttributeModel(
195
- { value: "2031-12-21T17:41:21.000" },
196
- {
197
- type: "datetime",
198
- format: "dd-MM-yyyy HH:mm",
199
- }
200
- );
201
-
202
- expect(attribute.readonlyvalue).toBe("12-21-2031 17:41");
203
- });
20
+ it("should be able to update", () => {
21
+ const attribute = new DatetimeAttributeModel(
22
+ {},
23
+ {
24
+ type: "datetime",
25
+ format: "dd-MM-yyyy HH:mm",
26
+ }
27
+ );
28
+
29
+ attribute.update("18-08-2016 13:45");
30
+ expect(attribute.getInputValue()).toBe("18-08-2016 13:45");
31
+ expect(attribute.getInitialInputValue("2016-08-18T13:45:23")).toBe(
32
+ "18-08-2016 13:45"
33
+ );
34
+
35
+ expect(attribute.readonlyvalue).toBe("18-08-2016 13:45");
36
+
37
+ attribute.update(null);
38
+ expect(attribute.getInputValue()).toBe("");
39
+
40
+ attribute.update("");
41
+ expect(attribute.value).toBeNull();
42
+
43
+ attribute.update("aaaa");
44
+ expect(attribute.value).toBe("Invalid Date");
45
+ });
46
+
47
+ it("should be able to handle min and max date in only date format and renders in format", () => {
48
+ const attribute = new DatetimeAttributeModel(
49
+ {},
50
+ {
51
+ type: "datetime",
52
+ format: "dd-MM-yyyy HH:mm",
53
+ mindate: "2010-10-01T00:00:00",
54
+ maxdate: "2010-10-31T23:59:59",
55
+ }
56
+ );
57
+
58
+ attribute.update("18-08-2016 13:45");
59
+
60
+ expect(attribute.isValid).toBe(false);
61
+ expect(attribute.formatValue(attribute.mindate)).toBe("01-10-2010 00:00");
62
+ expect(attribute.formatValue(attribute.maxdate)).toBe("31-10-2010 23:59");
63
+ });
64
+
65
+ it("should return AttributeWidth for dates", () => {
66
+ const attribute = new DatetimeAttributeModel(
67
+ {},
68
+ {
69
+ type: "date",
70
+ }
71
+ );
72
+ expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.SMALL);
73
+ });
74
+
75
+ it("should return AttributeWidth for times", () => {
76
+ const attribute = new DatetimeAttributeModel(
77
+ {},
78
+ {
79
+ type: "time",
80
+ }
81
+ );
82
+ expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.SMALL);
83
+ });
84
+
85
+ it("should return AttributeWidth for datetime", () => {
86
+ const attribute = new DatetimeAttributeModel(
87
+ {},
88
+ {
89
+ type: "datetime",
90
+ }
91
+ );
92
+ expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.MEDIUM);
93
+ });
94
+
95
+ it("can validate datetime with datetime format", () => {
96
+ const datetimeFormat = new DatetimeAttributeModel(
97
+ {},
98
+ {
99
+ type: "datetime",
100
+ format: "dd-MM-yyyy HH:mm",
101
+ }
102
+ );
103
+
104
+ expect(datetimeFormat.validate("19-10-2010 1:45")).toBe(true);
105
+ expect(datetimeFormat.validate("19-10-2010 13:45")).toBe(true);
106
+
107
+ expect(datetimeFormat.validate("19-10-2010")).toBe(false);
108
+ expect(datetimeFormat.validate("13:45")).toBe(false);
109
+ expect(datetimeFormat.validate("19-10-2010 1:45 am")).toBe(false);
110
+ });
111
+
112
+ it("can validate datetime with only date format", () => {
113
+ const dateFormat = new DatetimeAttributeModel(
114
+ {},
115
+ {
116
+ type: "datetime",
117
+ format: "dd-MM-yyyy",
118
+ }
119
+ );
120
+
121
+ expect(dateFormat.validate("19-10-2010")).toBe(true);
122
+
123
+ expect(dateFormat.validate("19-10-2010 1:45")).toBe(false);
124
+ expect(dateFormat.validate("13:45")).toBe(false);
125
+ expect(dateFormat.validate("19-10-2010 1:45 am")).toBe(false);
126
+ });
127
+
128
+ it("can validate datetime with datetime am/pm format", () => {
129
+ const datetimeAmPmFormat = new DatetimeAttributeModel(
130
+ {},
131
+ {
132
+ type: "datetime",
133
+ format: "dd-MM-yyyy hh:mm a",
134
+ }
135
+ );
136
+
137
+ expect(datetimeAmPmFormat.validate("19-10-2010 1:45 am")).toBe(true);
138
+ expect(datetimeAmPmFormat.validate("19-10-2010 1:45 pm")).toBe(true);
139
+
140
+ expect(datetimeAmPmFormat.validate("19-10-2010 1:45")).toBe(false);
141
+ expect(datetimeAmPmFormat.validate("19-10-2010 13:45")).toBe(false);
142
+ });
143
+
144
+ it("can handle old datetime format with ms", () => {
145
+ const attribute = new DatetimeAttributeModel(
146
+ { value: "2031-12-21T17:41:21.000" },
147
+ {
148
+ type: "datetime",
149
+ format: "dd-MM-yyyy HH:mm",
150
+ }
151
+ );
152
+
153
+ expect(attribute.readonlyvalue).toBe("21-12-2031 17:41");
204
154
  });
205
155
 
206
- describe("without date input and date readonly settings defined", () => {
207
- beforeAll(() => {
208
- // explicitly clear setting
209
- setSettings({ DATE_INPUT_FORMAT: "" });
210
- setSettings({ DATE_READONLY_FORMAT: "" });
211
- });
212
-
213
- it("returns date part of formatlabel as placeholder if attribute has date and time", () => {
214
- const attribute = new DatetimeAttributeModel(
215
- {},
216
- {
217
- type: "datetime",
218
- format: "dd-MM-yyyy HH:mm",
219
- formatlabel: "dd-MM-yyyy HH:mm",
220
- }
221
- );
222
-
223
- expect(attribute.placeholder).toBe("dd-MM-yyyy");
224
- });
156
+ it("returns date part of formatlabel as placeholder if attribute has date and time", () => {
157
+ const attribute = new DatetimeAttributeModel(
158
+ {},
159
+ {
160
+ type: "datetime",
161
+ format: "dd-MM-yyyy HH:mm",
162
+ formatlabel: "dd-MM-yyyy HH:mm",
163
+ }
164
+ );
165
+
166
+ expect(attribute.placeholder).toBe("dd-MM-yyyy");
225
167
  });
226
168
  });
@@ -1,10 +1,5 @@
1
1
  import DatetimeAttributeModel from "../DatetimeAttributeModel";
2
- import { setSettings } from "../../../constants/Settings";
3
-
4
2
  describe("timestampAttributeModel", () => {
5
- beforeAll(() => {
6
- setSettings({ DATE_INPUT_FORMAT: "dd-MM-yyyy" });
7
- });
8
3
  it("should be able to create an empty TimestampAttribute object", () => {
9
4
  const attribute = new DatetimeAttributeModel({}, { type: "timestamp" });
10
5
 
@@ -16,7 +16,7 @@ var _jsxRuntime = require("react/jsx-runtime");
16
16
  const Init = _ref => {
17
17
  let {
18
18
  store,
19
- history,
19
+ routerHistory,
20
20
  contextPath,
21
21
  theme,
22
22
  children,
@@ -30,7 +30,7 @@ const Init = _ref => {
30
30
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ErrorBoundary.default, {
31
31
  FallbackComponent: ErrorFallbackComponent,
32
32
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouter.Router, {
33
- history: history,
33
+ history: routerHistory,
34
34
  basename: contextPath,
35
35
  children: children
36
36
  })
@@ -14,7 +14,7 @@ import type { Props as FallbackProps } from "../react/ErrorBoundaryFallback";
14
14
 
15
15
  export type Props = {
16
16
  +store: ReduxStore,
17
- +history: RouterHistory,
17
+ +routerHistory: RouterHistory,
18
18
  +contextPath: string,
19
19
  +theme?: Theme | Array<Theme>,
20
20
  +children: ?Node,
@@ -25,7 +25,7 @@ export type Props = {
25
25
  */
26
26
  const Init = ({
27
27
  store,
28
- history,
28
+ routerHistory,
29
29
  contextPath,
30
30
  theme,
31
31
  children,
@@ -35,7 +35,7 @@ const Init = ({
35
35
  <ThemeProvider theme={theme}>
36
36
  <HelmetProvider>
37
37
  <ErrorBoundary FallbackComponent={ErrorFallbackComponent}>
38
- <Router history={history} basename={contextPath}>
38
+ <Router history={routerHistory} basename={contextPath}>
39
39
  {children}
40
40
  </Router>
41
41
  </ErrorBoundary>
@@ -1 +1 @@
1
- {"version":3,"file":"Init.js","names":["Init","store","history","contextPath","theme","children","ErrorFallbackComponent","displayName"],"sources":["../../src/react-client/Init.js"],"sourcesContent":["// @flow\nimport { Provider } from \"react-redux\";\nimport { HelmetProvider } from \"react-helmet-async\";\nimport { Router } from \"react-router\";\n\nimport ThemeProvider from \"../react-theme/ThemeProvider\";\nimport ErrorBoundary from \"../react/ErrorBoundary\";\n\nimport type { ComponentType, Node } from \"react\";\nimport type { RouterHistory } from \"react-router\";\nimport type { Theme } from \"../react-theme/types\";\nimport type { ReduxStore } from \"../redux/types\";\nimport type { Props as FallbackProps } from \"../react/ErrorBoundaryFallback\";\n\nexport type Props = {\n +store: ReduxStore,\n +history: RouterHistory,\n +contextPath: string,\n +theme?: Theme | Array<Theme>,\n +children: ?Node,\n +ErrorFallbackComponent?: ComponentType<FallbackProps>,\n};\n\n/**\n */\nconst Init = ({\n store,\n history,\n contextPath,\n theme,\n children,\n ErrorFallbackComponent,\n}: Props): Node => (\n <Provider store={store}>\n <ThemeProvider theme={theme}>\n <HelmetProvider>\n <ErrorBoundary FallbackComponent={ErrorFallbackComponent}>\n <Router history={history} basename={contextPath}>\n {children}\n </Router>\n </ErrorBoundary>\n </HelmetProvider>\n </ThemeProvider>\n </Provider>\n);\n\nInit.displayName = \"BI.Init\";\n\nexport default Init;\n"],"mappings":";;;;;;;AACA;AACA;AACA;AAEA;AACA;AAAmD;AAiBnD;AACA;AACA,MAAMA,IAAI,GAAG;EAAA,IAAC;IACZC,KAAK;IACLC,OAAO;IACPC,WAAW;IACXC,KAAK;IACLC,QAAQ;IACRC;EACK,CAAC;EAAA,oBACN,qBAAC,oBAAQ;IAAC,KAAK,EAAEL,KAAM;IAAA,uBACrB,qBAAC,sBAAa;MAAC,KAAK,EAAEG,KAAM;MAAA,uBAC1B,qBAAC,gCAAc;QAAA,uBACb,qBAAC,sBAAa;UAAC,iBAAiB,EAAEE,sBAAuB;UAAA,uBACvD,qBAAC,mBAAM;YAAC,OAAO,EAAEJ,OAAQ;YAAC,QAAQ,EAAEC,WAAY;YAAA,UAC7CE;UAAQ;QACF;MACK;IACD;EACH,EACP;AAAA,CACZ;AAEDL,IAAI,CAACO,WAAW,GAAG,SAAS;AAAC,eAEdP,IAAI;AAAA"}
1
+ {"version":3,"file":"Init.js","names":["Init","store","routerHistory","contextPath","theme","children","ErrorFallbackComponent","displayName"],"sources":["../../src/react-client/Init.js"],"sourcesContent":["// @flow\nimport { Provider } from \"react-redux\";\nimport { HelmetProvider } from \"react-helmet-async\";\nimport { Router } from \"react-router\";\n\nimport ThemeProvider from \"../react-theme/ThemeProvider\";\nimport ErrorBoundary from \"../react/ErrorBoundary\";\n\nimport type { ComponentType, Node } from \"react\";\nimport type { RouterHistory } from \"react-router\";\nimport type { Theme } from \"../react-theme/types\";\nimport type { ReduxStore } from \"../redux/types\";\nimport type { Props as FallbackProps } from \"../react/ErrorBoundaryFallback\";\n\nexport type Props = {\n +store: ReduxStore,\n +routerHistory: RouterHistory,\n +contextPath: string,\n +theme?: Theme | Array<Theme>,\n +children: ?Node,\n +ErrorFallbackComponent?: ComponentType<FallbackProps>,\n};\n\n/**\n */\nconst Init = ({\n store,\n routerHistory,\n contextPath,\n theme,\n children,\n ErrorFallbackComponent,\n}: Props): Node => (\n <Provider store={store}>\n <ThemeProvider theme={theme}>\n <HelmetProvider>\n <ErrorBoundary FallbackComponent={ErrorFallbackComponent}>\n <Router history={routerHistory} basename={contextPath}>\n {children}\n </Router>\n </ErrorBoundary>\n </HelmetProvider>\n </ThemeProvider>\n </Provider>\n);\n\nInit.displayName = \"BI.Init\";\n\nexport default Init;\n"],"mappings":";;;;;;;AACA;AACA;AACA;AAEA;AACA;AAAmD;AAiBnD;AACA;AACA,MAAMA,IAAI,GAAG;EAAA,IAAC;IACZC,KAAK;IACLC,aAAa;IACbC,WAAW;IACXC,KAAK;IACLC,QAAQ;IACRC;EACK,CAAC;EAAA,oBACN,qBAAC,oBAAQ;IAAC,KAAK,EAAEL,KAAM;IAAA,uBACrB,qBAAC,sBAAa;MAAC,KAAK,EAAEG,KAAM;MAAA,uBAC1B,qBAAC,gCAAc;QAAA,uBACb,qBAAC,sBAAa;UAAC,iBAAiB,EAAEE,sBAAuB;UAAA,uBACvD,qBAAC,mBAAM;YAAC,OAAO,EAAEJ,aAAc;YAAC,QAAQ,EAAEC,WAAY;YAAA,UACnDE;UAAQ;QACF;MACK;IACD;EACH,EACP;AAAA,CACZ;AAEDL,IAAI,CAACO,WAAW,GAAG,SAAS;AAAC,eAEdP,IAAI;AAAA"}
@@ -4,10 +4,8 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.default = void 0;
7
+ exports.setupClient = exports.setUnhandledRejectionEvent = exports.default = exports.addContentLoadedEvent = void 0;
8
8
  var _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
9
- var _elementClosest = _interopRequireDefault(require("element-closest"));
10
- require("focus-visible");
11
9
  var _reactDom = require("react-dom");
12
10
  var _objects = require("../utils/helpers/objects");
13
11
  var _setimmediate = _interopRequireDefault(require("setimmediate"));
@@ -25,16 +23,9 @@ var _exceptions = require("../exceptions");
25
23
  var _Init = _interopRequireDefault(require("./Init"));
26
24
  var _beforeRenderHooks = require("../redux/store/beforeRenderHooks");
27
25
  var _jsxRuntime = require("react/jsx-runtime");
28
- /* polyfills needed for ie11 */
29
- (0, _elementClosest.default)(window);
30
-
31
- /* polyfill for focus-visible */
32
-
33
26
  /*
34
27
  * deserialize serialized data from the server to provide a smooth dehydration.
35
28
  */
36
- /**
37
- */
38
29
  const parseDataToJSON = data => {
39
30
  try {
40
31
  return JSON.parse(data);
@@ -42,22 +33,42 @@ const parseDataToJSON = data => {
42
33
  throw new _exceptions.JsonParseException(`Error parsing content ${data}`);
43
34
  }
44
35
  };
45
-
46
- /**
47
- * Mount the webapplication to the DOM, used client side when JavaScript is enabled.
48
- */
49
- const client = props => {
36
+ const getDataFromServer = () => {
50
37
  var _context;
51
- if (typeof window.contextPath === "undefined") {
52
- throw new Error("Missing contextPath on window object");
53
- }
54
38
  const dataElement = document.querySelector('script[type="application/json"][data-app-state="app-json"]');
55
39
  if (!dataElement) {
56
40
  throw new Error("Error loading state, json not found");
57
41
  } else if ((0, _trim.default)(_context = dataElement.textContent).call(_context) === "") {
58
- return;
42
+ return {};
59
43
  }
60
- const data = parseDataToJSON(dataElement.textContent);
44
+ return parseDataToJSON(dataElement.textContent);
45
+ };
46
+
47
+ /**
48
+ */
49
+ const setUnhandledRejectionEvent = store => {
50
+ window.onunhandledrejection = event => {
51
+ if (event.detail) {
52
+ return (0, _setimmediate.default)(() => {
53
+ const errorMessage = event.detail.reason.message.toString();
54
+ store.dispatch((0, _Notification.showXHRErrorNotification)(errorMessage));
55
+ throw event.detail.reason;
56
+ });
57
+ }
58
+ return event;
59
+ };
60
+ };
61
+
62
+ /**
63
+ */
64
+ exports.setUnhandledRejectionEvent = setUnhandledRejectionEvent;
65
+ const setupClient = function () {
66
+ let customReducers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
67
+ let beforeRenderHooks = arguments.length > 1 ? arguments[1] : undefined;
68
+ if (typeof window.contextPath === "undefined") {
69
+ throw new Error("Missing contextPath on window object");
70
+ }
71
+ const data = getDataFromServer();
61
72
 
62
73
  // remove all resources from cache
63
74
  _Cache.default.clear("^res:");
@@ -67,9 +78,9 @@ const client = props => {
67
78
  basename: (0, _Settings.getBasePath)()
68
79
  });
69
80
  const {
70
- history,
81
+ routerHistory,
71
82
  store
72
- } = (0, _configureStore.default)(browserHistory, props.customReducers ?? {}, (0, _rehydrate.default)(data));
83
+ } = (0, _configureStore.default)(browserHistory, customReducers, (0, _rehydrate.default)(data));
73
84
  (0, _Preferences.setAllContentInDataSetting)(store.getState());
74
85
  (0, _Preferences.setLoginPreferences)(store.getState());
75
86
 
@@ -80,7 +91,7 @@ const client = props => {
80
91
  }
81
92
  });
82
93
  if ((0, _objects.has)(data, "error.name")) {
83
- const error = new _exceptions.FetchException(data.error.response);
94
+ const error = new _exceptions.FetchException(data?.error?.response);
84
95
  store.dispatch((0, _Error.handleError)(error));
85
96
  }
86
97
  if (_Cache.default.getItem("auth")) {
@@ -88,54 +99,73 @@ const client = props => {
88
99
  }
89
100
 
90
101
  // listen to history change and update the redux router store
91
- history.listen((location, action) => {
102
+ routerHistory.listen((location, action) => {
92
103
  store.dispatch((0, _RouterActions.locationChange)(location, action));
93
104
  });
94
-
95
- /**
96
- */
97
- window.onunhandledrejection = event => {
98
- if (event.detail) {
99
- return (0, _setimmediate.default)(() => {
100
- const errorMessage = event.detail.reason.message.toString();
101
- store.dispatch((0, _Notification.showXHRErrorNotification)(errorMessage));
102
- throw event.detail.reason;
103
- });
104
- }
105
- return event;
106
- };
105
+ setUnhandledRejectionEvent(store);
107
106
  if (document.body) {
108
107
  document.body.className = "js";
109
108
  }
110
- if (props.beforeRenderHooks) {
111
- (0, _beforeRenderHooks.handleBeforeRenderHooks)(props.beforeRenderHooks, {
109
+ if (beforeRenderHooks) {
110
+ (0, _beforeRenderHooks.handleBeforeRenderHooks)(beforeRenderHooks, {
112
111
  store
113
112
  });
114
113
  }
115
- addContentLoadedEvent(store, history, props.theme, props.render, props.ErrorFallbackComponent);
114
+ return {
115
+ store,
116
+ routerHistory
117
+ };
116
118
  };
117
119
 
118
120
  /**
119
121
  */
120
- const addContentLoadedEvent = (store, history, theme, render, ErrorFallbackComponent) => {
122
+ exports.setupClient = setupClient;
123
+ const addContentLoadedEvent = (store, routerHistory, theme, render, ErrorFallbackComponent, mount) => {
121
124
  window.addEventListener("DOMContentLoaded", () => {
122
125
  const applicationNode = document.querySelector("#application");
123
- if (applicationNode) {
124
- const isSSR = applicationNode.querySelector(".application");
125
- const mount = isSSR ? _reactDom.hydrate : _reactDom.render;
126
- mount( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Init.default, {
127
- store: store,
128
- history: history,
129
- contextPath: window.contextPath,
130
- theme: theme,
131
- ErrorFallbackComponent: ErrorFallbackComponent,
132
- children: render()
133
- }), applicationNode);
134
- } else {
126
+ if (!applicationNode) {
135
127
  throw new Error("No DOM element with id application found to attach client to");
136
128
  }
129
+ mount(applicationNode, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Init.default, {
130
+ store: store,
131
+ routerHistory: routerHistory,
132
+ contextPath: window.contextPath,
133
+ theme: theme,
134
+ ErrorFallbackComponent: ErrorFallbackComponent,
135
+ children: render()
136
+ }));
137
137
  });
138
138
  };
139
+
140
+ /**
141
+ */
142
+ exports.addContentLoadedEvent = addContentLoadedEvent;
143
+ const mountClient = (applicationNode, initComponent) => {
144
+ const isSSR = applicationNode.querySelector(".application");
145
+ if (isSSR) {
146
+ (0, _reactDom.hydrate)(initComponent, applicationNode);
147
+ } else {
148
+ (0, _reactDom.render)(initComponent, applicationNode);
149
+ }
150
+ };
151
+
152
+ /**
153
+ * Mount the webapplication to the DOM, setup redux store and caches, add unhandledRejectionEvent, used client side when JavaScript is enabled.
154
+ */
155
+ const client = _ref => {
156
+ let {
157
+ customReducers,
158
+ theme,
159
+ render,
160
+ beforeRenderHooks,
161
+ ErrorFallbackComponent
162
+ } = _ref;
163
+ const {
164
+ store,
165
+ routerHistory
166
+ } = setupClient(customReducers, beforeRenderHooks);
167
+ addContentLoadedEvent(store, routerHistory, theme, render, ErrorFallbackComponent, mountClient);
168
+ };
139
169
  var _default = client;
140
170
  exports.default = _default;
141
171
  //# sourceMappingURL=client.js.map