@beinformed/ui 1.32.0 → 1.33.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/esm/models/attributes/AttributeModel.js +1 -1
  3. package/esm/models/attributes/AttributeModel.js.map +1 -1
  4. package/esm/models/attributes/DatetimeAttributeModel.js +0 -6
  5. package/esm/models/attributes/DatetimeAttributeModel.js.map +1 -1
  6. package/esm/models/attributes/NumberAttributeModel.js +0 -6
  7. package/esm/models/attributes/NumberAttributeModel.js.map +1 -1
  8. package/esm/models/attributes/StringAttributeModel.js +46 -18
  9. package/esm/models/attributes/StringAttributeModel.js.map +1 -1
  10. package/lib/models/attributes/AttributeModel.js +1 -1
  11. package/lib/models/attributes/AttributeModel.js.flow +1 -1
  12. package/lib/models/attributes/AttributeModel.js.map +1 -1
  13. package/lib/models/attributes/DatetimeAttributeModel.js +0 -6
  14. package/lib/models/attributes/DatetimeAttributeModel.js.flow +0 -6
  15. package/lib/models/attributes/DatetimeAttributeModel.js.map +1 -1
  16. package/lib/models/attributes/NumberAttributeModel.js +0 -6
  17. package/lib/models/attributes/NumberAttributeModel.js.flow +0 -6
  18. package/lib/models/attributes/NumberAttributeModel.js.map +1 -1
  19. package/lib/models/attributes/StringAttributeModel.js +46 -18
  20. package/lib/models/attributes/StringAttributeModel.js.flow +67 -18
  21. package/lib/models/attributes/StringAttributeModel.js.map +1 -1
  22. package/lib/models/attributes/__tests__/StringAttributeModel.spec.js.flow +23 -0
  23. package/lib/models/filters/__tests__/ZipcodeFilter.spec.js.flow +111 -0
  24. package/package.json +1 -1
  25. package/src/models/attributes/AttributeModel.js +1 -1
  26. package/src/models/attributes/DatetimeAttributeModel.js +0 -6
  27. package/src/models/attributes/NumberAttributeModel.js +0 -6
  28. package/src/models/attributes/StringAttributeModel.js +67 -18
  29. package/src/models/attributes/__tests__/StringAttributeModel.spec.js +23 -0
  30. package/src/models/filters/__tests__/ZipcodeFilter.spec.js +111 -0
