@beinformed/ui 1.50.2 → 1.50.4
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 +14 -0
- package/esm/models/attributes/BooleanAttributeModel.js +2 -2
- package/esm/models/attributes/BooleanAttributeModel.js.map +1 -1
- package/esm/redux/_modularui/ModularUIConnector.js +21 -2
- package/esm/redux/_modularui/ModularUIConnector.js.map +1 -1
- package/lib/models/attributes/BooleanAttributeModel.js +2 -2
- package/lib/models/attributes/BooleanAttributeModel.js.flow +2 -2
- package/lib/models/attributes/BooleanAttributeModel.js.map +1 -1
- package/lib/models/attributes/__tests__/BooleanAttributeModel.spec.js.flow +8 -0
- package/lib/redux/_modularui/ModularUIConnector.js +21 -2
- package/lib/redux/_modularui/ModularUIConnector.js.flow +30 -2
- package/lib/redux/_modularui/ModularUIConnector.js.map +1 -1
- package/package.json +1 -1
- package/src/models/attributes/BooleanAttributeModel.js +2 -2
- package/src/models/attributes/__tests__/BooleanAttributeModel.spec.js +8 -0
- package/src/redux/_modularui/ModularUIConnector.js +30 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
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.50.4](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.50.3...v1.50.4) (2024-07-23)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **boolean-attribute:** handle null value on update method ([3631691](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/36316917499988f2bc52ed810adf4dbe2a305afa))
|
|
11
|
+
|
|
12
|
+
## [1.50.3](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.50.2...v1.50.3) (2024-07-22)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* **connector:** patch updateModel fetch property to updateHandler for modularui connector ([f4cb62d](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/f4cb62dc77d1504ae0e7bfc454146768c5100091))
|
|
18
|
+
|
|
5
19
|
## [1.50.2](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.50.1...v1.50.2) (2024-07-17)
|
|
6
20
|
|
|
7
21
|
|
|
@@ -222,12 +222,12 @@ export default class BooleanAttributeModel extends AttributeModel {
|
|
|
222
222
|
return this;
|
|
223
223
|
}
|
|
224
224
|
this.updateLastModification();
|
|
225
|
-
let values;
|
|
225
|
+
let values = [];
|
|
226
226
|
if (Array.isArray(value)) {
|
|
227
227
|
values = value;
|
|
228
228
|
} else if (typeof value === "string" && this.isMultiple) {
|
|
229
229
|
values = value.split(",");
|
|
230
|
-
} else {
|
|
230
|
+
} else if (value != null) {
|
|
231
231
|
values = [value.toString()];
|
|
232
232
|
}
|
|
233
233
|
values.forEach(val => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BooleanAttributeModel.js","names":["AttributeModel","DateUtil","ChoiceAttributeOptionCollection","ContentConfigurationElements","ChoiceAttributeOptionModel","RENDER_SECTION_LABEL","ATTRIBUTE_WIDTH","BooleanAttributeModel","constructor","attribute","attributeContributions","_defineProperty","_referenceDate","getData","now","_options","create","referenceDate","isApplicableModel","contributions","type","date","options","choicetype","_context","_findInstanceProperty","call","hint","layouthint","has","isMultiple","isTree","hasContentConfiguration","_hasContentConfiguration","contentConfiguration","_context2","content","optionElements","optionElementConfig","_mapInstanceProperty","optionElement","contentElement","selected","_context3","option","code","readonlyvalue","_context4","label","join","initvalue","Array","isArray","_initvalue","length","getValue","_context5","hasValue","getInputValue","toggleOption","_context6","_includesInstanceProperty","disableOption","enableOption","deselectAll","select","inputvalue","deselect","reset","mergeAttribute","oldAttribute","readonly","concept","isValid","update","value","updateLastModification","values","split","toString","forEach","val","some","updateByAttribute","otherAttribute","console","error","getFormData","inError","name","readonlyWidth","hasAlternativeLabel","SMALL","EXTRA_SMALL"],"sources":["../../../src/models/attributes/BooleanAttributeModel.js"],"sourcesContent":["// @flow\nimport AttributeModel from \"./AttributeModel\";\n\nimport { DateUtil } from \"../../utils/datetime/DateTimeUtil\";\n\nimport ChoiceAttributeOptionCollection from \"./ChoiceAttributeOptionCollection\";\nimport ContentConfigurationElements from \"../contentconfiguration/ContentConfigurationElements\";\nimport ChoiceAttributeOptionModel from \"./ChoiceAttributeOptionModel\";\n\nimport { RENDER_SECTION_LABEL } from \"../../constants/LayoutHints\";\nimport { ATTRIBUTE_WIDTH } from \"../../constants\";\n\nimport type { AttributeType } from \"../types\";\n\n/**\n * Model for a boolean attribute\n */\nexport default class BooleanAttributeModel extends AttributeModel {\n _referenceDate: string;\n _options: ChoiceAttributeOptionCollection;\n _hasContentConfiguration: boolean = false;\n\n /**\n */\n constructor(attribute: Object, attributeContributions: Object) {\n super(attribute, attributeContributions);\n\n this._referenceDate = this.getData(\"referenceDate\", DateUtil.now());\n this._options = ChoiceAttributeOptionCollection.create(\n attribute,\n attributeContributions,\n this.referenceDate,\n );\n }\n\n /**\n */\n static isApplicableModel(contributions: Object): boolean {\n return contributions.type === \"boolean\";\n }\n\n /**\n */\n get type(): string {\n return \"boolean\";\n }\n\n /**\n * Retrieve reference date of attribute which can be used as entryDate for content\n */\n get referenceDate(): string {\n return this._referenceDate;\n }\n\n /**\n * Set reference date for concepts and content\n */\n set referenceDate(date: string) {\n this._referenceDate = date;\n\n this.options.referenceDate = date;\n }\n\n /**\n * Getting the type of choice filter. For instance checkbox, radiobutton, combobox.\n */\n get choicetype(): \"checkbox\" | \"radiobutton\" | \"combobox\" | \"toggle\" {\n return (\n [\"checkbox\", \"radiobutton\", \"combobox\", \"toggle\"].find((hint) =>\n this.layouthint.has(hint),\n ) || \"radiobutton\"\n );\n }\n\n /**\n * Can multiple options be selected\n */\n get isMultiple(): boolean {\n return false;\n }\n\n /**\n * Check if options need to be rendered as tree\n */\n get isTree(): boolean {\n return false;\n }\n\n /**\n */\n set hasContentConfiguration(hasContentConfiguration: boolean) {\n this._hasContentConfiguration =\n this.contentConfiguration !== null || hasContentConfiguration;\n }\n\n /**\n */\n get hasContentConfiguration(): boolean {\n return this._hasContentConfiguration;\n }\n\n /**\n * Get content configuration configured on the attribute.\n * Only applicable for taxonomy element and knowledge codemaps,\n * content configuration for instrument questions is available on the form object\n */\n get contentConfiguration(): ContentConfigurationElements | null {\n if (\n !this.contributions.content ||\n !this.contributions.content.optionElements\n ) {\n return null;\n }\n\n // Add RENDER_SECTION_LABEL to all content configuration to make sure the label of a section is always rendered on taxonomy and knowlege codemaps\n const optionElementConfig = this.contributions.content.optionElements.map(\n (optionElement) => {\n if (\"contentElement\" in optionElement) {\n return {\n contentElement: {\n ...optionElement.contentElement,\n layouthint: [RENDER_SECTION_LABEL],\n },\n };\n }\n\n return optionElement;\n },\n );\n\n return new ContentConfigurationElements(optionElementConfig);\n }\n\n /**\n * Retrieve available choice options\n */\n get options(): ChoiceAttributeOptionCollection {\n return this._options;\n }\n\n /**\n * Getting all enabled options\n */\n get selected(): Array<string> {\n // $FlowFixMe[incompatible-call]\n return this.options.selected.map<string, ChoiceAttributeOptionModel>(\n (option: ChoiceAttributeOptionModel) => option.code,\n );\n }\n\n /**\n * Flatten options and filter out the options that are not selected\n */\n get readonlyvalue(): string {\n return this.options.selected.map((option) => option.label).join(\", \");\n }\n\n /**\n */\n get initvalue(): any {\n if (Array.isArray(this._initvalue) && this._initvalue.length === 0) {\n return null;\n }\n\n return this._initvalue;\n }\n\n /**\n * Retrieve list of selected options, joined with comma\n */\n getValue(): string | null {\n return this.options.selected.length > 0\n ? this.options.selected.map((option) => option.code).join(\",\")\n : null;\n }\n\n /**\n */\n hasValue(): boolean {\n return this.options.selected.length > 0;\n }\n\n /**\n * Get input value of attribute\n */\n getInputValue(): string {\n return this.selected.join(\",\");\n }\n\n /**\n * Setting an option selected or unselected based on the current state\n */\n toggleOption(code: string) {\n if (this.selected.includes(code)) {\n this.disableOption(code);\n } else {\n this.enableOption(code);\n }\n }\n\n /**\n * Enable a option\n */\n enableOption(code: string) {\n this.options.deselectAll();\n this.options.select(code);\n this.inputvalue = this.getInputValue();\n }\n\n /**\n * Disable a option\n */\n disableOption(code: string) {\n this.options.deselect(code);\n this.inputvalue = this.getInputValue();\n }\n\n /**\n * Reset boolean attribute to unselected list\n */\n reset() {\n this.options.deselectAll();\n }\n\n /**\n */\n mergeAttribute(oldAttribute: AttributeType) {\n // when attribute is readonly, don't merge the options no modifications necessary\n if (!this.readonly && oldAttribute instanceof BooleanAttributeModel) {\n this.concept = oldAttribute.concept;\n this.options.deselectAll();\n\n if (oldAttribute.isValid && oldAttribute.inputvalue !== null) {\n this.update(oldAttribute.inputvalue);\n }\n }\n }\n\n /**\n * Update attribute by name and value\n */\n update(value: any): BooleanAttributeModel {\n if (this.readonly) {\n return this;\n }\n\n this.updateLastModification();\n\n let values;\n\n if (Array.isArray(value)) {\n values = value;\n } else if (typeof value === \"string\" && this.isMultiple) {\n values = value.split(\",\");\n } else {\n values = [value.toString()];\n }\n\n values.forEach((val) => {\n if (val instanceof ChoiceAttributeOptionModel) {\n this.toggleOption(val.code);\n } else if (\n typeof val === \"string\" &&\n this.options.some((option) => option.code.toString() === val)\n ) {\n this.toggleOption(val);\n }\n });\n\n return this;\n }\n\n /**\n */\n updateByAttribute(otherAttribute: AttributeType): void {\n this.reset();\n if (otherAttribute instanceof BooleanAttributeModel) {\n this.update(otherAttribute.value);\n } else {\n console.error(\n `update of boolean attribute with ${otherAttribute.type} not supported`,\n );\n }\n }\n\n /**\n */\n getFormData(): { [string]: boolean | null } | null {\n if (this.inError()) {\n return null;\n }\n\n if (!this.hasValue()) {\n // no value for checkbox and toggle is same as a false value\n if (this.choicetype === \"checkbox\" || this.choicetype === \"toggle\") {\n return { [this.name]: false };\n }\n\n return { [this.name]: null };\n }\n\n return { [this.name]: this.value === \"true\" };\n }\n\n /**\n */\n get readonlyWidth(): $Keys<typeof ATTRIBUTE_WIDTH> {\n if (this.options.some((option) => option.hasAlternativeLabel)) {\n return ATTRIBUTE_WIDTH.SMALL;\n }\n\n return ATTRIBUTE_WIDTH.EXTRA_SMALL;\n }\n}\n"],"mappings":";;;;AACA,OAAOA,cAAc,MAAM,kBAAkB;AAE7C,SAASC,QAAQ,QAAQ,mCAAmC;AAE5D,OAAOC,+BAA+B,MAAM,mCAAmC;AAC/E,OAAOC,4BAA4B,MAAM,sDAAsD;AAC/F,OAAOC,0BAA0B,MAAM,8BAA8B;AAErE,SAASC,oBAAoB,QAAQ,6BAA6B;AAClE,SAASC,eAAe,QAAQ,iBAAiB;AAIjD;AACA;AACA;AACA,eAAe,MAAMC,qBAAqB,SAASP,cAAc,CAAC;EAKhE;AACF;EACEQ,WAAWA,CAACC,SAAiB,EAAEC,sBAA8B,EAAE;IAC7D,KAAK,CAACD,SAAS,EAAEC,sBAAsB,CAAC;IAACC,eAAA;IAAAA,eAAA;IAAAA,eAAA,mCALP,KAAK;IAOvC,IAAI,CAACC,cAAc,GAAG,IAAI,CAACC,OAAO,CAAC,eAAe,EAAEZ,QAAQ,CAACa,GAAG,CAAC,CAAC,CAAC;IACnE,IAAI,CAACC,QAAQ,GAAGb,+BAA+B,CAACc,MAAM,CACpDP,SAAS,EACTC,sBAAsB,EACtB,IAAI,CAACO,aACP,CAAC;EACH;;EAEA;AACF;EACE,OAAOC,iBAAiBA,CAACC,aAAqB,EAAW;IACvD,OAAOA,aAAa,CAACC,IAAI,KAAK,SAAS;EACzC;;EAEA;AACF;EACE,IAAIA,IAAIA,CAAA,EAAW;IACjB,OAAO,SAAS;EAClB;;EAEA;AACF;AACA;EACE,IAAIH,aAAaA,CAAA,EAAW;IAC1B,OAAO,IAAI,CAACL,cAAc;EAC5B;;EAEA;AACF;AACA;EACE,IAAIK,aAAaA,CAACI,IAAY,EAAE;IAC9B,IAAI,CAACT,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;IACnC,CAAC,MAAM;MACLU,OAAO,CAACC,KAAK,CACX,oCAAoCF,cAAc,CAAChE,IAAI,gBACzD,CAAC;IACH;EACF;;EAEA;AACF;EACEmE,WAAWA,CAAA,EAAwC;IACjD,IAAI,IAAI,CAACC,OAAO,CAAC,CAAC,EAAE;MAClB,OAAO,IAAI;IACb;IAEA,IAAI,CAAC,IAAI,CAAC/B,QAAQ,CAAC,CAAC,EAAE;MACpB;MACA,IAAI,IAAI,CAAClC,UAAU,KAAK,UAAU,IAAI,IAAI,CAACA,UAAU,KAAK,QAAQ,EAAE;QAClE,OAAO;UAAE,CAAC,IAAI,CAACkE,IAAI,GAAG;QAAM,CAAC;MAC/B;MAEA,OAAO;QAAE,CAAC,IAAI,CAACA,IAAI,GAAG;MAAK,CAAC;IAC9B;IAEA,OAAO;MAAE,CAAC,IAAI,CAACA,IAAI,GAAG,IAAI,CAACd,KAAK,KAAK;IAAO,CAAC;EAC/C;;EAEA;AACF;EACE,IAAIe,aAAaA,CAAA,EAAkC;IACjD,IAAI,IAAI,CAACpE,OAAO,CAAC4D,IAAI,CAAEtC,MAAM,IAAKA,MAAM,CAAC+C,mBAAmB,CAAC,EAAE;MAC7D,OAAOrF,eAAe,CAACsF,KAAK;IAC9B;IAEA,OAAOtF,eAAe,CAACuF,WAAW;EACpC;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"BooleanAttributeModel.js","names":["AttributeModel","DateUtil","ChoiceAttributeOptionCollection","ContentConfigurationElements","ChoiceAttributeOptionModel","RENDER_SECTION_LABEL","ATTRIBUTE_WIDTH","BooleanAttributeModel","constructor","attribute","attributeContributions","_defineProperty","_referenceDate","getData","now","_options","create","referenceDate","isApplicableModel","contributions","type","date","options","choicetype","_context","_findInstanceProperty","call","hint","layouthint","has","isMultiple","isTree","hasContentConfiguration","_hasContentConfiguration","contentConfiguration","_context2","content","optionElements","optionElementConfig","_mapInstanceProperty","optionElement","contentElement","selected","_context3","option","code","readonlyvalue","_context4","label","join","initvalue","Array","isArray","_initvalue","length","getValue","_context5","hasValue","getInputValue","toggleOption","_context6","_includesInstanceProperty","disableOption","enableOption","deselectAll","select","inputvalue","deselect","reset","mergeAttribute","oldAttribute","readonly","concept","isValid","update","value","updateLastModification","values","split","toString","forEach","val","some","updateByAttribute","otherAttribute","console","error","getFormData","inError","name","readonlyWidth","hasAlternativeLabel","SMALL","EXTRA_SMALL"],"sources":["../../../src/models/attributes/BooleanAttributeModel.js"],"sourcesContent":["// @flow\nimport AttributeModel from \"./AttributeModel\";\n\nimport { DateUtil } from \"../../utils/datetime/DateTimeUtil\";\n\nimport ChoiceAttributeOptionCollection from \"./ChoiceAttributeOptionCollection\";\nimport ContentConfigurationElements from \"../contentconfiguration/ContentConfigurationElements\";\nimport ChoiceAttributeOptionModel from \"./ChoiceAttributeOptionModel\";\n\nimport { RENDER_SECTION_LABEL } from \"../../constants/LayoutHints\";\nimport { ATTRIBUTE_WIDTH } from \"../../constants\";\n\nimport type { AttributeType } from \"../types\";\n\n/**\n * Model for a boolean attribute\n */\nexport default class BooleanAttributeModel extends AttributeModel {\n _referenceDate: string;\n _options: ChoiceAttributeOptionCollection;\n _hasContentConfiguration: boolean = false;\n\n /**\n */\n constructor(attribute: Object, attributeContributions: Object) {\n super(attribute, attributeContributions);\n\n this._referenceDate = this.getData(\"referenceDate\", DateUtil.now());\n this._options = ChoiceAttributeOptionCollection.create(\n attribute,\n attributeContributions,\n this.referenceDate,\n );\n }\n\n /**\n */\n static isApplicableModel(contributions: Object): boolean {\n return contributions.type === \"boolean\";\n }\n\n /**\n */\n get type(): string {\n return \"boolean\";\n }\n\n /**\n * Retrieve reference date of attribute which can be used as entryDate for content\n */\n get referenceDate(): string {\n return this._referenceDate;\n }\n\n /**\n * Set reference date for concepts and content\n */\n set referenceDate(date: string) {\n this._referenceDate = date;\n\n this.options.referenceDate = date;\n }\n\n /**\n * Getting the type of choice filter. For instance checkbox, radiobutton, combobox.\n */\n get choicetype(): \"checkbox\" | \"radiobutton\" | \"combobox\" | \"toggle\" {\n return (\n [\"checkbox\", \"radiobutton\", \"combobox\", \"toggle\"].find((hint) =>\n this.layouthint.has(hint),\n ) || \"radiobutton\"\n );\n }\n\n /**\n * Can multiple options be selected\n */\n get isMultiple(): boolean {\n return false;\n }\n\n /**\n * Check if options need to be rendered as tree\n */\n get isTree(): boolean {\n return false;\n }\n\n /**\n */\n set hasContentConfiguration(hasContentConfiguration: boolean) {\n this._hasContentConfiguration =\n this.contentConfiguration !== null || hasContentConfiguration;\n }\n\n /**\n */\n get hasContentConfiguration(): boolean {\n return this._hasContentConfiguration;\n }\n\n /**\n * Get content configuration configured on the attribute.\n * Only applicable for taxonomy element and knowledge codemaps,\n * content configuration for instrument questions is available on the form object\n */\n get contentConfiguration(): ContentConfigurationElements | null {\n if (\n !this.contributions.content ||\n !this.contributions.content.optionElements\n ) {\n return null;\n }\n\n // Add RENDER_SECTION_LABEL to all content configuration to make sure the label of a section is always rendered on taxonomy and knowlege codemaps\n const optionElementConfig = this.contributions.content.optionElements.map(\n (optionElement) => {\n if (\"contentElement\" in optionElement) {\n return {\n contentElement: {\n ...optionElement.contentElement,\n layouthint: [RENDER_SECTION_LABEL],\n },\n };\n }\n\n return optionElement;\n },\n );\n\n return new ContentConfigurationElements(optionElementConfig);\n }\n\n /**\n * Retrieve available choice options\n */\n get options(): ChoiceAttributeOptionCollection {\n return this._options;\n }\n\n /**\n * Getting all enabled options\n */\n get selected(): Array<string> {\n // $FlowFixMe[incompatible-call]\n return this.options.selected.map<string, ChoiceAttributeOptionModel>(\n (option: ChoiceAttributeOptionModel) => option.code,\n );\n }\n\n /**\n * Flatten options and filter out the options that are not selected\n */\n get readonlyvalue(): string {\n return this.options.selected.map((option) => option.label).join(\", \");\n }\n\n /**\n */\n get initvalue(): any {\n if (Array.isArray(this._initvalue) && this._initvalue.length === 0) {\n return null;\n }\n\n return this._initvalue;\n }\n\n /**\n * Retrieve list of selected options, joined with comma\n */\n getValue(): string | null {\n return this.options.selected.length > 0\n ? this.options.selected.map((option) => option.code).join(\",\")\n : null;\n }\n\n /**\n */\n hasValue(): boolean {\n return this.options.selected.length > 0;\n }\n\n /**\n * Get input value of attribute\n */\n getInputValue(): string {\n return this.selected.join(\",\");\n }\n\n /**\n * Setting an option selected or unselected based on the current state\n */\n toggleOption(code: string) {\n if (this.selected.includes(code)) {\n this.disableOption(code);\n } else {\n this.enableOption(code);\n }\n }\n\n /**\n * Enable a option\n */\n enableOption(code: string) {\n this.options.deselectAll();\n this.options.select(code);\n this.inputvalue = this.getInputValue();\n }\n\n /**\n * Disable a option\n */\n disableOption(code: string) {\n this.options.deselect(code);\n this.inputvalue = this.getInputValue();\n }\n\n /**\n * Reset boolean attribute to unselected list\n */\n reset() {\n this.options.deselectAll();\n }\n\n /**\n */\n mergeAttribute(oldAttribute: AttributeType) {\n // when attribute is readonly, don't merge the options no modifications necessary\n if (!this.readonly && oldAttribute instanceof BooleanAttributeModel) {\n this.concept = oldAttribute.concept;\n this.options.deselectAll();\n\n if (oldAttribute.isValid && oldAttribute.inputvalue !== null) {\n this.update(oldAttribute.inputvalue);\n }\n }\n }\n\n /**\n * Update attribute by name and value\n */\n update(value: any): BooleanAttributeModel {\n if (this.readonly) {\n return this;\n }\n\n this.updateLastModification();\n\n let values = [];\n\n if (Array.isArray(value)) {\n values = value;\n } else if (typeof value === \"string\" && this.isMultiple) {\n values = value.split(\",\");\n } else if (value != null) {\n values = [value.toString()];\n }\n\n values.forEach((val) => {\n if (val instanceof ChoiceAttributeOptionModel) {\n this.toggleOption(val.code);\n } else if (\n typeof val === \"string\" &&\n this.options.some((option) => option.code.toString() === val)\n ) {\n this.toggleOption(val);\n }\n });\n\n return this;\n }\n\n /**\n */\n updateByAttribute(otherAttribute: AttributeType): void {\n this.reset();\n if (otherAttribute instanceof BooleanAttributeModel) {\n this.update(otherAttribute.value);\n } else {\n console.error(\n `update of boolean attribute with ${otherAttribute.type} not supported`,\n );\n }\n }\n\n /**\n */\n getFormData(): { [string]: boolean | null } | null {\n if (this.inError()) {\n return null;\n }\n\n if (!this.hasValue()) {\n // no value for checkbox and toggle is same as a false value\n if (this.choicetype === \"checkbox\" || this.choicetype === \"toggle\") {\n return { [this.name]: false };\n }\n\n return { [this.name]: null };\n }\n\n return { [this.name]: this.value === \"true\" };\n }\n\n /**\n */\n get readonlyWidth(): $Keys<typeof ATTRIBUTE_WIDTH> {\n if (this.options.some((option) => option.hasAlternativeLabel)) {\n return ATTRIBUTE_WIDTH.SMALL;\n }\n\n return ATTRIBUTE_WIDTH.EXTRA_SMALL;\n }\n}\n"],"mappings":";;;;AACA,OAAOA,cAAc,MAAM,kBAAkB;AAE7C,SAASC,QAAQ,QAAQ,mCAAmC;AAE5D,OAAOC,+BAA+B,MAAM,mCAAmC;AAC/E,OAAOC,4BAA4B,MAAM,sDAAsD;AAC/F,OAAOC,0BAA0B,MAAM,8BAA8B;AAErE,SAASC,oBAAoB,QAAQ,6BAA6B;AAClE,SAASC,eAAe,QAAQ,iBAAiB;AAIjD;AACA;AACA;AACA,eAAe,MAAMC,qBAAqB,SAASP,cAAc,CAAC;EAKhE;AACF;EACEQ,WAAWA,CAACC,SAAiB,EAAEC,sBAA8B,EAAE;IAC7D,KAAK,CAACD,SAAS,EAAEC,sBAAsB,CAAC;IAACC,eAAA;IAAAA,eAAA;IAAAA,eAAA,mCALP,KAAK;IAOvC,IAAI,CAACC,cAAc,GAAG,IAAI,CAACC,OAAO,CAAC,eAAe,EAAEZ,QAAQ,CAACa,GAAG,CAAC,CAAC,CAAC;IACnE,IAAI,CAACC,QAAQ,GAAGb,+BAA+B,CAACc,MAAM,CACpDP,SAAS,EACTC,sBAAsB,EACtB,IAAI,CAACO,aACP,CAAC;EACH;;EAEA;AACF;EACE,OAAOC,iBAAiBA,CAACC,aAAqB,EAAW;IACvD,OAAOA,aAAa,CAACC,IAAI,KAAK,SAAS;EACzC;;EAEA;AACF;EACE,IAAIA,IAAIA,CAAA,EAAW;IACjB,OAAO,SAAS;EAClB;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AEF,OAAO,IAAI;EACb;;EAEA;AACF;EACEE,iBAAiBA,CAACC,cAA6B,EAAQ;IACrD,IAAI,CAAChB,KAAK,CAAC,CAAC;IACZ,IAAIgB,cAAc,YAAY7E,qBAAqB,EAAE;MACnD,IAAI,CAACmE,MAAM,CAACU,cAAc,CAACT,KAAK,CAAC;IACnC,CAAC,MAAM;MACLU,OAAO,CAACC,KAAK,CACX,oCAAoCF,cAAc,CAAChE,IAAI,gBACzD,CAAC;IACH;EACF;;EAEA;AACF;EACEmE,WAAWA,CAAA,EAAwC;IACjD,IAAI,IAAI,CAACC,OAAO,CAAC,CAAC,EAAE;MAClB,OAAO,IAAI;IACb;IAEA,IAAI,CAAC,IAAI,CAAC/B,QAAQ,CAAC,CAAC,EAAE;MACpB;MACA,IAAI,IAAI,CAAClC,UAAU,KAAK,UAAU,IAAI,IAAI,CAACA,UAAU,KAAK,QAAQ,EAAE;QAClE,OAAO;UAAE,CAAC,IAAI,CAACkE,IAAI,GAAG;QAAM,CAAC;MAC/B;MAEA,OAAO;QAAE,CAAC,IAAI,CAACA,IAAI,GAAG;MAAK,CAAC;IAC9B;IAEA,OAAO;MAAE,CAAC,IAAI,CAACA,IAAI,GAAG,IAAI,CAACd,KAAK,KAAK;IAAO,CAAC;EAC/C;;EAEA;AACF;EACE,IAAIe,aAAaA,CAAA,EAAkC;IACjD,IAAI,IAAI,CAACpE,OAAO,CAAC4D,IAAI,CAAEtC,MAAM,IAAKA,MAAM,CAAC+C,mBAAmB,CAAC,EAAE;MAC7D,OAAOrF,eAAe,CAACsF,KAAK;IAC9B;IAEA,OAAOtF,eAAe,CAACuF,WAAW;EACpC;AACF","ignoreList":[]}
|
|
@@ -7,7 +7,26 @@ import { getDisplayName } from "../../react/utils";
|
|
|
7
7
|
import { useUrl, useReload } from "./ModularUIUtils";
|
|
8
8
|
import { useModularUI } from "../../hooks/useModularUI";
|
|
9
9
|
import { useLocale } from "../../hooks/useI18n";
|
|
10
|
+
import FormModel from "../../models/form/FormModel";
|
|
10
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
const patchUpdateModelOption = oldOptions => {
|
|
13
|
+
if ("updateModel" in oldOptions && oldOptions.updateModel instanceof FormModel) {
|
|
14
|
+
return {
|
|
15
|
+
...oldOptions,
|
|
16
|
+
updateHandler: newModel => {
|
|
17
|
+
if (newModel instanceof FormModel) {
|
|
18
|
+
// $FLowFixMe
|
|
19
|
+
const clonedModel = oldOptions.updateModel.clone();
|
|
20
|
+
clonedModel.update(newModel);
|
|
21
|
+
return clonedModel;
|
|
22
|
+
}
|
|
23
|
+
return newModel;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return oldOptions;
|
|
28
|
+
};
|
|
29
|
+
|
|
11
30
|
/**
|
|
12
31
|
*/
|
|
13
32
|
const modularUIConnector = function (name, resource) {
|
|
@@ -42,7 +61,7 @@ const modularUIConnector = function (name, resource) {
|
|
|
42
61
|
// Provide connected models with a fetchModularUI method to be able
|
|
43
62
|
// to run the loadModularUI action from a handler / callback in the component
|
|
44
63
|
const handleFetch = (href, fetchOptions) => {
|
|
45
|
-
dispatch(loadModularUI(modelKey, href, fetchOptions));
|
|
64
|
+
dispatch(loadModularUI(modelKey, href, patchUpdateModelOption(fetchOptions)));
|
|
46
65
|
};
|
|
47
66
|
|
|
48
67
|
// Check if current model needs a reload
|
|
@@ -51,7 +70,7 @@ const modularUIConnector = function (name, resource) {
|
|
|
51
70
|
useEffect(() => {
|
|
52
71
|
if (doReload) {
|
|
53
72
|
dispatch(loadModularUI(modelKey, url, {
|
|
54
|
-
...otherOptions,
|
|
73
|
+
...patchUpdateModelOption(otherOptions),
|
|
55
74
|
isReload: true
|
|
56
75
|
}));
|
|
57
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModularUIConnector.js","names":["useEffect","useDispatch","useLocation","loadModularUI","reloadModel","removeModelByKey","Href","getDisplayName","useUrl","useReload","useModularUI","useLocale","jsx","_jsx","modularUIConnector","name","resource","options","arguments","length","undefined","propName","removeOnUnmount","otherOptions","Component","WrappedComponent","props","dispatch","location","url","displayName","contextId","modelEntry","modelKey","model","connectKey","handleManualReload","reloadOptions","handleFetch","href","fetchOptions","reload","state","doReload","isReload","locale","newProps","status","lastModification","hasModel","Boolean","fetchModularUI"],"sources":["../../../src/redux/_modularui/ModularUIConnector.js"],"sourcesContent":["// @flow\nimport { useEffect } from \"react\";\nimport { useDispatch } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport {\n loadModularUI,\n reloadModel,\n removeModelByKey,\n} from \"./ModularUIActions\";\n\nimport Href from \"../../models/href/Href\";\nimport { getDisplayName } from \"../../react/utils\";\n\nimport { useUrl, useReload } from \"./ModularUIUtils\";\nimport { useModularUI } from \"../../hooks/useModularUI\";\nimport { useLocale } from \"../../hooks/useI18n\";\n\nimport type { ComponentType, Node } from \"react\";\nimport type { Location } from \"react-router\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { ModularUIOptions } from \"./types\";\n\nexport type InjectedProps = {\n +modelKey: string,\n +location: Location,\n +status: string | null,\n +lastModification: number | null,\n +hasModel: boolean,\n +locale: string,\n +fetchModularUI: (href: string | Href, fetchOptions: Object) => void,\n +reloadModel: (model: ModularUIModel, options: Object) => void,\n +data?: ?ModularUIModel,\n};\n\n/**\n */\nconst modularUIConnector = (\n name: string,\n resource: string | Function,\n options: ModularUIOptions = { propName: \"data\", removeOnUnmount: false },\n): ((Component: ComponentType<any>) => (props: any) => Node) => {\n const {\n propName = \"data\",\n removeOnUnmount = false,\n ...otherOptions\n } = options;\n\n return (Component: ComponentType<any>) => {\n const WrappedComponent = (props: any) => {\n const dispatch = useDispatch();\n const location = useLocation();\n\n const url = useUrl(resource, { location, ...props });\n const displayName = getDisplayName(Component, name, props.contextId);\n\n // Load the model through the useModUI hook\n const modelEntry = useModularUI(displayName, url, otherOptions);\n const modelKey = modelEntry?.model?.connectKey;\n\n // handle manual reload of model\n const handleManualReload = (\n model: ModularUIModel,\n reloadOptions?: Object,\n ) => {\n dispatch(reloadModel(model, reloadOptions));\n };\n\n // Provide connected models with a fetchModularUI method to be able\n // to run the loadModularUI action from a handler / callback in the component\n const handleFetch = (href: string | Href, fetchOptions: Object) => {\n dispatch(loadModularUI(modelKey, href, fetchOptions));\n };\n\n // Check if current model needs a reload\n const reload = location?.state?.reload ?? 0;\n const doReload = useReload(modelEntry, reload);\n useEffect(() => {\n if (doReload) {\n dispatch(\n loadModularUI(modelKey, url, {
|
|
1
|
+
{"version":3,"file":"ModularUIConnector.js","names":["useEffect","useDispatch","useLocation","loadModularUI","reloadModel","removeModelByKey","Href","getDisplayName","useUrl","useReload","useModularUI","useLocale","FormModel","jsx","_jsx","patchUpdateModelOption","oldOptions","updateModel","updateHandler","newModel","clonedModel","clone","update","modularUIConnector","name","resource","options","arguments","length","undefined","propName","removeOnUnmount","otherOptions","Component","WrappedComponent","props","dispatch","location","url","displayName","contextId","modelEntry","modelKey","model","connectKey","handleManualReload","reloadOptions","handleFetch","href","fetchOptions","reload","state","doReload","isReload","locale","newProps","status","lastModification","hasModel","Boolean","fetchModularUI"],"sources":["../../../src/redux/_modularui/ModularUIConnector.js"],"sourcesContent":["// @flow\nimport { useEffect } from \"react\";\nimport { useDispatch } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport {\n loadModularUI,\n reloadModel,\n removeModelByKey,\n} from \"./ModularUIActions\";\n\nimport Href from \"../../models/href/Href\";\nimport { getDisplayName } from \"../../react/utils\";\n\nimport { useUrl, useReload } from \"./ModularUIUtils\";\nimport { useModularUI } from \"../../hooks/useModularUI\";\nimport { useLocale } from \"../../hooks/useI18n\";\n\nimport type { ComponentType, Node } from \"react\";\nimport type { Location } from \"react-router\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { ModularUIOptions } from \"./types\";\nimport FormModel from \"../../models/form/FormModel\";\n\nexport type InjectedProps = {\n +modelKey: string,\n +location: Location,\n +status: string | null,\n +lastModification: number | null,\n +hasModel: boolean,\n +locale: string,\n +fetchModularUI: (href: string | Href, fetchOptions: Object) => void,\n +reloadModel: (model: ModularUIModel, options: Object) => void,\n +data?: ?ModularUIModel,\n};\n\nconst patchUpdateModelOption = (oldOptions: Object) => {\n if (\n \"updateModel\" in oldOptions &&\n oldOptions.updateModel instanceof FormModel\n ) {\n return {\n ...oldOptions,\n updateHandler: (newModel: ModularUIModel): ModularUIModel => {\n if (newModel instanceof FormModel) {\n // $FLowFixMe\n const clonedModel: FormModel = oldOptions.updateModel.clone();\n clonedModel.update(newModel);\n return clonedModel;\n }\n return newModel;\n },\n };\n }\n\n return oldOptions;\n};\n\n/**\n */\nconst modularUIConnector = (\n name: string,\n resource: string | Function,\n options: ModularUIOptions = { propName: \"data\", removeOnUnmount: false },\n): ((Component: ComponentType<any>) => (props: any) => Node) => {\n const {\n propName = \"data\",\n removeOnUnmount = false,\n ...otherOptions\n } = options;\n\n return (Component: ComponentType<any>) => {\n const WrappedComponent = (props: any) => {\n const dispatch = useDispatch();\n const location = useLocation();\n\n const url = useUrl(resource, { location, ...props });\n const displayName = getDisplayName(Component, name, props.contextId);\n\n // Load the model through the useModUI hook\n const modelEntry = useModularUI(displayName, url, otherOptions);\n const modelKey = modelEntry?.model?.connectKey;\n\n // handle manual reload of model\n const handleManualReload = (\n model: ModularUIModel,\n reloadOptions?: Object,\n ) => {\n dispatch(reloadModel(model, reloadOptions));\n };\n\n // Provide connected models with a fetchModularUI method to be able\n // to run the loadModularUI action from a handler / callback in the component\n const handleFetch = (href: string | Href, fetchOptions: Object) => {\n dispatch(\n loadModularUI(modelKey, href, patchUpdateModelOption(fetchOptions)),\n );\n };\n\n // Check if current model needs a reload\n const reload = location?.state?.reload ?? 0;\n const doReload = useReload(modelEntry, reload);\n useEffect(() => {\n if (doReload) {\n dispatch(\n loadModularUI(modelKey, url, {\n ...patchUpdateModelOption(otherOptions),\n isReload: true,\n }),\n );\n }\n }, [dispatch, doReload, url, modelKey]);\n\n // Remove model when hoc unloads\n useEffect(() => {\n return () => {\n if (removeOnUnmount) {\n dispatch(removeModelByKey(modelKey));\n }\n };\n }, [dispatch, modelKey]);\n\n // Create new properties object to inject modularui properties to own props\n const locale = useLocale();\n const newProps: InjectedProps = {\n modelKey,\n [propName]: modelEntry ? modelEntry.model : null,\n location,\n status: modelEntry ? modelEntry.status : null,\n lastModification: modelEntry ? modelEntry.lastModification : null,\n hasModel: Boolean(modelEntry),\n locale,\n fetchModularUI: handleFetch,\n reloadModel: handleManualReload,\n };\n\n return <Component {...props} {...newProps} />;\n };\n\n WrappedComponent.displayName = `BI.modularui(${getDisplayName(\n WrappedComponent,\n name,\n )}`;\n\n return WrappedComponent;\n };\n};\n\nexport default modularUIConnector;\n"],"mappings":"AACA,SAASA,SAAS,QAAQ,OAAO;AACjC,SAASC,WAAW,QAAQ,aAAa;AACzC,SAASC,WAAW,QAAQ,cAAc;AAE1C,SACEC,aAAa,EACbC,WAAW,EACXC,gBAAgB,QACX,oBAAoB;AAE3B,OAAOC,IAAI,MAAM,wBAAwB;AACzC,SAASC,cAAc,QAAQ,mBAAmB;AAElD,SAASC,MAAM,EAAEC,SAAS,QAAQ,kBAAkB;AACpD,SAASC,YAAY,QAAQ,0BAA0B;AACvD,SAASC,SAAS,QAAQ,qBAAqB;AAM/C,OAAOC,SAAS,MAAM,6BAA6B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAcpD,MAAMC,sBAAsB,GAAIC,UAAkB,IAAK;EACrD,IACE,aAAa,IAAIA,UAAU,IAC3BA,UAAU,CAACC,WAAW,YAAYL,SAAS,EAC3C;IACA,OAAO;MACL,GAAGI,UAAU;MACbE,aAAa,EAAGC,QAAwB,IAAqB;QAC3D,IAAIA,QAAQ,YAAYP,SAAS,EAAE;UACjC;UACA,MAAMQ,WAAsB,GAAGJ,UAAU,CAACC,WAAW,CAACI,KAAK,CAAC,CAAC;UAC7DD,WAAW,CAACE,MAAM,CAACH,QAAQ,CAAC;UAC5B,OAAOC,WAAW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AG,gBAAgBhC,cAAc,CAC3D2B,gBAAgB,EAChBV,IACF,CAAC,EAAE;IAEH,OAAOU,gBAAgB;EACzB,CAAC;AACH,CAAC;AAED,eAAeX,kBAAkB","ignoreList":[]}
|
|
@@ -229,12 +229,12 @@ class BooleanAttributeModel extends _AttributeModel.default {
|
|
|
229
229
|
return this;
|
|
230
230
|
}
|
|
231
231
|
this.updateLastModification();
|
|
232
|
-
let values;
|
|
232
|
+
let values = [];
|
|
233
233
|
if (Array.isArray(value)) {
|
|
234
234
|
values = value;
|
|
235
235
|
} else if (typeof value === "string" && this.isMultiple) {
|
|
236
236
|
values = value.split(",");
|
|
237
|
-
} else {
|
|
237
|
+
} else if (value != null) {
|
|
238
238
|
values = [value.toString()];
|
|
239
239
|
}
|
|
240
240
|
values.forEach(val => {
|
|
@@ -246,13 +246,13 @@ export default class BooleanAttributeModel extends AttributeModel {
|
|
|
246
246
|
|
|
247
247
|
this.updateLastModification();
|
|
248
248
|
|
|
249
|
-
let values;
|
|
249
|
+
let values = [];
|
|
250
250
|
|
|
251
251
|
if (Array.isArray(value)) {
|
|
252
252
|
values = value;
|
|
253
253
|
} else if (typeof value === "string" && this.isMultiple) {
|
|
254
254
|
values = value.split(",");
|
|
255
|
-
} else {
|
|
255
|
+
} else if (value != null) {
|
|
256
256
|
values = [value.toString()];
|
|
257
257
|
}
|
|
258
258
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BooleanAttributeModel.js","names":["_AttributeModel","_interopRequireDefault","require","_DateTimeUtil","_ChoiceAttributeOptionCollection","_ContentConfigurationElements","_ChoiceAttributeOptionModel","_LayoutHints","_constants","BooleanAttributeModel","AttributeModel","constructor","attribute","attributeContributions","_defineProperty2","default","_referenceDate","getData","DateUtil","now","_options","ChoiceAttributeOptionCollection","create","referenceDate","isApplicableModel","contributions","type","date","options","choicetype","_context","_find","call","hint","layouthint","has","isMultiple","isTree","hasContentConfiguration","_hasContentConfiguration","contentConfiguration","_context2","content","optionElements","optionElementConfig","_map","optionElement","contentElement","RENDER_SECTION_LABEL","ContentConfigurationElements","selected","_context3","option","code","readonlyvalue","_context4","label","join","initvalue","Array","isArray","_initvalue","length","getValue","_context5","hasValue","getInputValue","toggleOption","_context6","_includes","disableOption","enableOption","deselectAll","select","inputvalue","deselect","reset","mergeAttribute","oldAttribute","readonly","concept","isValid","update","value","updateLastModification","values","split","toString","forEach","val","ChoiceAttributeOptionModel","some","updateByAttribute","otherAttribute","console","error","getFormData","inError","name","readonlyWidth","hasAlternativeLabel","ATTRIBUTE_WIDTH","SMALL","EXTRA_SMALL","exports"],"sources":["../../../src/models/attributes/BooleanAttributeModel.js"],"sourcesContent":["// @flow\nimport AttributeModel from \"./AttributeModel\";\n\nimport { DateUtil } from \"../../utils/datetime/DateTimeUtil\";\n\nimport ChoiceAttributeOptionCollection from \"./ChoiceAttributeOptionCollection\";\nimport ContentConfigurationElements from \"../contentconfiguration/ContentConfigurationElements\";\nimport ChoiceAttributeOptionModel from \"./ChoiceAttributeOptionModel\";\n\nimport { RENDER_SECTION_LABEL } from \"../../constants/LayoutHints\";\nimport { ATTRIBUTE_WIDTH } from \"../../constants\";\n\nimport type { AttributeType } from \"../types\";\n\n/**\n * Model for a boolean attribute\n */\nexport default class BooleanAttributeModel extends AttributeModel {\n _referenceDate: string;\n _options: ChoiceAttributeOptionCollection;\n _hasContentConfiguration: boolean = false;\n\n /**\n */\n constructor(attribute: Object, attributeContributions: Object) {\n super(attribute, attributeContributions);\n\n this._referenceDate = this.getData(\"referenceDate\", DateUtil.now());\n this._options = ChoiceAttributeOptionCollection.create(\n attribute,\n attributeContributions,\n this.referenceDate,\n );\n }\n\n /**\n */\n static isApplicableModel(contributions: Object): boolean {\n return contributions.type === \"boolean\";\n }\n\n /**\n */\n get type(): string {\n return \"boolean\";\n }\n\n /**\n * Retrieve reference date of attribute which can be used as entryDate for content\n */\n get referenceDate(): string {\n return this._referenceDate;\n }\n\n /**\n * Set reference date for concepts and content\n */\n set referenceDate(date: string) {\n this._referenceDate = date;\n\n this.options.referenceDate = date;\n }\n\n /**\n * Getting the type of choice filter. For instance checkbox, radiobutton, combobox.\n */\n get choicetype(): \"checkbox\" | \"radiobutton\" | \"combobox\" | \"toggle\" {\n return (\n [\"checkbox\", \"radiobutton\", \"combobox\", \"toggle\"].find((hint) =>\n this.layouthint.has(hint),\n ) || \"radiobutton\"\n );\n }\n\n /**\n * Can multiple options be selected\n */\n get isMultiple(): boolean {\n return false;\n }\n\n /**\n * Check if options need to be rendered as tree\n */\n get isTree(): boolean {\n return false;\n }\n\n /**\n */\n set hasContentConfiguration(hasContentConfiguration: boolean) {\n this._hasContentConfiguration =\n this.contentConfiguration !== null || hasContentConfiguration;\n }\n\n /**\n */\n get hasContentConfiguration(): boolean {\n return this._hasContentConfiguration;\n }\n\n /**\n * Get content configuration configured on the attribute.\n * Only applicable for taxonomy element and knowledge codemaps,\n * content configuration for instrument questions is available on the form object\n */\n get contentConfiguration(): ContentConfigurationElements | null {\n if (\n !this.contributions.content ||\n !this.contributions.content.optionElements\n ) {\n return null;\n }\n\n // Add RENDER_SECTION_LABEL to all content configuration to make sure the label of a section is always rendered on taxonomy and knowlege codemaps\n const optionElementConfig = this.contributions.content.optionElements.map(\n (optionElement) => {\n if (\"contentElement\" in optionElement) {\n return {\n contentElement: {\n ...optionElement.contentElement,\n layouthint: [RENDER_SECTION_LABEL],\n },\n };\n }\n\n return optionElement;\n },\n );\n\n return new ContentConfigurationElements(optionElementConfig);\n }\n\n /**\n * Retrieve available choice options\n */\n get options(): ChoiceAttributeOptionCollection {\n return this._options;\n }\n\n /**\n * Getting all enabled options\n */\n get selected(): Array<string> {\n // $FlowFixMe[incompatible-call]\n return this.options.selected.map<string, ChoiceAttributeOptionModel>(\n (option: ChoiceAttributeOptionModel) => option.code,\n );\n }\n\n /**\n * Flatten options and filter out the options that are not selected\n */\n get readonlyvalue(): string {\n return this.options.selected.map((option) => option.label).join(\", \");\n }\n\n /**\n */\n get initvalue(): any {\n if (Array.isArray(this._initvalue) && this._initvalue.length === 0) {\n return null;\n }\n\n return this._initvalue;\n }\n\n /**\n * Retrieve list of selected options, joined with comma\n */\n getValue(): string | null {\n return this.options.selected.length > 0\n ? this.options.selected.map((option) => option.code).join(\",\")\n : null;\n }\n\n /**\n */\n hasValue(): boolean {\n return this.options.selected.length > 0;\n }\n\n /**\n * Get input value of attribute\n */\n getInputValue(): string {\n return this.selected.join(\",\");\n }\n\n /**\n * Setting an option selected or unselected based on the current state\n */\n toggleOption(code: string) {\n if (this.selected.includes(code)) {\n this.disableOption(code);\n } else {\n this.enableOption(code);\n }\n }\n\n /**\n * Enable a option\n */\n enableOption(code: string) {\n this.options.deselectAll();\n this.options.select(code);\n this.inputvalue = this.getInputValue();\n }\n\n /**\n * Disable a option\n */\n disableOption(code: string) {\n this.options.deselect(code);\n this.inputvalue = this.getInputValue();\n }\n\n /**\n * Reset boolean attribute to unselected list\n */\n reset() {\n this.options.deselectAll();\n }\n\n /**\n */\n mergeAttribute(oldAttribute: AttributeType) {\n // when attribute is readonly, don't merge the options no modifications necessary\n if (!this.readonly && oldAttribute instanceof BooleanAttributeModel) {\n this.concept = oldAttribute.concept;\n this.options.deselectAll();\n\n if (oldAttribute.isValid && oldAttribute.inputvalue !== null) {\n this.update(oldAttribute.inputvalue);\n }\n }\n }\n\n /**\n * Update attribute by name and value\n */\n update(value: any): BooleanAttributeModel {\n if (this.readonly) {\n return this;\n }\n\n this.updateLastModification();\n\n let values;\n\n if (Array.isArray(value)) {\n values = value;\n } else if (typeof value === \"string\" && this.isMultiple) {\n values = value.split(\",\");\n } else {\n values = [value.toString()];\n }\n\n values.forEach((val) => {\n if (val instanceof ChoiceAttributeOptionModel) {\n this.toggleOption(val.code);\n } else if (\n typeof val === \"string\" &&\n this.options.some((option) => option.code.toString() === val)\n ) {\n this.toggleOption(val);\n }\n });\n\n return this;\n }\n\n /**\n */\n updateByAttribute(otherAttribute: AttributeType): void {\n this.reset();\n if (otherAttribute instanceof BooleanAttributeModel) {\n this.update(otherAttribute.value);\n } else {\n console.error(\n `update of boolean attribute with ${otherAttribute.type} not supported`,\n );\n }\n }\n\n /**\n */\n getFormData(): { [string]: boolean | null } | null {\n if (this.inError()) {\n return null;\n }\n\n if (!this.hasValue()) {\n // no value for checkbox and toggle is same as a false value\n if (this.choicetype === \"checkbox\" || this.choicetype === \"toggle\") {\n return { [this.name]: false };\n }\n\n return { [this.name]: null };\n }\n\n return { [this.name]: this.value === \"true\" };\n }\n\n /**\n */\n get readonlyWidth(): $Keys<typeof ATTRIBUTE_WIDTH> {\n if (this.options.some((option) => option.hasAlternativeLabel)) {\n return ATTRIBUTE_WIDTH.SMALL;\n }\n\n return ATTRIBUTE_WIDTH.EXTRA_SMALL;\n }\n}\n"],"mappings":";;;;;;;;;;;AACA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAEA,IAAAE,gCAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,6BAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,2BAAA,GAAAL,sBAAA,CAAAC,OAAA;AAEA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AAIA;AACA;AACA;AACe,MAAMO,qBAAqB,SAASC,uBAAc,CAAC;EAKhE;AACF;EACEC,WAAWA,CAACC,SAAiB,EAAEC,sBAA8B,EAAE;IAC7D,KAAK,CAACD,SAAS,EAAEC,sBAAsB,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA,oCALP,KAAK;IAOvC,IAAI,CAACC,cAAc,GAAG,IAAI,CAACC,OAAO,CAAC,eAAe,EAAEC,sBAAQ,CAACC,GAAG,CAAC,CAAC,CAAC;IACnE,IAAI,CAACC,QAAQ,GAAGC,wCAA+B,CAACC,MAAM,CACpDV,SAAS,EACT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,0BAAe,CAACC,KAAK;IAC9B;IAEA,OAAOD,0BAAe,CAACE,WAAW;EACpC;AACF;AAACC,OAAA,CAAAzF,OAAA,GAAAN,qBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"BooleanAttributeModel.js","names":["_AttributeModel","_interopRequireDefault","require","_DateTimeUtil","_ChoiceAttributeOptionCollection","_ContentConfigurationElements","_ChoiceAttributeOptionModel","_LayoutHints","_constants","BooleanAttributeModel","AttributeModel","constructor","attribute","attributeContributions","_defineProperty2","default","_referenceDate","getData","DateUtil","now","_options","ChoiceAttributeOptionCollection","create","referenceDate","isApplicableModel","contributions","type","date","options","choicetype","_context","_find","call","hint","layouthint","has","isMultiple","isTree","hasContentConfiguration","_hasContentConfiguration","contentConfiguration","_context2","content","optionElements","optionElementConfig","_map","optionElement","contentElement","RENDER_SECTION_LABEL","ContentConfigurationElements","selected","_context3","option","code","readonlyvalue","_context4","label","join","initvalue","Array","isArray","_initvalue","length","getValue","_context5","hasValue","getInputValue","toggleOption","_context6","_includes","disableOption","enableOption","deselectAll","select","inputvalue","deselect","reset","mergeAttribute","oldAttribute","readonly","concept","isValid","update","value","updateLastModification","values","split","toString","forEach","val","ChoiceAttributeOptionModel","some","updateByAttribute","otherAttribute","console","error","getFormData","inError","name","readonlyWidth","hasAlternativeLabel","ATTRIBUTE_WIDTH","SMALL","EXTRA_SMALL","exports"],"sources":["../../../src/models/attributes/BooleanAttributeModel.js"],"sourcesContent":["// @flow\nimport AttributeModel from \"./AttributeModel\";\n\nimport { DateUtil } from \"../../utils/datetime/DateTimeUtil\";\n\nimport ChoiceAttributeOptionCollection from \"./ChoiceAttributeOptionCollection\";\nimport ContentConfigurationElements from \"../contentconfiguration/ContentConfigurationElements\";\nimport ChoiceAttributeOptionModel from \"./ChoiceAttributeOptionModel\";\n\nimport { RENDER_SECTION_LABEL } from \"../../constants/LayoutHints\";\nimport { ATTRIBUTE_WIDTH } from \"../../constants\";\n\nimport type { AttributeType } from \"../types\";\n\n/**\n * Model for a boolean attribute\n */\nexport default class BooleanAttributeModel extends AttributeModel {\n _referenceDate: string;\n _options: ChoiceAttributeOptionCollection;\n _hasContentConfiguration: boolean = false;\n\n /**\n */\n constructor(attribute: Object, attributeContributions: Object) {\n super(attribute, attributeContributions);\n\n this._referenceDate = this.getData(\"referenceDate\", DateUtil.now());\n this._options = ChoiceAttributeOptionCollection.create(\n attribute,\n attributeContributions,\n this.referenceDate,\n );\n }\n\n /**\n */\n static isApplicableModel(contributions: Object): boolean {\n return contributions.type === \"boolean\";\n }\n\n /**\n */\n get type(): string {\n return \"boolean\";\n }\n\n /**\n * Retrieve reference date of attribute which can be used as entryDate for content\n */\n get referenceDate(): string {\n return this._referenceDate;\n }\n\n /**\n * Set reference date for concepts and content\n */\n set referenceDate(date: string) {\n this._referenceDate = date;\n\n this.options.referenceDate = date;\n }\n\n /**\n * Getting the type of choice filter. For instance checkbox, radiobutton, combobox.\n */\n get choicetype(): \"checkbox\" | \"radiobutton\" | \"combobox\" | \"toggle\" {\n return (\n [\"checkbox\", \"radiobutton\", \"combobox\", \"toggle\"].find((hint) =>\n this.layouthint.has(hint),\n ) || \"radiobutton\"\n );\n }\n\n /**\n * Can multiple options be selected\n */\n get isMultiple(): boolean {\n return false;\n }\n\n /**\n * Check if options need to be rendered as tree\n */\n get isTree(): boolean {\n return false;\n }\n\n /**\n */\n set hasContentConfiguration(hasContentConfiguration: boolean) {\n this._hasContentConfiguration =\n this.contentConfiguration !== null || hasContentConfiguration;\n }\n\n /**\n */\n get hasContentConfiguration(): boolean {\n return this._hasContentConfiguration;\n }\n\n /**\n * Get content configuration configured on the attribute.\n * Only applicable for taxonomy element and knowledge codemaps,\n * content configuration for instrument questions is available on the form object\n */\n get contentConfiguration(): ContentConfigurationElements | null {\n if (\n !this.contributions.content ||\n !this.contributions.content.optionElements\n ) {\n return null;\n }\n\n // Add RENDER_SECTION_LABEL to all content configuration to make sure the label of a section is always rendered on taxonomy and knowlege codemaps\n const optionElementConfig = this.contributions.content.optionElements.map(\n (optionElement) => {\n if (\"contentElement\" in optionElement) {\n return {\n contentElement: {\n ...optionElement.contentElement,\n layouthint: [RENDER_SECTION_LABEL],\n },\n };\n }\n\n return optionElement;\n },\n );\n\n return new ContentConfigurationElements(optionElementConfig);\n }\n\n /**\n * Retrieve available choice options\n */\n get options(): ChoiceAttributeOptionCollection {\n return this._options;\n }\n\n /**\n * Getting all enabled options\n */\n get selected(): Array<string> {\n // $FlowFixMe[incompatible-call]\n return this.options.selected.map<string, ChoiceAttributeOptionModel>(\n (option: ChoiceAttributeOptionModel) => option.code,\n );\n }\n\n /**\n * Flatten options and filter out the options that are not selected\n */\n get readonlyvalue(): string {\n return this.options.selected.map((option) => option.label).join(\", \");\n }\n\n /**\n */\n get initvalue(): any {\n if (Array.isArray(this._initvalue) && this._initvalue.length === 0) {\n return null;\n }\n\n return this._initvalue;\n }\n\n /**\n * Retrieve list of selected options, joined with comma\n */\n getValue(): string | null {\n return this.options.selected.length > 0\n ? this.options.selected.map((option) => option.code).join(\",\")\n : null;\n }\n\n /**\n */\n hasValue(): boolean {\n return this.options.selected.length > 0;\n }\n\n /**\n * Get input value of attribute\n */\n getInputValue(): string {\n return this.selected.join(\",\");\n }\n\n /**\n * Setting an option selected or unselected based on the current state\n */\n toggleOption(code: string) {\n if (this.selected.includes(code)) {\n this.disableOption(code);\n } else {\n this.enableOption(code);\n }\n }\n\n /**\n * Enable a option\n */\n enableOption(code: string) {\n this.options.deselectAll();\n this.options.select(code);\n this.inputvalue = this.getInputValue();\n }\n\n /**\n * Disable a option\n */\n disableOption(code: string) {\n this.options.deselect(code);\n this.inputvalue = this.getInputValue();\n }\n\n /**\n * Reset boolean attribute to unselected list\n */\n reset() {\n this.options.deselectAll();\n }\n\n /**\n */\n mergeAttribute(oldAttribute: AttributeType) {\n // when attribute is readonly, don't merge the options no modifications necessary\n if (!this.readonly && oldAttribute instanceof BooleanAttributeModel) {\n this.concept = oldAttribute.concept;\n this.options.deselectAll();\n\n if (oldAttribute.isValid && oldAttribute.inputvalue !== null) {\n this.update(oldAttribute.inputvalue);\n }\n }\n }\n\n /**\n * Update attribute by name and value\n */\n update(value: any): BooleanAttributeModel {\n if (this.readonly) {\n return this;\n }\n\n this.updateLastModification();\n\n let values = [];\n\n if (Array.isArray(value)) {\n values = value;\n } else if (typeof value === \"string\" && this.isMultiple) {\n values = value.split(\",\");\n } else if (value != null) {\n values = [value.toString()];\n }\n\n values.forEach((val) => {\n if (val instanceof ChoiceAttributeOptionModel) {\n this.toggleOption(val.code);\n } else if (\n typeof val === \"string\" &&\n this.options.some((option) => option.code.toString() === val)\n ) {\n this.toggleOption(val);\n }\n });\n\n return this;\n }\n\n /**\n */\n updateByAttribute(otherAttribute: AttributeType): void {\n this.reset();\n if (otherAttribute instanceof BooleanAttributeModel) {\n this.update(otherAttribute.value);\n } else {\n console.error(\n `update of boolean attribute with ${otherAttribute.type} not supported`,\n );\n }\n }\n\n /**\n */\n getFormData(): { [string]: boolean | null } | null {\n if (this.inError()) {\n return null;\n }\n\n if (!this.hasValue()) {\n // no value for checkbox and toggle is same as a false value\n if (this.choicetype === \"checkbox\" || this.choicetype === \"toggle\") {\n return { [this.name]: false };\n }\n\n return { [this.name]: null };\n }\n\n return { [this.name]: this.value === \"true\" };\n }\n\n /**\n */\n get readonlyWidth(): $Keys<typeof ATTRIBUTE_WIDTH> {\n if (this.options.some((option) => option.hasAlternativeLabel)) {\n return ATTRIBUTE_WIDTH.SMALL;\n }\n\n return ATTRIBUTE_WIDTH.EXTRA_SMALL;\n }\n}\n"],"mappings":";;;;;;;;;;;AACA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAEA,IAAAE,gCAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,6BAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,2BAAA,GAAAL,sBAAA,CAAAC,OAAA;AAEA,IAAAK,YAAA,GAA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b;IAEA,IAAI,CAAC,IAAI,CAAChC,QAAQ,CAAC,CAAC,EAAE;MACpB;MACA,IAAI,IAAI,CAACpC,UAAU,KAAK,UAAU,IAAI,IAAI,CAACA,UAAU,KAAK,QAAQ,EAAE;QAClE,OAAO;UAAE,CAAC,IAAI,CAACqE,IAAI,GAAG;QAAM,CAAC;MAC/B;MAEA,OAAO;QAAE,CAAC,IAAI,CAACA,IAAI,GAAG;MAAK,CAAC;IAC9B;IAEA,OAAO;MAAE,CAAC,IAAI,CAACA,IAAI,GAAG,IAAI,CAACf,KAAK,KAAK;IAAO,CAAC;EAC/C;;EAEA;AACF;EACE,IAAIgB,aAAaA,CAAA,EAAkC;IACjD,IAAI,IAAI,CAACvE,OAAO,CAAC+D,IAAI,CAAEvC,MAAM,IAAKA,MAAM,CAACgD,mBAAmB,CAAC,EAAE;MAC7D,OAAOC,0BAAe,CAACC,KAAK;IAC9B;IAEA,OAAOD,0BAAe,CAACE,WAAW;EACpC;AACF;AAACC,OAAA,CAAAzF,OAAA,GAAAN,qBAAA","ignoreList":[]}
|
|
@@ -59,6 +59,14 @@ describe("booleanAttributeModel", () => {
|
|
|
59
59
|
expect(attribute.inputvalue).toBe("false");
|
|
60
60
|
|
|
61
61
|
expect(attribute.getFormData()).toStrictEqual({ boolean: false });
|
|
62
|
+
|
|
63
|
+
attribute.enableOption("true");
|
|
64
|
+
attribute.update(null);
|
|
65
|
+
expect(attribute.inputvalue).toBe("true");
|
|
66
|
+
|
|
67
|
+
attribute.update("false");
|
|
68
|
+
attribute.update(null);
|
|
69
|
+
expect(attribute.inputvalue).toBe("false");
|
|
62
70
|
});
|
|
63
71
|
|
|
64
72
|
it("handles update empty string", () => {
|
|
@@ -14,7 +14,26 @@ var _utils = require("../../react/utils");
|
|
|
14
14
|
var _ModularUIUtils = require("./ModularUIUtils");
|
|
15
15
|
var _useModularUI = require("../../hooks/useModularUI");
|
|
16
16
|
var _useI18n = require("../../hooks/useI18n");
|
|
17
|
+
var _FormModel = _interopRequireDefault(require("../../models/form/FormModel"));
|
|
17
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
|
+
const patchUpdateModelOption = oldOptions => {
|
|
20
|
+
if ("updateModel" in oldOptions && oldOptions.updateModel instanceof _FormModel.default) {
|
|
21
|
+
return {
|
|
22
|
+
...oldOptions,
|
|
23
|
+
updateHandler: newModel => {
|
|
24
|
+
if (newModel instanceof _FormModel.default) {
|
|
25
|
+
// $FLowFixMe
|
|
26
|
+
const clonedModel = oldOptions.updateModel.clone();
|
|
27
|
+
clonedModel.update(newModel);
|
|
28
|
+
return clonedModel;
|
|
29
|
+
}
|
|
30
|
+
return newModel;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return oldOptions;
|
|
35
|
+
};
|
|
36
|
+
|
|
18
37
|
/**
|
|
19
38
|
*/
|
|
20
39
|
const modularUIConnector = function (name, resource) {
|
|
@@ -49,7 +68,7 @@ const modularUIConnector = function (name, resource) {
|
|
|
49
68
|
// Provide connected models with a fetchModularUI method to be able
|
|
50
69
|
// to run the loadModularUI action from a handler / callback in the component
|
|
51
70
|
const handleFetch = (href, fetchOptions) => {
|
|
52
|
-
dispatch((0, _ModularUIActions.loadModularUI)(modelKey, href, fetchOptions));
|
|
71
|
+
dispatch((0, _ModularUIActions.loadModularUI)(modelKey, href, patchUpdateModelOption(fetchOptions)));
|
|
53
72
|
};
|
|
54
73
|
|
|
55
74
|
// Check if current model needs a reload
|
|
@@ -58,7 +77,7 @@ const modularUIConnector = function (name, resource) {
|
|
|
58
77
|
(0, _react.useEffect)(() => {
|
|
59
78
|
if (doReload) {
|
|
60
79
|
dispatch((0, _ModularUIActions.loadModularUI)(modelKey, url, {
|
|
61
|
-
...otherOptions,
|
|
80
|
+
...patchUpdateModelOption(otherOptions),
|
|
62
81
|
isReload: true
|
|
63
82
|
}));
|
|
64
83
|
}
|
|
@@ -20,6 +20,7 @@ import type { ComponentType, Node } from "react";
|
|
|
20
20
|
import type { Location } from "react-router";
|
|
21
21
|
import type { ModularUIModel } from "../../models/types";
|
|
22
22
|
import type { ModularUIOptions } from "./types";
|
|
23
|
+
import FormModel from "../../models/form/FormModel";
|
|
23
24
|
|
|
24
25
|
export type InjectedProps = {
|
|
25
26
|
+modelKey: string,
|
|
@@ -33,6 +34,28 @@ export type InjectedProps = {
|
|
|
33
34
|
+data?: ?ModularUIModel,
|
|
34
35
|
};
|
|
35
36
|
|
|
37
|
+
const patchUpdateModelOption = (oldOptions: Object) => {
|
|
38
|
+
if (
|
|
39
|
+
"updateModel" in oldOptions &&
|
|
40
|
+
oldOptions.updateModel instanceof FormModel
|
|
41
|
+
) {
|
|
42
|
+
return {
|
|
43
|
+
...oldOptions,
|
|
44
|
+
updateHandler: (newModel: ModularUIModel): ModularUIModel => {
|
|
45
|
+
if (newModel instanceof FormModel) {
|
|
46
|
+
// $FLowFixMe
|
|
47
|
+
const clonedModel: FormModel = oldOptions.updateModel.clone();
|
|
48
|
+
clonedModel.update(newModel);
|
|
49
|
+
return clonedModel;
|
|
50
|
+
}
|
|
51
|
+
return newModel;
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return oldOptions;
|
|
57
|
+
};
|
|
58
|
+
|
|
36
59
|
/**
|
|
37
60
|
*/
|
|
38
61
|
const modularUIConnector = (
|
|
@@ -69,7 +92,9 @@ const modularUIConnector = (
|
|
|
69
92
|
// Provide connected models with a fetchModularUI method to be able
|
|
70
93
|
// to run the loadModularUI action from a handler / callback in the component
|
|
71
94
|
const handleFetch = (href: string | Href, fetchOptions: Object) => {
|
|
72
|
-
dispatch(
|
|
95
|
+
dispatch(
|
|
96
|
+
loadModularUI(modelKey, href, patchUpdateModelOption(fetchOptions)),
|
|
97
|
+
);
|
|
73
98
|
};
|
|
74
99
|
|
|
75
100
|
// Check if current model needs a reload
|
|
@@ -78,7 +103,10 @@ const modularUIConnector = (
|
|
|
78
103
|
useEffect(() => {
|
|
79
104
|
if (doReload) {
|
|
80
105
|
dispatch(
|
|
81
|
-
loadModularUI(modelKey, url, {
|
|
106
|
+
loadModularUI(modelKey, url, {
|
|
107
|
+
...patchUpdateModelOption(otherOptions),
|
|
108
|
+
isReload: true,
|
|
109
|
+
}),
|
|
82
110
|
);
|
|
83
111
|
}
|
|
84
112
|
}, [dispatch, doReload, url, modelKey]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModularUIConnector.js","names":["_react","require","_reactRedux","_reactRouter","_ModularUIActions","_Href","_interopRequireDefault","_utils","_ModularUIUtils","_useModularUI","_useI18n","_jsxRuntime","modularUIConnector","name","resource","options","arguments","length","undefined","propName","removeOnUnmount","otherOptions","Component","WrappedComponent","props","dispatch","useDispatch","location","useLocation","url","useUrl","displayName","getDisplayName","contextId","modelEntry","useModularUI","modelKey","model","connectKey","handleManualReload","reloadOptions","reloadModel","handleFetch","href","fetchOptions","loadModularUI","reload","state","doReload","useReload","useEffect","isReload","removeModelByKey","locale","useLocale","newProps","status","lastModification","hasModel","Boolean","fetchModularUI","jsx","_default","exports","default"],"sources":["../../../src/redux/_modularui/ModularUIConnector.js"],"sourcesContent":["// @flow\nimport { useEffect } from \"react\";\nimport { useDispatch } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport {\n loadModularUI,\n reloadModel,\n removeModelByKey,\n} from \"./ModularUIActions\";\n\nimport Href from \"../../models/href/Href\";\nimport { getDisplayName } from \"../../react/utils\";\n\nimport { useUrl, useReload } from \"./ModularUIUtils\";\nimport { useModularUI } from \"../../hooks/useModularUI\";\nimport { useLocale } from \"../../hooks/useI18n\";\n\nimport type { ComponentType, Node } from \"react\";\nimport type { Location } from \"react-router\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { ModularUIOptions } from \"./types\";\n\nexport type InjectedProps = {\n +modelKey: string,\n +location: Location,\n +status: string | null,\n +lastModification: number | null,\n +hasModel: boolean,\n +locale: string,\n +fetchModularUI: (href: string | Href, fetchOptions: Object) => void,\n +reloadModel: (model: ModularUIModel, options: Object) => void,\n +data?: ?ModularUIModel,\n};\n\n/**\n */\nconst modularUIConnector = (\n name: string,\n resource: string | Function,\n options: ModularUIOptions = { propName: \"data\", removeOnUnmount: false },\n): ((Component: ComponentType<any>) => (props: any) => Node) => {\n const {\n propName = \"data\",\n removeOnUnmount = false,\n ...otherOptions\n } = options;\n\n return (Component: ComponentType<any>) => {\n const WrappedComponent = (props: any) => {\n const dispatch = useDispatch();\n const location = useLocation();\n\n const url = useUrl(resource, { location, ...props });\n const displayName = getDisplayName(Component, name, props.contextId);\n\n // Load the model through the useModUI hook\n const modelEntry = useModularUI(displayName, url, otherOptions);\n const modelKey = modelEntry?.model?.connectKey;\n\n // handle manual reload of model\n const handleManualReload = (\n model: ModularUIModel,\n reloadOptions?: Object,\n ) => {\n dispatch(reloadModel(model, reloadOptions));\n };\n\n // Provide connected models with a fetchModularUI method to be able\n // to run the loadModularUI action from a handler / callback in the component\n const handleFetch = (href: string | Href, fetchOptions: Object) => {\n dispatch(loadModularUI(modelKey, href, fetchOptions));\n };\n\n // Check if current model needs a reload\n const reload = location?.state?.reload ?? 0;\n const doReload = useReload(modelEntry, reload);\n useEffect(() => {\n if (doReload) {\n dispatch(\n loadModularUI(modelKey, url, {
|
|
1
|
+
{"version":3,"file":"ModularUIConnector.js","names":["_react","require","_reactRedux","_reactRouter","_ModularUIActions","_Href","_interopRequireDefault","_utils","_ModularUIUtils","_useModularUI","_useI18n","_FormModel","_jsxRuntime","patchUpdateModelOption","oldOptions","updateModel","FormModel","updateHandler","newModel","clonedModel","clone","update","modularUIConnector","name","resource","options","arguments","length","undefined","propName","removeOnUnmount","otherOptions","Component","WrappedComponent","props","dispatch","useDispatch","location","useLocation","url","useUrl","displayName","getDisplayName","contextId","modelEntry","useModularUI","modelKey","model","connectKey","handleManualReload","reloadOptions","reloadModel","handleFetch","href","fetchOptions","loadModularUI","reload","state","doReload","useReload","useEffect","isReload","removeModelByKey","locale","useLocale","newProps","status","lastModification","hasModel","Boolean","fetchModularUI","jsx","_default","exports","default"],"sources":["../../../src/redux/_modularui/ModularUIConnector.js"],"sourcesContent":["// @flow\nimport { useEffect } from \"react\";\nimport { useDispatch } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport {\n loadModularUI,\n reloadModel,\n removeModelByKey,\n} from \"./ModularUIActions\";\n\nimport Href from \"../../models/href/Href\";\nimport { getDisplayName } from \"../../react/utils\";\n\nimport { useUrl, useReload } from \"./ModularUIUtils\";\nimport { useModularUI } from \"../../hooks/useModularUI\";\nimport { useLocale } from \"../../hooks/useI18n\";\n\nimport type { ComponentType, Node } from \"react\";\nimport type { Location } from \"react-router\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { ModularUIOptions } from \"./types\";\nimport FormModel from \"../../models/form/FormModel\";\n\nexport type InjectedProps = {\n +modelKey: string,\n +location: Location,\n +status: string | null,\n +lastModification: number | null,\n +hasModel: boolean,\n +locale: string,\n +fetchModularUI: (href: string | Href, fetchOptions: Object) => void,\n +reloadModel: (model: ModularUIModel, options: Object) => void,\n +data?: ?ModularUIModel,\n};\n\nconst patchUpdateModelOption = (oldOptions: Object) => {\n if (\n \"updateModel\" in oldOptions &&\n oldOptions.updateModel instanceof FormModel\n ) {\n return {\n ...oldOptions,\n updateHandler: (newModel: ModularUIModel): ModularUIModel => {\n if (newModel instanceof FormModel) {\n // $FLowFixMe\n const clonedModel: FormModel = oldOptions.updateModel.clone();\n clonedModel.update(newModel);\n return clonedModel;\n }\n return newModel;\n },\n };\n }\n\n return oldOptions;\n};\n\n/**\n */\nconst modularUIConnector = (\n name: string,\n resource: string | Function,\n options: ModularUIOptions = { propName: \"data\", removeOnUnmount: false },\n): ((Component: ComponentType<any>) => (props: any) => Node) => {\n const {\n propName = \"data\",\n removeOnUnmount = false,\n ...otherOptions\n } = options;\n\n return (Component: ComponentType<any>) => {\n const WrappedComponent = (props: any) => {\n const dispatch = useDispatch();\n const location = useLocation();\n\n const url = useUrl(resource, { location, ...props });\n const displayName = getDisplayName(Component, name, props.contextId);\n\n // Load the model through the useModUI hook\n const modelEntry = useModularUI(displayName, url, otherOptions);\n const modelKey = modelEntry?.model?.connectKey;\n\n // handle manual reload of model\n const handleManualReload = (\n model: ModularUIModel,\n reloadOptions?: Object,\n ) => {\n dispatch(reloadModel(model, reloadOptions));\n };\n\n // Provide connected models with a fetchModularUI method to be able\n // to run the loadModularUI action from a handler / callback in the component\n const handleFetch = (href: string | Href, fetchOptions: Object) => {\n dispatch(\n loadModularUI(modelKey, href, patchUpdateModelOption(fetchOptions)),\n );\n };\n\n // Check if current model needs a reload\n const reload = location?.state?.reload ?? 0;\n const doReload = useReload(modelEntry, reload);\n useEffect(() => {\n if (doReload) {\n dispatch(\n loadModularUI(modelKey, url, {\n ...patchUpdateModelOption(otherOptions),\n isReload: true,\n }),\n );\n }\n }, [dispatch, doReload, url, modelKey]);\n\n // Remove model when hoc unloads\n useEffect(() => {\n return () => {\n if (removeOnUnmount) {\n dispatch(removeModelByKey(modelKey));\n }\n };\n }, [dispatch, modelKey]);\n\n // Create new properties object to inject modularui properties to own props\n const locale = useLocale();\n const newProps: InjectedProps = {\n modelKey,\n [propName]: modelEntry ? modelEntry.model : null,\n location,\n status: modelEntry ? modelEntry.status : null,\n lastModification: modelEntry ? modelEntry.lastModification : null,\n hasModel: Boolean(modelEntry),\n locale,\n fetchModularUI: handleFetch,\n reloadModel: handleManualReload,\n };\n\n return <Component {...props} {...newProps} />;\n };\n\n WrappedComponent.displayName = `BI.modularui(${getDisplayName(\n WrappedComponent,\n name,\n )}`;\n\n return WrappedComponent;\n };\n};\n\nexport default modularUIConnector;\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,iBAAA,GAAAH,OAAA;AAMA,IAAAI,KAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,MAAA,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ACH,CAAC,EAAE,CAACX,QAAQ,EAAEW,QAAQ,CAAC,CAAC;;MAExB;MACA,MAAMiB,MAAM,GAAG,IAAAC,kBAAS,EAAC,CAAC;MAC1B,MAAMC,QAAuB,GAAG;QAC9BnB,QAAQ;QACR,CAACjB,QAAQ,GAAGe,UAAU,GAAGA,UAAU,CAACG,KAAK,GAAG,IAAI;QAChDV,QAAQ;QACR6B,MAAM,EAAEtB,UAAU,GAAGA,UAAU,CAACsB,MAAM,GAAG,IAAI;QAC7CC,gBAAgB,EAAEvB,UAAU,GAAGA,UAAU,CAACuB,gBAAgB,GAAG,IAAI;QACjEC,QAAQ,EAAEC,OAAO,CAACzB,UAAU,CAAC;QAC7BmB,MAAM;QACNO,cAAc,EAAElB,WAAW;QAC3BD,WAAW,EAAEF;MACf,CAAC;MAED,oBAAO,IAAArC,WAAA,CAAA2D,GAAA,EAACvC,SAAS;QAAA,GAAKE,KAAK;QAAA,GAAM+B;MAAQ,CAAG,CAAC;IAC/C,CAAC;IAEDhC,gBAAgB,CAACQ,WAAW,GAAG,gBAAgB,IAAAC,qBAAc,EAC3DT,gBAAgB,EAChBV,IACF,CAAC,EAAE;IAEH,OAAOU,gBAAgB;EACzB,CAAC;AACH,CAAC;AAAC,IAAAuC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEapD,kBAAkB","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -246,13 +246,13 @@ export default class BooleanAttributeModel extends AttributeModel {
|
|
|
246
246
|
|
|
247
247
|
this.updateLastModification();
|
|
248
248
|
|
|
249
|
-
let values;
|
|
249
|
+
let values = [];
|
|
250
250
|
|
|
251
251
|
if (Array.isArray(value)) {
|
|
252
252
|
values = value;
|
|
253
253
|
} else if (typeof value === "string" && this.isMultiple) {
|
|
254
254
|
values = value.split(",");
|
|
255
|
-
} else {
|
|
255
|
+
} else if (value != null) {
|
|
256
256
|
values = [value.toString()];
|
|
257
257
|
}
|
|
258
258
|
|
|
@@ -59,6 +59,14 @@ describe("booleanAttributeModel", () => {
|
|
|
59
59
|
expect(attribute.inputvalue).toBe("false");
|
|
60
60
|
|
|
61
61
|
expect(attribute.getFormData()).toStrictEqual({ boolean: false });
|
|
62
|
+
|
|
63
|
+
attribute.enableOption("true");
|
|
64
|
+
attribute.update(null);
|
|
65
|
+
expect(attribute.inputvalue).toBe("true");
|
|
66
|
+
|
|
67
|
+
attribute.update("false");
|
|
68
|
+
attribute.update(null);
|
|
69
|
+
expect(attribute.inputvalue).toBe("false");
|
|
62
70
|
});
|
|
63
71
|
|
|
64
72
|
it("handles update empty string", () => {
|
|
@@ -20,6 +20,7 @@ import type { ComponentType, Node } from "react";
|
|
|
20
20
|
import type { Location } from "react-router";
|
|
21
21
|
import type { ModularUIModel } from "../../models/types";
|
|
22
22
|
import type { ModularUIOptions } from "./types";
|
|
23
|
+
import FormModel from "../../models/form/FormModel";
|
|
23
24
|
|
|
24
25
|
export type InjectedProps = {
|
|
25
26
|
+modelKey: string,
|
|
@@ -33,6 +34,28 @@ export type InjectedProps = {
|
|
|
33
34
|
+data?: ?ModularUIModel,
|
|
34
35
|
};
|
|
35
36
|
|
|
37
|
+
const patchUpdateModelOption = (oldOptions: Object) => {
|
|
38
|
+
if (
|
|
39
|
+
"updateModel" in oldOptions &&
|
|
40
|
+
oldOptions.updateModel instanceof FormModel
|
|
41
|
+
) {
|
|
42
|
+
return {
|
|
43
|
+
...oldOptions,
|
|
44
|
+
updateHandler: (newModel: ModularUIModel): ModularUIModel => {
|
|
45
|
+
if (newModel instanceof FormModel) {
|
|
46
|
+
// $FLowFixMe
|
|
47
|
+
const clonedModel: FormModel = oldOptions.updateModel.clone();
|
|
48
|
+
clonedModel.update(newModel);
|
|
49
|
+
return clonedModel;
|
|
50
|
+
}
|
|
51
|
+
return newModel;
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return oldOptions;
|
|
57
|
+
};
|
|
58
|
+
|
|
36
59
|
/**
|
|
37
60
|
*/
|
|
38
61
|
const modularUIConnector = (
|
|
@@ -69,7 +92,9 @@ const modularUIConnector = (
|
|
|
69
92
|
// Provide connected models with a fetchModularUI method to be able
|
|
70
93
|
// to run the loadModularUI action from a handler / callback in the component
|
|
71
94
|
const handleFetch = (href: string | Href, fetchOptions: Object) => {
|
|
72
|
-
dispatch(
|
|
95
|
+
dispatch(
|
|
96
|
+
loadModularUI(modelKey, href, patchUpdateModelOption(fetchOptions)),
|
|
97
|
+
);
|
|
73
98
|
};
|
|
74
99
|
|
|
75
100
|
// Check if current model needs a reload
|
|
@@ -78,7 +103,10 @@ const modularUIConnector = (
|
|
|
78
103
|
useEffect(() => {
|
|
79
104
|
if (doReload) {
|
|
80
105
|
dispatch(
|
|
81
|
-
loadModularUI(modelKey, url, {
|
|
106
|
+
loadModularUI(modelKey, url, {
|
|
107
|
+
...patchUpdateModelOption(otherOptions),
|
|
108
|
+
isReload: true,
|
|
109
|
+
}),
|
|
82
110
|
);
|
|
83
111
|
}
|
|
84
112
|
}, [dispatch, doReload, url, modelKey]);
|