@beinformed/ui 1.60.1 → 1.60.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/esm/hooks/__tests__/useModelCatalog.spec.js.flow +0 -2
  3. package/esm/hooks/useModelCatalog.d.ts +1 -1
  4. package/esm/hooks/useModelCatalog.js +4 -4
  5. package/esm/hooks/useModelCatalog.js.flow +5 -5
  6. package/esm/hooks/useModelCatalog.js.map +1 -1
  7. package/esm/models/attributes/ChoiceAttributeOptionCollection.d.ts +6 -0
  8. package/esm/models/attributes/ChoiceAttributeOptionCollection.js +19 -6
  9. package/esm/models/attributes/ChoiceAttributeOptionCollection.js.flow +12 -0
  10. package/esm/models/attributes/ChoiceAttributeOptionCollection.js.map +1 -1
  11. package/esm/models/concepts/__tests__/ConceptIndexModel.spec.js.flow +4 -0
  12. package/esm/models/filters/ConceptIndexFilterModel.js +9 -8
  13. package/esm/models/filters/ConceptIndexFilterModel.js.flow +15 -11
  14. package/esm/models/filters/ConceptIndexFilterModel.js.map +1 -1
  15. package/esm/models/form/__tests__/FormModel.spec.js.flow +2 -0
  16. package/esm/modularui/UploadRequest.js +5 -4
  17. package/esm/modularui/UploadRequest.js.flow +16 -6
  18. package/esm/modularui/UploadRequest.js.map +1 -1
  19. package/lib/hooks/useModelCatalog.d.ts +1 -1
  20. package/lib/hooks/useModelCatalog.js +4 -4
  21. package/lib/hooks/useModelCatalog.js.map +1 -1
  22. package/lib/models/attributes/ChoiceAttributeOptionCollection.d.ts +6 -0
  23. package/lib/models/attributes/ChoiceAttributeOptionCollection.js +19 -6
  24. package/lib/models/attributes/ChoiceAttributeOptionCollection.js.map +1 -1
  25. package/lib/models/filters/ConceptIndexFilterModel.js +9 -8
  26. package/lib/models/filters/ConceptIndexFilterModel.js.map +1 -1
  27. package/lib/modularui/UploadRequest.js +4 -3
  28. package/lib/modularui/UploadRequest.js.map +1 -1
  29. package/package.json +5 -5
  30. package/src/hooks/__tests__/useModelCatalog.spec.js +0 -2
  31. package/src/hooks/useModelCatalog.js +5 -5
  32. package/src/models/attributes/ChoiceAttributeOptionCollection.js +12 -0
  33. package/src/models/concepts/__mock__/conceptindex_data.json +8 -2
  34. package/src/models/concepts/__tests__/ConceptIndexModel.spec.js +4 -0
  35. package/src/models/filters/ConceptIndexFilterModel.js +15 -11
  36. package/src/models/form/__tests__/FormModel.spec.js +2 -0
  37. package/src/modularui/UploadRequest.js +16 -6