@@ -117,16 +117,28 @@ export default class StringAttributeModel extends AttributeModel {
117
117
 
118
118
  if (this.isBSN()) {
119
119
  constraints.add(new BSNConstraint());
120
- } else if (this.isIBAN()) {
120
+ } else if (
121
+ this.isIBAN() &&
122
+ (this.operator === "" ||
123
+ this.operator === "exactly" ||
124
+ this.operator === "isNot")
125
+ ) {
126
+ // validate iban when no operator is set or exact or isNot
121
127
  constraints.add(new IBANConstraint());
122
128
  }
123
129
 
124
- if (this.isZipcode() && this.regexp) {
130
+ if (
131
+ this.isZipcode() &&
132
+ (this.operator === "" ||
133
+ this.operator === "exactly" ||
134
+ this.operator === "isNot")
135
+ ) {
136
+ // validate zip when regex is set is set or exact or isNot
125
137
  constraints.add(
126
138
  new RegexConstraint({
127
139
  messageKey: "Constraint.ZipCode.InvalidFormat",
128
140
  defaultMessage: "Must be a valid Dutch ZIP code, e.g. 1234 AB",
129
- regex: this.regexp,
141
+ regex: new RegExp("^[1-9][0-9]{3} ?[a-zA-Z]{2}$", "gi"),
130
142
  }),
131
143
  );
132
144
  } else if (this.isEmail() && this.regexp) {
@@ -162,15 +174,23 @@ export default class StringAttributeModel extends AttributeModel {
162
174
  formatIBAN(value: string): string {
163
175
  const noFormat = this.removeFormat(value);
164
176
 
165
- const groups = noFormat.replace(/\s/g, "").match(/.{1,4}/g);
166
- return groups == null ? "" : groups.join(" ");
177
+ if (
178
+ this.operator === "" ||
179
+ this.operator === "exactly" ||
180
+ this.operator === "isNot"
181
+ ) {
182
+ const groups = noFormat.replace(/\s/g, "").match(/.{1,4}/g);
183
+ return groups == null ? "" : groups.join(" ");
184
+ }
185
+
186
+ return noFormat;
167
187
  }
168
188
 
169
189
  /**
170
190
  */
171
191
  formatZipcode(value: string): string {
172
192
  const noFormat = this.removeFormat(value);
173
- if (noFormat.length > 4) {
193
+ if (noFormat.length === 6) {
174
194
  return (
175
195
  noFormat.substring(0, 4) + " " + noFormat.substring(4).toUpperCase()
176
196
  );
@@ -191,19 +211,29 @@ export default class StringAttributeModel extends AttributeModel {
191
211
  return "";
192
212
  }
193
213
 
194
- if (this.isIBAN()) {
195
- return this.formatIBAN(value);
214
+ if (typeof value !== "string") {
215
+ return value;
196
216
  }
197
217
 
198
- if (this.isZipcode()) {
199
- return this.formatZipcode(value);
200
- }
218
+ const values = this.isMultiple ? value.split(",") : [value];
201
219
 
202
- if (this.isBSN()) {
203
- return this.formatBSN(value);
204
- }
220
+ return values
221
+ .map((val) => {
222
+ if (this.isIBAN()) {
223
+ return this.formatIBAN(val);
224
+ }
205
225
 
206
- return value;
226
+ if (this.isZipcode()) {
227
+ return this.formatZipcode(val);
228
+ }
229
+
230
+ if (this.isBSN()) {
231
+ return this.formatBSN(val);
232
+ }
233
+
234
+ return val;
235
+ })
236
+ .join(",");
207
237
  }
208
238
 
209
239
  /**
@@ -214,7 +244,7 @@ export default class StringAttributeModel extends AttributeModel {
214
244
  }
215
245
 
216
246
  if (this.isIBAN() || this.isZipcode() || this.isBSN()) {
217
- return value.replace(/\.|\s/g, "");
247
+ return value.replace(/[^a-z0-9,]/gi, "");
218
248
  }
219
249
 
220
250
  return value;
@@ -238,7 +268,17 @@ export default class StringAttributeModel extends AttributeModel {
238
268
  set inputvalue(value: string) {
239
269
  this._inputvalue = value;
240
270
 
241
- this.value = value == null ? value : this.removeFormat(value);
271
+ if (value == null) {
272
+ this.value = value;
273
+ } else if (this.isMultiple) {
274
+ this.value = value
275
+ .split(",")
276
+ .map((val) => this.removeFormat(val))
277
+ .join(",");
278
+ } else {
279
+ this.value = this.removeFormat(value);
280
+ }
281
+
242
282
  this.validate(this.validateValue);
243
283
  }
244
284
 
@@ -246,7 +286,9 @@ export default class StringAttributeModel extends AttributeModel {
246
286
  */
247
287
  get readonlyvalue(): string {
248
288
  if (typeof this.value === "string") {
249
- return this.formatValue(this.value);
289
+ const formattedValue = this.formatValue(this.value);
290
+ // fix for rendering of multiple spaces
291
+ return formattedValue.replace(/ {2}/gi, " \u00A0");
250
292
  }
251
293
 
252
294
  return this.value == null ? "" : this.value;
@@ -280,4 +322,11 @@ export default class StringAttributeModel extends AttributeModel {
280
322
  // default value (also applied for email address + download attribute)
281
323
  return ATTRIBUTE_WIDTH.MEDIUM;
282
324
  }
325
+
326
+ /**
327
+ * Indicates if a value is multiple choice, used for filters
328
+ */
329
+ get isMultiple(): boolean {
330
+ return this.getContribution("multiplechoice", false);
331
+ }
283
332
  }
@@ -112,4 +112,27 @@ describe("stringAttributeModel", () => {
112
112
 
113
113
  expect(attribute).not.toBe(clonedAttribute);
114
114
  });
115
+
116
+ it("handles multiple spaces in the readonlyvalue", () => {
117
+ const attribute = new StringAttributeModel({}, { type: "string" });
118
+
119
+ attribute.update("test test");
120
+
121
+ expect(attribute.value).toBe("test test");
122
+ expect(attribute.inputvalue).toBe("test test");
123
+ expect(attribute.readonlyvalue).toBe("test \u00A0 \u00A0 test");
124
+ });
125
+
126
+ it("format isMultiple with escaped comma", () => {
127
+ const attribute = new StringAttributeModel(
128
+ {},
129
+ { type: "string", multiplechoice: true },
130
+ );
131
+
132
+ attribute.update("test test");
133
+
134
+ expect(attribute.value).toBe("test test");
135
+ expect(attribute.inputvalue).toBe("test test");
136
+ expect(attribute.readonlyvalue).toBe("test \u00A0 \u00A0 test");
137
+ });
115
138
  });
@@ -0,0 +1,111 @@
1
+ import FilterModel from "../FilterModel";
2
+
3
+ describe("filterModel", () => {
4
+ let data;
5
+ let contributions;
6
+
7
+ beforeEach(() => {
8
+ data = {
9
+ name: "zipfilter",
10
+ param: "zipfilter",
11
+ };
12
+
13
+ contributions = {
14
+ label: "zipfilter",
15
+ layouthint: ["zipcode"],
16
+ multiplechoice: false,
17
+ operator: "exactly",
18
+ type: "string",
19
+ };
20
+ });
21
+
22
+ it("should be able to create a filter from a typical modular UI json filter structure without value", () => {
23
+ const filter = new FilterModel(data, contributions);
24
+
25
+ expect(filter).toBeInstanceOf(FilterModel);
26
+ expect(filter.label).toBe("zipfilter");
27
+ expect(filter.name).toBe("zipfilter");
28
+ expect(filter.value).toBeNull();
29
+ expect(filter.inputvalue).toBeUndefined();
30
+ expect(filter.type).toBe("string");
31
+ });
32
+
33
+ it("modular ui input, zipcode no space", () => {
34
+ const stringFilterWithValue = { ...data };
35
+
36
+ stringFilterWithValue.value = "1234AB";
37
+
38
+ const filter = new FilterModel(stringFilterWithValue, contributions);
39
+
40
+ expect(filter).toBeInstanceOf(FilterModel);
41
+ expect(filter.attribute.value).toBe("1234AB");
42
+ expect(filter.attribute.inputvalue).toBe("1234 AB");
43
+ expect(filter.params).toStrictEqual([
44
+ {
45
+ name: "zipfilter",
46
+ value: "1234AB",
47
+ },
48
+ ]);
49
+
50
+ filter.reset();
51
+ expect(filter.attribute.inputvalue).toBe("");
52
+ expect(filter.attribute.value).toBeNull();
53
+ });
54
+
55
+ it("modular ui input, zipcode space", () => {
56
+ const filter = new FilterModel(data, contributions);
57
+
58
+ filter.update(filter.attribute, "1234 AB");
59
+
60
+ expect(filter).toBeInstanceOf(FilterModel);
61
+ expect(filter.attribute.value).toBe("1234AB");
62
+ expect(filter.attribute.inputvalue).toBe("1234 AB");
63
+ expect(filter.params).toStrictEqual([
64
+ {
65
+ name: "zipfilter",
66
+ value: "1234AB",
67
+ },
68
+ ]);
69
+
70
+ expect(filter.isValid).toBe(true);
71
+ });
72
+
73
+ it("modular ui input, wrong zipcode", () => {
74
+ const filter = new FilterModel(data, contributions);
75
+
76
+ filter.update(filter.attribute, "123");
77
+
78
+ expect(filter).toBeInstanceOf(FilterModel);
79
+ expect(filter.attribute.value).toBe("123");
80
+ expect(filter.attribute.inputvalue).toBe("123");
81
+ expect(filter.params).toStrictEqual([
82
+ {
83
+ name: "zipfilter",
84
+ value: "123",
85
+ },
86
+ ]);
87
+
88
+ expect(filter.isValid).toBe(false);
89
+ });
90
+
91
+ it("modular ui input - starts with, zipcode part", () => {
92
+ const filter = new FilterModel(data, {
93
+ operator: "startsWith",
94
+ contributions,
95
+ });
96
+
97
+ filter.update(filter.attribute, "123");
98
+
99
+ expect(filter).toBeInstanceOf(FilterModel);
100
+ expect(filter.attribute.value).toBe("123");
101
+ expect(filter.attribute.inputvalue).toBe("123");
102
+ expect(filter.params).toStrictEqual([
103
+ {
104
+ name: "zipfilter",
105
+ value: "123",
106
+ },
107
+ ]);
108
+
109
+ expect(filter.isValid).toBe(true);
110
+ });
111
+ });