@beinformed/ui 1.33.0-beta.5 → 1.33.0-beta.6
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 +7 -0
- package/esm/models/filters/StringFilterModel.js +31 -1
- package/esm/models/filters/StringFilterModel.js.map +1 -1
- package/lib/models/filters/StringFilterModel.js +31 -1
- package/lib/models/filters/StringFilterModel.js.flow +36 -1
- package/lib/models/filters/StringFilterModel.js.map +1 -1
- package/lib/models/filters/__tests__/ZipcodeFilter.spec.js.flow +30 -12
- package/package.json +1 -1
- package/src/models/filters/StringFilterModel.js +36 -1
- package/src/models/filters/__tests__/ZipcodeFilter.spec.js +30 -12
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [1.33.0-beta.6](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.33.0-beta.5...v1.33.0-beta.6) (2023-08-28)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **formatting:** remove formatting on exactly and not ([b80518d](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/b80518d5d74a1f54943e1e835a708f193555b85b))
|
|
11
|
+
|
|
5
12
|
## [1.33.0-beta.5](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.33.0-beta.4...v1.33.0-beta.5) (2023-08-28)
|
|
6
13
|
|
|
7
14
|
## [1.33.0-beta.4](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.33.0-beta.3...v1.33.0-beta.4) (2023-08-28)
|
|
@@ -28,7 +28,7 @@ export default class StringFilterModel extends BaseFilterModel {
|
|
|
28
28
|
}
|
|
29
29
|
return [{
|
|
30
30
|
name: this.param,
|
|
31
|
-
value: this.value
|
|
31
|
+
value: this.removeFormat(this.value)
|
|
32
32
|
}];
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -98,5 +98,35 @@ export default class StringFilterModel extends BaseFilterModel {
|
|
|
98
98
|
}
|
|
99
99
|
return value;
|
|
100
100
|
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
*/
|
|
104
|
+
isBSN() {
|
|
105
|
+
return this.layouthint.has("bsn");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
*/
|
|
110
|
+
isIBAN() {
|
|
111
|
+
return this.layouthint.has("iban");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
*/
|
|
116
|
+
isZipcode() {
|
|
117
|
+
return this.layouthint.has("zipcode");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
*/
|
|
122
|
+
removeFormat(value) {
|
|
123
|
+
if (value == null || value.toString() === "") {
|
|
124
|
+
return "";
|
|
125
|
+
}
|
|
126
|
+
if ((this.operator === "exactly" || this.operator === "isNot") && (this.isIBAN() || this.isZipcode() || this.isBSN())) {
|
|
127
|
+
return value.replace(/[^a-z0-9,]/gi, "");
|
|
128
|
+
}
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
101
131
|
}
|
|
102
132
|
//# sourceMappingURL=StringFilterModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringFilterModel.js","names":["BaseFilterModel","StringFilterModel","constructor","data","contributions","_defineProperty","update","attribute","value","_inputvalue","_value","params","param","name","inputvalue","reset","isValid","_isValid","toString","operator","_context","_context2","values","isMultiple","_mapInstanceProperty","split","call","val","_trimInstanceProperty","outputValues","formattedValue","formatValue","push","validate","join","getContribution"],"sources":["../../../src/models/filters/StringFilterModel.js"],"sourcesContent":["// @flow\nimport BaseFilterModel from \"./BaseFilterModel\";\n\nimport type { AttributeType, FilterType } from \"../types\";\n\n/**\n * StringFilterModel can handle string filters with multiple setting\n */\nexport default class StringFilterModel extends BaseFilterModel {\n _isValid: boolean = true;\n _value: string | null;\n _inputvalue: string;\n\n /**\n */\n constructor(data: Object, contributions: Object) {\n super(data, contributions);\n\n this.update(this.attribute, data.value ?? \"\");\n\n // when formatted value set this to initial input value\n this._inputvalue = this._value ?? \"\";\n }\n\n /**\n * Retrieve the parameters with its value for this filter\n */\n get params(): Array<{ name: string, value: ?string }> {\n if (!this.param) {\n return [];\n }\n\n return [\n {\n name: this.param,\n value: this.value,\n },\n ];\n }\n\n /**\n * Getting the value of the filter\n */\n get value(): string | null {\n return this._value;\n }\n\n /**\n */\n get inputvalue(): string {\n return this._inputvalue;\n }\n\n /**\n * Reset the value of this filter to undefined\n */\n reset(): FilterType {\n this._inputvalue = \"\";\n this._value = null;\n\n return this;\n }\n\n /**\n */\n get isValid(): boolean {\n return this._isValid;\n }\n\n /**\n * Update this filter with input name and value\n */\n update(attribute: AttributeType, value: string) {\n this._inputvalue = typeof value !== \"string\" ? value.toString() : value;\n\n if (this.operator === \"exactly\" || this.operator === \"isNot\") {\n const values = this.isMultiple\n ? this._inputvalue.split(\",\").map((val) => val.trim())\n : [this._inputvalue.trim()];\n\n const outputValues = [];\n for (const val of values) {\n const formattedValue = this.formatValue(val);\n if (formattedValue !== \"\") {\n outputValues.push(formattedValue);\n\n if (!this.attribute.validate(formattedValue)) {\n this._isValid = false;\n }\n }\n }\n\n this._value = outputValues.join(\",\");\n } else {\n this._value = value;\n }\n }\n\n /**\n */\n get operator(): string {\n return this.getContribution(\"operator\", \"\");\n }\n\n /**\n */\n formatValue(value: string): string {\n if (this.operator === \"exactly\" || this.operator === \"isNot\") {\n return this.attribute.formatValue(value);\n }\n return value;\n }\n}\n"],"mappings":";;;AACA,OAAOA,eAAe,MAAM,mBAAmB;AAI/C;AACA;AACA;AACA,eAAe,MAAMC,iBAAiB,SAASD,eAAe,CAAC;EAK7D;AACF;EACEE,WAAWA,CAACC,IAAY,EAAEC,aAAqB,EAAE;IAC/C,KAAK,CAACD,IAAI,EAAEC,aAAa,CAAC;IAACC,eAAA,mBAPT,IAAI;IAAAA,eAAA;IAAAA,eAAA;IAStB,IAAI,CAACC,MAAM,CAAC,IAAI,CAACC,SAAS,EAAEJ,IAAI,CAACK,KAAK,IAAI,EAAE,CAAC;;IAE7C;IACA,IAAI,CAACC,WAAW,GAAG,IAAI,CAACC,MAAM,IAAI,EAAE;EACtC;;EAEA;AACF;AACA;EACE,IAAIC,MAAMA,CAAA,EAA4C;IACpD,IAAI,CAAC,IAAI,CAACC,KAAK,EAAE;MACf,OAAO,EAAE;IACX;IAEA,OAAO,CACL;MACEC,IAAI,EAAE,IAAI,CAACD,KAAK;MAChBJ,KAAK,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"StringFilterModel.js","names":["BaseFilterModel","StringFilterModel","constructor","data","contributions","_defineProperty","update","attribute","value","_inputvalue","_value","params","param","name","removeFormat","inputvalue","reset","isValid","_isValid","toString","operator","_context","_context2","values","isMultiple","_mapInstanceProperty","split","call","val","_trimInstanceProperty","outputValues","formattedValue","formatValue","push","validate","join","getContribution","isBSN","layouthint","has","isIBAN","isZipcode","replace"],"sources":["../../../src/models/filters/StringFilterModel.js"],"sourcesContent":["// @flow\nimport BaseFilterModel from \"./BaseFilterModel\";\n\nimport type { AttributeType, FilterType } from \"../types\";\n\n/**\n * StringFilterModel can handle string filters with multiple setting\n */\nexport default class StringFilterModel extends BaseFilterModel {\n _isValid: boolean = true;\n _value: string | null;\n _inputvalue: string;\n\n /**\n */\n constructor(data: Object, contributions: Object) {\n super(data, contributions);\n\n this.update(this.attribute, data.value ?? \"\");\n\n // when formatted value set this to initial input value\n this._inputvalue = this._value ?? \"\";\n }\n\n /**\n * Retrieve the parameters with its value for this filter\n */\n get params(): Array<{ name: string, value: ?string }> {\n if (!this.param) {\n return [];\n }\n\n return [\n {\n name: this.param,\n value: this.removeFormat(this.value),\n },\n ];\n }\n\n /**\n * Getting the value of the filter\n */\n get value(): string | null {\n return this._value;\n }\n\n /**\n */\n get inputvalue(): string {\n return this._inputvalue;\n }\n\n /**\n * Reset the value of this filter to undefined\n */\n reset(): FilterType {\n this._inputvalue = \"\";\n this._value = null;\n\n return this;\n }\n\n /**\n */\n get isValid(): boolean {\n return this._isValid;\n }\n\n /**\n * Update this filter with input name and value\n */\n update(attribute: AttributeType, value: string) {\n this._inputvalue = typeof value !== \"string\" ? value.toString() : value;\n\n if (this.operator === \"exactly\" || this.operator === \"isNot\") {\n const values = this.isMultiple\n ? this._inputvalue.split(\",\").map((val) => val.trim())\n : [this._inputvalue.trim()];\n\n const outputValues = [];\n for (const val of values) {\n const formattedValue = this.formatValue(val);\n if (formattedValue !== \"\") {\n outputValues.push(formattedValue);\n\n if (!this.attribute.validate(formattedValue)) {\n this._isValid = false;\n }\n }\n }\n\n this._value = outputValues.join(\",\");\n } else {\n this._value = value;\n }\n }\n\n /**\n */\n get operator(): string {\n return this.getContribution(\"operator\", \"\");\n }\n\n /**\n */\n formatValue(value: string): string {\n if (this.operator === \"exactly\" || this.operator === \"isNot\") {\n return this.attribute.formatValue(value);\n }\n return value;\n }\n\n /**\n */\n isBSN(): boolean {\n return this.layouthint.has(\"bsn\");\n }\n\n /**\n */\n isIBAN(): boolean {\n return this.layouthint.has(\"iban\");\n }\n\n /**\n */\n isZipcode(): boolean {\n return this.layouthint.has(\"zipcode\");\n }\n\n /**\n */\n removeFormat(value: ?string): string {\n if (value == null || value.toString() === \"\") {\n return \"\";\n }\n\n if (\n (this.operator === \"exactly\" || this.operator === \"isNot\") &&\n (this.isIBAN() || this.isZipcode() || this.isBSN())\n ) {\n return value.replace(/[^a-z0-9,]/gi, \"\");\n }\n\n return value;\n }\n}\n"],"mappings":";;;AACA,OAAOA,eAAe,MAAM,mBAAmB;AAI/C;AACA;AACA;AACA,eAAe,MAAMC,iBAAiB,SAASD,eAAe,CAAC;EAK7D;AACF;EACEE,WAAWA,CAACC,IAAY,EAAEC,aAAqB,EAAE;I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A,CAAA,EAAY;IAChB,OAAO,IAAI,CAACF,UAAU,CAACC,GAAG,CAAC,MAAM,CAAC;EACpC;;EAEA;AACF;EACEE,SAASA,CAAA,EAAY;IACnB,OAAO,IAAI,CAACH,UAAU,CAACC,GAAG,CAAC,SAAS,CAAC;EACvC;;EAEA;AACF;EACEzB,YAAYA,CAACN,KAAc,EAAU;IACnC,IAAIA,KAAK,IAAI,IAAI,IAAIA,KAAK,CAACW,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;MAC5C,OAAO,EAAE;IACX;IAEA,IACE,CAAC,IAAI,CAACC,QAAQ,KAAK,SAAS,IAAI,IAAI,CAACA,QAAQ,KAAK,OAAO,MACxD,IAAI,CAACoB,MAAM,CAAC,CAAC,IAAI,IAAI,CAACC,SAAS,CAAC,CAAC,IAAI,IAAI,CAACJ,KAAK,CAAC,CAAC,CAAC,EACnD;MACA,OAAO7B,KAAK,CAACkC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;IAC1C;IAEA,OAAOlC,KAAK;EACd;AACF"}
|
|
@@ -35,7 +35,7 @@ class StringFilterModel extends _BaseFilterModel.default {
|
|
|
35
35
|
}
|
|
36
36
|
return [{
|
|
37
37
|
name: this.param,
|
|
38
|
-
value: this.value
|
|
38
|
+
value: this.removeFormat(this.value)
|
|
39
39
|
}];
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -105,6 +105,36 @@ class StringFilterModel extends _BaseFilterModel.default {
|
|
|
105
105
|
}
|
|
106
106
|
return value;
|
|
107
107
|
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
*/
|
|
111
|
+
isBSN() {
|
|
112
|
+
return this.layouthint.has("bsn");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
*/
|
|
117
|
+
isIBAN() {
|
|
118
|
+
return this.layouthint.has("iban");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
*/
|
|
123
|
+
isZipcode() {
|
|
124
|
+
return this.layouthint.has("zipcode");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
*/
|
|
129
|
+
removeFormat(value) {
|
|
130
|
+
if (value == null || value.toString() === "") {
|
|
131
|
+
return "";
|
|
132
|
+
}
|
|
133
|
+
if ((this.operator === "exactly" || this.operator === "isNot") && (this.isIBAN() || this.isZipcode() || this.isBSN())) {
|
|
134
|
+
return value.replace(/[^a-z0-9,]/gi, "");
|
|
135
|
+
}
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
108
138
|
}
|
|
109
139
|
exports.default = StringFilterModel;
|
|
110
140
|
//# sourceMappingURL=StringFilterModel.js.map
|
|
@@ -33,7 +33,7 @@ export default class StringFilterModel extends BaseFilterModel {
|
|
|
33
33
|
return [
|
|
34
34
|
{
|
|
35
35
|
name: this.param,
|
|
36
|
-
value: this.value,
|
|
36
|
+
value: this.removeFormat(this.value),
|
|
37
37
|
},
|
|
38
38
|
];
|
|
39
39
|
}
|
|
@@ -110,4 +110,39 @@ export default class StringFilterModel extends BaseFilterModel {
|
|
|
110
110
|
}
|
|
111
111
|
return value;
|
|
112
112
|
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
*/
|
|
116
|
+
isBSN(): boolean {
|
|
117
|
+
return this.layouthint.has("bsn");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
*/
|
|
122
|
+
isIBAN(): boolean {
|
|
123
|
+
return this.layouthint.has("iban");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
*/
|
|
128
|
+
isZipcode(): boolean {
|
|
129
|
+
return this.layouthint.has("zipcode");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
*/
|
|
134
|
+
removeFormat(value: ?string): string {
|
|
135
|
+
if (value == null || value.toString() === "") {
|
|
136
|
+
return "";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (
|
|
140
|
+
(this.operator === "exactly" || this.operator === "isNot") &&
|
|
141
|
+
(this.isIBAN() || this.isZipcode() || this.isBSN())
|
|
142
|
+
) {
|
|
143
|
+
return value.replace(/[^a-z0-9,]/gi, "");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
113
148
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringFilterModel.js","names":["_BaseFilterModel","_interopRequireDefault","require","StringFilterModel","BaseFilterModel","constructor","data","contributions","_defineProperty2","default","update","attribute","value","_inputvalue","_value","params","param","name","inputvalue","reset","isValid","_isValid","toString","operator","_context","_context2","values","isMultiple","_map","split","call","val","_trim","outputValues","formattedValue","formatValue","push","validate","join","getContribution","exports"],"sources":["../../../src/models/filters/StringFilterModel.js"],"sourcesContent":["// @flow\nimport BaseFilterModel from \"./BaseFilterModel\";\n\nimport type { AttributeType, FilterType } from \"../types\";\n\n/**\n * StringFilterModel can handle string filters with multiple setting\n */\nexport default class StringFilterModel extends BaseFilterModel {\n _isValid: boolean = true;\n _value: string | null;\n _inputvalue: string;\n\n /**\n */\n constructor(data: Object, contributions: Object) {\n super(data, contributions);\n\n this.update(this.attribute, data.value ?? \"\");\n\n // when formatted value set this to initial input value\n this._inputvalue = this._value ?? \"\";\n }\n\n /**\n * Retrieve the parameters with its value for this filter\n */\n get params(): Array<{ name: string, value: ?string }> {\n if (!this.param) {\n return [];\n }\n\n return [\n {\n name: this.param,\n value: this.value,\n },\n ];\n }\n\n /**\n * Getting the value of the filter\n */\n get value(): string | null {\n return this._value;\n }\n\n /**\n */\n get inputvalue(): string {\n return this._inputvalue;\n }\n\n /**\n * Reset the value of this filter to undefined\n */\n reset(): FilterType {\n this._inputvalue = \"\";\n this._value = null;\n\n return this;\n }\n\n /**\n */\n get isValid(): boolean {\n return this._isValid;\n }\n\n /**\n * Update this filter with input name and value\n */\n update(attribute: AttributeType, value: string) {\n this._inputvalue = typeof value !== \"string\" ? value.toString() : value;\n\n if (this.operator === \"exactly\" || this.operator === \"isNot\") {\n const values = this.isMultiple\n ? this._inputvalue.split(\",\").map((val) => val.trim())\n : [this._inputvalue.trim()];\n\n const outputValues = [];\n for (const val of values) {\n const formattedValue = this.formatValue(val);\n if (formattedValue !== \"\") {\n outputValues.push(formattedValue);\n\n if (!this.attribute.validate(formattedValue)) {\n this._isValid = false;\n }\n }\n }\n\n this._value = outputValues.join(\",\");\n } else {\n this._value = value;\n }\n }\n\n /**\n */\n get operator(): string {\n return this.getContribution(\"operator\", \"\");\n }\n\n /**\n */\n formatValue(value: string): string {\n if (this.operator === \"exactly\" || this.operator === \"isNot\") {\n return this.attribute.formatValue(value);\n }\n return value;\n }\n}\n"],"mappings":";;;;;;;;;;AACA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA;AACA;AACA;AACe,MAAMC,iBAAiB,SAASC,wBAAe,CAAC;EAK7D;AACF;EACEC,WAAWA,CAACC,IAAY,EAAEC,aAAqB,EAAE;IAC/C,KAAK,CAACD,IAAI,EAAEC,aAAa,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA,oBAPT,IAAI;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAStB,IAAI,CAACC,MAAM,CAAC,IAAI,CAACC,SAAS,EAAEL,IAAI,CAACM,KAAK,IAAI,EAAE,CAAC;;IAE7C;IACA,IAAI,CAACC,WAAW,GAAG,IAAI,CAACC,MAAM,IAAI,EAAE;EACtC;;EAEA;AACF;AACA;EACE,IAAIC,MAAMA,CAAA,EAA4C;IACpD,IAAI,CAAC,IAAI,CAACC,KAAK,EAAE;MACf,OAAO,EAAE;IACX;IAEA,OAAO,CACL;MACEC,IAAI,EAAE,IAAI,CAACD,KAAK;MAChBJ,KAAK,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"StringFilterModel.js","names":["_BaseFilterModel","_interopRequireDefault","require","StringFilterModel","BaseFilterModel","constructor","data","contributions","_defineProperty2","default","update","attribute","value","_inputvalue","_value","params","param","name","removeFormat","inputvalue","reset","isValid","_isValid","toString","operator","_context","_context2","values","isMultiple","_map","split","call","val","_trim","outputValues","formattedValue","formatValue","push","validate","join","getContribution","isBSN","layouthint","has","isIBAN","isZipcode","replace","exports"],"sources":["../../../src/models/filters/StringFilterModel.js"],"sourcesContent":["// @flow\nimport BaseFilterModel from \"./BaseFilterModel\";\n\nimport type { AttributeType, FilterType } from \"../types\";\n\n/**\n * StringFilterModel can handle string filters with multiple setting\n */\nexport default class StringFilterModel extends BaseFilterModel {\n _isValid: boolean = true;\n _value: string | null;\n _inputvalue: string;\n\n /**\n */\n constructor(data: Object, contributions: Object) {\n super(data, contributions);\n\n this.update(this.attribute, data.value ?? \"\");\n\n // when formatted value set this to initial input value\n this._inputvalue = this._value ?? \"\";\n }\n\n /**\n * Retrieve the parameters with its value for this filter\n */\n get params(): Array<{ name: string, value: ?string }> {\n if (!this.param) {\n return [];\n }\n\n return [\n {\n name: this.param,\n value: this.removeFormat(this.value),\n },\n ];\n }\n\n /**\n * Getting the value of the filter\n */\n get value(): string | null {\n return this._value;\n }\n\n /**\n */\n get inputvalue(): string {\n return this._inputvalue;\n }\n\n /**\n * Reset the value of this filter to undefined\n */\n reset(): FilterType {\n this._inputvalue = \"\";\n this._value = null;\n\n return this;\n }\n\n /**\n */\n get isValid(): boolean {\n return this._isValid;\n }\n\n /**\n * Update this filter with input name and value\n */\n update(attribute: AttributeType, value: string) {\n this._inputvalue = typeof value !== \"string\" ? value.toString() : value;\n\n if (this.operator === \"exactly\" || this.operator === \"isNot\") {\n const values = this.isMultiple\n ? this._inputvalue.split(\",\").map((val) => val.trim())\n : [this._inputvalue.trim()];\n\n const outputValues = [];\n for (const val of values) {\n const formattedValue = this.formatValue(val);\n if (formattedValue !== \"\") {\n outputValues.push(formattedValue);\n\n if (!this.attribute.validate(formattedValue)) {\n this._isValid = false;\n }\n }\n }\n\n this._value = outputValues.join(\",\");\n } else {\n this._value = value;\n }\n }\n\n /**\n */\n get operator(): string {\n return this.getContribution(\"operator\", \"\");\n }\n\n /**\n */\n formatValue(value: string): string {\n if (this.operator === \"exactly\" || this.operator === \"isNot\") {\n return this.attribute.formatValue(value);\n }\n return value;\n }\n\n /**\n */\n isBSN(): boolean {\n return this.layouthint.has(\"bsn\");\n }\n\n /**\n */\n isIBAN(): boolean {\n return this.layouthint.has(\"iban\");\n }\n\n /**\n */\n isZipcode(): boolean {\n return this.layouthint.has(\"zipcode\");\n }\n\n /**\n */\n removeFormat(value: ?string): string {\n if (value == null || value.toString() === \"\") {\n return \"\";\n }\n\n if (\n (this.operator === \"exactly\" || this.operator === \"isNot\") &&\n (this.isIBAN() || this.isZipcode() || this.isBSN())\n ) {\n return value.replace(/[^a-z0-9,]/gi, \"\");\n }\n\n return value;\n }\n}\n"],"mappings":";;;;;;;;;;AACA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA;AACA;AACA;AACe,MAAMC,iBAAiB,SAASC,wBAAe,CAAC;EAK7D;AACF;EACEC,WAAWA,CAACC,IAAY,EAAEC,aAAqB,EAAE;IAC/C,KAAK,CAACD,IAAI,EAAEC,aAAa,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA,oBAPT,IAAI;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAStB,IAAI,CAACC,MAAM,CAAC,IAAI,CAACC,SAAS,EAAEL,IAAI,CAACM,KAAK,IAAI,EAAE,CAAC;;IAE7C;IACA,IAAI,CAACC,WAAW,GAAG,IAAI,CAACC,MAAM,IAAI,EAAE;EACtC;;EAEA;AACF;AACA;EACE,IAAIC,MAAMA,CAAA,EAA4C;IACpD,IAAI,CAAC,IAAI,CAACC,KAAK,EAAE;MACf,OAAO,EAAE;IACX;IAEA,OAAO,CACL;MACEC,IAAI,EAAE,IAAI,CAACD,KAAK;MAChBJ,KAAK,EAAE,IAAI,CAACM,YAAY,CAAC,IA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AAK,OAAO,MACxD,IAAI,CAACoB,MAAM,CAAC,CAAC,IAAI,IAAI,CAACC,SAAS,CAAC,CAAC,IAAI,IAAI,CAACJ,KAAK,CAAC,CAAC,CAAC,EACnD;MACA,OAAO7B,KAAK,CAACkC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;IAC1C;IAEA,OAAOlC,KAAK;EACd;AACF;AAACmC,OAAA,CAAAtC,OAAA,GAAAN,iBAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import StringFilterModel from "../
|
|
1
|
+
import StringFilterModel from "../StringFilterModel";
|
|
2
2
|
|
|
3
3
|
describe("Zipcode Filter", () => {
|
|
4
4
|
let data;
|
|
@@ -25,7 +25,7 @@ describe("Zipcode Filter", () => {
|
|
|
25
25
|
expect(filter).toBeInstanceOf(StringFilterModel);
|
|
26
26
|
expect(filter.label).toBe("zipfilter");
|
|
27
27
|
expect(filter.name).toBe("zipfilter");
|
|
28
|
-
expect(filter.value).
|
|
28
|
+
expect(filter.value).toBe("");
|
|
29
29
|
expect(filter.inputvalue).toBe("");
|
|
30
30
|
expect(filter.type).toBe("string");
|
|
31
31
|
});
|
|
@@ -38,8 +38,8 @@ describe("Zipcode Filter", () => {
|
|
|
38
38
|
const filter = new StringFilterModel(stringFilterWithValue, contributions);
|
|
39
39
|
|
|
40
40
|
expect(filter).toBeInstanceOf(StringFilterModel);
|
|
41
|
-
expect(filter.
|
|
42
|
-
expect(filter.
|
|
41
|
+
expect(filter.value).toBe("1234 AB");
|
|
42
|
+
expect(filter.inputvalue).toBe("1234 AB");
|
|
43
43
|
expect(filter.params).toStrictEqual([
|
|
44
44
|
{
|
|
45
45
|
name: "zipfilter",
|
|
@@ -48,8 +48,8 @@ describe("Zipcode Filter", () => {
|
|
|
48
48
|
]);
|
|
49
49
|
|
|
50
50
|
filter.reset();
|
|
51
|
-
expect(filter.
|
|
52
|
-
expect(filter.
|
|
51
|
+
expect(filter.inputvalue).toBe("");
|
|
52
|
+
expect(filter.value).toBeNull();
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
it("modular ui input, zipcode space", () => {
|
|
@@ -58,8 +58,26 @@ describe("Zipcode Filter", () => {
|
|
|
58
58
|
filter.update(filter.attribute, "1234 AB");
|
|
59
59
|
|
|
60
60
|
expect(filter).toBeInstanceOf(StringFilterModel);
|
|
61
|
-
expect(filter.
|
|
62
|
-
expect(filter.
|
|
61
|
+
expect(filter.value).toBe("1234 AB");
|
|
62
|
+
expect(filter.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, exact", () => {
|
|
74
|
+
const filter = new StringFilterModel(data, contributions);
|
|
75
|
+
|
|
76
|
+
filter.update(filter.attribute, "1234 AB");
|
|
77
|
+
|
|
78
|
+
expect(filter).toBeInstanceOf(StringFilterModel);
|
|
79
|
+
expect(filter.value).toBe("1234 AB");
|
|
80
|
+
expect(filter.inputvalue).toBe("1234 AB");
|
|
63
81
|
expect(filter.params).toStrictEqual([
|
|
64
82
|
{
|
|
65
83
|
name: "zipfilter",
|
|
@@ -76,8 +94,8 @@ describe("Zipcode Filter", () => {
|
|
|
76
94
|
filter.update(filter.attribute, "123");
|
|
77
95
|
|
|
78
96
|
expect(filter).toBeInstanceOf(StringFilterModel);
|
|
79
|
-
expect(filter.
|
|
80
|
-
expect(filter.
|
|
97
|
+
expect(filter.value).toBe("123");
|
|
98
|
+
expect(filter.inputvalue).toBe("123");
|
|
81
99
|
expect(filter.params).toStrictEqual([
|
|
82
100
|
{
|
|
83
101
|
name: "zipfilter",
|
|
@@ -97,8 +115,8 @@ describe("Zipcode Filter", () => {
|
|
|
97
115
|
filter.update(filter.attribute, "123");
|
|
98
116
|
|
|
99
117
|
expect(filter).toBeInstanceOf(StringFilterModel);
|
|
100
|
-
expect(filter.
|
|
101
|
-
expect(filter.
|
|
118
|
+
expect(filter.value).toBe("123");
|
|
119
|
+
expect(filter.inputvalue).toBe("123");
|
|
102
120
|
expect(filter.params).toStrictEqual([
|
|
103
121
|
{
|
|
104
122
|
name: "zipfilter",
|
package/package.json
CHANGED
|
@@ -33,7 +33,7 @@ export default class StringFilterModel extends BaseFilterModel {
|
|
|
33
33
|
return [
|
|
34
34
|
{
|
|
35
35
|
name: this.param,
|
|
36
|
-
value: this.value,
|
|
36
|
+
value: this.removeFormat(this.value),
|
|
37
37
|
},
|
|
38
38
|
];
|
|
39
39
|
}
|
|
@@ -110,4 +110,39 @@ export default class StringFilterModel extends BaseFilterModel {
|
|
|
110
110
|
}
|
|
111
111
|
return value;
|
|
112
112
|
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
*/
|
|
116
|
+
isBSN(): boolean {
|
|
117
|
+
return this.layouthint.has("bsn");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
*/
|
|
122
|
+
isIBAN(): boolean {
|
|
123
|
+
return this.layouthint.has("iban");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
*/
|
|
128
|
+
isZipcode(): boolean {
|
|
129
|
+
return this.layouthint.has("zipcode");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
*/
|
|
134
|
+
removeFormat(value: ?string): string {
|
|
135
|
+
if (value == null || value.toString() === "") {
|
|
136
|
+
return "";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (
|
|
140
|
+
(this.operator === "exactly" || this.operator === "isNot") &&
|
|
141
|
+
(this.isIBAN() || this.isZipcode() || this.isBSN())
|
|
142
|
+
) {
|
|
143
|
+
return value.replace(/[^a-z0-9,]/gi, "");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
113
148
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import StringFilterModel from "../
|
|
1
|
+
import StringFilterModel from "../StringFilterModel";
|
|
2
2
|
|
|
3
3
|
describe("Zipcode Filter", () => {
|
|
4
4
|
let data;
|
|
@@ -25,7 +25,7 @@ describe("Zipcode Filter", () => {
|
|
|
25
25
|
expect(filter).toBeInstanceOf(StringFilterModel);
|
|
26
26
|
expect(filter.label).toBe("zipfilter");
|
|
27
27
|
expect(filter.name).toBe("zipfilter");
|
|
28
|
-
expect(filter.value).
|
|
28
|
+
expect(filter.value).toBe("");
|
|
29
29
|
expect(filter.inputvalue).toBe("");
|
|
30
30
|
expect(filter.type).toBe("string");
|
|
31
31
|
});
|
|
@@ -38,8 +38,8 @@ describe("Zipcode Filter", () => {
|
|
|
38
38
|
const filter = new StringFilterModel(stringFilterWithValue, contributions);
|
|
39
39
|
|
|
40
40
|
expect(filter).toBeInstanceOf(StringFilterModel);
|
|
41
|
-
expect(filter.
|
|
42
|
-
expect(filter.
|
|
41
|
+
expect(filter.value).toBe("1234 AB");
|
|
42
|
+
expect(filter.inputvalue).toBe("1234 AB");
|
|
43
43
|
expect(filter.params).toStrictEqual([
|
|
44
44
|
{
|
|
45
45
|
name: "zipfilter",
|
|
@@ -48,8 +48,8 @@ describe("Zipcode Filter", () => {
|
|
|
48
48
|
]);
|
|
49
49
|
|
|
50
50
|
filter.reset();
|
|
51
|
-
expect(filter.
|
|
52
|
-
expect(filter.
|
|
51
|
+
expect(filter.inputvalue).toBe("");
|
|
52
|
+
expect(filter.value).toBeNull();
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
it("modular ui input, zipcode space", () => {
|
|
@@ -58,8 +58,26 @@ describe("Zipcode Filter", () => {
|
|
|
58
58
|
filter.update(filter.attribute, "1234 AB");
|
|
59
59
|
|
|
60
60
|
expect(filter).toBeInstanceOf(StringFilterModel);
|
|
61
|
-
expect(filter.
|
|
62
|
-
expect(filter.
|
|
61
|
+
expect(filter.value).toBe("1234 AB");
|
|
62
|
+
expect(filter.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, exact", () => {
|
|
74
|
+
const filter = new StringFilterModel(data, contributions);
|
|
75
|
+
|
|
76
|
+
filter.update(filter.attribute, "1234 AB");
|
|
77
|
+
|
|
78
|
+
expect(filter).toBeInstanceOf(StringFilterModel);
|
|
79
|
+
expect(filter.value).toBe("1234 AB");
|
|
80
|
+
expect(filter.inputvalue).toBe("1234 AB");
|
|
63
81
|
expect(filter.params).toStrictEqual([
|
|
64
82
|
{
|
|
65
83
|
name: "zipfilter",
|
|
@@ -76,8 +94,8 @@ describe("Zipcode Filter", () => {
|
|
|
76
94
|
filter.update(filter.attribute, "123");
|
|
77
95
|
|
|
78
96
|
expect(filter).toBeInstanceOf(StringFilterModel);
|
|
79
|
-
expect(filter.
|
|
80
|
-
expect(filter.
|
|
97
|
+
expect(filter.value).toBe("123");
|
|
98
|
+
expect(filter.inputvalue).toBe("123");
|
|
81
99
|
expect(filter.params).toStrictEqual([
|
|
82
100
|
{
|
|
83
101
|
name: "zipfilter",
|
|
@@ -97,8 +115,8 @@ describe("Zipcode Filter", () => {
|
|
|
97
115
|
filter.update(filter.attribute, "123");
|
|
98
116
|
|
|
99
117
|
expect(filter).toBeInstanceOf(StringFilterModel);
|
|
100
|
-
expect(filter.
|
|
101
|
-
expect(filter.
|
|
118
|
+
expect(filter.value).toBe("123");
|
|
119
|
+
expect(filter.inputvalue).toBe("123");
|
|
102
120
|
expect(filter.params).toStrictEqual([
|
|
103
121
|
{
|
|
104
122
|
name: "zipfilter",
|