@@ -98,16 +98,16 @@ const useContentTOC = function (content) {
98
98
  /**
99
99
  */
100
100
  exports.useContentTOC = useContentTOC;
101
- const useContent = function (contentSection) {
101
+ const useContent = function (content) {
102
102
  let key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "content";
103
103
  let options = arguments.length > 2 ? arguments[2] : undefined;
104
104
  const {
105
105
  entryDate
106
106
  } = useEntryDate();
107
- const href = (0, _createHref.createHref)("content", contentSection, entryDate, null, []);
107
+ const location = (0, _useRouter.useLocation)();
108
+ const href = (0, _createHref.createHref)("content", content, entryDate, location, []);
108
109
  return (0, _useModularUIBasic.useModularUIBasic)(key, href, {
109
- expectedModels: ["Content"],
110
- targetModel: _ContentModel.default,
110
+ expectedModels: ["Content", "ContentTOC"],
111
111
  ...options
112
112
  });
113
113
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useModelCatalog.js","names":["_reactRedux","require","_useRouter","_createHref","_ModelCatalogModel","_interopRequireDefault","_ConceptIndexModel","_ConceptDetailModel","_BusinessScenarioModel","_ContentIndexModel","_ContentTOCModel","_ContentModel","_useModularUIBasic","_models","_modelcatalog","_ModelCatalog","useModelCatalog","options","useModularUIBasic","expectedModels","targetModel","ModelCatalogModel","exports","useConceptIndex","href","key","arguments","length","undefined","entryDate","useEntryDate","url","filterParameters","setParameter","ConceptIndexModel","useConceptDetail","concept","location","useLocation","createHref","useContentIndex","ContentIndexModel","useContentTOC","content","ContentTOCModel","useContent","contentSection","ContentModel","useContentType","contentType","ContentTypeModel","getSearchHref","uri","filters","filterString","_keys","default","filterValue","value","Array","isArray","join","replace","push","useConceptSearch","useContentSearch","dispatch","useDispatch","useSelector","getEntryDate","setEntryDate","updateEntryDate"],"sources":["../../src/hooks/useModelCatalog.js"],"sourcesContent":["// @flow\nimport { useSelector, useDispatch } from \"react-redux\";\nimport { useLocation } from \"./useRouter\";\n\nimport { createHref, filterParameters } from \"../utils/helpers/createHref\";\n\nimport ModelCatalogModel from \"../models/modelcatalog/ModelCatalogModel\";\nimport ConceptIndexModel from \"../models/concepts/ConceptIndexModel\";\nimport ConceptDetailModel from \"../models/concepts/ConceptDetailModel\";\nimport { default as BusinessScenarioModel } from \"../models/concepts/BusinessScenarioModel\";\nimport ContentIndexModel from \"../models/content/ContentIndexModel\";\nimport ContentTOCModel from \"../models/content/ContentTOCModel\";\nimport ContentModel from \"../models/content/ContentModel\";\n\nimport { useModularUIBasic } from \"./useModularUIBasic\";\nimport { ContentTypeModel } from \"../models\";\n\nimport { getEntryDate } from \"../redux/selectors/modelcatalog\";\nimport { updateEntryDate } from \"../redux/actions/ModelCatalog\";\n\nimport type Href from \"../models/href/Href\";\nimport type { UseModularUIBasicOptions } from \"./useModularUIBasic\";\nimport type { UpdateEntryDateAction } from \"../redux\";\nexport type SearchFilter = {\n index?: string,\n label?: string,\n type?: string | Array<string>,\n modelCategory?: string | Array<string>,\n entryDate?: string,\n};\n\n/**\n */\nexport const useModelCatalog = (\n options?: UseModularUIBasicOptions<ModelCatalogModel>,\n): ?ModelCatalogModel =>\n useModularUIBasic(\"modelcatalog\", \"/modelcatalog\", {\n expectedModels: [\"ModelCatalog\"],\n targetModel: ModelCatalogModel,\n ...options,\n });\n\n/**\n */\nexport const useConceptIndex = (\n href: string | Href,\n key?: string = \"conceptindex\",\n options?: UseModularUIBasicOptions<ConceptIndexModel>,\n): ?ConceptIndexModel => {\n const { entryDate } = useEntryDate();\n const url = filterParameters(href, [\n \"index\",\n \"label\",\n \"modelcategory\",\n \"type\",\n ]);\n url.setParameter(\"entryDate\", entryDate);\n\n return useModularUIBasic(key, url, {\n expectedModels: [\"ConceptIndex\"],\n targetModel: ConceptIndexModel,\n ...options,\n });\n};\n\n/**\n */\nexport const useConceptDetail = (\n concept: string | Href,\n key?: string = \"conceptdetail\",\n options?: UseModularUIBasicOptions<\n ConceptDetailModel | BusinessScenarioModel,\n >,\n): ?ConceptDetailModel | ?BusinessScenarioModel => {\n const { entryDate } = useEntryDate();\n const location = useLocation();\n\n const href = createHref(\"concepts\", concept, entryDate, location, []);\n\n return useModularUIBasic(key, href, {\n expectedModels: [\"ConceptDetail\", \"BusinessScenario\"],\n ...options,\n });\n};\n\n/**\n */\nexport const useContentIndex = (\n href: string | Href,\n key?: string = \"contentindex\",\n options?: UseModularUIBasicOptions<ContentIndexModel>,\n): ?ContentIndexModel => {\n const url = filterParameters(href, [\"index\", \"label\", \"type\"]);\n return useModularUIBasic(key, url, {\n expectedModels: [\"ContentIndex\"],\n targetModel: ContentIndexModel,\n ...options,\n });\n};\n\n/**\n */\nexport const useContentTOC = (\n content: string | Href,\n key?: string = \"contenttoc\",\n options?: UseModularUIBasicOptions<ContentTOCModel>,\n): ?ContentTOCModel => {\n const { entryDate } = useEntryDate();\n const location = useLocation();\n\n const href = createHref(\"content\", content, entryDate, location, []);\n\n return useModularUIBasic(key, href, {\n expectedModels: [\"ContentTOC\"],\n targetModel: ContentTOCModel,\n ...options,\n });\n};\n\n/**\n */\nexport const useContent = (\n contentSection: string | Href,\n key?: string = \"content\",\n options?: UseModularUIBasicOptions<ContentModel>,\n): ?ContentModel => {\n const { entryDate } = useEntryDate();\n\n const href = createHref(\"content\", contentSection, entryDate, null, []);\n\n return useModularUIBasic(key, href, {\n expectedModels: [\"Content\"],\n targetModel: ContentModel,\n ...options,\n });\n};\n\n/**\n */\nexport const useContentType = (\n contentType: string | Href,\n key?: string = \"contenttypes\",\n options?: UseModularUIBasicOptions<ContentTypeModel>,\n): ?ContentTypeModel => {\n const href = createHref(\"contenttypes\", contentType, null, null, []);\n return useModularUIBasic(key, href, {\n expectedModels: [\"ContentType\"],\n targetModel: ContentTypeModel,\n ...options,\n });\n};\n\n/**\n */\nconst getSearchHref = (uri: string, filters: SearchFilter): string => {\n const filterString = [];\n\n for (const key of Object.keys(filters)) {\n const filterValue = filters[key];\n if (filterValue) {\n let value: string = Array.isArray(filterValue)\n ? filterValue.join(\",\")\n : filterValue;\n if (key === \"type\") {\n value = value.replace(\"#\", \"%23\"); // handles un-encoded #\n }\n filterString.push(`${key}=${value}`);\n }\n }\n\n return filterString.length ? `${uri}?${filterString.join(\"&\")}` : uri;\n};\n\n/**\n */\nexport const useConceptSearch = (\n filters: SearchFilter,\n key?: string = \"conceptSearch\",\n options?: UseModularUIBasicOptions<ConceptIndexModel>,\n): ?ConceptIndexModel => {\n const href = getSearchHref(\"/concepts\", filters);\n return useConceptIndex(href, key, options);\n};\n\n/**\n */\nexport const useContentSearch = (\n filters: SearchFilter,\n key?: string = \"contentSearch\",\n options?: UseModularUIBasicOptions<ContentIndexModel>,\n): ?ContentIndexModel => {\n const href = getSearchHref(\"/content\", filters);\n return useContentIndex(href, key, options);\n};\n\n/**\n * Retrieve and update the entrydate for the modelcatalog\n */\nexport const useEntryDate = (): ({\n entryDate: ISO_DATE,\n setEntryDate: (entryDate: ISO_DATE) => UpdateEntryDateAction,\n}) => {\n const dispatch = useDispatch();\n const entryDate = useSelector(getEntryDate);\n\n return {\n entryDate,\n setEntryDate: (entryDate: ISO_DATE) => dispatch(updateEntryDate(entryDate)),\n };\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,WAAA,GAAAF,OAAA;AAEA,IAAAG,kBAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,kBAAA,GAAAD,sBAAA,CAAAJ,OAAA;AACA,IAAAM,mBAAA,GAAAF,sBAAA,CAAAJ,OAAA;AACA,I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;EAC5E,CAAC;AACH,CAAC;AAACP,OAAA,CAAAQ,YAAA,GAAAA,YAAA","ignoreList":[]}
1
+ {"version":3,"file":"useModelCatalog.js","names":["_reactRedux","require","_useRouter","_createHref","_ModelCatalogModel","_interopRequireDefault","_ConceptIndexModel","_ConceptDetailModel","_BusinessScenarioModel","_ContentIndexModel","_ContentTOCModel","_ContentModel","_useModularUIBasic","_models","_modelcatalog","_ModelCatalog","useModelCatalog","options","useModularUIBasic","expectedModels","targetModel","ModelCatalogModel","exports","useConceptIndex","href","key","arguments","length","undefined","entryDate","useEntryDate","url","filterParameters","setParameter","ConceptIndexModel","useConceptDetail","concept","location","useLocation","createHref","useContentIndex","ContentIndexModel","useContentTOC","content","ContentTOCModel","useContent","useContentType","contentType","ContentTypeModel","getSearchHref","uri","filters","filterString","_keys","default","filterValue","value","Array","isArray","join","replace","push","useConceptSearch","useContentSearch","dispatch","useDispatch","useSelector","getEntryDate","setEntryDate","updateEntryDate"],"sources":["../../src/hooks/useModelCatalog.js"],"sourcesContent":["// @flow\nimport { useSelector, useDispatch } from \"react-redux\";\nimport { useLocation } from \"./useRouter\";\n\nimport { createHref, filterParameters } from \"../utils/helpers/createHref\";\n\nimport ModelCatalogModel from \"../models/modelcatalog/ModelCatalogModel\";\nimport ConceptIndexModel from \"../models/concepts/ConceptIndexModel\";\nimport ConceptDetailModel from \"../models/concepts/ConceptDetailModel\";\nimport { default as BusinessScenarioModel } from \"../models/concepts/BusinessScenarioModel\";\nimport ContentIndexModel from \"../models/content/ContentIndexModel\";\nimport ContentTOCModel from \"../models/content/ContentTOCModel\";\nimport ContentModel from \"../models/content/ContentModel\";\n\nimport { useModularUIBasic } from \"./useModularUIBasic\";\nimport { ContentTypeModel } from \"../models\";\n\nimport { getEntryDate } from \"../redux/selectors/modelcatalog\";\nimport { updateEntryDate } from \"../redux/actions/ModelCatalog\";\n\nimport type Href from \"../models/href/Href\";\nimport type { UseModularUIBasicOptions } from \"./useModularUIBasic\";\nimport type { UpdateEntryDateAction } from \"../redux\";\nexport type SearchFilter = {\n index?: string,\n label?: string,\n type?: string | Array<string>,\n modelCategory?: string | Array<string>,\n entryDate?: string,\n};\n\n/**\n */\nexport const useModelCatalog = (\n options?: UseModularUIBasicOptions<ModelCatalogModel>,\n): ?ModelCatalogModel =>\n useModularUIBasic(\"modelcatalog\", \"/modelcatalog\", {\n expectedModels: [\"ModelCatalog\"],\n targetModel: ModelCatalogModel,\n ...options,\n });\n\n/**\n */\nexport const useConceptIndex = (\n href: string | Href,\n key?: string = \"conceptindex\",\n options?: UseModularUIBasicOptions<ConceptIndexModel>,\n): ?ConceptIndexModel => {\n const { entryDate } = useEntryDate();\n const url = filterParameters(href, [\n \"index\",\n \"label\",\n \"modelcategory\",\n \"type\",\n ]);\n url.setParameter(\"entryDate\", entryDate);\n\n return useModularUIBasic(key, url, {\n expectedModels: [\"ConceptIndex\"],\n targetModel: ConceptIndexModel,\n ...options,\n });\n};\n\n/**\n */\nexport const useConceptDetail = (\n concept: string | Href,\n key?: string = \"conceptdetail\",\n options?: UseModularUIBasicOptions<\n ConceptDetailModel | BusinessScenarioModel,\n >,\n): ?ConceptDetailModel | ?BusinessScenarioModel => {\n const { entryDate } = useEntryDate();\n const location = useLocation();\n\n const href = createHref(\"concepts\", concept, entryDate, location, []);\n\n return useModularUIBasic(key, href, {\n expectedModels: [\"ConceptDetail\", \"BusinessScenario\"],\n ...options,\n });\n};\n\n/**\n */\nexport const useContentIndex = (\n href: string | Href,\n key?: string = \"contentindex\",\n options?: UseModularUIBasicOptions<ContentIndexModel>,\n): ?ContentIndexModel => {\n const url = filterParameters(href, [\"index\", \"label\", \"type\"]);\n return useModularUIBasic(key, url, {\n expectedModels: [\"ContentIndex\"],\n targetModel: ContentIndexModel,\n ...options,\n });\n};\n\n/**\n */\nexport const useContentTOC = (\n content: string | Href,\n key?: string = \"contenttoc\",\n options?: UseModularUIBasicOptions<ContentTOCModel>,\n): ?ContentTOCModel => {\n const { entryDate } = useEntryDate();\n const location = useLocation();\n\n const href = createHref(\"content\", content, entryDate, location, []);\n\n return useModularUIBasic(key, href, {\n expectedModels: [\"ContentTOC\"],\n targetModel: ContentTOCModel,\n ...options,\n });\n};\n\n/**\n */\nexport const useContent = (\n content: string | Href,\n key?: string = \"content\",\n options?: UseModularUIBasicOptions<ContentModel>,\n): ?ContentModel | ?ContentTOCModel => {\n const { entryDate } = useEntryDate();\n const location = useLocation();\n\n const href = createHref(\"content\", content, entryDate, location, []);\n\n return useModularUIBasic(key, href, {\n expectedModels: [\"Content\", \"ContentTOC\"],\n ...options,\n });\n};\n\n/**\n */\nexport const useContentType = (\n contentType: string | Href,\n key?: string = \"contenttypes\",\n options?: UseModularUIBasicOptions<ContentTypeModel>,\n): ?ContentTypeModel => {\n const href = createHref(\"contenttypes\", contentType, null, null, []);\n return useModularUIBasic(key, href, {\n expectedModels: [\"ContentType\"],\n targetModel: ContentTypeModel,\n ...options,\n });\n};\n\n/**\n */\nconst getSearchHref = (uri: string, filters: SearchFilter): string => {\n const filterString = [];\n\n for (const key of Object.keys(filters)) {\n const filterValue = filters[key];\n if (filterValue) {\n let value: string = Array.isArray(filterValue)\n ? filterValue.join(\",\")\n : filterValue;\n if (key === \"type\") {\n value = value.replace(\"#\", \"%23\"); // handles un-encoded #\n }\n filterString.push(`${key}=${value}`);\n }\n }\n\n return filterString.length ? `${uri}?${filterString.join(\"&\")}` : uri;\n};\n\n/**\n */\nexport const useConceptSearch = (\n filters: SearchFilter,\n key?: string = \"conceptSearch\",\n options?: UseModularUIBasicOptions<ConceptIndexModel>,\n): ?ConceptIndexModel => {\n const href = getSearchHref(\"/concepts\", filters);\n return useConceptIndex(href, key, options);\n};\n\n/**\n */\nexport const useContentSearch = (\n filters: SearchFilter,\n key?: string = \"contentSearch\",\n options?: UseModularUIBasicOptions<ContentIndexModel>,\n): ?ContentIndexModel => {\n const href = getSearchHref(\"/content\", filters);\n return useContentIndex(href, key, options);\n};\n\n/**\n * Retrieve and update the entrydate for the modelcatalog\n */\nexport const useEntryDate = (): ({\n entryDate: ISO_DATE,\n setEntryDate: (entryDate: ISO_DATE) => UpdateEntryDateAction,\n}) => {\n const dispatch = useDispatch();\n const entryDate = useSelector(getEntryDate);\n\n return {\n entryDate,\n setEntryDate: (entryDate: ISO_DATE) => dispatch(updateEntryDate(entryDate)),\n };\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,WAAA,GAAAF,OAAA;AAEA,IAAAG,kBAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,kBAAA,GAAAD,sBAAA,CAAAJ,OAAA;AACA,IAAAM,mBAAA,GAAAF,sBAAA,CAAAJ,OAAA;AACA,IAAAO,sBAAA,GAAAH,sBAAA,CAAAJ,OAAA;AACA,IAAAQ,kBAAA,GAAAJ,sBAAA,CAAAJ,OAAA;AACA,IAAAS,gBAAA,GAAAL,sBAAA,CAAAJ,OAAA;AACA,IAAAU,aAAA,GAAAN,sBAAA,CAAAJ,OAAA;AAEA,IAAAW,kBAAA,GAAAX,OAAA;AACA,IAAAY,OAAA,GAAAZ,OAAA;AAEA,IAAAa,aAAA,GAAAb,OAAA;AACA,IAAAc,aAAA,GAAAd,OAAA;AAaA;AACA;AACO,MAAMe,eAAe,GAC1BC,OAAqD,IAErD,IAAAC,oCAAiB,EAAC,cAAc,EAAE,eAAe,EAAE;EACjDC,cAAc,EAAE,CAAC,cAAc,CAAC;EAChCC,WAAW,EAAEC,0BAAiB;EAC9B,GAAGJ;AACL,CAAC,CAAC;;AAEJ;AACA;AADAK,OAAA,CAAAN,eAAA,GAAAA,eAAA;AAEO,MAAMO,eAAe,GAAG,SAAAA,CAC7BC,IAAmB,EAGI;EAAA,IAFvBC,GAAY,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,cAAc;EAAA,IAC7BT,OAAqD,GAAAS,SAAA,CAA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,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;EAErD,MAAMJ,IAAI,GAAGyB,aAAa,CAAC,UAAU,EAAEE,OAAO,CAAC;EAC/C,OAAOX,eAAe,CAAChB,IAAI,EAAEC,GAAG,EAAER,OAAO,CAAC;AAC5C,CAAC;;AAED;AACA;AACA;AAFAK,OAAA,CAAAyC,gBAAA,GAAAA,gBAAA;AAGO,MAAMjC,YAAY,GAAGA,CAAA,KAGtB;EACJ,MAAMkC,QAAQ,GAAG,IAAAC,uBAAW,EAAC,CAAC;EAC9B,MAAMpC,SAAS,GAAG,IAAAqC,uBAAW,EAACC,0BAAY,CAAC;EAE3C,OAAO;IACLtC,SAAS;IACTuC,YAAY,EAAGvC,SAAmB,IAAKmC,QAAQ,CAAC,IAAAK,6BAAe,EAACxC,SAAS,CAAC;EAC5E,CAAC;AACH,CAAC;AAACP,OAAA,CAAAQ,YAAA,GAAAA,YAAA","ignoreList":[]}
@@ -39,6 +39,12 @@ declare class ChoiceAttributeOptionCollection extends ResourceCollection<ChoiceA
39
39
  /**
40
40
  */
41
41
  addOption(data: string | Array<string>, contributions: Object): ChoiceAttributeOptionCollection;
42
+ /**
43
+ */
44
+ getOptionByCode(code: string): ChoiceAttributeOptionModel | void;
45
+ /**
46
+ */
47
+ hasOptionByCode(code: string): boolean;
42
48
  /**
43
49
  * Get all options that have selected property true
44
50
  */
@@ -167,6 +167,19 @@ class ChoiceAttributeOptionCollection extends _ResourceCollection.default {
167
167
  return this;
168
168
  }
169
169
 
170
+ /**
171
+ */
172
+ getOptionByCode(code) {
173
+ var _context4;
174
+ return (0, _find.default)(_context4 = this.collection).call(_context4, option => option.code === code);
175
+ }
176
+
177
+ /**
178
+ */
179
+ hasOptionByCode(code) {
180
+ return this.collection.some(option => option.code === code);
181
+ }
182
+
170
183
  /**
171
184
  * Get all options that have selected property true
172
185
  */
@@ -187,8 +200,8 @@ class ChoiceAttributeOptionCollection extends _ResourceCollection.default {
187
200
  * Deselect all options
188
201
  */
189
202
  deselectAll() {
190
- var _context4;
191
- this.collection = (0, _map.default)(_context4 = this.collection).call(_context4, option => {
203
+ var _context5;
204
+ this.collection = (0, _map.default)(_context5 = this.collection).call(_context5, option => {
192
205
  const newOption = option.clone();
193
206
  newOption.selected = false;
194
207
  if (newOption.children) {
@@ -216,8 +229,8 @@ class ChoiceAttributeOptionCollection extends _ResourceCollection.default {
216
229
  * Toggle an option by it's code
217
230
  */
218
231
  toggle(optionCode, action) {
219
- var _context5;
220
- this.collection = (0, _map.default)(_context5 = this.collection).call(_context5, option => {
232
+ var _context6;
233
+ this.collection = (0, _map.default)(_context6 = this.collection).call(_context6, option => {
221
234
  const newOption = option.clone();
222
235
  if (newOption.code === optionCode) {
223
236
  newOption.selected = action === "select";
@@ -231,8 +244,8 @@ class ChoiceAttributeOptionCollection extends _ResourceCollection.default {
231
244
  /**
232
245
  */
233
246
  setReferenceDate(date) {
234
- var _context6;
235
- return (0, _map.default)(_context6 = this.collection).call(_context6, option => {
247
+ var _context7;
248
+ return (0, _map.default)(_context7 = this.collection).call(_context7, option => {
236
249
  option.referenceDate = date;
237
250
  if (option.children) {
238
251
  option.children.referenceDate = date;
@@ -1 +1 @@
1
- {"version":3,"file":"ChoiceAttributeOptionCollection.js","names":["_ResourceCollection","_interopRequireDefault","require","_ChoiceAttributeOptionModel","_ListHeaderModel","_constants","ChoiceAttributeOptionCollection","ResourceCollection","constructor","modelOptions","_defineProperty2","default","_modelOptions","origin","contextPath","getBasePathModularUI","referenceDate","Date","toISOString","split","sortOptions","_sortOptions","collection","forEach","option","children","create","data","arguments","length","undefined","contributions","type","addBooleanOptions","value","dynamicschema","addDynamicSchema","options","addOptions","addHeaders","all","_context","_sort","call","a","b","label","localeCompare","getSelectedOptions","selectedOptions","Array","isArray","_context2","_context3","push","_map","_filter","selected","key","toString","getOptionCount","code","foundOption","_find","count","selectedValues","optionContributions","optionCode","addOption","optionType","optionDynamicschema","elementsContributions","addBooleanOption","defaultLabel","isBooleanType","hasAlternativeLabel","optionValue","optionModel","ChoiceAttributeOptionModel","add","deselectAll","_context4","newOption","clone","select","toggle","deselect","action","_context5","setReferenceDate","date","_context6","headers","_headers","child","ListHeaderModel","mergeOptions","withOptions","addNotExistingOptions","removeNotExistingOptions","newCollection","withOption","mergeOption","some","opt","callbackfn","thisArg","optionIndex","collectionArray","result","_default","exports"],"sources":["../../../src/models/attributes/ChoiceAttributeOptionCollection.js"],"sourcesContent":["// @flow\nimport ResourceCollection from \"../base/ResourceCollection\";\nimport ChoiceAttributeOptionModel from \"./ChoiceAttributeOptionModel\";\nimport ListHeaderModel from \"../list/ListHeaderModel\";\n\nimport { getBasePathModularUI } from \"../../constants\";\n\nimport type { ChoiceAttributeOptionModelOptions } from \"./ChoiceAttributeOptionModel\";\n/**\n */\nclass ChoiceAttributeOptionCollection extends ResourceCollection<ChoiceAttributeOptionModel> {\n _modelOptions: ChoiceAttributeOptionModelOptions;\n _headers: Array<ListHeaderModel> = [];\n _sortOptions: boolean = false;\n\n constructor(modelOptions?: ChoiceAttributeOptionModelOptions) {\n super();\n this._modelOptions = modelOptions || {\n origin: \"\",\n contextPath: getBasePathModularUI(),\n referenceDate: new Date().toISOString().split(\"T\")[0],\n };\n }\n\n /**\n */\n set sortOptions(sortOptions: boolean) {\n this._sortOptions = sortOptions;\n\n this.collection.forEach((option) => {\n if (option.children) {\n option.children.sortOptions = sortOptions;\n }\n });\n }\n\n /**\n */\n get sortOptions(): boolean {\n return this._sortOptions;\n }\n\n /**\n */\n static create(\n data: Object = {},\n contributions: Object = {},\n modelOptions?: ChoiceAttributeOptionModelOptions,\n ): ChoiceAttributeOptionCollection {\n const collection = new ChoiceAttributeOptionCollection(modelOptions);\n\n if (contributions.type === \"boolean\") {\n collection.addBooleanOptions(data.value, contributions);\n } else if (data.dynamicschema != null) {\n collection.addDynamicSchema(data, contributions);\n } else if (contributions.options != null) {\n collection.addOptions(data, contributions);\n }\n\n if (contributions.children != null) {\n collection.addHeaders(contributions.children);\n }\n\n return collection;\n }\n\n /**\n * Retrieve all items in collection\n */\n get all(): Array<ChoiceAttributeOptionModel> {\n return this.sortOptions\n ? this.collection.sort((a, b) => a.label.localeCompare(b.label))\n : this.collection;\n }\n\n /**\n */\n getSelectedOptions(data: Object): Array<string> {\n const selectedOptions = [];\n\n if (Array.isArray(data.options)) {\n selectedOptions.push(\n ...data.options\n .filter((option) => option.selected)\n .map((option) => option.key),\n );\n } else if (Array.isArray(data.value)) {\n selectedOptions.push(...data.value);\n } else if (typeof data.value === \"boolean\") {\n selectedOptions.push(data.value.toString());\n } else {\n selectedOptions.push(data.value);\n }\n\n return selectedOptions;\n }\n\n /**\n */\n getOptionCount(code: string, options: Array<Object>): number | null {\n if (Array.isArray(options)) {\n const foundOption = options.find((option) => option.key === code);\n if (foundOption) {\n return foundOption.count;\n }\n }\n\n return null;\n }\n\n /**\n */\n addOptions(\n data: Object,\n contributions: Object,\n ): ChoiceAttributeOptionCollection {\n const selectedValues = this.getSelectedOptions(data);\n\n contributions.options.forEach((optionContributions) => {\n const optionCode = optionContributions.code || optionContributions.key;\n\n this.addOption(selectedValues, {\n ...optionContributions,\n count: this.getOptionCount(optionCode, data.options),\n optionType: contributions.optionType ?? \"generic\",\n });\n });\n\n return this;\n }\n\n /**\n * Create options based on data and dynamischema\n */\n addDynamicSchema(\n data: Object,\n contributions: Object,\n ): ChoiceAttributeOptionCollection {\n const selectedValues = this.getSelectedOptions(data);\n data.dynamicschema.forEach((optionDynamicschema) => {\n this.addOption(selectedValues, {\n ...optionDynamicschema,\n count: this.getOptionCount(optionDynamicschema.code, data.options),\n optionType: contributions.optionType ?? \"generic\",\n elementsContributions: contributions.children,\n });\n });\n\n return this;\n }\n\n /**\n */\n addBooleanOption(\n code: \"true\" | \"false\",\n defaultLabel: string,\n data: string | Array<string>,\n options: Array<Object> = [],\n ) {\n const foundOption = options.find((option) => option.code === code);\n\n const label = foundOption ? foundOption.label : defaultLabel;\n\n this.addOption(data, {\n code,\n label,\n isBooleanType: true,\n hasAlternativeLabel: foundOption != null,\n });\n }\n\n /**\n * Create two static options for true and false,\n * there might be alternative labels configured for each option value\n */\n addBooleanOptions(\n value: any,\n contributions: Object,\n ): ChoiceAttributeOptionCollection {\n const optionValue = value == null ? [] : [value.toString()];\n\n this.addBooleanOption(\"true\", \"Yes\", optionValue, contributions.options);\n this.addBooleanOption(\"false\", \"No\", optionValue, contributions.options);\n\n return this;\n }\n\n /**\n */\n addOption(\n data: string | Array<string>,\n contributions: Object,\n ): ChoiceAttributeOptionCollection {\n const optionModel = new ChoiceAttributeOptionModel(\n Array.isArray(data) ? data : [data],\n contributions,\n this._modelOptions,\n );\n\n this.add(optionModel);\n\n return this;\n }\n\n /**\n * Get all options that have selected property true\n */\n get selected(): Array<ChoiceAttributeOptionModel> {\n const selectedOptions = [];\n\n this.collection.forEach((option: ChoiceAttributeOptionModel) => {\n if (option.selected && option.selected === true) {\n selectedOptions.push(option);\n }\n\n if (option.children) {\n selectedOptions.push(...option.children.selected);\n }\n });\n\n return selectedOptions;\n }\n\n /**\n * Deselect all options\n */\n deselectAll() {\n this.collection = this.collection.map((option) => {\n const newOption = option.clone();\n\n newOption.selected = false;\n\n if (newOption.children) {\n newOption.children.deselectAll();\n }\n\n return newOption;\n });\n }\n\n /**\n * Select an option by it's code\n */\n select(optionCode: string) {\n this.toggle(optionCode, \"select\");\n }\n\n /**\n * Deselect an option by it's code\n */\n deselect(optionCode: string) {\n this.toggle(optionCode, \"deselect\");\n }\n\n /**\n * Toggle an option by it's code\n */\n toggle(optionCode: string, action: \"select\" | \"deselect\") {\n this.collection = this.collection.map((option) => {\n const newOption = option.clone();\n\n if (newOption.code === optionCode) {\n newOption.selected = action === \"select\";\n } else if (newOption.children) {\n newOption.children.toggle(optionCode, action);\n }\n\n return newOption;\n });\n }\n\n /**\n */\n setReferenceDate(date: ISO_DATE): Array<ChoiceAttributeOptionModel> {\n return this.collection.map((option) => {\n option.referenceDate = date;\n if (option.children) {\n option.children.referenceDate = date;\n }\n\n return option;\n });\n }\n\n /**\n */\n set referenceDate(date: ISO_DATE) {\n this.collection = this.setReferenceDate(date);\n }\n\n /**\n */\n addHeaders(headers: Array<Object>) {\n this._headers = headers.map((child) => new ListHeaderModel(child));\n }\n\n /**\n */\n get headers(): Array<ListHeaderModel> {\n if (this._headers) {\n return this._headers;\n }\n\n return [];\n }\n\n /**\n */\n mergeOptions(\n withOptions: ChoiceAttributeOptionCollection,\n addNotExistingOptions: boolean = false,\n removeNotExistingOptions: boolean = false,\n ) {\n const newCollection = [];\n\n this.collection.forEach((option) => {\n const foundOption = withOptions.find(\n (withOption) => withOption.code === option.code,\n );\n if (foundOption) {\n option.mergeOption(foundOption);\n newCollection.push(option);\n } else if (!removeNotExistingOptions) {\n newCollection.push(option);\n }\n });\n\n if (addNotExistingOptions) {\n this.collection = [\n ...newCollection,\n ...withOptions.filter(\n (option) => !this.collection.some((opt) => opt.code === option.code),\n ),\n ];\n } else {\n this.collection = newCollection;\n }\n }\n\n /**\n */\n some(\n callbackfn: (\n value: ChoiceAttributeOptionModel,\n index: number,\n array: Array<ChoiceAttributeOptionModel>,\n ) => any,\n thisArg?: any,\n ): boolean {\n return this.collection.some((option, optionIndex, collectionArray) => {\n const result = callbackfn(option, optionIndex, collectionArray);\n if (!result && option.children) {\n return option.children.some(callbackfn, thisArg);\n }\n return result;\n });\n }\n}\n\nexport default ChoiceAttributeOptionCollection;\n"],"mappings":";;;;;;;;;;;;AACA,IAAAA,mBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,2BAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,gBAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA,IAAAG,UAAA,GAAAH,OAAA;AAGA;AACA;AACA,MAAMI,+BAA+B,SAASC,2BAAkB,CAA6B;EAK3FC,WAAWA,CAACC,YAAgD,EAAE;IAC5D,KAAK,CAAC,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAA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C;MAC5B,CAAC,MAAM,IAAI,CAAC2E,wBAAwB,EAAE;QACpCC,aAAa,CAAC9C,IAAI,CAAC9B,MAAM,CAAC;MAC5B;IACF,CAAC,CAAC;IAEF,IAAI0E,qBAAqB,EAAE;MACzB,IAAI,CAAC5E,UAAU,GAAG,CAChB,GAAG8E,aAAa,EAChB,GAAG,IAAA5C,OAAA,CAAA7C,OAAA,EAAAsF,WAAW,EAAAtD,IAAA,CAAXsD,WAAW,EACXzE,MAAM,IAAK,CAAC,IAAI,CAACF,UAAU,CAACiF,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAAC3C,IAAI,KAAKrC,MAAM,CAACqC,IAAI,CACrE,CAAC,CACF;IACH,CAAC,MAAM;MACL,IAAI,CAACvC,UAAU,GAAG8E,aAAa;IACjC;EACF;;EAEA;AACF;EACEG,IAAIA,CACFE,UAIQ,EACRC,OAAa,EACJ;IACT,OAAO,IAAI,CAACpF,UAAU,CAACiF,IAAI,CAAC,CAAC/E,MAAM,EAAEmF,WAAW,EAAEC,eAAe,KAAK;MACpE,MAAMC,MAAM,GAAGJ,UAAU,CAACjF,MAAM,EAAEmF,WAAW,EAAEC,eAAe,CAAC;MAC/D,IAAI,CAACC,MAAM,IAAIrF,MAAM,CAACC,QAAQ,EAAE;QAC9B,OAAOD,MAAM,CAACC,QAAQ,CAAC8E,IAAI,CAACE,UAAU,EAAEC,OAAO,CAAC;MAClD;MACA,OAAOG,MAAM;IACf,CAAC,CAAC;EACJ;AACF;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAApG,OAAA,GAEcL,+BAA+B","ignoreList":[]}
1
+ {"version":3,"file":"ChoiceAttributeOptionCollection.js","names":["_ResourceCollection","_interopRequireDefault","require","_ChoiceAttributeOptionModel","_ListHeaderModel","_constants","ChoiceAttributeOptionCollection","ResourceCollection","constructor","modelOptions","_defineProperty2","default","_modelOptions","origin","contextPath","getBasePathModularUI","referenceDate","Date","toISOString","split","sortOptions","_sortOptions","collection","forEach","option","children","create","data","arguments","length","undefined","contributions","type","addBooleanOptions","value","dynamicschema","addDynamicSchema","options","addOptions","addHeaders","all","_context","_sort","call","a","b","label","localeCompare","getSelectedOptions","selectedOptions","Array","isArray","_context2","_context3","push","_map","_filter","selected","key","toString","getOptionCount","code","foundOption","_find","count","selectedValues","optionContributions","optionCode","addOption","optionType","optionDynamicschema","elementsContributions","addBooleanOption","defaultLabel","isBooleanType","hasAlternativeLabel","optionValue","optionModel","ChoiceAttributeOptionModel","add","getOptionByCode","_context4","hasOptionByCode","some","deselectAll","_context5","newOption","clone","select","toggle","deselect","action","_context6","setReferenceDate","date","_context7","headers","_headers","child","ListHeaderModel","mergeOptions","withOptions","addNotExistingOptions","removeNotExistingOptions","newCollection","withOption","mergeOption","opt","callbackfn","thisArg","optionIndex","collectionArray","result","_default","exports"],"sources":["../../../src/models/attributes/ChoiceAttributeOptionCollection.js"],"sourcesContent":["// @flow\nimport ResourceCollection from \"../base/ResourceCollection\";\nimport ChoiceAttributeOptionModel from \"./ChoiceAttributeOptionModel\";\nimport ListHeaderModel from \"../list/ListHeaderModel\";\n\nimport { getBasePathModularUI } from \"../../constants\";\n\nimport type { ChoiceAttributeOptionModelOptions } from \"./ChoiceAttributeOptionModel\";\n/**\n */\nclass ChoiceAttributeOptionCollection extends ResourceCollection<ChoiceAttributeOptionModel> {\n _modelOptions: ChoiceAttributeOptionModelOptions;\n _headers: Array<ListHeaderModel> = [];\n _sortOptions: boolean = false;\n\n constructor(modelOptions?: ChoiceAttributeOptionModelOptions) {\n super();\n this._modelOptions = modelOptions || {\n origin: \"\",\n contextPath: getBasePathModularUI(),\n referenceDate: new Date().toISOString().split(\"T\")[0],\n };\n }\n\n /**\n */\n set sortOptions(sortOptions: boolean) {\n this._sortOptions = sortOptions;\n\n this.collection.forEach((option) => {\n if (option.children) {\n option.children.sortOptions = sortOptions;\n }\n });\n }\n\n /**\n */\n get sortOptions(): boolean {\n return this._sortOptions;\n }\n\n /**\n */\n static create(\n data: Object = {},\n contributions: Object = {},\n modelOptions?: ChoiceAttributeOptionModelOptions,\n ): ChoiceAttributeOptionCollection {\n const collection = new ChoiceAttributeOptionCollection(modelOptions);\n\n if (contributions.type === \"boolean\") {\n collection.addBooleanOptions(data.value, contributions);\n } else if (data.dynamicschema != null) {\n collection.addDynamicSchema(data, contributions);\n } else if (contributions.options != null) {\n collection.addOptions(data, contributions);\n }\n\n if (contributions.children != null) {\n collection.addHeaders(contributions.children);\n }\n\n return collection;\n }\n\n /**\n * Retrieve all items in collection\n */\n get all(): Array<ChoiceAttributeOptionModel> {\n return this.sortOptions\n ? this.collection.sort((a, b) => a.label.localeCompare(b.label))\n : this.collection;\n }\n\n /**\n */\n getSelectedOptions(data: Object): Array<string> {\n const selectedOptions = [];\n\n if (Array.isArray(data.options)) {\n selectedOptions.push(\n ...data.options\n .filter((option) => option.selected)\n .map((option) => option.key),\n );\n } else if (Array.isArray(data.value)) {\n selectedOptions.push(...data.value);\n } else if (typeof data.value === \"boolean\") {\n selectedOptions.push(data.value.toString());\n } else {\n selectedOptions.push(data.value);\n }\n\n return selectedOptions;\n }\n\n /**\n */\n getOptionCount(code: string, options: Array<Object>): number | null {\n if (Array.isArray(options)) {\n const foundOption = options.find((option) => option.key === code);\n if (foundOption) {\n return foundOption.count;\n }\n }\n\n return null;\n }\n\n /**\n */\n addOptions(\n data: Object,\n contributions: Object,\n ): ChoiceAttributeOptionCollection {\n const selectedValues = this.getSelectedOptions(data);\n\n contributions.options.forEach((optionContributions) => {\n const optionCode = optionContributions.code || optionContributions.key;\n\n this.addOption(selectedValues, {\n ...optionContributions,\n count: this.getOptionCount(optionCode, data.options),\n optionType: contributions.optionType ?? \"generic\",\n });\n });\n\n return this;\n }\n\n /**\n * Create options based on data and dynamischema\n */\n addDynamicSchema(\n data: Object,\n contributions: Object,\n ): ChoiceAttributeOptionCollection {\n const selectedValues = this.getSelectedOptions(data);\n data.dynamicschema.forEach((optionDynamicschema) => {\n this.addOption(selectedValues, {\n ...optionDynamicschema,\n count: this.getOptionCount(optionDynamicschema.code, data.options),\n optionType: contributions.optionType ?? \"generic\",\n elementsContributions: contributions.children,\n });\n });\n\n return this;\n }\n\n /**\n */\n addBooleanOption(\n code: \"true\" | \"false\",\n defaultLabel: string,\n data: string | Array<string>,\n options: Array<Object> = [],\n ) {\n const foundOption = options.find((option) => option.code === code);\n\n const label = foundOption ? foundOption.label : defaultLabel;\n\n this.addOption(data, {\n code,\n label,\n isBooleanType: true,\n hasAlternativeLabel: foundOption != null,\n });\n }\n\n /**\n * Create two static options for true and false,\n * there might be alternative labels configured for each option value\n */\n addBooleanOptions(\n value: any,\n contributions: Object,\n ): ChoiceAttributeOptionCollection {\n const optionValue = value == null ? [] : [value.toString()];\n\n this.addBooleanOption(\"true\", \"Yes\", optionValue, contributions.options);\n this.addBooleanOption(\"false\", \"No\", optionValue, contributions.options);\n\n return this;\n }\n\n /**\n */\n addOption(\n data: string | Array<string>,\n contributions: Object,\n ): ChoiceAttributeOptionCollection {\n const optionModel = new ChoiceAttributeOptionModel(\n Array.isArray(data) ? data : [data],\n contributions,\n this._modelOptions,\n );\n\n this.add(optionModel);\n\n return this;\n }\n\n /**\n */\n getOptionByCode(code: string): ChoiceAttributeOptionModel | void {\n return this.collection.find((option) => option.code === code);\n }\n\n /**\n */\n hasOptionByCode(code: string): boolean {\n return this.collection.some((option) => option.code === code);\n }\n\n /**\n * Get all options that have selected property true\n */\n get selected(): Array<ChoiceAttributeOptionModel> {\n const selectedOptions = [];\n\n this.collection.forEach((option: ChoiceAttributeOptionModel) => {\n if (option.selected && option.selected === true) {\n selectedOptions.push(option);\n }\n\n if (option.children) {\n selectedOptions.push(...option.children.selected);\n }\n });\n\n return selectedOptions;\n }\n\n /**\n * Deselect all options\n */\n deselectAll() {\n this.collection = this.collection.map((option) => {\n const newOption = option.clone();\n\n newOption.selected = false;\n\n if (newOption.children) {\n newOption.children.deselectAll();\n }\n\n return newOption;\n });\n }\n\n /**\n * Select an option by it's code\n */\n select(optionCode: string) {\n this.toggle(optionCode, \"select\");\n }\n\n /**\n * Deselect an option by it's code\n */\n deselect(optionCode: string) {\n this.toggle(optionCode, \"deselect\");\n }\n\n /**\n * Toggle an option by it's code\n */\n toggle(optionCode: string, action: \"select\" | \"deselect\") {\n this.collection = this.collection.map((option) => {\n const newOption = option.clone();\n\n if (newOption.code === optionCode) {\n newOption.selected = action === \"select\";\n } else if (newOption.children) {\n newOption.children.toggle(optionCode, action);\n }\n\n return newOption;\n });\n }\n\n /**\n */\n setReferenceDate(date: ISO_DATE): Array<ChoiceAttributeOptionModel> {\n return this.collection.map((option) => {\n option.referenceDate = date;\n if (option.children) {\n option.children.referenceDate = date;\n }\n\n return option;\n });\n }\n\n /**\n */\n set referenceDate(date: ISO_DATE) {\n this.collection = this.setReferenceDate(date);\n }\n\n /**\n */\n addHeaders(headers: Array<Object>) {\n this._headers = headers.map((child) => new ListHeaderModel(child));\n }\n\n /**\n */\n get headers(): Array<ListHeaderModel> {\n if (this._headers) {\n return this._headers;\n }\n\n return [];\n }\n\n /**\n */\n mergeOptions(\n withOptions: ChoiceAttributeOptionCollection,\n addNotExistingOptions: boolean = false,\n removeNotExistingOptions: boolean = false,\n ) {\n const newCollection = [];\n\n this.collection.forEach((option) => {\n const foundOption = withOptions.find(\n (withOption) => withOption.code === option.code,\n );\n if (foundOption) {\n option.mergeOption(foundOption);\n newCollection.push(option);\n } else if (!removeNotExistingOptions) {\n newCollection.push(option);\n }\n });\n\n if (addNotExistingOptions) {\n this.collection = [\n ...newCollection,\n ...withOptions.filter(\n (option) => !this.collection.some((opt) => opt.code === option.code),\n ),\n ];\n } else {\n this.collection = newCollection;\n }\n }\n\n /**\n */\n some(\n callbackfn: (\n value: ChoiceAttributeOptionModel,\n index: number,\n array: Array<ChoiceAttributeOptionModel>,\n ) => any,\n thisArg?: any,\n ): boolean {\n return this.collection.some((option, optionIndex, collectionArray) => {\n const result = callbackfn(option, optionIndex, collectionArray);\n if (!result && option.children) {\n return option.children.some(callbackfn, th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I,CACrE,CAAC,CACF;IACH,CAAC,MAAM;MACL,IAAI,CAACvC,UAAU,GAAGkF,aAAa;IACjC;EACF;;EAEA;AACF;EACErB,IAAIA,CACFyB,UAIQ,EACRC,OAAa,EACJ;IACT,OAAO,IAAI,CAACvF,UAAU,CAAC6D,IAAI,CAAC,CAAC3D,MAAM,EAAEsF,WAAW,EAAEC,eAAe,KAAK;MACpE,MAAMC,MAAM,GAAGJ,UAAU,CAACpF,MAAM,EAAEsF,WAAW,EAAEC,eAAe,CAAC;MAC/D,IAAI,CAACC,MAAM,IAAIxF,MAAM,CAACC,QAAQ,EAAE;QAC9B,OAAOD,MAAM,CAACC,QAAQ,CAAC0D,IAAI,CAACyB,UAAU,EAAEC,OAAO,CAAC;MAClD;MACA,OAAOG,MAAM;IACf,CAAC,CAAC;EACJ;AACF;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAvG,OAAA,GAEcL,+BAA+B","ignoreList":[]}
@@ -18,17 +18,18 @@ class ConceptIndexFilterModel extends _BaseFilterModel.default {
18
18
  */
19
19
  constructor(data, contributions, modelOptions) {
20
20
  super(data, contributions, modelOptions);
21
- if (data.options) {
22
- var _context, _context2;
23
- const selectedValues = (0, _map.default)(_context = (0, _filter.default)(_context2 = data.options).call(_context2, option => option.selected)).call(_context, option => option.key);
24
- data.options.forEach(option => {
25
- if (this.attribute instanceof _ChoiceAttributeModel.default) {
26
- this.attribute.options.addOption(selectedValues, {
21
+ if (this.attribute instanceof _ChoiceAttributeModel.default) {
22
+ const attribute = this.attribute;
23
+ if (attribute && data.options) {
24
+ var _context, _context2, _context3;
25
+ const selectedValues = (0, _map.default)(_context = (0, _filter.default)(_context2 = data.options).call(_context2, option => option.selected)).call(_context, option => option.key);
26
+ (0, _filter.default)(_context3 = data.options).call(_context3, option => !attribute.options.hasOptionByCode(option.key)).forEach(option => {
27
+ attribute.options.addOption(selectedValues, {
27
28
  code: option.key,
28
29
  label: option.key
29
30
  });
30
- }
31
- });
31
+ });
32
+ }
32
33
  }
33
34
  }
34
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ConceptIndexFilterModel.js","names":["_BaseFilterModel","_interopRequireDefault","require","_ChoiceAttributeModel","ConceptIndexFilterModel","BaseFilterModel","constructor","data","contributions","modelOptions","options","_context","_context2","selectedValues","_map","default","_filter","call","option","selected","key","forEach","attribute","ChoiceAttributeModel","addOption","code","label","exports"],"sources":["../../../src/models/filters/ConceptIndexFilterModel.js"],"sourcesContent":["// @flow\nimport BaseFilterModel from \"../filters/BaseFilterModel\";\nimport ChoiceAttributeModel from \"../attributes/ChoiceAttributeModel\";\n\nimport type { ModelOptions } from \"../types\";\n\n/**\n * The concept index model is a special filter used to index all first concept label letters in de modelcatalog.\n */\nexport default class ConceptIndexFilterModel extends BaseFilterModel {\n /**\n * Construct a filter\n */\n constructor(\n data: Object,\n contributions: Object,\n modelOptions?: ModelOptions,\n ) {\n super(data, contributions, modelOptions);\n\n if (data.options) {\n const selectedValues = data.options\n .filter((option) => option.selected)\n .map((option) => option.key);\n\n data.options.forEach((option) => {\n if (this.attribute instanceof ChoiceAttributeModel) {\n this.attribute.options.addOption(selectedValues, {\n code: option.key,\n label: option.key,\n });\n }\n });\n }\n }\n}\n"],"mappings":";;;;;;;;;AACA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAF,sBAAA,CAAAC,OAAA;AAIA;AACA;AACA;AACe,MAAME,uBAAuB,SAASC,wBAAe,CAAC;EACnE;AACF;AACA;EACEC,WAAWA,CACTC,IAAY,EACZC,aAAqB,EACrBC,YAA2B,EAC3B;IACA,KAAK,CAACF,IAAI,EAAEC,aAAa,EAAEC,YAAY,CAAC;IAExC,IAAIF,IAAI,CAACG,OAAO,EAAE;MAAA,IAAAC,QAAA,EAAAC,SAAA;MAChB,MAAMC,cAAc,GAAG,IAAAC,IAAA,CAAAC,OAAA,EAAAJ,QAAA,OAAAK,OAAA,CAAAD,OAAA,EAAAH,SAAA,GAAAL,IAAI,CAACG,OAAO,EAAAO,IAAA,CAAAL,SAAA,EACxBM,MAAM,IAAKA,MAAM,CAACC,QAAQ,CAAC,EAAAF,IAAA,CAAAN,QAAA,EAC9BO,MAAM,IAAKA,MAAM,CAACE,GAAG,CAAC;MAE9Bb,IAAI,CAACG,OAAO,CAACW,OAAO,CAAEH,MAAM,IAAK;QAC/B,IAAI,IAAI,CAACI,SAAS,YAAYC,6BAAoB,EAAE;UAClD,IAAI,CAACD,SAAS,CAACZ,OAAO,CAACc,SAAS,CAACX,cAAc,EAAE;YAC/CY,IAAI,EAAEP,MAAM,CAACE,GAAG;YAChBM,KAAK,EAAER,MAAM,CAACE;UAChB,CAAC,CAAC;QACJ;MACF,CAAC,CAAC;IACJ;EACF;AACF;AAACO,OAAA,CAAAZ,OAAA,GAAAX,uBAAA","ignoreList":[]}
1
+ {"version":3,"file":"ConceptIndexFilterModel.js","names":["_BaseFilterModel","_interopRequireDefault","require","_ChoiceAttributeModel","ConceptIndexFilterModel","BaseFilterModel","constructor","data","contributions","modelOptions","attribute","ChoiceAttributeModel","options","_context","_context2","_context3","selectedValues","_map","default","_filter","call","option","selected","key","hasOptionByCode","forEach","addOption","code","label","exports"],"sources":["../../../src/models/filters/ConceptIndexFilterModel.js"],"sourcesContent":["// @flow\nimport BaseFilterModel from \"../filters/BaseFilterModel\";\nimport ChoiceAttributeModel from \"../attributes/ChoiceAttributeModel\";\n\nimport type { ModelOptions } from \"../types\";\n\n/**\n * The concept index model is a special filter used to index all first concept label letters in de modelcatalog.\n */\nexport default class ConceptIndexFilterModel extends BaseFilterModel {\n /**\n * Construct a filter\n */\n constructor(\n data: Object,\n contributions: Object,\n modelOptions?: ModelOptions,\n ) {\n super(data, contributions, modelOptions);\n\n if (this.attribute instanceof ChoiceAttributeModel) {\n const attribute: ChoiceAttributeModel = this.attribute;\n\n if (attribute && data.options) {\n const selectedValues = data.options\n .filter((option) => option.selected)\n .map((option) => option.key);\n\n data.options\n .filter((option) => !attribute.options.hasOptionByCode(option.key))\n .forEach((option) => {\n attribute.options.addOption(selectedValues, {\n code: option.key,\n label: option.key,\n });\n });\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;AACA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAF,sBAAA,CAAAC,OAAA;AAIA;AACA;AACA;AACe,MAAME,uBAAuB,SAASC,wBAAe,CAAC;EACnE;AACF;AACA;EACEC,WAAWA,CACTC,IAAY,EACZC,aAAqB,EACrBC,YAA2B,EAC3B;IACA,KAAK,CAACF,IAAI,EAAEC,aAAa,EAAEC,YAAY,CAAC;IAExC,IAAI,IAAI,CAACC,SAAS,YAAYC,6BAAoB,EAAE;MAClD,MAAMD,SAA+B,GAAG,IAAI,CAACA,SAAS;MAEtD,IAAIA,SAAS,IAAIH,IAAI,CAACK,OAAO,EAAE;QAAA,IAAAC,QAAA,EAAAC,SAAA,EAAAC,SAAA;QAC7B,MAAMC,cAAc,GAAG,IAAAC,IAAA,CAAAC,OAAA,EAAAL,QAAA,OAAAM,OAAA,CAAAD,OAAA,EAAAJ,SAAA,GAAAP,IAAI,CAACK,OAAO,EAAAQ,IAAA,CAAAN,SAAA,EACxBO,MAAM,IAAKA,MAAM,CAACC,QAAQ,CAAC,EAAAF,IAAA,CAAAP,QAAA,EAC9BQ,MAAM,IAAKA,MAAM,CAACE,GAAG,CAAC;QAE9B,IAAAJ,OAAA,CAAAD,OAAA,EAAAH,SAAA,GAAAR,IAAI,CAACK,OAAO,EAAAQ,IAAA,CAAAL,SAAA,EACDM,MAAM,IAAK,CAACX,SAAS,CAACE,OAAO,CAACY,eAAe,CAACH,MAAM,CAACE,GAAG,CAAC,CAAC,CAClEE,OAAO,CAAEJ,MAAM,IAAK;UACnBX,SAAS,CAACE,OAAO,CAACc,SAAS,CAACV,cAAc,EAAE;YAC1CW,IAAI,EAAEN,MAAM,CAACE,GAAG;YAChBK,KAAK,EAAEP,MAAM,CAACE;UAChB,CAAC,CAAC;QACJ,CAAC,CAAC;MACN;IACF;EACF;AACF;AAACM,OAAA,CAAAX,OAAA,GAAAd,uBAAA","ignoreList":[]}
@@ -11,6 +11,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/he
11
11
  var _constants = require("../constants");
12
12
  var _xhr = _interopRequireDefault(require("../utils/fetch/xhr"));
13
13
  var _ErrorModel = _interopRequireDefault(require("../models/error/ErrorModel"));
14
+ var _models = require("../models");
14
15
  /**
15
16
  * Upload a file to the upload file service of Be Informed
16
17
  */
@@ -57,7 +58,7 @@ class UploadRequest {
57
58
  */
58
59
  uploadFile(file) {
59
60
  const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;
60
- if (this.exceedsMaxFileSize(file)) {
61
+ if ((0, _constants.getSetting)("USE_CLIENTSIDE_VALIDATION") && this.exceedsMaxFileSize(file)) {
61
62
  this._progressHandler(file, {
62
63
  error: "errorExceedsMaxFileSize"
63
64
  });
@@ -65,7 +66,7 @@ class UploadRequest {
65
66
  "max-filesize": maxFileSize
66
67
  }, true));
67
68
  }
68
- if (this.isNotAllowedFileType(file)) {
69
+ if ((0, _constants.getSetting)("USE_CLIENTSIDE_VALIDATION") && this.isNotAllowedFileType(file)) {
69
70
  this._progressHandler(file, {
70
71
  error: "errorExtensionNotAllowed"
71
72
  });
@@ -96,7 +97,7 @@ class UploadRequest {
96
97
  token: response.token
97
98
  });
98
99
  return response;
99
- });
100
+ }).catch(e => _promise.default.reject(new _models.ErrorResponse(e)));
100
101
  }
101
102
  }
102
103
  var _default = exports.default = UploadRequest;
@@ -1 +1 @@
1
- {"version":3,"file":"UploadRequest.js","names":["_constants","require","_xhr","_interopRequireDefault","_ErrorModel","UploadRequest","constructor","uploadConstraints","progressHandler","options","_defineProperty2","default","getBasePathModularUI","_uploadConstraints","_progressHandler","_origin","origin","_contextPath","contextPath","getFileExtension","file","name","split","pop","toLowerCase","isNotAllowedFileType","allowedFileTypes","fileTypes","length","fileExtension","some","fileType","_context","_includes","extensions","call","exceedsMaxFileSize","maxFileSize","fileSize","size","uploadFile","error","_promise","reject","ErrorModel","extension","join","xhr","url","getUploadPath","method","HTTP_METHODS","POST","headers","type","encodeURIComponent","toString","onProgress","e","lengthComputable","progress","Math","ceil","loaded","total","data","then","response","token","_default","exports"],"sources":["../../src/modularui/UploadRequest.js"],"sourcesContent":["// @flow\nimport {\n getBasePathModularUI,\n getUploadPath,\n HTTP_METHODS,\n} from \"../constants\";\n\nimport xhr from \"../utils/fetch/xhr\";\n\nimport type {\n FilesizeConstraintsType,\n FiletypeConstraintsType,\n} from \"../models\";\nimport ErrorModel from \"../models/error/ErrorModel\";\n\ntype ProgressHandler = (file: File, uploadInfo: Object) => void;\n\ntype UploadRequestOptions = {\n origin?: string,\n contextPath?: string,\n};\n\ntype UploadResponse = {\n token: string,\n};\n\n/**\n * Upload a file to the upload file service of Be Informed\n */\nclass UploadRequest {\n _uploadConstraints: {\n fileTypes: FiletypeConstraintsType,\n maxFileSize: FilesizeConstraintsType,\n acceptedFiles: Array<string>,\n };\n _progressHandler: ProgressHandler;\n _origin: string = \"\";\n _contextPath: string = getBasePathModularUI();\n\n constructor(\n uploadConstraints: {\n fileTypes: FiletypeConstraintsType,\n maxFileSize: FilesizeConstraintsType,\n acceptedFiles: Array<string>,\n },\n progressHandler: ProgressHandler,\n options?: UploadRequestOptions,\n ) {\n this._uploadConstraints = uploadConstraints;\n this._progressHandler = progressHandler;\n this._origin = options?.origin || \"\";\n this._contextPath = options?.contextPath || getBasePathModularUI();\n }\n\n /**\n */\n getFileExtension(file: File): string {\n return file.name.split(\".\").pop().toLowerCase();\n }\n\n /**\n */\n isNotAllowedFileType(file: File): boolean {\n const allowedFileTypes = this._uploadConstraints.fileTypes;\n\n if (allowedFileTypes.length > 0) {\n const fileExtension = this.getFileExtension(file);\n\n return !allowedFileTypes.some((fileType) =>\n fileType.extensions.includes(fileExtension),\n );\n }\n\n return false;\n }\n\n /**\n */\n exceedsMaxFileSize(file: File): boolean {\n const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;\n return maxFileSize > -1 && file.size > maxFileSize;\n }\n\n /**\n */\n uploadFile(file: File): Promise<UploadResponse> {\n const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;\n\n if (this.exceedsMaxFileSize(file)) {\n this._progressHandler(file, { error: \"errorExceedsMaxFileSize\" });\n return Promise.reject(\n new ErrorModel(\n \"Constraint.File.MaxFileSizeExceeded\",\n \"Maximum file upload size is ${max-filesize}\",\n {\n \"max-filesize\": maxFileSize,\n },\n true,\n ),\n );\n }\n\n if (this.isNotAllowedFileType(file)) {\n this._progressHandler(file, { error: \"errorExtensionNotAllowed\" });\n return Promise.reject(\n new ErrorModel(\n \"Constraint.File.InvalidExtension\",\n \"Allowed extensions are: ${extensions}\",\n {\n extension: this.getFileExtension(file),\n extensions: this._uploadConstraints.fileTypes.join(\", \"),\n },\n true,\n ),\n );\n }\n\n return xhr({\n url: getUploadPath(this._contextPath, this._origin),\n method: HTTP_METHODS.POST,\n headers: {\n \"Content-Type\": file.type,\n \"x-filename\": encodeURIComponent(file.name),\n \"x-filesize\": file.size.toString(),\n },\n onProgress: (e: ProgressEvent) => {\n if (this._progressHandler && e.lengthComputable) {\n this._progressHandler(file, {\n progress: Math.ceil((e.loaded / e.total) * 100),\n });\n }\n },\n data: file,\n }).then((response) => {\n this._progressHandler(file, { progress: 100, token: response.token });\n return response;\n });\n }\n}\n\nexport default UploadRequest;\n"],"mappings":";;;;;;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AAMA,IAAAC,IAAA,GAAAC,sBAAA,CAAAF,OAAA;AAMA,IAAAG,WAAA,GAAAD,sBAAA,CAAAF,OAAA;AAaA;AACA;AACA;AACA,MAAMI,aAAa,CAAC;EAUlBC,WAAWA,CACTC,iBAIC,EACDC,eAAgC,EAChCC,OAA8B,EAC9B;IAAA,IAAAC,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,O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AAI,IAAI,CAAC5C,gBAAgB,IAAI4C,CAAC,CAACC,gBAAgB,EAAE;UAC/C,IAAI,CAAC7C,gBAAgB,CAACM,IAAI,EAAE;YAC1BwC,QAAQ,EAAEC,IAAI,CAACC,IAAI,CAAEJ,CAAC,CAACK,MAAM,GAAGL,CAAC,CAACM,KAAK,GAAI,GAAG;UAChD,CAAC,CAAC;QACJ;MACF,CAAC;MACDC,IAAI,EAAE7C;IACR,CAAC,CAAC,CAAC8C,IAAI,CAAEC,QAAQ,IAAK;MACpB,IAAI,CAACrD,gBAAgB,CAACM,IAAI,EAAE;QAAEwC,QAAQ,EAAE,GAAG;QAAEQ,KAAK,EAAED,QAAQ,CAACC;MAAM,CAAC,CAAC;MACrE,OAAOD,QAAQ;IACjB,CAAC,CAAC;EACJ;AACF;AAAC,IAAAE,QAAA,GAAAC,OAAA,CAAA3D,OAAA,GAEcN,aAAa","ignoreList":[]}
1
+ {"version":3,"file":"UploadRequest.js","names":["_constants","require","_xhr","_interopRequireDefault","_ErrorModel","_models","UploadRequest","constructor","uploadConstraints","progressHandler","options","_defineProperty2","default","getBasePathModularUI","_uploadConstraints","_progressHandler","_origin","origin","_contextPath","contextPath","getFileExtension","file","name","split","pop","toLowerCase","isNotAllowedFileType","allowedFileTypes","fileTypes","length","fileExtension","some","fileType","_context","_includes","extensions","call","exceedsMaxFileSize","maxFileSize","fileSize","size","uploadFile","getSetting","error","_promise","reject","ErrorModel","extension","join","xhr","url","getUploadPath","method","HTTP_METHODS","POST","headers","type","encodeURIComponent","toString","onProgress","e","lengthComputable","progress","Math","ceil","loaded","total","data","then","response","token","catch","ErrorResponse","_default","exports"],"sources":["../../src/modularui/UploadRequest.js"],"sourcesContent":["// @flow\nimport {\n getBasePathModularUI,\n getSetting,\n getUploadPath,\n HTTP_METHODS,\n} from \"../constants\";\n\nimport xhr from \"../utils/fetch/xhr\";\n\nimport type {\n FilesizeConstraintsType,\n FiletypeConstraintsType,\n} from \"../models\";\nimport ErrorModel from \"../models/error/ErrorModel\";\nimport { ErrorResponse } from \"../models\";\n\ntype ProgressHandler = (file: File, uploadInfo: Object) => void;\n\ntype UploadRequestOptions = {\n origin?: string,\n contextPath?: string,\n};\n\ntype UploadResponse = {\n token: string,\n};\n\n/**\n * Upload a file to the upload file service of Be Informed\n */\nclass UploadRequest {\n _uploadConstraints: {\n fileTypes: FiletypeConstraintsType,\n maxFileSize: FilesizeConstraintsType,\n acceptedFiles: Array<string>,\n };\n _progressHandler: ProgressHandler;\n _origin: string = \"\";\n _contextPath: string = getBasePathModularUI();\n\n constructor(\n uploadConstraints: {\n fileTypes: FiletypeConstraintsType,\n maxFileSize: FilesizeConstraintsType,\n acceptedFiles: Array<string>,\n },\n progressHandler: ProgressHandler,\n options?: UploadRequestOptions,\n ) {\n this._uploadConstraints = uploadConstraints;\n this._progressHandler = progressHandler;\n this._origin = options?.origin || \"\";\n this._contextPath = options?.contextPath || getBasePathModularUI();\n }\n\n /**\n */\n getFileExtension(file: File): string {\n return file.name.split(\".\").pop().toLowerCase();\n }\n\n /**\n */\n isNotAllowedFileType(file: File): boolean {\n const allowedFileTypes = this._uploadConstraints.fileTypes;\n\n if (allowedFileTypes.length > 0) {\n const fileExtension = this.getFileExtension(file);\n\n return !allowedFileTypes.some((fileType) =>\n fileType.extensions.includes(fileExtension),\n );\n }\n\n return false;\n }\n\n /**\n */\n exceedsMaxFileSize(file: File): boolean {\n const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;\n return maxFileSize > -1 && file.size > maxFileSize;\n }\n\n /**\n */\n uploadFile(file: File): Promise<UploadResponse> {\n const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;\n\n if (\n getSetting(\"USE_CLIENTSIDE_VALIDATION\") &&\n this.exceedsMaxFileSize(file)\n ) {\n this._progressHandler(file, { error: \"errorExceedsMaxFileSize\" });\n return Promise.reject(\n new ErrorModel(\n \"Constraint.File.MaxFileSizeExceeded\",\n \"Maximum file upload size is ${max-filesize}\",\n {\n \"max-filesize\": maxFileSize,\n },\n true,\n ),\n );\n }\n\n if (\n getSetting(\"USE_CLIENTSIDE_VALIDATION\") &&\n this.isNotAllowedFileType(file)\n ) {\n this._progressHandler(file, { error: \"errorExtensionNotAllowed\" });\n return Promise.reject(\n new ErrorModel(\n \"Constraint.File.InvalidExtension\",\n \"Allowed extensions are: ${extensions}\",\n {\n extension: this.getFileExtension(file),\n extensions: this._uploadConstraints.fileTypes.join(\", \"),\n },\n true,\n ),\n );\n }\n\n return xhr({\n url: getUploadPath(this._contextPath, this._origin),\n method: HTTP_METHODS.POST,\n headers: {\n \"Content-Type\": file.type,\n \"x-filename\": encodeURIComponent(file.name),\n \"x-filesize\": file.size.toString(),\n },\n onProgress: (e: ProgressEvent) => {\n if (this._progressHandler && e.lengthComputable) {\n this._progressHandler(file, {\n progress: Math.ceil((e.loaded / e.total) * 100),\n });\n }\n },\n data: file,\n })\n .then((response) => {\n this._progressHandler(file, { progress: 100, token: response.token });\n return response;\n })\n .catch((e) => Promise.reject(new ErrorResponse(e)));\n }\n}\n\nexport default UploadRequest;\n"],"mappings":";;;;;;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AAOA,IAAAC,IAAA,GAAAC,sBAAA,CAAAF,OAAA;AAMA,IAAAG,WAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAaA;AACA;AACA;AACA,MAAMK,aAAa,CAAC;EAUlBC,WAAWA,CACTC,iBAIC,EACDC,eAAgC,EAChCC,OAA8B,EAC9B;IAAA,IAAAC,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA,mBAXgB,EAAE;IAAA,IAAAD,gBAAA,CAAAC,OAAA,wBACG,IAAAC,+BAAoB,EAAC,CAAC;IAW3C,IAAI,CAACC,kBAAkB,GAAGN,iBAAiB;IAC3C,IAAI,CAACO,gBAAgB,GAAGN,eAAe;IACvC,I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IAAI,CAACC,IAAI,CAAEJ,CAAC,CAACK,MAAM,GAAGL,CAAC,CAACM,KAAK,GAAI,GAAG;UAChD,CAAC,CAAC;QACJ;MACF,CAAC;MACDC,IAAI,EAAE9C;IACR,CAAC,CAAC,CACC+C,IAAI,CAAEC,QAAQ,IAAK;MAClB,IAAI,CAACtD,gBAAgB,CAACM,IAAI,EAAE;QAAEyC,QAAQ,EAAE,GAAG;QAAEQ,KAAK,EAAED,QAAQ,CAACC;MAAM,CAAC,CAAC;MACrE,OAAOD,QAAQ;IACjB,CAAC,CAAC,CACDE,KAAK,CAAEX,CAAC,IAAKhB,QAAA,CAAAhC,OAAA,CAAQiC,MAAM,CAAC,IAAI2B,qBAAa,CAACZ,CAAC,CAAC,CAAC,CAAC;EACvD;AACF;AAAC,IAAAa,QAAA,GAAAC,OAAA,CAAA9D,OAAA,GAEcN,aAAa","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beinformed/ui",
3
- "version": "1.60.1",
3
+ "version": "1.60.3",
4
4
  "description": "Toolbox for be informed javascript layouts",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "bugs": "https://support.beinformed.com",
@@ -108,13 +108,13 @@
108
108
  "cross-env": "^7.0.3",
109
109
  "documentation": "^14.0.2",
110
110
  "eslint": "^8.57.0",
111
- "eslint-config-prettier": "^10.0.1",
111
+ "eslint-config-prettier": "^10.0.2",
112
112
  "eslint-plugin-babel": "^5.3.1",
113
113
  "eslint-plugin-ft-flow": "^3.0.11",
114
114
  "eslint-plugin-jest": "^28.11.0",
115
115
  "eslint-plugin-jsdoc": "^50.6.3",
116
116
  "eslint-plugin-react": "^7.37.4",
117
- "eslint-plugin-react-hooks": "^5.1.0",
117
+ "eslint-plugin-react-hooks": "^5.2.0",
118
118
  "eslint-plugin-you-dont-need-lodash-underscore": "^6.14.0",
119
119
  "flow-bin": "^0.200.1",
120
120
  "flow-copy-source": "^2.0.9",
@@ -129,7 +129,7 @@
129
129
  "jscodeshift": "^17.1.2",
130
130
  "lint-staged": "^15.4.3",
131
131
  "polished": "^4.0.0",
132
- "prettier": "^3.5.1",
132
+ "prettier": "^3.5.3",
133
133
  "react": "^19.0.0",
134
134
  "react-dom": "^19.0.0",
135
135
  "react-helmet-async": "^2.0.5",
@@ -141,7 +141,7 @@
141
141
  "redux-thunk": "^2.4.2",
142
142
  "rimraf": "^6.0.1",
143
143
  "styled-components": "^5.3.11",
144
- "typescript": "^5.7.3",
144
+ "typescript": "^5.8.2",
145
145
  "xhr-mock": "^2.5.1"
146
146
  },
147
147
  "scarfSettings": {
@@ -8,7 +8,6 @@ import { useLocation } from "react-router";
8
8
  import {
9
9
  ConceptIndexModel,
10
10
  ContentIndexModel,
11
- ContentModel,
12
11
  ContentTypeModel,
13
12
  ContentTOCModel,
14
13
  Href,
@@ -147,7 +146,6 @@ describe("modelcatalog hooks", () => {
147
146
  () => useContent("/contentdetail"),
148
147
  "content",
149
148
  "/content/contentdetail?entryDate=" + DateUtil.now(),
150
- ContentModel,
151
149
  );
152
150
  });
153
151
 
@@ -120,17 +120,17 @@ export const useContentTOC = (
120
120
  /**
121
121
  */
122
122
  export const useContent = (
123
- contentSection: string | Href,
123
+ content: string | Href,
124
124
  key?: string = "content",
125
125
  options?: UseModularUIBasicOptions<ContentModel>,
126
- ): ?ContentModel => {
126
+ ): ?ContentModel | ?ContentTOCModel => {
127
127
  const { entryDate } = useEntryDate();
128
+ const location = useLocation();
128
129
 
129
- const href = createHref("content", contentSection, entryDate, null, []);
130
+ const href = createHref("content", content, entryDate, location, []);
130
131
 
131
132
  return useModularUIBasic(key, href, {
132
- expectedModels: ["Content"],
133
- targetModel: ContentModel,
133
+ expectedModels: ["Content", "ContentTOC"],
134
134
  ...options,
135
135
  });
136
136
  };
@@ -202,6 +202,18 @@ class ChoiceAttributeOptionCollection extends ResourceCollection<ChoiceAttribute
202
202
  return this;
203
203
  }
204
204
 
205
+ /**
206
+ */
207
+ getOptionByCode(code: string): ChoiceAttributeOptionModel | void {
208
+ return this.collection.find((option) => option.code === code);
209
+ }
210
+
211
+ /**
212
+ */
213
+ hasOptionByCode(code: string): boolean {
214
+ return this.collection.some((option) => option.code === code);
215
+ }
216
+
205
217
  /**
206
218
  * Get all options that have selected property true
207
219
  */
@@ -108,7 +108,10 @@
108
108
  {
109
109
  "code": "W",
110
110
  "label": "W"
111
- }
111
+ },
112
+ { "code": "_", "label": "punctuation" },
113
+ { "code": "Ö", "label": "Ö" },
114
+ { "code": "Л", "label": "Л" }
112
115
  ],
113
116
  "type": null
114
117
  },
@@ -188,7 +191,10 @@
188
191
  },
189
192
  {
190
193
  "key": "W"
191
- }
194
+ },
195
+ { "key": "_" },
196
+ { "key": "Ö" },
197
+ { "key": "Л" }
192
198
  ]
193
199
  },
194
200
  "label": {
@@ -34,5 +34,9 @@ describe("conceptIndexModel", () => {
34
34
  expect(firstItem.conceptTypeLink.href.toString()).toBe(
35
35
  "/concepttypes/bundle-com.beinformed.fs.demo.metamodels/High%20level%20requirements.bixml/ArchitecturalSignificantRequirement",
36
36
  );
37
+
38
+ const conceptIndexAttribute = conceptIndex.indexfilter?.attribute;
39
+ expect(conceptIndexAttribute.label).toBe("Index");
40
+ expect(conceptIndexAttribute.options.size).toBe(27);
37
41
  });
38
42
  });
@@ -18,19 +18,23 @@ export default class ConceptIndexFilterModel extends BaseFilterModel {
18
18
  ) {
19
19
  super(data, contributions, modelOptions);
20
20
 
21
- if (data.options) {
22
- const selectedValues = data.options
23
- .filter((option) => option.selected)
24
- .map((option) => option.key);
21
+ if (this.attribute instanceof ChoiceAttributeModel) {
22
+ const attribute: ChoiceAttributeModel = this.attribute;
25
23
 
26
- data.options.forEach((option) => {
27
- if (this.attribute instanceof ChoiceAttributeModel) {
28
- this.attribute.options.addOption(selectedValues, {
29
- code: option.key,
30
- label: option.key,
24
+ if (attribute && data.options) {
25
+ const selectedValues = data.options
26
+ .filter((option) => option.selected)
27
+ .map((option) => option.key);
28
+
29
+ data.options
30
+ .filter((option) => !attribute.options.hasOptionByCode(option.key))
31
+ .forEach((option) => {
32
+ attribute.options.addOption(selectedValues, {
33
+ code: option.key,
34
+ label: option.key,
35
+ });
31
36
  });
32
- }
33
- });
37
+ }
34
38
  }
35
39
  }
36
40
  }
@@ -284,6 +284,8 @@ describe("formModel", () => {
284
284
 
285
285
  form.currentFormObject.getAttributeByKey("DateOfBirth").inputvalue = "bla";
286
286
 
287
+ expect(form.errorCollection).toHaveLength(0);
288
+
287
289
  form.handleErrors({
288
290
  data: {
289
291
  errors: [
@@ -1,6 +1,7 @@
1
1
  // @flow
2
2
  import {
3
3
  getBasePathModularUI,
4
+ getSetting,
4
5
  getUploadPath,
5
6
  HTTP_METHODS,
6
7
  } from "../constants";
@@ -12,6 +13,7 @@ import type {
12
13
  FiletypeConstraintsType,
13
14
  } from "../models";
14
15
  import ErrorModel from "../models/error/ErrorModel";
16
+ import { ErrorResponse } from "../models";
15
17
 
16
18
  type ProgressHandler = (file: File, uploadInfo: Object) => void;
17
19
 
@@ -86,7 +88,10 @@ class UploadRequest {
86
88
  uploadFile(file: File): Promise<UploadResponse> {
87
89
  const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;
88
90
 
89
- if (this.exceedsMaxFileSize(file)) {
91
+ if (
92
+ getSetting("USE_CLIENTSIDE_VALIDATION") &&
93
+ this.exceedsMaxFileSize(file)
94
+ ) {
90
95
  this._progressHandler(file, { error: "errorExceedsMaxFileSize" });
91
96
  return Promise.reject(
92
97
  new ErrorModel(
@@ -100,7 +105,10 @@ class UploadRequest {
100
105
  );
101
106
  }
102
107
 
103
- if (this.isNotAllowedFileType(file)) {
108
+ if (
109
+ getSetting("USE_CLIENTSIDE_VALIDATION") &&
110
+ this.isNotAllowedFileType(file)
111
+ ) {
104
112
  this._progressHandler(file, { error: "errorExtensionNotAllowed" });
105
113
  return Promise.reject(
106
114
  new ErrorModel(
@@ -131,10 +139,12 @@ class UploadRequest {
131
139
  }
132
140
  },
133
141
  data: file,
134
- }).then((response) => {
135
- this._progressHandler(file, { progress: 100, token: response.token });
136
- return response;
137
- });
142
+ })
143
+ .then((response) => {
144
+ this._progressHandler(file, { progress: 100, token: response.token });
145
+ return response;
146
+ })
147
+ .catch((e) => Promise.reject(new ErrorResponse(e)));
138
148
  }
139
149
  }
140
150